How to get video play paused status with Vimeo API?

孤者浪人 提交于 2019-12-13 07:38:52

问题


I was just wondering how I can detect if the video is playing or paused (or even loaded/ buffering) on the Vimeo API (http://player.vimeo.com/playground) it's a lot different to Youtube!

Joe


回答1:


Check the richest example of using vimeo Player Javascript API. It uses froogaloop library to communicate vimeo JS API. Don't forget to add id and parameters to the iframe element.

  <iframe id="player_1" src="http://player.vimeo.com/video/7100569?api=1&amp;player_id=player_1" width="540" height="304" frameborder="0" webkitallowfullscreen></iframe>



回答2:


The Vimeo Player JavaScript API provides the following method:

paused():Boolean

This return returns false if the video is playing, true otherwise.

Full details here: http://developer.vimeo.com/player/js-api




回答3:


Turns out you have to pass a callback as a second param to .api(), which will receive true / false based as the pause state of the player:

player.api('paused', function(paused) {
    // paused will be true or false here
});

https://github.com/vimeo/player-api/issues/31




回答4:


Looks like their documenentation slightly changed since last answer. After you get the instance of the player you can check the playing/pause state by:

player.getPaused().then(function(paused) {
    if(paused){
        player.play();
    }else{
       player.pause();
    }

});

From vimeo player api docs




回答5:


            var onPlay = function(data) {
              console.log("play")
            };

            var onPause = function(data) {
              console.log("pause")
            };

            player.addEvent('play', onPlay);
            player.addEvent('pause', onPause);


来源:https://stackoverflow.com/questions/15973698/how-to-get-video-play-paused-status-with-vimeo-api

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