Reputation: 2413
I have used seekToTime in my application and its working properly. But I want to have some more information about it. Which is, if I have a streaming video file of 1 minute now I want to play it from second 15th to second 45 (first 15 seconds and the last 15 seconds will not play).
How can I do it?
I know that by use of seekToTime I can play a video from 15th second but how to stop it at 45th second and also get noticed by the method that the video has played for the specified time period?
CMTime timer = CMTimeMake(15, 1);
[player seekToTime:timer];
The above code takes me to the 15th second of the streaming file but how to stop it on 45th second and get notified too?
I have searched a lot but couldn't get any info.
Thanks
EDIT:
As @codeghost suggested, simply use forwardPlaybackEndTime
.
You can simply use:
yourAVPlayerItem.forwardPlaybackEndTime = CMTimeMake(10, 1);
Here 10 is the time till the AVPlayerItem will play.
Upvotes: 5
Views: 6024
Reputation: 55
You can use [AVPlayer addPeriodicTimeObserverForInterval:queue:usingBlock:]
for that purpose.
Get the AVPlayer.currentTime
periodically, and call pause or stop on the exact time.
Upvotes: 0
Reputation: 7900
I don't know if there is something build-in for this in AVPlayer
, but what i would do is build an function and call it with :
[self performSelector:@selector(stopPlaying) withObject:nil afterDelay:45];
-(void)stopPlaying{
[player pause];
}
this will stop playing after 45 seconds,and of course you can put instead 45 any number of seconds that you want.
Upvotes: 0