Click here to Skip to main content
15,881,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am making an app in which I want the users to record video and upload in it like you tube. I am able to record the video and also upload it to the firebase storage but I am unable to load the uploaded video in the video view. Whenever I run the app I get only to see the black screen. Here is my code

private var path = "https://firebasestorage.googleapis.com/v0/b/video-app-af9bf.appspot.com/o/Videos%2FVideo_20200812_141638_.mp4?alt=media&token=d87f94e0-6ca3-4de2-856c-b228884185f7"


    val view = fragmentview.findViewById<VideoView>(R.id.v)
    val uri = Uri.parse(path)
    view.setVideoURI(uri)
    view.requestFocus()
     view.start();




This is my xml file


<?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:background="@drawable/gradient_2"
        android:layout_height="match_parent">
    
        <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
            android:id="@+id/swiperefresh"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/gradient_2"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.4"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.02"
            tools:ignore="InvalidId,MissingConstraints">
    
    
    
    
            <androidx.recyclerview.widget.RecyclerView
    
                android:id="@+id/watchvideorecyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0"
                tools:ignore="PxUsage"/>
    
    
    
    
        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    
        <ImageView
            android:id="@+id/memefragment"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:background="@drawable/ic_happy"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.64"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.025"
            tools:ignore="MissingConstraints" />
    
        <ImageView
            android:id="@+id/videofragment"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:background="@drawable/ic_videocam"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.348"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.025"
            tools:ignore="DuplicateIds,MissingConstraints" />
    
        <VideoView
            android:id="@+id/v"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
        <View
            android:layout_width="1dp"
            android:layout_height="42dp"
            android:background="#fff"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.024"
            tools:ignore="MissingConstraints" />
    
    
    </androidx.constraintlayout.widget.ConstraintLayout>


What I have tried:

I am trying to display video from firebase storage to video view using url.
Posted
Updated 14-Aug-20 19:48pm

1 solution

To start with:
Make sure that video in Storage is actually in a format that Android devices can play. VideoView can play only the types of videos that Android supports[^].
private var path = "https://firebasestorage.googleapis.com/v0/b/video-app-af9bf.appspot.com/o/Videos%2FVideo_20200812_141638_.mp4?alt=media&token=d87f94e0-6ca3-4de2-856c-b228884185f7"
val view = fragmentview.findViewById<VideoView>(R.id.v)
val uri = Uri.parse(path)
view.setVideoURI(uri)
view.requestFocus()
 view.start();

You are passing the uri directly into the VideoView. This would mean you are trying to stream the video from the given uri. Firebase Storage doesn't support video streaming, thus the issue. Streaming from a uri requires that the server on the other end be able to stream the given resource.

Since you want to play a video from Storage, you'll have to:
1. download the entire file first
2. save it to a local storage
3. then pass this local storage file path to the VideoView for playback.

For an easy test, pass the hard coded local url to your VideoView and see for yourself.

Try out.
 
Share this answer
 
Comments
Member 14883729 15-Aug-20 4:12am    
But when I have tried it in another activity then it worked properly
Sandeep Mewara 15-Aug-20 4:23am    
As shared, if tis is streaming it wouldnt. Believe the other activity would be an image or a media that is locally downloaded.
Member 14883729 15-Aug-20 4:25am    
Sir actually I am a beginner and I learnt programming from you tube and I want someone help to solve some coding problems. Can I contact you personally through Instagram or messenger
Sandeep Mewara 15-Aug-20 7:05am    
Sorry, I don't use them. You need to learn yourself and ask for queries using this forum only. People who can help will answer.
Member 14883729 15-Aug-20 7:05am    
Ok thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900