【发布时间】:2014-04-26 23:13:10
【问题描述】:
这些天我搜索这个问题,但我找不到解决方案。我在 UIWebview 中使用 youtube 和 iframe。我想通过以下代码使其在不自动播放的情况下直接播放
embedHTML = [NSString stringWithFormat:@"\
<html>\
<body style='margin:0px;padding:0px;'>\
<script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>\
<script type='text/javascript'>\
function onYouTubeIframeAPIReady()\
{\
ytplayer=new YT.Player('playerId')\
}\
</script>\
<iframe id='playerId' type='text/html' width='%d' height='%d' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=0' frameborder='0'>\
</body>\
</html>", (int)myWidth, (int)myHeight, _youtubeCode];
但它不起作用。如果使用此代码,则单击 webview 播放视频,它允许弹出视频播放器播放视频。
我只能通过以下代码成功播放视频,但它必须自动播放视频
embedHTML = [NSString stringWithFormat:@"\
<html>\
<body style='margin:0px;padding:0px;'>\
<script type='text/javascript' src='http://www.youtube.com/iframe_api'></script>\
<script type='text/javascript'>\
function onYouTubeIframeAPIReady()\
{\
ytplayer=new YT.Player('playerLiveId',{events:{onReady:onPlayerReady}})\
}\
function onPlayerReady(a)\
{ \
a.target.playVideo(); \
}\
</script>\
<iframe id='playerLiveId' type='text/html' width='%d' height='%d' src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'>\
</body>\
</html>", (int)myWidth, (int)myHeight, _youtubeCode];
我需要你的帮助。顺便说一句,对不起我的英语。
【问题讨论】:
标签: ios iframe uiwebview youtube-api