Vimeo API播放失败,因为用户未先与文档进行交互

时间:2019-03-07 15:49:42

标签: vimeo vimeo-api vimeo-player

Vimeo播放器现在即使具有allow =“ autoplay”属性也可以播放,请检查jsfiddle控制台错误,单击小图标播放按钮:

https://jsfiddle.net/0vfLtdm8/

var player = document.getElementById('video-player');
var vimeoPlayer = new Vimeo.Player(player);

playbtn.onclick = function() {
  vimeoPlayer.play();
}
vimeoPlayer.on('error', function(error) {
  console.log(error);	
});
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<script src="https://player.vimeo.com/api/player.js"></script>

<div id="video-outer-full">
  <div id="video-inner">
    <i class="far fa-play-circle" id="playbtn"></i>
    <iframe id="video-player" class="video" width="560" height="315" src="https://player.vimeo.com/video/309741585" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen allow="autoplay"></iframe>
  </div>
</div>

1 个答案:

答案 0 :(得分:1)

@Toniq,这是特定于jsfiddle和类似于Codepen的服务的问题。

在这些测试页上,他们将用户定义的测试内容包装在iframe中,该iframe没有allow =“ autoplay”来阻止play()动作的发生。

enter image description here

Vimeo播放器iframe还必须具有allow =“ autoplay”属性。

您可以在api演示页面上看到,如果按右上角的自定义播放按钮,则不会出现此问题。

https://player.vimeo.com/api/demo