swift - 无法在 Carplay 音乐上显示专辑封面
问题描述
我正在构建一个可以与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 中(在真实设备上),因为现在正在播放的组件只是被代理了。
推荐阅读
- python - 如何修复“NameError:名称'checker_start'未定义”
- node.js - Ionic 4 聊天应用程序以及如何向特定用户发送消息?
- powermock - 如何使 powermock 与 Java11 一起工作?
- regex - 正则表达式 - 根据不同的字符串条件替换特定的字符串
- javascript - 从 qgis2threejs 导出的 3D 地图代码修改后的空白页
- java - JavaFX 正在工作,但 try-catch-finally 代码不起作用
- c# - 通过单击整个项目来检查 wpf 中的 ckeckbox
- laravel - 附加多对多关系,同时仍绑定到创建的事件
- android - 我的列表视图没有填充,我的适配器有问题吗?
- matlab - 从其回调中停止 Matlab 计时器(在外部输入/事件之后)