Stream audio in android studio

0

I'm using the following code to play a saved sound in the cloud

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("https://firebasestorage.googleapis.com/v0/b/vozes-leagueof-legends.appspot.com/o/Aatrox%2Fataque2.mp3?alt=media&token=b523f118-126d-428d-856d-461c0c2e9686"), "audio/mp3");
startActivity(intent);

But it plays the audio in Play Music, and I wanted it to play in the app itself, does anyone have a clue how to do it?

    
asked by anonymous 19.07.2017 / 19:45

1 answer

1

You need to create a MediaPlayer to play it in the app itself.

For example:

MediaPlayer mp = new MediaPlayer();
try {
     mp.setDataSource("https://firebasestorage.googleapis.com/v0/b/vozes-leagueof-legends.appspot.com/o/Aatrox%2Fataque2.mp3?alt=media&token=b523f118-126d-428d-856d-461c0c2e9686");
     mp.prepare();
     mp.start();
} catch (IOException e) {
     Log.e("Log", "prepare() failed");
}

Then you can include other options, such as pause, stop, and volume control.

link

    
19.07.2017 / 21:49