Play audio files with default player

I want to play an MP3 file using the default Android player. I managed to play the file, but it plays in the background. I want to have all the nice controls for pause, play, etc.

My code now is something like:

String link = "http://www.example.com/file.mp3";

MediaPlayer mp = new MediaPlayer();
mp.setDataSource(link);
mp.prepare();
mp.start(); 

How can I make it so that when this file starts playing, it switches to another screen with the player and all the nice controls?

+3
source share
1 answer

MediaPlayer , . , , :

Uri uri = Uri.parse("http://www.site.com/file.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

, : http://developer.android.com/reference/android/content/Intent.html

+5

Source: https://habr.com/ru/post/1774477/


All Articles