问题
I'm trying to use Youtube chromeless player through the JS API and I'm having problems with seekto() function.
The problem is that sometimes (I can't tell when the problem arises), calling seekTo() function backwards to a point in the video that is not loaded don't come back and instead stays in the current time.
This is what I do (imagine the video is 240 seconds length):
- I start playing a video -> loadVideoById().
- I move forward to (let's say) the middle of the video -> seekTo(120)
- Video jumps correctly to the position I asked.
- I try to move backwards to 25% time of the video -> seekTo(60)
- Sometimes the video jumps back to 60 but more often it only goes back to 120.
So, is anyone else having this issue?
回答1:
Posting some code will help us to help you, but have you tried player.seekTo(60, true);
- the second parameter is important - setting it to true will make the player send a new request to the server for the video.
回答2:
I had the same problem you have described. What I found out is that if you query the API for the video duration and after that seek to the backward location then it seems to work.
For example, this is my test:
var duration = ytplayer.getDuration();
ytplayer.seekTo(0, true);
It showed me that always returned to the initial position.
回答3:
I have the same problem but none of these solutions worked for me. I ended up using this to get it working with the HTML5 viewer (Chrome and Firefox)
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PLAYING){ // for Chrome and Firefox to "restart" properly
var ct = player.getCurrentTime();
var dur = player.getDuration();
if (ct > (dur-.5) ){
player.seekTo(0, true);
}
}
}
回答4:
Be carefull, in the doc it says :
"The player will advance to the closest keyframe before that time unless the player has already downloaded the portion of the video to which the user is seeking. In that case, the player will advance to the closest keyframe before or after the specified time as dictated by the seek() method of the Flash player's NetStream object. (See Adobe's documentation for more information.)"
https://developers.google.com/youtube/js_api_reference?hl=fr#seekTo
来源:https://stackoverflow.com/questions/9955856/youtube-player-js-api-seekto-function-not-working