开发者

Play audio files with default player

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 开发者_StackOverflow中文版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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜