I need to browse the audio files on the user's device using the user's playlists and songs from their Music app, then pass the selected audio file to our player.
Does the Android MediaStore
contain the master copy of all audio files, and the user defined playlists they my set up from other apps? I'm looking for an API similar to the MediaLibrary
on iOS.
The MediaStore Reference Documentation doesn't give me enough detail on how to actually use the API, and it doesn't seem to be covered in the Training, API Guides or Samples section of the docs. The Random Music Player sample seems to be out of date, and doesn't compile with Android Studio.
I assume my browser code needs to live in a Service. Right? Are there examples/docs of this available?
What about the Content Provider
API? This sometimes shows up in code samples, but it isn't clear if it will give access to the user's audio files or not.
I tried to use the following Intents, but they didn't give me access to the audio files in the manner I need. Are there existing Intents that should be used?
Using Intent.ACTION_GET_CONTENT
brings up a file browser of the file system on the device, showing audio files. Close, but not quite what is needed here.
private fun pickAudioFileWithACTION_GET_CONTENT() {
val intent = Intent( Intent.ACTION_GET_CONTENT )
intent.setType("audio/*")
val chooserIntent = Intent.createChooser( intent, "Select soundfile")
startActivityForResult( chooserIntent, SELECT_MUSIC )
}
Using MediaStore.INTENT_ACTION_MEDIA_SEARCH
allows an app selection that has a picker but also plays. I don't have control over what happens, so I don't think this is what is needed either.
private fun pickAudioFileWithMediaStoreINTENT_ACTION_MEDIA_SEARCH() {
val mediaSearchIntent = Intent( MediaStore.INTENT_ACTION_MEDIA_SEARCH )
val mediaSearchChooserIntent = Intent.createChooser( mediaSearchIntent, "Select soundfile")
startActivityForResult( mediaSearchChooserIntent, SELECT_MUSIC )
}
Suggestions for how this should work and pointers to documentation and/or samples would be appreciated.