I have a code which embed a youtube video in web view through HTML. Video is playing perfectly alright. What i want to do is get callbacks when in Objective c when a user pause , close , play video. Any Help? There are many other questions but none of them explained how to modify for javascript and Objective C- Callback. Being a new i need a detailed answer Here is my code
- (void)playVideoWithId:(NSString *)videoId {
static NSString *youTubeVideoHTML = @"<!DOCTYPE html><html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = \"http://www.youtube.com/player_api\"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'%0.0f', height:'%0.0f', videoId:'%@', events: { 'onReady': onPlayerReady, } }); } function onPlayerReady(event) { event.target.playVideo(); } </script> </body> </html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, self.view.frame.size.width, self.view.frame.size.height, videoId];
videoWebview.mediaPlaybackRequiresUserAction = NO;
[self.view bringSubviewToFront:videoWebview];
[videoWebview loadHTMLString:html baseURL:nil];
}