For a number of days now, I've been scratching my head as to why I wasn't able to play store identifiers for Apple Music catalog or library content. Turns out, setting the store identifiers directly with MPMusicPlayerApplicationController
will play the content, whereas using MPMusicPlayerStoreQueueDescriptor
and passing it to MPMusicPlayerApplicationController
results in no effect.
I still get the following error logs:
[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong]
[core] "Error returned from daemon: Error Domain=com.apple.accounts Code=9 "(null)""
iTunesCloud] ACAccountStore 0x283e1bdb0 - Error retrieving iTunesStore accounts. err=Error Domain=com.apple.accounts Code=9 "(null)"
[iTunesCloud] [ICUserIdentityStore] Failed to fetch local store account with error: Error Domain=com.apple.accounts Code=9 "(null)".
...but gone is Error Domain=MPMusicPlayerControllerErrorDomain Code=6 "Failed to prepare to play" UserInfo={NSDebugDescription=Failed to prepare to play}
.
Hopefully this might be useful for someone else who stumbles into this :)
Here's some code so you see what I mean:
class AMPlayer {
private(set) var player: MPMusicPlayerController!
// Every time `queue` is set, it'll ensure the player queue is "updated"
private var queue: MPMusicPlayerStoreQueueDescriptor! {
didSet {
guard self.queue != nil,
let storeIDs = self.queue.storeIDs,
!storeIDs.isEmpty
else { return }
self.player.setQueue(with: storeIDs)
}
}
// This is how I set the queue from outside the class
public func setQueue(with resourceIDs: [String]) {
self.queue = MPMusicPlayerStoreQueueDescriptor(storeIDs: resourceIDs)
}
// This is how I start playback
public func play() {
self.player.prepareToPlay { (error) in
if let error = error as? MPError {
print("Error while preparing to play: \(error)")
} else {
self.player.play()
}
}
}
}
[SDKPlayback] applicationQueuePlayer _establishConnectionIfNeeded timeout [ping did not pong] [SDKPlayback] Failed to prepareToPlay error: Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Preparing queue timed out" UserInfo={NSDebugDescription=Preparing queue timed out}
– Mephitic