Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can use webview as youtube player </p> <p><strong>Try Below Code</strong> it is working for me</p> <p>in .h file</p> <pre><code>@property (strong, nonatomic) UIWebView *webView; </code></pre> <p>and in your .m file </p> <pre><code> NSString *videoURL = @"http://www.youtube.com/embed/M7lc1UVf-VE?autoplay=1&amp;origin=http://example.com"; // if your url is not in embed format or it is dynamic then you have to convert it in embed format. videoURL = [videoURL stringByReplacingOccurrencesOfString:@"watch?v=" withString:@"embed/"]; NSRange range = [videoURLString rangeOfString:@"&amp;"]; @try { videoURLString = [videoURLString substringToIndex:range.location]; } @catch (NSException *exception) { } // here your link is converted in embed format. NSString* embedHTML = [NSString stringWithFormat:@"\ &lt;html&gt;&lt;head&gt;\ &lt;style type=\"text/css\"&gt;\ iframe {position:absolute; top:50%%; margin-top:-130px;}\ body {\ background-color: transparent;\ color: white;\ }\ &lt;/style&gt;\ &lt;/head&gt;&lt;body style=\"margin:0\"&gt;\ &lt;iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen&gt;&lt;/iframe&gt;\ &lt;/body&gt;&lt;/html&gt;",videoURL]; self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; [self.view addSubview:self.webView]; [self.webView loadHTMLString:embedHTML baseURL:nil]; </code></pre> <p>Here you can change <strong>webview frame</strong> as you want and also can change <strong>videoUrl</strong>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload