Apple Music playback randomly failing

Hi, I'm trying to play Apple Music songs using storeID like this:


playerController = MPMusicPlayerController.applicationMusicPlayer
playerController?.beginGeneratingPlaybackNotifications()
playerController?.setQueue(with: [storeID])
playerController?.prepareToPlay() { error in
     if error == nil {
          playerController?.play()
     }
}


The problem is that sometimes the playback starts as expected and sometimes just gives me this log without explaining anything else:


[SDKPlayback] -[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x1d4a44680 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}

[SDKPlayback] Failed validators: {(
    play
)}

I can't observe that error to try something else, cause the play() method doesn't give's any return, closure, notification, to track it.


Do you know how can I at least observe that? Is it normal?


I tested this in iOS 11.4 and iOS 12 beta and I'm sure that the items are available to playback.


Thank you so much in advance!

Accepted Reply

Finally I solved this listening for MPMusicPlayerControllerPlaybackStateDidChange, when I receive that notification I just check if the MPMusicPlayerController.nowPlayingItem is nil or not and if is still nil I repeat all the process to start playing that song. Something like this:

@objc func handleMusicPlayerControllerPlaybackStateDidChange() {
    if self.playerController?.nowPlayingItem == nil {
        self.playAppleMusic(song: song)
    }
}


Hope it can help somebody!

Replies

Finally I solved this listening for MPMusicPlayerControllerPlaybackStateDidChange, when I receive that notification I just check if the MPMusicPlayerController.nowPlayingItem is nil or not and if is still nil I repeat all the process to start playing that song. Something like this:

@objc func handleMusicPlayerControllerPlaybackStateDidChange() {
    if self.playerController?.nowPlayingItem == nil {
        self.playAppleMusic(song: song)
    }
}


Hope it can help somebody!

Thank you, this helped a lot