[英]Can not show album artwork on Carplay music
我正在構建一個可以與Apple Carplay集成的iOS音樂應用程序,我可以在Carplay上正常播放音樂,並可以顯示歌曲的一些信息,如標題、專輯、藝術家姓名。 但是無法顯示專輯封面。
這是在 Carplay 上顯示媒體信息的批量代碼:
if let nowPlayingItem: PlaylistItem = self.nowPlayingItem {
let info: NSMutableDictionary = NSMutableDictionary()
info[MPMediaItemPropertyArtist] = nowPlayingItem.mediaItem?.artist?.name
info[MPMediaItemPropertyAlbumTitle] = nowPlayingItem.mediaItem?.album?.title
info[MPMediaItemPropertyTitle] = nowPlayingItem.mediaItem?.title
info[MPMediaItemPropertyPlaybackDuration] = nowPlayingItem.mediaItem?.playbackDuration
info[MPMediaItemPropertyArtwork] = nowPlayingItem.mediaItem?.artwork()
let sec: TimeInterval = CMTimeGetSeconds(time)
info[MPNowPlayingInfoPropertyElapsedPlaybackTime] = Int(sec)
MPNowPlayingInfoCenter.default().nowPlayingInfo = info as? [String: Any]
}
這是我當前的應用程序:
這就是我想要的:
那我該怎么辦? 請幫我找到解決方案。
您可能正在模擬器上進行測試。 雖然有時需要以下代碼來顯示正在播放的屏幕,但目前無法讓 CarPlay 模擬器確定玩家實際正在播放:
#if targetEnvironment(simulator)
UIApplication.shared.endReceivingRemoteControlEvents()
UIApplication.shared.beginReceivingRemoteControlEvents()
#endif
我無法讓專輯插圖顯示在模擬器中正在播放的屏幕上。 您是否可以使用實體車載收音機(我強烈建議您在提交到 App Store 之前對其進行測試)? 我知道這可能不是很有說服力,但如果你的作品出現在 iPhone 的通知中心播放器中,它也會出現在 CarPlay 中(在真實設備上),因為現在正在播放的組件只是被代理了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.