2016-09-15 37 views
0

我希望當用戶倒帶視頻,改變視頻側的文本,但現在我想先開始設置此代碼。我在互聯網上發佈此代碼,我真的不知道不知道爲什麼這個代碼不起作用。jQuery和Vimeo Froogaloop2 API onPlayProgress

<!DOCTYPE html> 
<html> 
<head> 
    <title> </title> 

</head> 
<body> 

<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> 

<div> 
    <button>Play</button> 
    <button>Pause</button> 
    <p>Status: <span class="status">&hellip;</span></p> 
</div> 


    <script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script> 
    <script> $(function() { 
    var iframe = $('#player1')[0]; 
    var player = $f(iframe); 
    var status = $('.status'); 

    // When the player is ready, add listeners for pause, finish, and playProgress 
    player.addEvent('ready', function() { 
     status.text('ready'); 

     player.addEvent('pause', onPause); 
     player.addEvent('finish', onFinish); 
     player.addEvent('playProgress', onPlayProgress); 
    }); 

    // Call the API when a button is pressed 
    $('button').bind('click', function() { 
     player.api($(this).text().toLowerCase()); 
    }); 

    function onPause() { 
     status.text('paused'); 
    } 

    function onFinish() { 
     status.text('finished'); 
    } 

    function onPlayProgress(data) { 
     status.text(data.seconds + 's played'); 
    } 
}); 
</script> 
</body> 
</html> 

因此,如果任何人有想法如何解決這一問題,懇求幫助!

回答

0

上面的代碼幾乎爲Vimeo視頻內發生的事件設置了處理程序。您需要使用的事件是「seekTo」。因此,您可以像添加其他播放器一樣添加事件,並且如果當前播放時間少於seekTo播放時間,則我們知道我們檢測到了倒帶。

而在裏面的倒帶邏輯,我們可以操縱我們的文本在一邊。