Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access playlist created by android default music app and call the music app to play it?

I am writing an android app, and I want to access the playlist created by android default music app.

In my app, the user should be able to browse the playlist and select any playlist to play.

So basically I want to know how to access it and when user selects any playlist, how to pass it to default music app to play it in background.

Is it something to do with ContentProvider or mediastore?? I really don't know how to access data on other apps.

Thank you so much!

like image 764
Kelly Avatar asked Sep 10 '11 07:09

Kelly


People also ask

Where is my music playlist on my Android phone?

For Android Smartphone On your Android smartphone, launch the YouTube app (if you have not installed it, here's the link). Tap the “Menu” button and select the “My Channel” option. Go to the Playlists tab and select your playlist.

What is the default music app for Android?

It was clear from the start that YouTube Music was intended as a direct replacement for Google Play Music, and Google just announced that YouTube Music will be the default, preinstalled music player for new Android 10 and Android 9 devices.

What is your default music player app?

Your Android phone should automatically play music using Spotify whenever you ask Google Assistant to play a song, artist, or album.


1 Answers

To play the songs from above playlists, I m calling the function

PlaySongsFromAPlaylist( PlayListID ); // 0 < PlayListID < count

from the above onCreate method. And remaining code is as per mentioned below.

public void PlaySongsFromAPlaylist(int playListID){

    String[] ARG_STRING = {MediaStore.Audio.Media._ID,MediaStore.Audio.Media.DATA,MediaStore.Audio.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE,android.provider.MediaStore.MediaColumns.DATA};
    Uri membersUri = MediaStore.Audio.Playlists.Members.getContentUri("external", playListID);
    Cursor songsWithingAPlayList = mThis.managedQuery(membersUri, ARG_STRING, null, null, null);
    int theSongIDIwantToPlay = 0; // PLAYING FROM THE FIRST SONG
    if(songsWithingAPlayList != null)
    {
        songsWithingAPlayList.moveToPosition(theSongIDIwantToPlay);
        String DataStream = songsWithingAPlayList.getString(4);
        PlayMusic(DataStream);
        songsWithingAPlayList.close();
    }   
}

 public static void PlayMusic(String DataStream){
    MediaPlayer mpObject = new MediaPlayer();
    if(DataStream == null)
        return;
    try {
        mpObject.setDataSource(DataStream);
        mpObject.prepare();
        mpObject.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
 }

Hope this will work. :)

like image 170
Ankur Avatar answered Oct 17 '22 18:10

Ankur