0

Hi I have a Youtube Url not embed Url.

I want to play that video on UIWebView when I come to that screen.

Tried

appending autoplay=1,

Tried

[self.webView setAllowsInlineMediaPlayback:YES];     
self.webView.allowsInlineMediaPlayback=YES;`  
self.webView.mediaPlaybackRequiresUserAction = NO; 
aberna
  • 5,594
  • 2
  • 28
  • 33
Ajith Kumar
  • 1,202
  • 1
  • 10
  • 22
  • 1
    possible duplicate http://stackoverflow.com/questions/15717754/objective-c-how-to-autoplay-a-youtube-video-in-a-uiwebview – nickalchemist Feb 13 '15 at 06:15

1 Answers1

0
[self loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]]; 


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>";  

- (void)playVideoWithId:(NSString *)videoId {
    NSString *html = [NSString stringWithFormat:youTubeVideoHTML, self.frame.size.width, self.frame.size.height, videoId];

    [self loadHTMLString:html baseURL:[[NSBundle mainBundle] resourceURL]];
}
nickalchemist
  • 2,211
  • 6
  • 31
  • 58