播放实时视频时,SeekToTime方法在iOS 9中不起作用。即使在搜索之后,视频也不会从搜索位置播放。
在以前的iOS版本中,它可以正常工作。
以下是代码...
-(无效)loadVideo {
[player pause];
player = nil;
asset = [AVAsset assetWithURL:[NSURL URLWithString:@"http://playertest.longtailvideo.com/adaptive/wowzaid3/playlist.m3u8"]];
playerItem = [AVPlayerItem playerItemWithAsset:asset];
player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = CGRectMake(20, 0, 600, 400);
[self.view.layer addSublayer:playerLayer];
[player play];
[self addPlayerTimeObserver];
}
-(IBAction)SeekToTimeInVideo:(id)sender {
[玩家暂停];
[self.player seekToTime:CMTimeMakeWithSeconds(10.0, 25.0) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished)
{
[player play];
}];
}
任何的想法 ??这是iOS 9中的错误吗?
最佳答案
刚刚也遇到了这个问题。我看到的情况是,当您调用-[AVPlayer seekToTime:]
时,如果AVPlayer暂停了,播放器将跳至最近的HLS段的末尾。
我的解决方案是在调用[player play]
之前立即调用-[AVPlayer seekToTime:]
...因此,您将获得以下信息:
[self.player play]
[self.player seekToTime:CMTimeMakeWithSeconds(10.0, 25.0) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished)
{
[player play];
}];