Search code examples
iosobjective-cmpmovieplayercontroller

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.


Solution

  • 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
    
     }