将视频从 Firebase 存储加载到 videoView [英] Load Video from Firebase Storage to videoView

查看:32
本文介绍了将视频从 Firebase 存储加载到 videoView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我正在尝试的视频视图播放来自 Firebase 存储的视频:

I want to play a video from Firebase storage with a videoview I'm trying like this:

storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        //Toast.makeText(Chat.this, uri.toString(), Toast.LENGTH_SHORT).show();
                        MediaController mc = new MediaController(Chat.this);
                        videoView.setMediaController(mc);
                        videoView.setVideoURI(uri);
                        videoView.requestFocus();
                        //videoView.start();
                    }
                });

但它不会播放.视频为空.

But it wont play. The video is empty.

推荐答案

首先要确定 Storage 中的视频实际上是 Android 设备可以播放的格式.VideoView 无法播放所有内容 - 只有 Android 支持的视频类型.

First of all, be certain that the video in Storage is actually in a format that Android devices can play. VideoView cannot play everything - only the types of videos that Android supports.

您现在通过将 uri 直接传递到 VideoView 所做的操作被解释为尝试从给定 uri 流式传输视频.Firebase 存储不支持视频流,所以这行不通.从 uri 流式传输要求另一端的服务器能够流式传输给定的资源.

What you're doing now by passing the uri directly into the VideoView is interpreted as an attempt to stream the video from the given uri. Firebase Storage doesn't support video streaming, so that's won't work. Streaming from a uri requires that the server on the other end be able to stream the given resource.

如果要从 Storage 播放视频,您必须先下载整个,保存到本地文件,然后将 VideoView 指向本地文件进行播放.

If want to play a video from Storage, you'll have to download entirety first, saved to a local file, then point the VideoView at the local file for playback.

这篇关于将视频从 Firebase 存储加载到 videoView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆