1

I have this application(written by a previous workmate), it calls a video website to show video list, and when a user clicks on one vedio, the app automatically create a MPMoviePlayer and plays the video.

What I am asked to do is to add ads when users pause the video. But it seems I can't get the MPMoviePlayerPlaybackStateDidChangeNotification by adding an observer.

I did some research and found these solutions:

Media Callbacks with Embedded YouTube Videos on iOS

How to receive NSNotifications from UIWebView embedded YouTube video playback

Get Notification when a video starts or stops in UIWebView

But none of them work, at least for ios8. Here is the code I use from the advice from the third url:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playbackStateDidChange:)
                                                 name:@"MPAVControllerPlaybackStateChangedNotification"
                                               object:nil];
- (void)playbackStateDidChange:(NSNotification *)note
{
    NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
    int playbackState = [[note.userInfo objectForKey:@"MPAVControllerNewStateParameter"] intValue];
    switch (playbackState) {
        case 1: //end
            ;
            break;
        case 2: //start
            ;
            break;
        default:
            break;
    }
}

So what can I do? If I want to create MPMoviePlayer by myself, does that mean I have to implement a view which looks like the video list html the app uses now? I think this is a lot of work to do. So if there is any way to get PlaybackState notification from the MPMoviePlayer embedded in UIWebview?

Any help would be appreciated.

Community
  • 1
  • 1
Demonedge
  • 1,363
  • 4
  • 18
  • 33

1 Answers1

0

Please show your observer and selector triggered by the notification. One more thing - try to clarify "pause the video" meaning - is that pausing of the webview or direct pausing of the MoviePlayer? There shouldn't be any reason why notification would not sent from the player, so showing your code may be helpful.

points 1 and 2 from your research present different issue, the last one solved with correct observer, that's the direction (as long as the video player is actually MPMoviePlayer type).

DocForNoc
  • 346
  • 2
  • 13
  • Thx! I added my code above, it's just the same code from the third url. By pausing I mean pausing the MoviePlayer because the app calls the MoviePlayer when the video plays. – Demonedge Oct 20 '15 at 15:16