使用默认播放器播放音频文件

时间:2010-11-12 09:14:30

标签: android controls android-mediaplayer media

我想使用默认的Android播放器播放MP3文件。我设法让文件播放但它在后台播放。我想拥有暂停,播放等所有不错的控件。

我的代码现在是这样的:

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

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

当这个文件开始播放时,我怎么能用播放器和所有不错的控件进入另一个屏幕?

1 个答案:

答案 0 :(得分:5)

当您想要实现自己的媒体播放器时,应使用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