Download and play .mp3 file from firebase storage to memory

后端 未结 3 1548
借酒劲吻你
借酒劲吻你 2021-02-10 21:29

I need to download an mp3 file from my firebase storage gs://fir-b9532.appspot.com/songs/song1.mp3 and play it into my android application. I want to store the mp3 file temporar

3条回答
  •  自闭症患者
    2021-02-10 22:01

    Instead of downloading the audio file and temporarly keep it on the memory i found another solution by live-streaming the song from the full URL that firebase storage provide ("https://firebasestorage.googleapis.com/v0/b/fir-b9532.appspot.com/o/songs%2Fsong1.mp3?alt=media&token=a4424b28-93c3-4a0c-a6b9-9136dcf63335").

    I just load my MediaPlayer like this:

    try {
            MediaPlayer player = new MediaPlayer();
            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setDataSource("https://firebasestorage.googleapis.com/v0/b/fir-b9532.appspot.com/o/songs%2Fsong1.mp3?alt=media&token=a4424b28-93c3-4a0c-a6b9-9136dcf63335");
            player.prepare();
            player.start();
        } catch (Exception e) {
            // TODO: handle exception
        }
    

提交回复
热议问题