'how Retrieve video from Firebase Storage? kotlin

how can I upload a video hosted in firebase to a videoview?

var storageRef = FirebaseStorage.getInstance().reference.child("videos/$recivir.mp4")
val mediaController = MediaController(this)
mediaController.setAnchorView(videoView)


Solution 1:[1]

From the official documentation about how to download files with Cloud Storage on Android here https://firebase.google.com/docs/storage/android/download-files#download_files, you can download the media (your video) using getBytes(), getStream(), or getDownloadUrl(), depends on what format you want to use.

You can use getDownloadUrl() to get the url of the video in Firebase Storage and set the url into the video view.

storageRef.child("users/me/profile.png").downloadUrl.addOnSuccessListener {
    // Got the download URL for 'users/me/profile.png'
    videoView.setVideoPath(it); // "it" is the url of the video from Firebase Firestore
    videoView.start();
}.addOnFailureListener {
    // Handle any errors
}

Solution 2:[2]

progressDialog.show()

    //timestamp
    val timestamp = ""+System.currentTimeMillis()

    //file path and name in firebase storage
    val filePathAndName = "Videos/video_$timestamp"

    //storage reference
    val storageReference = FirebaseStorage.getInstance().getReference(filePathAndName)
    //upload video using uri of video to storage
    storageReference.putFile(videoUri!!)
        .addOnSuccessListener { taskSnapshot ->
             //uploaded,get url of uploaded video
            val uriTask = taskSnapshot.storage.downloadUrl
            while (!uriTask.isSuccessful);
            val downloadUri = uriTask.result
            if (uriTask.isSuccessful){
                //video url is received successfully

                //now we can add video details to firebase db
                val hashMap = HashMap<String, Any>()
                hashMap["id"] = "$timestamp"
                hashMap["title"] = "$title"
                hashMap["timestamp"] = "$timestamp"
                hashMap["videoUri"] = "$downloadUri"

                //put the above info to db
                val dbReference = FirebaseDatabase.getInstance().getReference("Videos")
                dbReference.child(timestamp)
                    .setValue(hashMap)
                    .addOnSuccessListener { taskSnapshot ->
                        //video info added successfully
                        progressDialog.dismiss()
                        Toast.makeText(this,"Video Uploaded", Toast.LENGTH_SHORT).show()
                    }
                    .addOnFailureListener { e ->
                        //failed adding video info
                        progressDialog.dismiss()
                        Toast.makeText(this,"${e.message}", Toast.LENGTH_SHORT).show()

                    }
            }

        }
        .addOnFailureListener { e ->
            //failed uploading
            progressDialog.dismiss()
            Toast.makeText(this,"${e.message}",Toast.LENGTH_SHORT).show()
        }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Manikandan Ram