Con*_*211 24
自从Vimeo推出新的Video Player API以来,现在已经过时了.
重要提示:一定要删除的?api=1从URL中的iframe中.这在以前需要使用Froogaloop库时不再需要.如果你留下它,'结束','寻找'和其他事件将永远不会发生.
包括新脚本:
<script src="https://player.vimeo.com/api/player.js"></script>
Run Code Online (Sandbox Code Playgroud)
然后使用以下示例:
$(document).ready(function(){
var iframe = $('#container iframe');
var player = new Vimeo.Player(iframe);
player.on('ended', function() {
console.log('Finished.');
});
});
Run Code Online (Sandbox Code Playgroud)
首先,您需要在HTML中包含Vimeo的'Frogaloop库的路径(在您的Jquery包含之后):
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>
然后你需要嵌入你的Vimeo视频(再次在你的HTML中):
<iframe id="PLAYER1" src="https://player.vimeo.com/video/76979871?api=1&player_id=PLAYER1" width="630" height="354" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
这里'api = 1'打开api - 默认情况下这是关闭性能的.并且,player_id ='PLAYER1'是您的iframe的ID.
然后在JavaScript文件中,您需要以下内容:
$(function() {
//Gets the iframe by id
var iframe = $('#PLAYER1');
//Creates a player var using the iframe
var player = $f(iframe);
// When the player is ready/loaded, add a finish event listener
player.addEvent('ready', function() {
//Adds an event 'finish' that executes a function 'onFinish' when the video has ended.
player.addEvent('finish', onFinish);
});
//Define the onFinish function that will be called
function onFinish(id) {
console.log('THE VIDEO HAS FINISHED PLAYING');
}
});
Run Code Online (Sandbox Code Playgroud)
然后只需播放视频,然后检查控制台输出.
感谢@Raptor将我指向api文档.