[英]How to set current playback duration and elapsed time on iOS 7 lockscreen?
[英]AVPlayer set initial playback time iOS
為AVPlayer
添加了KVO
何時播放視頻,因為queuePlayer
是AVPlayer
[self.queuePlayer addObserver:self forKeyPath:@"status" options:0 context:NULL];
observer
method
:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"status"]) {
if (self.queuePlayer.status == AVPlayerStatusReadyToPlay) {
NSInteger step = (NSInteger)(startTimeForVideo/0.04);
[self.queuePlayer.currentItem stepByCount:step];
//CMTime seekTime = CMTimeMake(startTimeForVideo*timeScale,timeScale);
//if (CMTIME_IS_VALID(seekTime))
// [self.queuePlayer seekToTime:seekTime toleranceBefore:kCMTimePositiveInfinity toleranceAfter:kCMTimePositiveInfinity];
//else
// NSLog(@"In valid time");
[self.queuePlayer play];
} else if (self.queuePlayer.status == AVPlayerStatusFailed) {
/* An error was encountered */
}
}
這里有startTimeForVideo
playBack time
video
playBack time
seekToTime
既不工作也不工作stepByCount
編輯 : methods
中使用的object
Values
是correct
,即使no luck
作為queuePlayer
KVO
方法的queuePlayer
是AVPlayer
:
if (self.queuePlayer.status == AVPlayerStatusReadyToPlay)
{
//firstly make cmtime as here startTimeForVideo is Float64 value in seconds
//get video's time scale as CMTime has it.
int32_t timeScale = self.queuePlayer.currentItem.asset.duration.timescale
CMTime seektime=CMTimeMakeWithSeconds(startTimeForVideo, timeScale);
//use this cmtime for seekToTime.
[self.queuePlayer seekToTime:seektime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}
............
編輯 :這里kCMTimeZero
在兩個tolerance field
用於kCMTimeZero
中的exact location
seekToTime: toleranceBefore: toleranceAfter:
method
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.