Stream audio in android studio

Asked

Viewed 743 times

0

I am using the following code to play a sound saved 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 he plays the audio in Play Music , and I wanted him to play in the app itself, someone has a tip on how to do this?

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 like pause, stop and volume control.

https://developer.android.com/guide/topics/media-apps/volume-and-earphones.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.