简体   繁体   English

如何用javascript控制HTML5视频?

[英]How to control HTML5 video with javascript?

I've searched so much about HTML5 video control and I'm stuck at controlling video with javascript.There is a rule in application you should know. 我已经搜索了很多关于HTML5视频控制的内容,而且我一直坚持用javascript控制视频。你应该知道应用程序中有一条规则。

There will not be any user interaction with browser at any time . 任何时候都不会与浏览器进行任何用户交互

What I'm trying to achieve is 我想要实现的是
1) Open video as fullscreen and play video 1)以全屏模式打开视频并播放视频
2) When video is ended,close video and video will be gone from screen so html content will be seen 2)当视频结束时,关闭的视频和视频将从屏幕消失,因此将看到html内容
3) Display controls of video will not be seen at all times. 3)不会一直看到视频的显示控制。

What is the easiest way to achieve such actions with javascript? 使用javascript实现此类操作的最简单方法是什么?

VideoJS is pure CSS based video player and it's open source.It's my only choice if I'm going to solve this problem with HTML5. VideoJS是纯粹的基于CSS的视频播放器,它是开源的。如果我要用HTML5来解决这个问题,这是我唯一的选择。

For controls of video,VideoJS has some options in the beginning. 对于视频控件,VideoJS在开始时有一些选项。

$("video").VideoJS({ 
      controlsbelow: false,
      showControlAtStart: false
});

For Full Screen problem,I found my own solution,I wish to share it with you. 对于全屏问题,我找到了自己的解决方案,我希望与您分享。
Since I know screen size,I made a panel above of all content. 由于我知道屏幕尺寸,因此我在所有内容上面制作了一个面板。

.fullscreen {
    width:1280px;
    height:800px;
    z-index:10001;
    top:0;
    left:0;
    position:fixed;
}

Note that browser is in full screen mode,so don't mix this as normal full screen resolution of video content. 请注意,浏览器处于全屏模式,因此请勿将其视为视频内容的正常全屏分辨率。

At the end of my video I'm changing visibility to hidden (display:none) 在我的视频结束时,我将可见性更改为隐藏(显示:无)

$("video").bind("ended", function () {
      $("#videoContainer").removeClass("fullscreen").addClass("hidden");
});

Then both container window and video content becomes full screen. 然后容器窗口和视频内容都变为全屏。 Thank you all. 谢谢你们。

To hide the controls you just leave out the controls attribut on the on video element. 要隐藏控件,您只需省略on视频元素上的控件。

You can enter fullscreen for example when a user clicks a button but you can not it seem exit fullscreen when the video ends with the "ended" event. 例如,当用户单击按钮时,您可以输入全屏,但当视频以“已结束”事件结束时,您似乎无法退出全屏。

So you can not combine exitfullscreen with "ended" event. 因此,您无法将exitfullscreen与“已结束”事件相结合。

This seems to be made on porpuse so that you can only enter and exit fullscreen when the user does something. 这似乎是在porpuse上进行的,因此当用户执行某些操作时,您只能进入和退出全屏。

Demo : http://netkoder.dk/test/test0267.html 演示: http//netkoder.dk/test/test0267.html

1)As for fullsreen: 1)至于全屏:

Is there a way to make HTML5 video fullscreen? 有没有办法让HTML5视频全屏?

2) maybe you could consider going with a jQuery plugin like and lightbox, maybe something like this 2)也许你可以考虑使用像灯箱这样的jQuery插件,也许是这样的

EDIT: and check @Mzialla´s answer. 编辑:并检查@ Mzialla的答案。

3)As for the video player check this out: 3)对于视频播放器,请检查:

http://videojs.com/ http://videojs.com/

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM