Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load Video from Firebase Storage to 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.

like image 948
Mehdi Glida Avatar asked Feb 05 '17 15:02

Mehdi Glida


1 Answers

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.

like image 118
Doug Stevenson Avatar answered Nov 15 '22 00:11

Doug Stevenson