将视频从Firebase存储加载到videoView [英] Load Video from Firebase Storage to videoView
问题描述
我想用视频播放器从Firebase存储中播放视频我试图这样做:
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();
}
});
但是不会玩。这个视频是空的。首先,要确定存储中的视频实际上是Android设备可以使用的格式玩。 VideoView无法播放所有内容 - 只有Android支持的类型的视频
通过将uri直接传递给VideoView,您现在正在做的是将视频从给定的uri中流式传输。 Firebase存储不支持视频流,所以这是行不通的。如果想从存储中播放视频,则必须下载首先保存到本地文件,然后将VideoView指向本地文件进行播放。
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.
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.
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.
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屋!