8

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.

AL.
  • 36,815
  • 10
  • 142
  • 281
Mehdi Glida
  • 547
  • 2
  • 5
  • 11

4 Answers4

7

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.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • I've bee looking for solution for the past two days and got a hint here. Great applause for this statment **Firebase Storage doesn't support video streaming, so that's won't work.** Like you stated above, I've successfully downloaded the files from Firebase Storage to my Mobile Storage. Now, the question is I have an adapter too. where do I set the path of local storage to the `VideoView`. `MainActivity`? or my `MessageAdapter`? Can you please look into this [post](https://stackoverflow.com/q/44447813/7004388). Please guide me. – coderpc Jun 09 '17 at 20:14
  • 1
    it's working when using video player other than videoView! Just like exo player.. – Arslan Maqbool Dec 14 '17 at 13:34
0

I think the time is late for the answer, but this answer to those who are looking for it later:

Via RecyclerView View dial Uri from the data Snapshot in adapter

        @Override
        protected void onStart() {
                super.onStart();

    final FirebaseRecyclerAdap...///

            ) {
                @Override
                protected void popul...////


    /////
     viewHolder.setVideo(Uri.parse(String.valueOf(videoUri)),model.getVideo());

        //  Here the position is sent to videoview adapter
        final String post_key = getRef( position ).getKey().toString();
        final String post_id = String.valueOf(post_key);

        viewHolder.setUid(model.getUid());

        //  Here the position is sent to videoview adapter
        viewHolder.setVideo(post_id);
        viewHolder.setUserprofile(getApplication(),model.getUserprofile());

        }
        yourAdpater ....


        }

        public static class ViewHolder extends RecyclerView.ViewHolder {

        View mView;
        Videoview post_video ;

        public ViewHolder(View itemView) {

        super(itemView);
        mView = itemView;

        post_video = (VideoView ) mView.findViewById(R.id.videoView);

        }

        public void setVideo(final String post_id) {

        mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

        // 
        Uri uri=Uri.parse(dataSnapshot.child(post_id).child("video").getValue(true).toString());

//You can set up the video display as you like

                    post_video.setVideoURI(uri);
                    post_video.requestFocus();
                    post_video.start();


        @Override
        public void onCancelled(DatabaseError databaseError) {
    }
});
}

The databases should look like this:

look here.

good luck.

-1

may be possible this by storing videos URLs in Database, then present them in Recyclerview which consists of Webview/Youtube Integration in Single row

-3

I had the same problem and the following solution worked for me:

Add this string to AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />