1

我正在尝试设置 MPNowPlayingInfoCenter,大多数键值对都可以正常工作,但是播放时间存在某种问题

let mpic = MPNowPlayingInfoCenter.defaultCenter()    

mpic.nowPlayingInfo = [
    MPMediaItemPropertyArtwork:albumArtWork,
    MPMediaItemPropertyTitle:titleString,
    MPMediaItemPropertyArtist:artistName,
    MPMediaItemPropertyPlaybackDuration:99,
    MPNowPlayingInfoPropertyElapsedPlaybackTime:String(stringInterpolationSegment:self.myPlayer.currentItem?.currentTime()),
    MPNowPlayingInfoPropertyPlaybackRate:1.0
]

这有效,InfoCenter 将正确开始计数。

一旦我尝试类似

MPMediaItemPropertyPlaybackDuration:String(stringInterpolationSegment:self.myPlayer.currentItem?.duration())

它会失败。我应该将 CMTime 转换为双倍吗?还有其他我应该访问的财产吗?

4

1 回答 1

0

尝试这个

    let elapsedTime = NSNumber(double : CMTimeGetSeconds(AudioAvPlayer.currentItem!.currentTime()))
    let keys = NSArray(objects:
        MPMediaItemPropertyTitle,
        MPMediaItemPropertyArtist,
        MPMediaItemPropertyPlaybackDuration,
        MPNowPlayingInfoPropertyPlaybackRate,
        MPNowPlayingInfoPropertyElapsedPlaybackTime)
    let values = NSArray (objects:
        m_PlayContent.Title,
        m_PlayContent.Artist,
        m_PlayContent.Duration,
        NSNumber(integer: 1),
        elapsedTime)
    let mediaInfo = NSDictionary(objects: values as [AnyObject], forKeys: keys as! [NSCopying])
    MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = mediaInfo as [NSObject : AnyObject]

持续时间应为 String / like : 02:24

于 2015-09-27T06:26:56.140 回答