我想从URL下载一个视频。但它给出了一个错误:
下载视频文件的代码如下:private var downloadreference:Long=0 private lateinit var DownloadManager:DownloadManager
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val action = intent.action
if (action == DownloadManager.ACTION_DOWNLOAD_COMPLETE) {
val downloadId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
if (downloadId != downloadReference) {
context.unregisterReceiver(this)
return
}
val query = DownloadManager.Query()
query.setFilterById(downloadReference)
val cursor = downloadManager.query(query)
cursor?.let {
if (cursor.moveToFirst()) {
val columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)
if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(columnIndex)) {
var localFile = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
if (localFile.contains("file:///")) {
localFile = localFile.removePrefix("file:///").substringBeforeLast(File.separator)
}
//context.toast(context.resources.getString(R.string.saved, localFile), Toast.LENGTH_LONG)
} else if (DownloadManager.STATUS_FAILED == cursor.getInt(columnIndex)) {
// val message = context.resources.getString("error : ", cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_REASON)))
//context.toast(message, Toast.LENGTH_LONG)
}
}
cursor.close()
}
context.unregisterReceiver(this)
}
}
}
/////////// New Testing........
fun downloadFile(url: String, mimeType: String? = null) {
val guessFileName = URLUtil.guessFileName(url, null, mimeType)
System.out.println("LLLLLLLLLLLLLLLLLLL2 ");
// Timber.d("mimeType -> $mimeType guessFileName -> $guessFileName created by url -> $url")
val context = this
downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val downloadUri = Uri.parse(url)
val request = DownloadManager.Request(downloadUri)
request.apply {
setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE or DownloadManager.Request.NETWORK_WIFI)
//setAllowedOverRoaming(true)
setTitle(guessFileName)
setDescription(guessFileName)
setVisibleInDownloadsUi(true)
allowScanningByMediaScanner()
setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
//request.setDestinationUri(Uri.fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)))
setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, guessFileName)
context.registerReceiver(receiver, IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE))
downloadReference = downloadManager.enqueue(this)
}
System.out.println("LLLLLLLLLLLLLLLLLLL23 ");
}
使用以下库:
implementation 'com.mindorks.android:prdownloader:0.5.0'
从给定url下载视频的代码如下:
fun downfile(urll:String,fileName:String){
if(!isFilePresent(fileName)) {
var mFile2: File? = File(Environment.getExternalStorageDirectory(), "WallpapersBillionaire")
System.out.println("File Foond " + mFile2!!.absolutePath)
var mFile3: File? = File(Environment.getExternalStorageDirectory(), "WallpapersBillionaire")
var downloadId = PRDownloader.download(urll, mFile2!!.absolutePath, fileName)
.build()
.setOnStartOrResumeListener(object : OnStartOrResumeListener {
override fun onStartOrResume() {
System.out.println("??????????????????? start")
}
})
.setOnPauseListener(object : OnPauseListener {
override fun onPause() {
}
})
.setOnCancelListener(object : OnCancelListener {
override fun onCancel() {
}
})
.setOnProgressListener(object : OnProgressListener {
override fun onProgress(progress: Progress) {
circlePeView.visibility = View.VISIBLE
var per = (progress.currentBytes.toFloat() / progress.totalBytes.toFloat()) * 100.00
//var perint = per*100
System.out.println("::??????????????????? Per : " + per + " ?? : " + progress.currentBytes + " ?? : " + progress.totalBytes)
circlePeView.setProgress(per.toInt())
}
})
.start(object : OnDownloadListener {
override fun onDownloadComplete() {
circlePeView.visibility = View.GONE
circlePeView.setProgress(0)
prefs = getSharedPreferences(PREFS_FILENAME, 0)
val editor = prefs!!.edit()
editor.putString(wall, "WallpapersBillionaire/" + fileName)
editor.apply()
try {
val myWallpaperManager = WallpaperManager.getInstance(applicationContext)
try {
myWallpaperManager.setResource(R.raw.wallp)
} catch (e: IOException) {
// TODO Auto-generated catch block
e.printStackTrace()
}
val intent = Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
ComponentName(this@AnimattedViewpagerActivity, VideoLiveWallpaperService::class.java))
startActivity(intent)
} catch (e: Exception) {
val intent = Intent()
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
try {
startActivity(intent)
}catch (e2: java.lang.Exception){
Toast.makeText(applicationContext,"Please long click on your home screen. Select Video Live Wallpapers form thier. Thanks",Toast.LENGTH_LONG).show()
}
}
System.out.println("??????????????????? complete")
}
override fun onError(error: Error) {
System.out.println("??????????????????? error " + error)
}
})
System.out.println("??????????????????? called")
}else{
System.out.println("File Foond ")
circlePeView.visibility = View.GONE
circlePeView.setProgress(0)
prefs = getSharedPreferences(PREFS_FILENAME, 0)
val editor = prefs!!.edit()
editor.putString(wall, "WallpapersBillionaire/" + fileName)
editor.apply()
try {
val myWallpaperManager = WallpaperManager.getInstance(applicationContext)
try {
myWallpaperManager.setResource(R.raw.wallp)
} catch (e: IOException) {
// TODO Auto-generated catch block
e.printStackTrace()
}
val intent = Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
ComponentName(this@AnimattedViewpagerActivity, VideoLiveWallpaperService::class.java))
startActivity(intent)
} catch (e: Exception) {
val intent = Intent()
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER)
try {
startActivity(intent)
}catch (e2: java.lang.Exception){
Toast.makeText(applicationContext,"Please long click on your home screen. Select Video Live Wallpapers form thier. Thanks",Toast.LENGTH_LONG).show()
}
}
System.out.println("??????????????????? complete")
}
}
我有一个URL:-“http://fitnation.theclientdemos.com:9000/media/uploads/videoplayback_3_jtvchi1”当我在浏览器上运行这个URL时,我的VDO开始下载。 请帮助在视图中播放此视频(让视图名称为:-vdoView) 为此,我尝试以下代码:-
编辑:经过一些测试后,这里是关于这个主题的一些附加信息。我试着从互联网上获取音频的视频只是一个示例mp4文件: http://download.wavetlan.com/svv/media/http/mp4/convertedfiles/mediaCoder/mediaCoder_test6_1m9s_xvid_vbr_306kbps_320x240_25fps_mpeg1layer3_cbr_3
问题内容: 我目前正在我的应用程序中显示视频,希望用户能够将其保存到其设备图库/相册照片/相机胶卷中。这就是我正在做的事情,但视频未保存在相册中:/ 我也调查这个: 但是我有错误“无法从文件创建数据(空)”。我的“ assetChangeRequest”为零。我不了解我的网址是有效的,并且当我使用浏览器访问它时,它会下载快速时间文件。 如果有人可以帮助我,将不胜感激!我正在使用Swift,并将iO
在视频影像商店可购买或租赁视频影像。 可通过与「下载内容」相同的方法下载内容。已下载的内容可进入(视频影像)观赏。 若要使用(PS Store),需先注册PlayStation®Network账号。即使未使用PS Vita注册PlayStation®Network也可阅览PlayStation®Store。下载内容时需先注册,请遵循显示的画面注册。 PlayStation®Network和Play
问题内容: 我创建了用于从Youtube下载视频的代码,但该代码不适用于Wi-fi连接和移动连接。我哪里出错了? 问题答案: 3个步骤: 检查YouTube的源代码(HTML),您将获得这样的链接(http%253A%252F%252Fo-o.preferred.telemar-cnf1.v18.lscache6.c.youtube.com%252Fvideoplayback …) ; 解码url
问题内容: 我一直在尝试创建一种从python代码流式传输youtube url(最好仅是音频,尽管这没什么大不了)的方法。我尝试了很多事情,但似乎没有一个真正起作用。到目前为止,我已经能够使用youtube数据API搜索视频或播放列表,获取第一个视频或播放列表,并将其传递到pafy中以获取不同的流媒体网址。有谁知道一种通过python播放youtube音频/视频而无需先下载视频的方法吗?我认为可