Question

I want to know when a user selects a song using media picker, what playlist they picked the song from. For some reason, the playlist doesn't seem to exist.

Basically when a user goes to a playlist in media picker let's call it "gym songs" and they select a song, mediaPicker:didPickMediaItems: function returns the song details but doesn't say which playlist the user selected the sone from.

So what I want to do is play that song and continue playing the other songs in that playlist. But without the playlist info, it starts playing that song and goes on playing the rest of the songs in "all songs" list.

This is my code:

(void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection

{

    MPMediaItem *selectedSong = [[mediaItemCollection items] objectAtIndex:0];

    MPMediaQuery *songQuery = [MPMediaQuery songsQuery];
    [musicPlayer setQueueWithQuery:songQuery];
    for (MPMediaItem *oneSong in [songQuery items]) {

        if ([selectedSong isEqual:oneSong]) {
            musicPlayer.nowPlayingItem = oneSong;
            [musicPlayer play];

            // Exit the loop
            break;
        }
    }
    [self dismissModalViewControllerAnimated: YES]; }
Was it helpful?

Solution

This data is not made available. Your only option is to do all this yourself in code. Put up a tableview and populate it with all the playlists in the library. When the user chooses a playlist put up another tableview with all the tracks in that playlist and allow the user to choose one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top