简体   繁体   English

在Media Player Android上播放MediaStore的音频

[英]Playing audio from MediaStore on a Media Player Android

Is there a way to play audio obtained from MediaStore through the use of the MediaPLayer, Or am I going in the completely wrong direction? 有没有办法通过使用MediaPLayer播放从MediaStore获得的音频,或者我是否朝着完全错误的方向前进? I've looked and MediaStore.Audio so far but nothing is really helping me. 到目前为止我看过MediaStore.Audio,但没有什么能真正帮助我。 I just need to know if I'm on the right track 我只需要知道我是否走在正确的轨道上

First, I assume you have basic knowledge of querying a ContentProvider and working with Cursors. 首先,我假设您具有查询ContentProvider和使用游标的基本知识。 If you dont, I suggest you research it here 如果你不这样做,我建议你在这里研究一下

Once you have a basic knowledge of how to use a ContentProvider, query the URI MediaStore.Audio.Media.EXTERNAL_CONTENT_URI for the column Audio.Media.DATA , along with any other fields you need. 获得有关如何使用ContentProvider的基本知识后,请查询Audio.Media.DATA列的URI MediaStore.Audio.Media.EXTERNAL_CONTENT_URI以及您需要的任何其他字段。

Let's say you put the returned cursor in yourCursor 假设您将返回的光标放在yourCursor

String path = yourCursor.getString(getColumnIndex(Audio.Media.DATA));

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

That's a very basic implementation. 这是一个非常基本的实现。 Get comfy with the android docs if you need to get fancy with it. 如果您需要了解它,请熟悉Android文档。

Have a look at the bundled music application source: 看看捆绑的音乐应用程序源:
https://android.googlesource.com/platform/packages/apps/Music https://android.googlesource.com/platform/packages/apps/Music

  1. List music using content providers 使用内容提供商列出音乐
  2. Use MediaPlayer in order to play the file you will get from the cursor 使用MediaPlayer播放您将从光标中获取的文件

You also have examples on the android developer website: http://developer.android.com/guide/topics/media/index.html 您还可以在Android开发者网站上找到示例: http//developer.android.com/guide/topics/media/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM