UIWebview中的Youtube视频自动播放
我在这个论坛上发现了很多关于嵌入YouTube视频和自动播放的问题,但没有一个问题清除我的疑虑。
I found many questions in this forum regarding embedding youtube video and autoplay, but none of them cleared all my doubts.
我找到了两种方法来嵌入youtube视频UIWebView
I found two methods to embed youtube video in UIWebView
1)
NSString *youTubeHTMLTemplate = @"<html><head><style type=\"text/css\">body { background-color: transparent;color: white;}</style></head><body style=\"margin:0\"><embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" width=\"%0.0f\" height=\"%0.0f\"></embed></body></html>";
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, fullYopuTubeUrl, htmlFrameWidth, htmlFrameHeight];
2)
NSString *youTubeHTMLTemplate = @"<html><body style=\"margin:0;padding:0;\"><iframe class=\"youtube-player\" type=\"text/html\" width=\"%f\" height=\"%f\" src=\"http://www.youtube.com/embed/%@\" frameborder=\"0\" allowfullscreen></iframe></body></html>";
finalHtml = [NSString stringWithFormat:youTubeHTMLTemplate, htmlFrameWidth, htmlFrameHeight, videoID];
如果我使用(1)方法并遵循给定的方法其他我的视频自动播放。想法是在UIWebView中找到按钮并向其发送补充事件。
If I use (1) method and follow the approach given here my video autoplays. Idea is to find button in UIWebView and send touch up event to it.
如果我使用(2)并遵循相同的方法,则视频不会自动播放。
If I use (2) and follow the same approach video does not autoplay.
我认为建议使用(2)方法,因为(1)仅用于Flash视频(对吗?)。
I think that the (2) approach is recommended as the (1) is for Flash Videos only (Right?).
无论如何(2)是否可行?此链接显示NO。
Is by any means (2) is possible ? This link says NO.
任何人都可以确认
- 如果我是对的,推荐使用(2)
- 无法使用(2)进行自动播放。
问。如果我是正确的,建议推荐(2)
Q. If I am correct that (2) is recommended
A。是(2)方法适用于没有闪存支持的i设备。
A. Yes (2) method is for i-devices where no flash support.
Q.无法使用(2)进行自动播放。
Q. Autoplay with (2) is not possible.
A。目前无法自动播放。
A. No autoplay is not possible as of now.
更新:我可以使用Youtube JS API自动播放youtube视频,请参阅 https://developers.google.com/youtube/js_api_reference
Update: I am able to autoplay youtube video by using Youtube JS APIs see https://developers.google.com/youtube/js_api_reference
只需从中调用playVideo onPlayerReady
Just call playVideo from onPlayerReady
function onPlayerReady(event) {
event.target.playVideo();
}