Question

I want to play an MP3 file using the default Android player. I managed to get the file playing but it plays in the background. I want to have all the nice controls for pausing, playing, 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 do it that when this file begins to play to go to another screen with the player and all the nice controls?

Was it helpful?

Solution

The MediaPlayer class should be used when you want to implement your own media player. If you want to use an existing player, you'll have to launch the appropriate intent, for example:

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

If the particular Action doesn't work, take a look here: http://developer.android.com/reference/android/content/Intent.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top