java.lang.illegalargumentException:位置不应是完整的URL
我正在尝试下载从firebase到本地存储的视频文件,这是我用来下载视频文件的代码
private fun downloadVideo(videoModel: VideoModel) {
val videoUrl = videoModel.url
val storageRef = FirebaseStorage.getInstance().getReference(videoUrl)
storageRef.metadata
.addOnSuccessListener { storageMeta ->
val fileName = storageMeta.name
val fileType = storageMeta.contentType
val fileDiroctory = Environment.DIRECTORY_DOWNLOADS
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val uri = Uri.parse(videoUrl)
val request = DownloadManager.Request(uri)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(fileDiroctory,"$fileName.mp4")
downloadManager.enqueue(request)
}
.addOnFailureListener {
Toast.makeText(context,"Please try again",Toast.LENGTH_SHORT).show()
}
,以下是我收到的错误,
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kathayat.pahadiwallpaper, PID: 3703
java.lang.IllegalArgumentException: location should not be a full URL.
at com.google.firebase.storage.FirebaseStorage.getReference(FirebaseStorage.java:317)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.downloadVideo(VideoAdapter.kt:92)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.onBindViewHolder$lambda-1(VideoAdapter.kt:81)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.$r8$lambda$__m2A7Vc78QjfOEKSP6EkyLGWoE(Unknown Source:0)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter$$ExternalSyntheticLambda0.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
我正在从View Holdeholder RecyClerview Adapter和Firebase中调用下载函数,
override fun onBindViewHolder(holder: VideoHolder, position: Int) {
val videoUrl = videoList[position]
videoList[position]?.let { holder.setVideoData(it) }
holder.downloadVideo.setOnClickListener {
if (videoUrl != null) {
downloadVideo(videoUrl)
}
}
在Firebase中,视频为仅使用URL ID上传
data class VideoModel(
var url:String = ""
)
实际视频保存在firebase存储中
,然后我将此视频从firebase firestore数据库
I am trying to download video file from firebase to local storage here is the code that i have used to download the video file
private fun downloadVideo(videoModel: VideoModel) {
val videoUrl = videoModel.url
val storageRef = FirebaseStorage.getInstance().getReference(videoUrl)
storageRef.metadata
.addOnSuccessListener { storageMeta ->
val fileName = storageMeta.name
val fileType = storageMeta.contentType
val fileDiroctory = Environment.DIRECTORY_DOWNLOADS
val downloadManager = context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val uri = Uri.parse(videoUrl)
val request = DownloadManager.Request(uri)
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
request.setDestinationInExternalPublicDir(fileDiroctory,"$fileName.mp4")
downloadManager.enqueue(request)
}
.addOnFailureListener {
Toast.makeText(context,"Please try again",Toast.LENGTH_SHORT).show()
}
And below is the ERROR that i am getting
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.kathayat.pahadiwallpaper, PID: 3703
java.lang.IllegalArgumentException: location should not be a full URL.
at com.google.firebase.storage.FirebaseStorage.getReference(FirebaseStorage.java:317)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.downloadVideo(VideoAdapter.kt:92)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.onBindViewHolder$lambda-1(VideoAdapter.kt:81)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter.$r8$lambda$__m2A7Vc78QjfOEKSP6EkyLGWoE(Unknown Source:0)
at com.kathayat.pahadiwallpaper.adapater.VideoAdapter$ExternalSyntheticLambda0.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:7125)
at android.view.View.performClickInternal(View.java:7102)
at android.view.View.access$3500(View.java:801)
at android.view.View$PerformClick.run(View.java:27336)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I am calling the download function from viewholder recyclerview adapter
override fun onBindViewHolder(holder: VideoHolder, position: Int) {
val videoUrl = videoList[position]
videoList[position]?.let { holder.setVideoData(it) }
holder.downloadVideo.setOnClickListener {
if (videoUrl != null) {
downloadVideo(videoUrl)
}
}
And in firebase the video is uploaded just using the url id
data class VideoModel(
var url:String = ""
)
The actual video's are saved in firebase storage
And and i am getting this videos to my application from firebase firestore Database
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获得基于视频下载URL的
storagereference
,您应该使用refererencefromurl
而不是getReference
。To get a
StorageReference
based on download URL for the video, you should userefererenceFromUrl
instead ofgetReference
.