Vimeo javascript api player.play() not playing

妖精的绣舞 提交于 2020-02-23 04:12:02

问题


This odd behaviour seems to have started in the last week or so.

The following html/javascript combo should load a Vimeo video, and then when the user presses play, it should load and play a different video. It is useful if you want to play a pre-roll before a main video.

If you test it on a desktop browser (I've tried Safari, Chrome and Firefox) it loads the second video, then pauses it. Stranger still, it sometimes works the first time, then the issue arises if you reload the page and try again.

Would appreciate any thoughts on how to solve this.

<iframe allowfullscreen="" scrolling="no" src="https://player.vimeo.com/video/258684937" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen allow="autoplay; encrypted-media"></iframe>

<script src="https://player.vimeo.com/api/player.js"></script>

<script>
var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);

player.on('play', function(){
    player.off('play')
    player.loadVideo(76979871).then(function(){
        player.setAutopause(false).then(function(autopause) {
            player.play();
       });
    });
});
</script>

回答1:


A simple fix is to delay the player.play() call...

var iframe = document.querySelector('iframe');
var player = new Vimeo.Player(iframe);

player.on('play', function(){
    player.off('play')
    player.loadVideo(76979871).then(function(){
        player.setAutopause(false).then(function(autopause) {
          // wait 1 second then play  
          setTimeout(play2,1000);
       });
    });
});
function play2(){
  player.play();
}


来源:https://stackoverflow.com/questions/51001654/vimeo-javascript-api-player-play-not-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!