嘿,伙计们!
我是javascript的新手,有点新手,这就是为什么我尽量少用js的原因,但这一部分我真的需要它。
我有一个全屏视频,它第一次正确播放,但我希望它在重新加载时再次使用嵌入的URL。所以我做了这个js。
function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('video', {
videoId: 'A3rvUNcueFg', // YouTube Video ID
playerVars: {
autoplay: 1, // Auto-play the video on load
controls: 0, // Show pause/play buttons in player
showinfo: 0, // Hide the video title
loop: 1, // Run the video in a loop
fs: 1, // Hide the full screen button
cc_load_policty: 0, // Hide closed captions
iv_load_policy: 3, // Hide the Video Annotations
autohide: 1, // Hide video controls when playing
start: 13,
end: 295,
rel: 0,
playlist: 'A3rvUNcueFg'
},
events: {
onReady: function(e) {
e.target.mute();
var Embed = e.target.getVideoEmbedCode();
}
}
});
YT.PlayerState.ENDED: function(e) {
var player;
player = new YT.Player(Embed)
}
所以我想要它做的是,我想让它静音(这部分可以工作)。然后获取嵌入的URL,这样我就可以在视频结束后在相同的起始点重新加载视频。因为它现在重新加载并从头开始。
提前谢谢你,Jeroen
发布于 2017-02-28 22:54:13
在你的视频对象中加入seekTo选项怎么样?您可以向它传递您想要跳过以开始视频的秒数。
function onYouTubeIframeAPIReady() {
var player;
var time = //whatever time you want it to start from each loop; NEW CODE
player = new YT.Player('video', {
videoId: 'A3rvUNcueFg', // YouTube Video ID
playerVars: {
autoplay: 1, // Auto-play the video on load
controls: 0, // Show pause/play buttons in player
showinfo: 0, // Hide the video title
loop: 1, // Run the video in a loop
fs: 1, // Hide the full screen button
cc_load_policty: 0, // Hide closed captions
iv_load_policy: 3, // Hide the Video Annotations
autohide: 1, // Hide video controls when playing
start: 13,
end: 295,
rel: 0,
playlist: 'A3rvUNcueFg'
},
events: {
onReady: function(e) {
e.target.mute();
var Embed = e.target.getVideoEmbedCode();
}
}
});
YT.PlayerState.ENDED: function(e) {
var player;
player = new YT.Player(Embed);
player.seekTo(time); //NEW CODE
}
参考:https://developers.google.com/youtube/iframe_api_reference#Playback_controls
Player.seekTo(seconds:数字,allowSeekAhead:布尔值):空
https://stackoverflow.com/questions/42520150
复制