MPNowPlayingInfoCenter信息被AVPlayer覆盖

时间:2015-11-29 00:20:37

标签: ios swift avplayer mpnowplayinginfocenter

我正在使用一个iOS应用程序,它使用AVPlayer播放由AVPlayerItems代表的歌曲。

我已经尝试设置MPNowPlayingInfoCenter.defaultCenter()的nowPlayingInfo属性,但似乎信息被AVPlayer立即覆盖,因为它需要更新其他信息,如elapsedTime和playbackDuration。

即使在程序执行后立即

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo?[MPMediaItemPropertyTitle] = "Title"

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo的打印输出

  

信息:[“MPNowPlayingInfoPropertyElapsedPlaybackTime”:34.89555007300078,“AVNowPlayingInfoControllerIdentifierKey”:< __ NSConcreteUUID 0x13778e9b0> 9141DD1C-FD09-4210-B3C7-B948522E3AF6,“playbackDuration”:198.2516666666667,“MPNowPlayingInfoPropertyPlaybackRate”:1]

我做错了什么?是否可以在AVPlayerItem中存储标题/专辑名称等其他元数据,以便在信息中心显示?

另外,什么是AVNowPlayingInfoControllerIdentifierKey?似乎没有任何名为AVNowPlayingInfoController的类。

1 个答案:

答案 0 :(得分:2)

问题在于这一行什么都不做:

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo?[MPMediaItemPropertyTitle] =
    "Title"

即使该行实际上做了任何事情,您也可以提取 nowPlayingInfo副本作为单独的字典,然后写入该单独的字典。你不会写入实际正在播放的信息,这就是你想要做的。

正确的方法是形成字典,然后将MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo 设置为该字典

例如:

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = 
    [MPMediaItemPropertyTitle : "Title"]

(当然字典可以有更多条目。)

相关问题