I’m using UIWebView to play YouTube videos in an iPad.
How can I detect when a YouTube video is finished playing?
I see the play icon in the status bar and I tried to use MPMusicPlayerController notifications to detect playbackStateDidChange, but it didn’t work.
Any ideas how to detect this event? Again, I’m talking about iPad not iPhone.
Thanks in advance.
Update:
If you use zero solution to detect the end of playing and also want the Youtube video to start automatically set the UIWebView to :
self.webView.mediaPlaybackRequiresUserAction = NO ;
I just want to clarify about the YouTube frame API:
“Important: This is an experimental feature, which means that it might
change unexpectedly” (08/05/2012)
No, there’s no way to directly get web page event from
UIWebView. But we can accomplish this by using Javascript.These links may help:
Calling Objective-C from JavaScript in an iPhone UIWebView
Javascript callback in Objective-C
YouTube iFrame API
updated with an example:
in UIWebView’s delegate, i put:
}
the web page is load when
viewDidLoad:and in youtube.html i put:
you can see i add
to YouTube’s iFrame API demo, and it catches the player end playing event and try to load a request with scheme “callback”, then the UIWebView Delegate could catch it.
You can use this method to trigger any event using JavaScript;