I believe what you are looking for is exactly the API of MediaStorage
android.
It has so many ways to access any type of media that is in the device’s internal and external storage.
To get all the music from the apparatus, take a look at the MediaStorage.Audio
and to get the playlists recorded on the device a look at MediaStorage.Audio.PlayLists
.
I found a complete tutorial to build an app Music Player using this API, in link.
You will have to use a Contentresolver to make a Query
about music and playlists. It would have something like:
ContentResolver musicResolver = getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
// Iterar sobre o cursor...
Below the code to play a song using the MediaPlayer
from the Cursor
, from this question of ONLY:
public void onItemClick(AdapterView<?> parent, View v, int position,long id) {
int music_column_index = musiccursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
musicCursor.moveToPosition(position);
String filename = musicCursor.getString(music_column_index);
try {
if (mMediaPlayer.isPlaying()) {
mMediaPlayer.reset();
}
mMediaPlayer.setDataSource(filename);
mMediaPlayer.prepare();
mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
mp = null;
}
});
} catch (Exception e) {}
}
In this code, a query is made for all songs on the device.
To check the playlists, I found a snippet
, without reliable source that follows the same principle of music query:
public void checkforplaylists(Context context) {
ContentResolver cr = context.getContentResolver();
final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
final String id = MediaStore.Audio.Playlists._ID;
final String name = MediaStore.Audio.Playlists.NAME;
final String[] columns = {id, name};
final Cursor playlists = cr.query(uri, columns, null, null, null);
if(playlists == null) {
Log.e(TAG,"Found no playlists.");
return;
}
Log.e(TAG,"Found playlists.");
// Iterar sobre o cursor...
}
Leonardo, from a look at these sites, they have some examples of how to create a player: [1] http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/ [2] http://alucard1990.hubpages.com/hub/How-to-Make-a-Simple-Media-Player-for-Android
– Marabita
I think his doubt is to access the playlists of the Play Music app from google, is that it? Or just create a playlist?
– Wakim
@Wakim my question is how to access the songs that already exist on my phone and how to access the playlists already created on the phone. An example of App that does this is from Nike.
– Leonardo Patricio
@Marabita need to access the songs that already exist on mobile and not those that are added to the App.
– Leonardo Patricio
@Leonardopatricio You can get the songs from the sdcard, but the songs from the 'play music' I find more complicated because they are probably protected by DRM.
– Marabita
But it’s possible somehow because the Nike app or the 4shared app can access them.
– Leonardo Patricio