I launch roadblock by integrating music into my Android app. The goal is to allow users to see and play songs that they already have access to through Google Play Music (or any other player such as Winamp, Poweramp, doubleTwist, etc.).
So far I have tried several approaches, but each has a problem.
Approach # 1: Use the ContentResolver request to get playlists and songs from music on Google Play, and then use MediaPlayer
First, hover over the playlists:
String[] proj = { MediaStore.Audio.Playlists.NAME, MediaStore.Audio.Playlists._ID }; Uri playlistUri = Uri.parse("content://com.google.android.music.MusicContent/playlists"); Cursor playlistCursor = getContentResolver().query(playlistUri, proj, null, null, null);
Then try again to get the songs in each playlist, and read them as follows:
String[] proj2 = { MediaStore.Audio.Playlists.Members.TITLE, MediaStore.Audio.Playlists.Members._ID }; String playListRef = "content://com.google.android.music.MusicContent/playlists/" + playListId + "/members"; Uri songUri = Uri.parse(playListRef); Cursor songCursor = getContentResolver().query(songUri, proj2, null, null, null);
This works to get playlists and songs, but then you cannot play them (even if you tell Google Play Music "Keep on device"). In particular, the following code does not play this song, as indicated above:
mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mediaPlayer.setDataSource(dataPath); mediaPlayer.prepare(); mediaPlayer.start(); } catch (Exception e) {}
In fact, I scanned the device and could not find the files anywhere (although I confirmed that they were local, completely disconnecting the network - on both the Galaxy Nexus and Galaxy S3).
Approach # 2: challenge Google Play Music or another player using intent
According to this message, you can simply call the player using intentions, for example:
Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(YOUR_SONG_URI); intent.setDataAndType(Uri.fromFile(file), "audio/*"); startActivity(intent);
But I donβt think that this approach allows you to control any type, for example, to transmit a specific song that needs to be played, or to be notified when the song will be played. In addition, @CommonWares indicates that the music application and its intentions are not part of the public Android SDK API and are subject to change without notice.
The main functionality that I am trying to achieve exists in iOS, thanks to tight integration with iTunes. I would think that Google would want to achieve the same integration, as this could mean selling a lot more music in the Play store.
In summary: Can I browse and play songs that they already have access to on Android? What is the best way to do this using Google Play Music or any other application? Thanks.