简体   繁体   English

HTML 视频源元件; 指定不同的视频尺寸

[英]HTML Video Source element; Specify different vidieo sizes

I want to embed a video in a simple, largely JavaScript-free web page.我想在一个简单的、基本上没有 JavaScript 的 web 页面中嵌入视频。 But I have two versions, one at 1920x1080 and one at 960x540.但是我有两个版本,一个是 1920x1080,一个是 960x540。 Ideally, the latter should be used in a smaller embedded window to save the user download, but the former if they go full screen on a PC.理想情况下,后者应该使用更小的嵌入式 window 以节省用户下载,但前者如果他们 go 在 PC 上全屏。

I was expecting to see something on the <Source> element, but could not find it.我期待在 <Source> 元素上看到一些东西,但找不到它。 I would think that it is a very common requirement.我认为这是一个非常普遍的要求。

Is there a fairly easy way to do this?有没有一种相当简单的方法可以做到这一点? Or do we just make the user always use the big file?还是我们只是让用户总是使用大文件?

(One option is to put the small one inline, and then put a direct link to the full video after it, if the user clicks the latter they get the full resolution.) (一种选择是将小的内联,然后在其后放置完整视频的直接链接,如果用户单击后者,他们将获得完整的分辨率。)

The video contains a lot of text, so the larger one does look better full screen.该视频包含大量文字,因此较大的视频在全屏时看起来更好。 It is twice as large though.虽然是两倍大。 (Handbrake compressed at 30 quality.) (手刹以 30 质量压缩。)

If there was some widely used JavaScript control that would be good.如果有一些广泛使用的 JavaScript 控件会很好。 But I do not want to have a dependency on a large framework such as React or Angular.但我不想依赖大型框架,例如 React 或 Angular。 This is essentially a static web page.这本质上是一个 static web 页面。

There are no media queries available for the video tag.没有可用于视频标签的媒体查询。 You're stuck with JS or HLS streaming to create responsive video on the web.您在 web 上使用 JS 或 HLS 流来创建响应式视频。

Here's a simple JS example that will do what you are looking for.这是一个简单的 JS 示例,可以满足您的需求。

<div id="video"> </div>

<script>

    //get screen width and pixel ratio
    var width = screen.width;
    var smallVideo= <smallvideo>;
    var bigVideo = <bigVideo>;    
    if (width<500){
        console.log("this is a very small screen, no video will be requested");
        }

    else if (width< 1400){
            console.log("let’s call this mobile sized");
            var videoTag = "\<video preload=\"auto\" width=\"100%\" autoplay muted controls src=\"" +smallVideo +"\"/\>";
            document.getElementById('video').innerHTML = videoTag;
            }
    else{
            var videoTag = "\<video preload=\"auto\" width=\"100%\" autoplay muted controls src=\"" +bigVideo +"\"/\>";
            document.getElementById('video').innerHTML = videoTag;

    }

</script>

What is the "Source" you expect?您期望的“来源”是什么?

I'm not sure but maybe you can handle it by javascript.我不确定,但也许你可以通过 javascript 来处理它。

In html, just show that former video, then when user interact with this, you can redircet to latter video.在 html 中,只显示前一个视频,然后当用户与之交互时,您可以重定向到后一个视频。

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

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