簡體   English   中英

MPMusicPlayerController 無法播放 Apple Music 歌曲

[英]MPMusicPlayerController fails to play Apple Music songs

我正在使用MPMusicPlayerController.systemMusicPlayer的實例來排隊存儲 ID 數組。 這已經工作了幾個月了。 今天早些時候我更新到 iOS 14.3,播放器現在無法播放歌曲。

下面的代碼是復制錯誤所需的最少數量:

// 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

當我播放歌曲而不是播放歌曲時,應用程序完全凍結(意味着它不響應用戶交互),並且我看到以下日志:

[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

MPMusicPlayerController在 iOS 14.2 上播放音樂很好。

任何人都可以確認或闡明這里發生了什么嗎?

與此同時,我向 Apple 提交了一份 TSI/錯誤報告。

我可以確認問題仍然存在,但是在進行了一些測試后,我發現它實際上在做的是阻止主線程執行。 因此,至少對我有用的解決方法是在后台線程中執行播放 function,如下所示:

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

現在問題有時可能仍然存在,但我發現將其移至后台線程使其變得不那么乏味且不那么頻繁。 此外,添加准備玩似乎也使它在 99% 的時間里都能正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM