Load Video from Firebase Storage to Videoview

Load Video from Firebase Storage to videoView

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.

Display a video in a VideoView from Firebase URL in Android

The culprit here is android.widget.VideoView which extends SurfaceView.

This blog says:

Playing a video using a VideoView inside of a row of a ListView seems to work at first, until the user tries to scroll the list. As
soon as the list starts to scroll, the video turns black (sometimes displays white). It keeps
playing in the background but you can’t see it anymore because it
renders the rest of the video as a black box.

I wrote my own VideoView class which extends TextureView with the help of this github repository. Though It has some issues as it was written 3 years ago I managed to fix them on my own. Very soon I'll update this answer with my custom Optimized VideoView github repository (just with few modifications). Until then, the link which I've provided would help you.

With the custom Optimized VideoView, the videos will play on scroll in the ListView just like our Instagram, Facebook, Twitter. We can make the videos play/pause by setting setOnTouchListener() on VideoView in our activity and can customize it in our own way.

Now, our VideoView in the Layouts would be:

<your.packagename.VideoView
android:id="@+id/admin_video_view"
android:layout_width="300dp"
android:layout_height="300dp" />


Related Topics



Leave a reply



Submit