我正在尝试设置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转换为双倍吗?我应该访问其他任何财产吗?
答案 0 :(得分: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