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

发布于 2024-10-02 10:28:42 字数 301 浏览 0 评论 0原文

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

我现在的代码类似于:

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

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

当此文件开始播放时,如何才能使用播放器和所有不错的控件转到另一个屏幕?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶…霜飞 2024-10-09 10:28:42

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文