"Remote call timed out" error when trying to play large collection of music items with MusicKit's ApplicationMusicPlayer

I am using MusicKit ApplicationMusicPlayer to play music in my app. Everything works fine as long as I'm not playing large playlists that contain hundreds of songs. When I to play collection of songs that is larger than around 300 I'm always getting the error message saying:

"Prepare to play failed" UserInfo={NSDebugDescription=Prepare to play failed, NSUnderlyingError=0x121d42dc0 {Error Domain=MPMusicPlayerControllerErrorDomain Code=9 "Remote call timed out" UserInfo={NSDebugDescription=Remote call timed out}}}))

It doesn't matter if songs are downloaded to the device or not.

I am aware that there is another initializer for player's queue that accepts Playlist instances but in my app users can choose to sort playlist tracks in different order than the default and that makes using that initializer not feasible for me.

I tried everything I could think of, I tried to fall back on MPMusicPlayerController and pass array of MPMusicPlayerPlayParameters to it but the result was the same.

typealias QueueEntry = ApplicationMusicPlayer.Queue.Entry

let player = ApplicationMusicPlayer.shared

let entries: [QueueEntry] = tracks
      .compactMap {
          guard let song = $0 as? Song else { return nil }
             return QueueEntry(song)
          }
Task(priority: .high) { [player] in
    do {
        player.queue = .init(entries, startingAt: nil)
        try await player.play() // prepareToPlay failed
    } catch {
        print(error)
    }
}
"Remote call timed out" error when trying to play large collection of music items with MusicKit's ApplicationMusicPlayer
 
 
Q