简体   繁体   中英

MPMusicPlayerController fails to play Apple Music songs

I am using an instance of MPMusicPlayerController.systemMusicPlayer to enqueue an array of store IDs. This has worked for months now. Earlier today I updated to iOS 14.3, and the player is now failing to play songs.

The code below is the minimal amount needed to replicate the bug:

// note: repo using any play method you want
let player = MPMusicPlayerController.systemMusicPlayer
let descriptor: MPMusicPlayerStoreQueueDescriptor?

func setup() {
 let storeIDs: [String] = ["lorem", "ipsum"] // fetch real IDs from the API
 descriptor = MPMusicPlayerStoreQueueDescriptor(queue: storeIDs)
}

func play() {
 self.player.setQueue(with: descriptor!)
 self.player.play()
}

// Expected: plays song with store ID "lorem"
// Actual: app freezes and I see error logs

When I play a song, instead of playing it, the app completely freezes (meaning it doesn't respond to user interaction), and I see the following logs:

[SDKPlayback] ASYNC-WATCHDOG-1: Attempting to wake up the remote process
[SDKPlayback] SYNC-WATCHDOG-1: Attempting to wake up the remote process
[SDKPlayback] ASYNC-WATCHDOG-2: Tearing down connection
[SDKPlayback] SYNC-WATCHDOG-2: Tearing down connection

The MPMusicPlayerController plays music just fine on iOS 14.2.

Can anybody confirm or shed some light on what's going on here?

I filed a TSI/bug report with Apple in the meantime.

I can confirm the issue is still present, but after doing some testing I found out that what it's actually doing is blocking the main thread from executing. So a workaround that at least worked for me is executing the play function inside the background thread like this:

DispatchQueue.global(qos: .background).async {
player.prepareToPlay()
player.play()
}

Now the issue may still be present sometimes but i found that moving it to the background thread makes it way less tedious and less often. Also adding prepare to play also seems to make it work 99% of the time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM