I'm trying to get current play queue from MPMusicPlayerController.
I came up with a very bad solution, where I pause the music, Skip to next item, until end of list. (with volume=0)
I thought I could do this when the user needs the list (music will be interrupted unfortunately) or in between the first track change.
I have written the following:
Code:
if (wasPlaying) [m.player.musicPlayer pause];
//Remeber play time
MPMediaItem *nowPlayingItem = m.player.musicPlayer.nowPlayingItem;
NSTimeInterval currentPlaybackTime = m.player.musicPlayer.currentPlaybackTime;
//So skip through record finding the list
int c=0;
NSMutableArray *mediaItemsInList=[[NSMutableArray alloc] initWithCapacity:10]; //[[NSMutableArray alloc] init];
while ((nowPlayingItem!=nil) && (c<15)) // (m.player.musicPlayer.playbackState!=MPMusicPlaybackStateStopped)
{
nowPlayingItem = [m.player.musicPlayer nowPlayingItem];
if (nowPlayingItem!=nil) [mediaItemsInList addObject:nowPlayingItem];
[m.player.musicPlayer skipToNextItem];
c++;
NSLog([NSString stringWithFormat:@"%d:%@ %@",c,[nowPlayingItem valueForProperty: MPMediaItemPropertyTitle],
[nowPlayingItem valueForProperty: MPMediaItemPropertyArtist]]);
}
NSArray *ar=mediaItemsInList;
MPMediaItemCollection *mediaItemCollection=[[ MPMediaItemCollection alloc] collectionWithItems:ar];
//Set media list
[m.player setUserMediaItemCollection:mediaItemCollection];
[m.player.musicPlayer setQueueWithItemCollection: mediaItemCollection];
[mediaItemCollection release];
[mediaItemsInList release];
Oh yes... I also found after skipping 15 songs it kept repeating the track information, so for some reason the skipToNextItem is not moving forward. But I gues the first 15 tracks are better than NONE
The code gives a SIGABRT error at:
Code:
MPMediaItemCollection *mediaItemCollection=[[ MPMediaItemCollection alloc] collectionWithItems:ar];
If anyone has any better iteas I would like to know? Or has a solution for the above... If I fix it I will post the code