在我的页面初始化脚本中,我有以下代码:
var iframe = document.getElementById('video');
var player = Froogaloop(iframe);
player.addEvent('ready', function() {
player.addEvent('play', function() {
console.log('Played video');
});
player.addEvent('pause', function() {
console.log('Paused video');
});
player.addEvent('finish', function() {
console.log('Finished video');
});
});
<script src="//f.vimeocdn.com/js/froogaloop2.min.js"></script>
<iframe id="video" src="//player.vimeo.com/video/132283541?title=0&byline=0&portrait=0&color=e00400&api=1&player_id=video" width="200" height="150" frameborder="0" crossorigin="anonymous" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen=""></iframe>
视频播放完毕后,我会收到暂停事件报告和完成事件报告。有谁知道这是为什么?如果我的代码没有任何问题,是否有解决方法,使用超时或类似的东西?
答案 0 :(得分:0)
我将js片段更改为如下所示:
var iframe = document.getElementById('video');
var player = Froogaloop(iframe);
player.addEvent('ready', function() {
var pauseEvent = null;
var finishEvent = null;
player.addEvent('play', function() {
console.log('Played video');
pauseEvent = null;
finishEvent = null;
});
player.addEvent('pause', function() {
pauseEvent = setTimeout( function() {
console.log('Paused video');
}, 5);
if (finishEvent) {
clearTimeout(pauseEvent);
}
});
player.addEvent('finish', function() {
finishEvent = setTimeout( function() {
console.log('Finished video');
}, 5);
if (pauseEvent) {
clearTimeout(pauseEvent);
};
});
});
虽然我认为人们可以看到它有点令人费解,但这是有效的。有两个clearTimeout调用,因为我们无法确定&#39;完成&#39;和(假的)暂停&#39;报告的顺序与检测它们的顺序相同。
虽然我希望这对其他人有所帮助,但我确信这不是关于这个神秘问题的最后一句话。