为KVO
添加了AVPlayer
何时播放视频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
个seekToTime
stepByCount
无法正常使用Values
编辑:object
中使用的methods
correct
为no luck
,即使{{1}}
答案 0 :(得分:4)
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
的{{1}} exact location
{/ 1}}