I have implemented MPMusicPlayerController playing song functionality in the app. Everything working fine but very first time of launching the app is not working.Second time onwards it is working awesome. What I understood is setNowPlayingItem is not setting on first time . Any ideas/suggestions could be very helpful. Thanks for your valuable time.
Code
MPMediaItemCollection *collection = [[MPMediaItemCollection alloc] initWithItems:[NSArray arrayWithObjects:selectedMediaItem1, nil]];
[appDelegate.musicPlayer setQueueWithItemCollection:collection];
[appDelegate.musicPlayer setNowPlayingItem:selectedMediaItem1];
[appDelegate.musicPlayer prepareToPlay];
[appDelegate.musicPlayer play];
It's a bug! I opened a Technical Support Incident about this. We hope in iOS 10. Music and apple music will likely have a big update.
you should also set a currentPlaybackTime for your player,
// Restore the now-playing item and its current playback time.
appDelegate.musicPlayer.nowPlayingItem = nowPlayingItem;
appDelegate.musicPlayer.currentPlaybackTime = currentPlaybackTime;
Check this link for more details: https://developer.apple.com/library/ios/documentation/Audio/Conceptual/iPodLibraryAccess_Guide/UsingMediaPlayback/UsingMediaPlayback.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.