MPMusicPlayerController prepareToPlay errors

I'm getting a variety of errors when I call prepareToPlay on the MPMusicPlayerController. Sometimes they happen, sometimes they don't. I'm trying to play songs from the Apple Music service. When I don't get the errors, it plays just fine. I have iOS v13.5.1 on my iPhone Xs and I'm using Xcode 11.5. This is my code:

Code Block
let applicationMusicPlayer = MPMusicPlayerController.applicationMusicPlayer
applicationMusicPlayer.setQueue(with: [trackID])
applicationMusicPlayer.prepareToPlay(completionHandler:{ error in
if let error = error {
print(error.localizedDescription)
return
}
DispatchQueue.main.async{
applicationMusicPlayer.play()
}
}


These are the various errors I'm getting:


[SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=2 "Queue was interrupted by another queue" UserInfo={NSDebugDescription=Queue was interrupted by another queue}

[SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Preparing queue timed out" UserInfo={NSDebugDescription=Preparing queue timed out}


[SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play}


[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]

I'm also getting this issue. For the most part, songs play correctly and as expected, but there are select songs that produce Code 6, specifically Calabria (Firebeatz Remix), id 927908043

SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play}
Any idea why certain songs fail to play?
Hello,

I am also running into this issue. Most songs play wonderfully, but others consistently won't play.

For example, I am unable to play Tones and I - Dance Monkey, id: 1475546088.

Code Block
 [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Prepare queue failed with unexpected start item" UserInfo={NSDebugDescription=Prepare queue failed with unexpected start item}

Using the same code, I can play DJ Khaled - POPSTAR (feat. Drake), id: 1523923824.

In both cases, the MPMusicPlayerStoreQueueDescriptor.startItemID and MPMusicPlayerStoreQueueDescriptor.storeIDs properties look correct.

I have tried using both MPMusicPlayerController.applicationQueuePlayer and MPMusicPlayerController.systemMusicPlayer.

I am on iOS 13.6.

Any help will be much appreciated, and I hope we can figure this out!

I ran into this same issue where I had to fall back to the usual Apple Music API and MusicKit is still missing a bunch of features. Every song in a users playlist (found in their library) would report the same error when attempting to play.

Each track in these playlists look like:

a.3828342394

But the IDs that come from MusicKit search (MusicCatalogSearchRequest), don't have the "a." prefix.. mostly. Some do.

removing this prefix with id.replacingOccurrences(of: "a.", with: "") solved the issue for me. I have no idea why Apples media player can't handle these without modification, nor why there's nothing in the documentation that mentions this limitation. Maybe it's just another bug that will go ignored.

Hello folks,

Thank you for reaching out to us with those questions about Media Player's MPMusicPlayerController.

I stumbled upon this forums thread just now. That's because I don't personally monitor posts tagged with Apple Music API. I highly recommend you select tags for the relevant client-side frameworks you're using. In this case, it would have been better to include the Media Player tag, and ideally, the MusicKit tag as well. This will give you the best chances of your post becoming visible to engineers who can actually help. That said, I was able to just fix that up on your behalf.

Unfortunately, there is not enough information for us to diagnose this issue. Could you file a new ticket on Feedback Assistant including a sysdiagnose captured right after reproducing the issue?

Thank you very much in advance for your help.

Best regards,

I have the same issue when running the iPad version on my M1 Mac, and it's blocking the main thread.

[SDKPlayback] systemMusicPlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] SYNC-WATCHDOG-1: Attempting to wake up the remote process [SDKPlayback] systemMusicPlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] SYNC-WATCHDOG-2: Tearing down connection

This drives me crazy.

I have the same issue when running the iPad version on my M1 Mac, and it's blocking the main thread. 

[SDKPlayback] systemMusicPlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] SYNC-WATCHDOG-1: Attempting to wake up the remote process [SDKPlayback] systemMusicPlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] SYNC-WATCHDOG-2: Tearing down connection 

This drives me crazy.

Playing music with SystemMusicPlayer NEVER works on my M1. The code that works on my phone produces this on the Mac:

systemMusicPlayer _establishConnectionIfNeeded failed [application failed to launch] Failed to prepareToPlay with error: Error Domain=MPMusicPlayerControllerErrorDomain Code=10 "Failed to obtain remoteObject [nil server]" UserInfo={NSDebugDescription=Failed to obtain remoteObject [nil server]}

MPMusicPlayerController prepareToPlay errors
 
 
Q