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

我想使用默认的Android播放器播放MP3文件.我设法使文件播放,但它在后台播放.我想要所有用于暂停,播放等的漂亮控件.

我的代码现在类似于:

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

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

当该文件开始播放并与播放器和所有不错的控件一起转到另一个屏幕时,我该怎么办?

解决方法:

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

上一篇:c#-将元素添加到Microsoft WinForm控件


下一篇:c# – 如何在没有容器更新的情况下从容器中删除控件