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.