Playing audio from MediaStore on a Media Player Android

廉价感情. 提交于 2019-12-06 09:00:39

问题


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? I've looked and MediaStore.Audio so far but nothing is really helping me. I just need to know if I'm on the right track


回答1:


First, I assume you have basic knowledge of querying a ContentProvider and working with Cursors. 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.

Let's say you put the returned cursor in 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.




回答2:


Have a look at the bundled music application source:
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

You also have examples on the android developer website: http://developer.android.com/guide/topics/media/index.html



来源:https://stackoverflow.com/questions/6832522/playing-audio-from-mediastore-on-a-media-player-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!