本文介绍了从AVPlayer设置MPNowPlayingInfoCenter持续时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试设置MPNowPlayingInfoCenter,大多数键值对都可以正常工作,但是播放时间存在一些问题
I am trying to set MPNowPlayingInfoCenter, most of the key-value pairs work fine, but there is some kind of issue with playback time
let mpic = MPNowPlayingInfoCenter.defaultCenter()
mpic.nowPlayingInfo = [
MPMediaItemPropertyArtwork:albumArtWork,
MPMediaItemPropertyTitle:titleString,
MPMediaItemPropertyArtist:artistName,
MPMediaItemPropertyPlaybackDuration:99,
MPNowPlayingInfoPropertyElapsedPlaybackTime:String(stringInterpolationSegment:self.myPlayer.currentItem?.currentTime()),
MPNowPlayingInfoPropertyPlaybackRate:1.0
]
这有效,信息中心将正确开始计数.
this works and InfoCenter will correctly start counting.
我尝试尝试类似的方法
MPMediaItemPropertyPlaybackDuration:String(stringInterpolationSegment:self.myPlayer.currentItem?.duration())
它将失败.我应该将CMTime转换为两倍吗?我还应该访问其他财产吗?
it will fail. Should I be converting CMTime to double? Is there any other property I should access?
推荐答案
尝试一下
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
duration should be as String / like : 02:24
这篇关于从AVPlayer设置MPNowPlayingInfoCenter持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!