Vimeo JavaScript API API Player.play()无法播放 [英] Vimeo javascript api player.play() not playing

查看:364
本文介绍了Vimeo JavaScript API API Player.play()无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种奇怪的现象似乎是在上个星期左右开始的.

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

以下html/javascript组合应该加载Vimeo视频,然后当用户按下播放时,它应该加载并播放其他视频.如果您要在主视频之前播放预片,这很有用.

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.

如果您在台式机浏览器(我尝试过Safari,Chrome和Firefox)上对其进行测试,则它将加载第二个视频,然后将其暂停.仍然陌生人,有时它是第一次工作,然后如果您重新加载页面并重试,就会出现问题.

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>

推荐答案

一个简单的解决方法是延迟player.play()调用...

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();
}

这篇关于Vimeo JavaScript API API Player.play()无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆