iOS10.3.x Can't set nowPlayingItem on MPMusicPlayer

I have a released app that just started having trouble setting the nowPlayingItem on MPMusicPlayer for Apple Music tracks. This code works as expected for iTunes tracks on the device, but if the mediaitem set is an Apple Music track, a random track that is in the user's Apple Music library - but not in the current playerqueue - ends up playing. I suspect something has changed in iOS10.3.x or Apple Music is burbing just now. Anyone have ideas of how I could fix this?


Basic code is:


                        
MPMusicPlayerController *musicPlayer;
[musicPlayer stop];
NSLog(@"*** trying to set nowplayingitem to %@", [UIAppDelegate.activeTrack.mediaitem valueForProperty:MPMediaItemPropertyTitle]);
musicPlayer.nowPlayingItem = UIAppDelegate.activeTrack.mediaitem ;
NSLog(@"nowplaying item is:%@", musicPlayer.nowPlayingItem.title);
[musicPlayer play];
 if (![musicPlayer.nowPlayingItem.title isEqualToString:UIAppDelegate.activeTrack.name]){
              NSLog(@">>>>>>> now playing does not equal current track so return and scratch head");
               return;
                        }

2017-04-14 09:43:14.535079-0400 MyFitnessDJ[720:241825] *** trying to set nowplayingitem to Blame

2017-04-14 09:43:14.761134-0400 MyFitnessDJ[720:241825] nowplaying item is:(null)

2017-04-14 09:43:14.819226-0400 MyFitnessDJ[720:241825] >>>>>>> now playing does not equal current track so return and scratch head


Does anyone have any idea why the nowplaying item would not set to the correct Apple Music track with iOS10.3.x or could there be a burb in Apple Music?

Replies

Seems that stopping the music player too soon before trying to set the nowplayingItem caused the music player to play a random track. Still don't understand why, but if the music player is not stopped, the nowPlayingItem can be set.

In case anyone comes across this post due to a similar problem in iOS 11, I'm back to having the same trouble. Keeping the musicPlayer playing doesn't work reliably.


As of the iOS11 general release, trying to set nowPlayingItem on a playing (or not) MPMusicPlayerController yields an unexpected result. Sometimes, it hangs the system for up to 5 seconds then possibly plays the track requested, or sometimes it hangs up to 5 seconds and plays a differing track (one that is on the device, but not necessarily in the queue) or sometimes the previously playing track continues with no apparent effect from the call. Oh, and sometimes it plays the requested track immediately as expected ;-)


I've filed a bug report, but if anyone has any luck making this work consistantly, please post a hint as to how you have made it work.

I just can’t believe that this still has not been fixed! Currently using iOS 11.2.1...this is so disappointing, a basic feature which my app requires! The MPMedia framework is by far the worst I have come across in terms of performance and glitches! I have already spent so much time updating my music app to support tracks from iCloud and Apple Music, now all that work amounts to guess what?!?! Nothing!!!! Perhaps it’s time to finally make the move to Android!

If somebody has already filed a bug report about this, please post the bug report number. If you haven't, please file a bug report about this. File bug reports using our bug reporting system at https://developer.apple.com/bug-reporting/


If you can modify the "Interacting with Apple Music Content" sample on https://developer.apple.com/musickit/ to reproduce the issue, please include your modified version with the bug report.

@3ZS - thanks for commenting! I filed bug 34552165 - Can't reliably set nowPlayingItem on MPMusicPlayerController


on Sept 20, 2017. So far, I've heard nothing.


I've also been able to replicate the 7-10 second freeze by calling musicPlayer.currentPlaybackTime or musicPlayer.nowPlayingItem.title at one second intervals after track play in the Add Music sample code. Would it help to see that code?


I'm super glad that someone is looking at this and would be so grateful if the issue can be solved soon. I'm more than happy to answer any other questions about this. I want be helpful!!

@3ZS In case it helps, I've filed another bug report (36297908 - UI freeze in MPMusicPlayerController when calling currentPlaybackTime) using the Add Music sample code that regularly demostrates this bug. Please let me know if I can help this issue get solved more quickly!

Dear 3ZS or anyone at Apple,

I'm trying to be patient.

I've had less than reliable results from MPMusicPlayer for more than 10 months - first dev forum thread 76019 - and have submitted two bug reports - 34552165 four months ago and 36297908 three weeks ago. There have also been several other developers reference this issue in dev forums posts - 92467, 93386, 94231, 84259.

Could someone with knowledge of this issue please give us an update? I know that everything takes time, but some info on what / when / or how to fix this would be most appreciated!


I'm trying to be patient. Really!

Hello davenorfleet,


Reporting issues on the forums is great if you want to discuss them, but if you want to make sure Apple SW engineering is looking at a problem you always need to file bug reports using our bug reporting system at https://developer.apple.com/bug-reporting/


Thank you for creating these bug reports. SW engineering is looking at them. If they have questions they will reach out to you.


The best way to keep your data fresh for SW engineering in your bug reports is to update your bug report with the results of testing on each seed that comes out.


The following is an FYI:

If your bug reports had been duped to another bug report, which your's aren't (this is just an FYI), then you should still test with each seed that is released but with your results create new bug reports that focus on the testing with the seed and (importantly) don't mention your old bug reports. If you mention your old bug reports, your new reports might be closed as a duplicate of your old bug report when they are actually new with new information.

Thanks so much for the reply, 3ZS. I've submitted another bug report using the latest iOS seed, so maybe that will help.


For anyone else seeing this issue, please take 3ZS's advice and submit (or update) your bug reports using the latest iOS seed.

Thank you for replying 3ZS.


Would just like to confirm that the bug is still there, iOS 11.2.5

I have just filed a bug report too...hope this gets resolved soon...

Back in November I sent in a bug report (35338820) with a modified version of "Interacting with Apple Music Content" demonstrating a very similar hang. Still no feedback and no fix. Also updated it several times with new beta releases with no feedback from the engineers.

As of iOS 11.3 beta 2 (since it's in public beta, I hope it's OK to discuss here) this seems to be fixed! The app has to be compiled with the corresponding beta of Xcode, so a released app complied on a previous Xcode may still be flaky. Anyone else see the fix?