seekToTime is not working for Live assets in iOS 9

443 views Asked by At

SeekToTime method is not working in iOS 9 while playing live videos. Even after seek, video is not playing from seeked position. In previous iOS versions it works fine. Following is the code...

-(void)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{ [player pause];

[self.player seekToTime:CMTimeMakeWithSeconds(10.0, 25.0) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished)
{
    [player play];

}];

}

Any idea ?? Is this a bug in iOS 9.

1

There are 1 answers

0
irtemed88 On

Just encountered this issue too. The case I was seeing was if AVPlayer was paused when you call -[AVPlayer seekToTime:], the player would jump to the end of the most recent HLS segment.

My solution was to call [player play] right before calling -[AVPlayer seekToTime:]... So you'll have this:

[self.player play]
[self.player seekToTime:CMTimeMakeWithSeconds(10.0, 25.0) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished)
{
    [player play];
}];