gpt4 book ai didi

ios - Apple Music 歌曲播放无法正常工作

转载 作者:行者123 更新时间:2023-11-30 11:29:07 25 4
gpt4 key购买 nike

尝试使用以下代码使用 MPMusicPlayerController 播放歌曲

let musicPlayerController = MPMusicPlayerController.systemMusicPlayer

func beginPlayback(itemID: String) {

let descripter = MPMusicPlayerStoreQueueDescriptor(storeIDs: [itemID])
descripter.startItemID = itemID

musicPlayerController.setQueue(with: descripter)

musicPlayerController.prepareToPlay(completionHandler: {(error : Error?) in
print()
self.musicPlayerController.play()
})


}

但是,在控制台中我经常看到

[MPMusicPlayerController prepareToPlay] timeout

要么什么也没有发生,要么播放器会以错误的歌曲开始,可能是我设备本地的歌曲。

我正在尝试播放 Apple Music 库中的一首歌曲,我使用他们的 API 来获取我的播放列表,然后播放歌曲,轨道响应如下所示:

attributes =     {
albumName = Villains;
artistName = "Queens of the Stone Age";
artwork = {
height = 1200;
url = "https://is3-ssl.mzstatic.com/image/thumb/Music117/v4/8b/19/86/8b19867d-f500-5396-bd6f-e89c0a69adcd/dj.tvdpbelw.jpg/{w}x{h}bb.jpg";
width = 1200;
};
durationInMillis = 341825;
name = "Feet Don\U0092't Fail Me";
playParams = {
id = "i.B0VN4GGf7Eldk";
isLibrary = 1;
kind = song;
};
trackNumber = 1;
};
href = "/v1/me/library/songs/i.B0VN4GGf7Eldk";
id = "i.B0VN4GGf7Eldk";
type = "library-songs";

}

我在这里使用“id”作为 beginPlayback 的 itemID 播放参数 (i.B0VN4GGf7Eldk)。这是正确的还是应该是别的什么?试图找出为什么这不会播放。

编辑:

也在控制台中看到这一点

[SDKPlayback] -[MPMusicPlayerController prepareToPlayWithCompletionHandler:] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1 "No commands provided." UserInfo={NSDebugDescription=No commands provided.} [SDKPlayback] -[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0" UserInfo={NSDebugDescription=Failed to send command 0, NSUnderlyingError=0x1c8045b20 {Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}}}

最佳答案

事实证明,对于库项目,我不应该使用 Web API。我应该只是从 MediaPlayer API 访问该库。

我可以通过以下方式访问我的播放列表

let playlistQuery = MPMediaQuery.playlists()

那么每个商品都有一个商店ID

let playlist = playlistQuery.first
for item in playlist.items {
print(item.playbackStoreId)
}

我可以使用该 ID 来播放项目。

关于ios - Apple Music 歌曲播放无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com