MPMusicPlayerControllers nowPlayingItem not changing song

MPMusicPlayerControllers nowPlayingItem no longer seems to be able to change a song. The code use to work but seems to be broken on iOS 16, 17 and now the iOS 18 beta.

When newSong is triggered, the song restarts but it does not change songs. Instead I get the following error: Failed to set now playing item error=<MPMusicPlayerControllerErrorDomain.5 "Unable to play item <MPConcreteMediaItem: 0x9e9f0ef70> 206357861099970620" {}>.

The documentation seems to indicate I’m doing things correctly.

class MusicPlayer {
    var songTwo: MPMediaItem?
    let player = MPMusicPlayerController.applicationMusicPlayer
    
    func start() async {
        await MPMediaLibrary.requestAuthorization()

        let myPlaylistsQuery = MPMediaQuery.playlists()
        let playlists = myPlaylistsQuery.collections!.filter { $0.items.count > 2}
        let playlist = playlists.first!
        let songOne = playlist.items.first!
        songTwo = playlist.items[1]
        
        player.setQueue(with: playlist)
        play(songOne)
    }
    
    func newSong() {
        guard let songTwo else { return }
        play(songTwo)
    }
    
    private func play(_ song: MPMediaItem) {
        player.stop()
        player.nowPlayingItem = song
        player.prepareToPlay()
        player.play()
    }
}

Feedback: FB14368686

MPMusicPlayerControllers nowPlayingItem not changing song
 
 
Q