Reputation: 2284
In my app Im playing an video using MPmoviePlayerViewController.
actually some videos are too long to watch around 3-5 mins.
I want to allow user to SKIP the video after 10 seconds if he wants.
My requirement is I need to display the count down 10, 9, 8 -- 0 after 10th secod of the the video we display a skip button.
_moviePlayerViewController = [[MPMoviePlayerViewController alloc] init ];
[_moviePlayerViewController.view setFrame:self.view.frame];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayerViewController.moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(MPMoviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
_moviePlayerViewController.moviePlayer.shouldAutoplay = YES;
[_moviePlayerViewController.moviePlayer setFullscreen:YES];
_moviePlayerViewController.moviePlayer.repeatMode = MPMovieRepeatModeNone;
_moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
_moviePlayerViewController.moviePlayer.scalingMode = MPMovieScalingModeNone;
_moviePlayerViewController.moviePlayer.contentURL =[NSURL fileURLWithPath:videoPath];
in this application we have play back option, ie if the user quit the application he can resume the video from the point of going background.
in both the case (resume after come foreground, and just now started video)
the user should see a skip button when the video play time is 10 seconds.
Can any one help please
Upvotes: 0
Views: 310
Reputation: 657
For playback option you can use [_moviePlayerViewController.moviePlayer pause];
when going in background and can again resume play from where it was when again come to foreground.
In case if user quit application you can provide playback option also. You can manage a counter variable separately, which count for how seconds the video is playing. Store the value of this counter when user quit application, in short store the value when player stops playing. Now when you again come back to this view you can check the actual length of video and compare with the duration for which it has already played and play back.This can be tricky but the pause thing mentioned above did work.
EDIT: For hiding and displaying skip button after 10sec the counter solution is perfect.
Upvotes: 1
Reputation: 5684
What the problem? Use dispatch_after
for 5 seconds pause then inside dispatch block run one second timer to count seconds remaining
EDIT
Oh I'm sorry, you need just one NSTimer
and seconds counter ivar to track how many seconds passed from the video start
Upvotes: 1