Trying to play song using MPMusicPlayerController using the following code
let musicPlayerController = MPMusicPlayerController.systemMusicPlayer
func beginPlayback(itemID: String) {
let descripter = MPMusicPlayerStoreQueueDescriptor(storeIDs: [itemID])
descripter.startItemID = itemID
musicPlayerController.setQueue(with: descripter)
musicPlayerController.prepareToPlay(completionHandler: {(error : Error?) in
print()
self.musicPlayerController.play()
})
}
However, in the console I frequently see
[MPMusicPlayerController prepareToPlay] timeout
and the either nothing happens or the player will start with the wrong song, probably something local from my device.
I'm trying to play one song from my Apple Music Library, I use their API to get my playlist, and then the songs, the track response looks like this:
attributes = {
albumName = Villains;
artistName = "Queens of the Stone Age";
artwork = {
height = 1200;
url = "https://is3-ssl.mzstatic.com/image/thumb/Music117/v4/8b/19/86/8b19867d-f500-5396-bd6f-e89c0a69adcd/dj.tvdpbelw.jpg/{w}x{h}bb.jpg";
width = 1200;
};
durationInMillis = 341825;
name = "Feet Don\U0092't Fail Me";
playParams = {
id = "i.B0VN4GGf7Eldk";
isLibrary = 1;
kind = song;
};
trackNumber = 1;
};
href = "/v1/me/library/songs/i.B0VN4GGf7Eldk";
id = "i.B0VN4GGf7Eldk";
type = "library-songs";
}
I'm using the "id" here as the itemID playback parameter to beginPlayback (i.B0VN4GGf7Eldk). Is that right or should it be something else? Trying to figure out why this won't play.
Edit:
Also seeing this in the console
[SDKPlayback] -[MPMusicPlayerController prepareToPlayWithCompletionHandler:] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1 "No commands provided." UserInfo={NSDebugDescription=No commands provided.} [SDKPlayback] -[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x1c8045b20 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}