我在这个论坛中发现了很多关于嵌入 youtube 视频和自动播放的问题,但没有一个能解决我所有的疑问.
I found many questions in this forum regarding embedding youtube video and autoplay, but none of them cleared all my doubts.
我找到了两种在 UIWebView 中嵌入 youtube 视频的方法
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)是可能的吗?这个链接说不.
Is by any means (2) is possible ? This link says NO.
谁能确认一下
Q.如果我是正确的,推荐(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.
问.无法使用 (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
只需从 onPlayerReady 调用 playVideo
Just call playVideo from onPlayerReady
function onPlayerReady(event) {
event.target.playVideo();
}
这篇关于UIWebview 内的 Youtube 视频自动播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!