Andrew Drozdov
Andrew Drozdov

Reputation: 2183

How to tell if MoviePlayerController has ever played?

I want to prevent a user from performing an action until they have at least pressed play on the MoviePlayerController. Would also be helpful to know if they have watched the video all the way through, or how far they have watched.

Upvotes: 0

Views: 73

Answers (3)

cyrilchampier
cyrilchampier

Reputation: 2248

you can also save the state in a persistent way, so the user will not have to view the video at each application session:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"videoViewed"];

and elswhere in the program:

if ([[NSUserDefaults standardUserDefaults] boolForKey:@"videoViewed"]) {
  do stuff
}

Upvotes: 0

Andrew Drozdov
Andrew Drozdov

Reputation: 2183

At some point register for a playback notification like so:

[[NSNotificationCenter defaultCenter] addObserver:self 
    selector:@selector(playbackStateChanged) 
    name:MPMoviePlayerPlaybackStateDidChangeNotification object:nil];

Then, within playbackStateChanged, you can indicate that you have played the video with some BOOL:

 - (void) playbackStateChanged {

   if(moviePlayerController.playbackState == MPMoviePlaybackStatePlaying){
     hasPlayed = YES; //BOOL value
   }// reading the playback

 }

Upvotes: 1

lakshmen
lakshmen

Reputation: 29064

You can set a variable called countOfTimesButtons. You can have an IBAction on the play button and when it is clicked, you can increase the countOfTimesButtons pressed. If the countOfTimesButtons is greater than 0, you can do something depending on your circumstance.

Hope this helps...

Upvotes: 0

Related Questions