Thank you, @JoeKun for taking the time to look at this and for clarifying the behavior on prepareToPlay. I modified my code to read like yours and am seeing a different error when running on my device (I am an Apple Music subscriber)
private func playAppleMusic(songs : [Song]) {
Task.init {
do {
let player = SystemMusicPlayer.shared
player.queue = MusicPlayer.Queue(for: songs)
try await player.play()
} catch let error {
print("playAppleMusic error: \(error.localizedDescription)")
}
}
}
When running this, I see: playAppleMusic error: The operation couldn’t be completed. (MPMusicPlayerControllerErrorDomain error 6.). Do you have pointers on how to understand this error better? I'm unable to find documentation on MPMusicPlayerControllerErrorDomain.
Thank you!