Java 如何使用 MediaPlayer 和 MediaController 为 Android 实现音频播放器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2220575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:52:32  来源:igfitidea点击:

How to implement an audio player for Android using MediaPlayer And MediaController?

javaandroidaudiomedia-player

提问by Nick Mitin

I want to create an Android application that is a client for an Internet radio station. And I want it look native to Android? But im confused with Android API logic and documentation. What i've got is that I need MediaPlayer and MediaController classes. Am I right, and is there any good example of AUDIO player for Android?

我想创建一个 Android 应用程序,它是 Internet 广播电台的客户端。我希望它看起来是 Android 原生的?但我对 Android API 逻辑和文档感到困惑。我得到的是我需要 MediaPlayer 和 MediaController 类。我是对的,是否有任何适用于 Android 的 AUDIO 播放器的好例子?

Especially, I'm very interested how to use MediaPlayerand MediaControllerclasses together.

特别是,我对如何一起使用MediaPlayerMediaController类很感兴趣。

UPD:

更新:

Finally I've got the code, that does exactly what I want:

最后我得到了代码,这正是我想要的:

Intent i = new Intent(Intent.ACTION_VIEW);    
Uri u = Uri.parse(%file_uri%));    
i.setData(u);    
startActivity(i);

采纳答案by Micha?l

you can look at those links :

你可以看看这些链接:

http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-i

http://www.helloandroid.com/tutorials/musicdroid-audio-player-part-i

Hope it will help.

希望它会有所帮助。

[EDIT]

[编辑]

You have also some example on the official android developer website :

您在官方 android 开发者网站上也有一些示例:

http://developer.android.com/guide/topics/media/index.html

http://developer.android.com/guide/topics/media/index.html