Html 更改正在 HTML5 视频中播放的视频

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2772409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:57:43  来源:igfitidea点击:

Change video being played in HTML5 video

videohtml

提问by Krt_Malta

I'm using the tags in HTML5 to play a video on a web browser... (and I'm very impressed with this new feature)

我正在使用 HTML5 中的标签在网络浏览器上播放视频......(这个新功能给我留下了深刻的印象)

Is there the functionality to change the video being played through Javascript? Say when I select another video from a list, a Javascript function would be called which would contain something on the lines of MyVideo.VideoLocation = //location of new video to be played. Is this possible please?

是否有更改通过 Javascript 播放的视频的功能?假设当我从列表中选择另一个视频时,将调用一个 Javascript 函数,该函数将包含MyVideo.VideoLocation = //location of new video to be played. 请问这可能吗?

Thanks and regards, Krt_Malta

感谢和问候, Krt_Malta

回答by Phil Crosby

Webkit requires that you call "load()" after changing the source:

Webkit 要求您在更改源后调用“load()”:

videoTag.src = "newVideo";
videoTag.load();
videoTag.play();

Apple has a useful tutorial.

Apple 有一个有用的教程

回答by samccone

Here is the solution, tested on Ipad/Iphone/Webkit/Firefox

这是在 Ipad/Iphone/Webkit/Firefox 上测试的解决方案

<script>

function playNext(path,target)
{
target[0].src=path;
target[0].load();
target[0].play();
}

playNext("pathToMovie",$('#video_1'));

</script>

回答by Delan Azabani

The property to be used:

要使用的属性:

videoTag.src

If it doesn't auto-start playing after that:

如果在那之后它没有自动开始播放:

videoTag.play()