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>
@Toniq这是一个特定于jsfiddle和codepen之类的服务问题。
在那些测试页面上,他们将用户定义的测试内容包装在iframe中,该iframe没有allow =“autoplay”,这会阻止play()动作的发生。
此外,Vimeo播放器iframe必须具有allow =“autoplay”属性。
您可以在api演示页面上看到,如果按右上角的自定义播放按钮,则不会出现此问题。