gpt4 book ai didi

youtube - YouTube stopVideo()是暂停而不是停止吗?

转载 作者:行者123 更新时间:2023-12-03 05:47:17 25 4
gpt4 key购买 nike

我的网站运行的是Bootstrap 3.0,我尝试在YouTube上托管一个介绍性视频和完整长度的视频。载入页面时,介绍性视频会自动播放,然后我有一个按钮,可以打开一个模态窗口,其中显示带有音频的完整视频。

我想在模态窗口关闭时完全停止播放视频,这样,如果他们再次单击按钮将其打开,则视频将从头开始播放。不幸的是,stopVideo函数似乎没有按我期望的那样工作。基本上,这只是暂停视频,因此,如果我打开模式备份,则视频将从停下来的位置开始播放。

如果重新打开视频,如何使视频停止并从头开始?

这是我当前的代码:

$('#myModal').on('show.bs.modal', function () {
$('#placeholder')[0].contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
$('#full')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
});

$('#myModal').on('hidden.bs.modal', function () {
$('#full')[0].contentWindow.postMessage('{"event":"command","func":"' + 'stopVideo' + '","args":""}', '*');
$('#placeholder')[0].contentWindow.postMessage('{"event":"command","func":"' + 'playVideo' + '","args":""}', '*');
});

谢谢!

最佳答案

打开模式后,您可以使用seekTo返回视频的开头。
seekTo之后播放视频

Doc from API

player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void

Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (playing, video cued, etc.), the player will play the video. The seconds parameter identifies the time to which the player should advance.

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

The allowSeekAhead parameter determines whether the player will make a new request to the server if the seconds parameter specifies a time outside of the currently buffered video data.

We recommend that you set this parameter to false while the user drags the mouse along a video progress bar and then set it to true when the user releases the mouse. This approach lets a user scroll to different points of a video without requesting new video streams by scrolling past unbuffered points in the video. When the user releases the mouse button, the player advances to the desired point in the video and requests a new video stream if necessary.

关于youtube - YouTube stopVideo()是暂停而不是停止吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25851493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com