简体   繁体   English

MPMusicPlayerController 无法播放 Apple Music 歌曲

[英]MPMusicPlayerController fails to play Apple Music songs

I am using an instance of MPMusicPlayerController.systemMusicPlayer to enqueue an array of store IDs.我正在使用MPMusicPlayerController.systemMusicPlayer的实例来排队存储 ID 数组。 This has worked for months now.这已经工作了几个月了。 Earlier today I updated to iOS 14.3, and the player is now failing to play songs.今天早些时候我更新到 iOS 14.3,播放器现在无法播放歌曲。

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. MPMusicPlayerController在 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.与此同时,我向 Apple 提交了一份 TSI/错误报告。

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:因此,至少对我有用的解决方法是在后台线程中执行播放 function,如下所示:

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.此外,添加准备玩似乎也使它在 99% 的时间里都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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