我正在使用适用于YouTube的JS API并显示视频播放器use of embedSWF is recommended by Google in the documentation,如下所示:
<script type="text/javascript" src="swfobject.js"></script>
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/VIDEO_ID?enablejsapi=1&playerapiid=ytplayer&version=3","ytapiplayer", "425", "356", "8", null, null, params, atts);
</script>
虽然这在我的计算机和Android设备上运行良好,但在iOS上, ytapiplayer div不会变成嵌入式播放器,而只是显示其原始内容,即显示Flash Player 8+的错误消息和JS是必需的。
是否有可能让我在iOS上工作?如果是这样,怎么样?
提前致谢!
答案 0 :(得分:3)
也许您应该尝试新的YouTube iframe播放器API? https://developers.google.com/youtube/iframe_api_reference
它可以在不考虑Flash的情况下与移动设备配合使用。 嵌入示例:
<script type="text/javascript" src="//www.youtube.com/iframe_api"></script>
function onYouTubePlayerAPIReady() {
var videoBox = document.getElementById('video1');
videoBox.ytplayer = new YT.Player(videoBox, {
videoId: 'kXDiGtgPL6E',
playerVars: {
//controls: 0,
wmode:'transparent'
},
height: '200',
width: '320'
});
}
答案 1 :(得分:0)
几个月前我为一个项目做了这件事......
Javascript,与您拥有的非常相似:
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript">
var flashvars = {};
flashvars.youTubeVideo = "VitQwgsBq-w";
flashvars.controllerAlign = "top";
flashvars.queTo = "0";
flashvars.controlBarAlpha = ".3";
var params = {};
var attributes = {};
swfobject.embedSWF("images/youTubeLoader.swf", "youTubeDiv", "250px", "200px", "9.0.0", false, flashvars, params, attributes);
</script>
swfobject.js要做的是查找名为“youTubeDiv”的HTML div并用SWF youtube播放器替换所有内容
(我做了这个b / c iframe解决方案与我正在处理的HTML5项目有z-index问题)
现在HTML:
<div id="youTubeDiv">
<iframe width="250px" height="200px" src="http://www.youtube.com/embed/VitQwgsBq-w" frameborder="0" allowfullscreen></iframe>
</div>