How to make YouTube video starts to play automatic

2019-08-13 19:44发布

I have video embedded in my application using this solution (html string in UIWebView): http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

Unfortunately client requires his own thumbnail. I would like to solve it by creating UIWebView once he taps on this thumbnail and play the video inside automatically.

How can I do it?

2条回答
一夜七次
2楼-- · 2019-08-13 20:06

Try this:-

NSString *htmlString = [NSString stringWithFormat:@"<html><head>"
                        "<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 50\"/></head>"
                        "<body style=\"background:#F00;margin-top:0px;margin-left:0px\">"
                        "<div><object width=\"50\" height=\"50\">"
                        "<param name=\"movie\" value=\"%@\"></param>"
                        "<param name=\"wmode\" value=\"transparent\"></param>"
                        "<embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"50\" height=\"50\"></embed>"
                        "</object></div></body></html>",[d objectForKey:@"hrefUrl"],[d objectForKey:@"hrefUrl"]];

[videoView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.your-url.com"]];
查看更多
等我变得足够好
3楼-- · 2019-08-13 20:12

Following is the html string to play video automatically inside UIWebView...

NSString *embedHTML = [NSString stringWithFormat:@"<html><body><video controls=\"controls\" autoplay=\"autoplay\"><source src=\"%@\" type=\"video/mp4\"/></video></body></html>", url];
[_webView loadHTMLString:embedHTML baseURL:baseURL];

I have tried the following one, it is working fine and also starts to play automatically.

NSString *embedHTML = @"<html><body bgcolor="black"><embed id="yt" src="http://www.youtube.com/watch?v=9vyYHVB-QnY"type="application/x-shockwave-flash" width="320.00" height="370.00"></embed></body></html>";
[_webView loadHTMLString:embedHTML baseURL:baseURL]; 
查看更多
登录 后发表回答