admin管理员组文章数量:1419252
I want to create a custom progress bar using YouTube API and I think the best event listener to do the progress calculations would be YT.PlayerState.PLAYING
event listener.
But this event is not working at all. I think it's totally wrong. Any ideas?
player.addEventListener("YT.PlayerState.PLAYING", function() {
console.log(player.getDuration());
});
Adding or removing an event listener
player.addEventListener(event:String, listener:String):Void
Adds a listener function for the specified event. The Events section below identifies the different events that the player might fire. The listener is a string that specifies the function that will execute when the specified event fires.
player.removeEventListener(event:String, listener:String):Void
Removes a listener function for the specified event. The listener is a string that identifies the function that will no longer execute when the specified event fires.
Events
onStateChange
This event fires whenever the player's state changes. The value that the API passes to your event listener function will specify an integer that corresponds to the new player state. Possible values are:
-1 (unstarted)
0 (ended)
1 (playing)
2 (paused)
3 (buffering)
5 (video cued).
When the player first loads a video, it will broadcast an unstarted (-1) event. When a video is cued and ready to play, the player will broadcast a video cued (5) event. In your code, you can specify the integer values or you can use one of the following namespaced variables:
YT.PlayerState.ENDED
YT.PlayerState.PLAYING
YT.PlayerState.PAUSED
YT.PlayerState.BUFFERING
YT.PlayerState.CUED
I want to create a custom progress bar using YouTube API and I think the best event listener to do the progress calculations would be YT.PlayerState.PLAYING
event listener.
But this event is not working at all. I think it's totally wrong. Any ideas?
player.addEventListener("YT.PlayerState.PLAYING", function() {
console.log(player.getDuration());
});
Adding or removing an event listener
player.addEventListener(event:String, listener:String):Void
Adds a listener function for the specified event. The Events section below identifies the different events that the player might fire. The listener is a string that specifies the function that will execute when the specified event fires.
player.removeEventListener(event:String, listener:String):Void
Removes a listener function for the specified event. The listener is a string that identifies the function that will no longer execute when the specified event fires.
Events
onStateChange
This event fires whenever the player's state changes. The value that the API passes to your event listener function will specify an integer that corresponds to the new player state. Possible values are:
-1 (unstarted)
0 (ended)
1 (playing)
2 (paused)
3 (buffering)
5 (video cued).
When the player first loads a video, it will broadcast an unstarted (-1) event. When a video is cued and ready to play, the player will broadcast a video cued (5) event. In your code, you can specify the integer values or you can use one of the following namespaced variables:
YT.PlayerState.ENDED
YT.PlayerState.PLAYING
YT.PlayerState.PAUSED
YT.PlayerState.BUFFERING
YT.PlayerState.CUED
Share
Improve this question
edited Aug 22, 2016 at 18:06
SurvivalMachine
8,36615 gold badges62 silver badges91 bronze badges
asked Sep 17, 2014 at 22:03
M1XM1X
5,37413 gold badges65 silver badges129 bronze badges
1 Answer
Reset to default 6YT.PlayerState.PLAYING
is a state not an event the event you can listen for is onStateChange
then if the state is playing you can get the information from the player and update the seek bar accordingly.
player.addEventListener("onStateChange", updateBar);
function updateBar () {
if (YT.PlayerState.PLAYING) {
console.log(player.getCurrentTime());
setTimeout(updateBar,200);
}
}
I answerd this before but badly :-( I still leave the link to the old lazy answer code here: http://jsfiddle/nvtsazbr/
本文标签: javascriptCustom progress bar using YouTube APIStack Overflow
版权声明:本文标题:javascript - Custom progress bar using YouTube API - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745301215a2652381.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论