Vimeo api播放失败,因为用户没有先与文档交互

问题描述 投票:0回答:1

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>
vimeo vimeo-api vimeo-player
1个回答
1
投票

@Toniq这是一个特定于jsfiddle和codepen之类的服务问题。

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

enter image description here

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.