I'm developing an app that will stream mp3 file stored in firebase storage. Nearly I'm having 100 songs like song1,song2,song3..... if a song is selected I have to stream that particular song without downloading. In such case I need to write plenty of code because for each song I have to mention the firebase storage url. the url would be like
https://firebasestorage.googleapis.com/......song1.mp3?alt=media&token=8a8a0593-e8bb-40c7-87e0-814d9c8342f3
For each song the alt=media&token= part of the url varies, so I have to mention the unique url for all songs. But here I need some simplified coding to play the songs by mentioning its name alone from firebase storage.
Please suggest a way to stream the audio file by using its name alone that is stored in firebase storage.
To stream an mp3 file, upload your mp3 file to your public-html directory (or to a subdirectory of your public-html directory) preferably in MP3 format. OGG is also supported in Chrome and Firefox, but not in Safari and Internet Explorer. For example: Create a subdirectory (e.g., media) in your public-html directory.
You can explicitly specify metadata when you upload the file to Firebase. If you specify setContentType("audio/mpeg") it should map the file to an MP3 correctly.
here for start you can upload any file in GC storage. firebase.google.com/docs/storage/android/upload-files to play/stream music you can use developer.android.com/guide/topics/media/… We've got a streaming download API: firebase.google.com/docs/reference/android/com/google/firebase/…
There are two ways to download files with Firebase Storage, using references in the SDK or a download URL. iOS and Android users can download files into memory, disk, or from a download URL. The web SDK can download files just from a download URL. StorageReference storageRef = FirebaseStorage.
You have two choices if you want to get files out of a Firebase Storage bucket.
You can't get the file data any other way from within a mobile app. Firebase Storage doesn't support special media streaming protocols, such as RTSP.
I did it using downloadUrl
.
val storage = FirebaseStorage.getInstance()
storage.reference.child("songs/song1.mp3").downloadUrl.addOnSuccessListener({
val mediaPlayer = MediaPlayer()
mediaPlayer.setDataSource(it.toString())
mediaPlayer.setOnPreparedListener { player ->
player.start()
}
mediaPlayer.prepareAsync()
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With