如何让YouTube视频开始在UIWebView中自动播放

时间:2012-03-01 09:44:01

标签: iphone ios youtube

我使用此解决方案(UIWebView中的html字符串)在我的应用程序中嵌入了视频: http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

不幸的是,客户需要自己的缩略图。我想通过创建UIWebView来解决它,一旦他点击这个缩略图并自动播放视频。

我该怎么做?

2 个答案:

答案 0 :(得分:0)

试试这个: -

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

答案 1 :(得分:-2)

以下是在UIWebView中自动播放视频的html字符串...

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

我尝试了下面的一个,它工作正常,也开始自动播放。

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]; 
相关问题