I'm creating an app that can playback songs from Apple Music using the MPMusicPlayerController for people with a subscription.
I've run into a problem where certain songs fail to play whilst others work fine and I'm not sure why this would be the case.
The ID for a song that wouldn't work is 627511704
. I've double checked some songs that don't work using the iTunes search API just to confirm that they do actually exist on the store which they did.
Here's the code where I attempt to queue the MPMusicPlayerController
with an ID
func playWithAppleMusic(track: Track) {
guard let id = track.appleMusicID else { return }
self.appleMusicPlayer = MPMusicPlayerController.applicationMusicPlayer()
self.appleMusicPlayer?.prepareToPlay()
self.appleMusicPlayer?.setQueueWithStoreIDs([String(id)])
self.appleMusicPlayer?.currentPlaybackTime = 0
self.appleMusicPlayer?.repeatMode = .none
self.appleMusicPlayer?.shuffleMode = .off
self.appleMusicPlayer?.play()
self.startTimer()
}
I have also tried using an instance of MPMusicPlayerController.systemMusicPlayer()
instead but that also did not work and wouldn't queue the song in the Apple Music app either.
Anybody know if I am doing something wrong here or is it just Apple's API being buggy again?
Thanks