首页 文章

Youtube iframe API无法用于移动设备?

提问于
浏览
5

我很迷惑 . 带有标准示例的Youtube Iframe API:https://developers.google.com/youtube/iframe_api_reference?hl=de始终用于我的移动设备,现在不再起作用了..

我试过这个小提琴:http://jsfiddle.net/77PJB/3/

<div id="player"></div>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
    height: '250',
    width: '444',
videoId: 'M7lc1UVf-VE',
events: {
  'onReady': onPlayerReady
}
});
}

function onPlayerReady(event) {
event.target.playVideo();

}

与iPad,iPhone和三星galaxy nexus . 视频没有播放..有什么变化吗?

谢谢

3 回答

  • 0

    移动注意事项自动播放和脚本播放在某些移动浏览器(例如Chrome和Safari)中,HTML5元素仅允许在用户交互(例如点击播放器)启动时进行播放 . 以下是Apple文档的摘录:“警告:为了防止用户通过蜂窝网络进行未经请求的下载,嵌入式媒体无法在iOS上的Safari中自动播放 - 用户始终会启动播放 . ”由于此限制,自动播放,playVideo(),loadVideoById()等功能和参数将无法在所有移动环境中使用 .

    来自:https://developers.google.com/youtube/iframe_api_reference#Mobile_considerations

    一个简单的解决方法,具有“播放”按钮的自定义外观:

    使用pointer-events: none;覆盖元素 . pointer-events 适用于所有现代mobile browsers或只是将视频容器放在按钮上 opacity: 0 .

  • 1

    大多数移动设备都不允许使用自动播放功能,因此如果您认为它可以正常工作

  • 7

    如果浏览器不是移动浏览器,则仅限.playVideo() . 检测移动浏览器的方法有很多种,如下所示:Detecting a mobile browser

    例如:

    if(typeof window.orientation == 'undefined'){
      player.playVideo();
    };
    

相关问题