简体   繁体   English

用于HTML5视频的高清控件

[英]HD control for HTML5 video

I have set up an Html5 video and it has the basic controls. 我已经设置了一个Html5视频,它具有基本的控件。 However, the video I uploaded is quite heavy and I would like to give a lower resolution option, like an HD switch control. 但是,我上传的视频非常繁琐,我想提供一个较低分辨率的选项,例如HD开关控件。 I looked on the internet on how to apply an HD button to html5 but the primary solution seems to install a video player. 我在互联网上看过如何对html5应用高清按钮,但主要的解决方案似乎是安装视频播放器。 Is there a simpler way to implement an HD button without needing to install the video player? 有没有更简单的方法来实现HD按钮而无需安装视频播放器? I already set up my html5 video with several jQuery commands and I would not like to go through the effort of starting from scratch again. 我已经用几个jQuery命令设置了html5视频,但我不想再次尝试从头开始。 I also looked that one could customise the html5 video controls as well. 我还看着人们也可以自定义html5视频控件。 Would one be able to set up a customised HD button through html/javascript only? 能否仅通过html / javascript设置自定义的高清按钮? If yes, how one does it? 如果是,怎么办?

Here's the code I have at the moment 这是我目前的代码

<video src="../Frustrated/Frustrated.mp4" controls preload="metadata"> <source src="../Frustrated/Frustrated.mp4" type="video/mp4">

you could probably make this look a lot more elegant, but the code sample below will allow you to have buttons which change the source between HD and regular versions (based on the ID of the button, but you can change the logic if needed). 您可能会使外观看起来更加优雅,但是下面的代码示例将允许您使用一些按钮,这些按钮可在高清版本和常规版本之间更改来源(基于按钮的ID,但可以根据需要更改逻辑)。 The code also checks to see if the browser supports mp4, ogg or webm and defaults to the first supported format (so you'd potentially need encodes for each type if you make use of that part of the code 该代码还会检查浏览器是否支持mp4,ogg或webm,并默认使用第一种受支持的格式(因此,如果您使用该部分代码,则可能需要对每种类型进行编码

<video width="400" controls id="video">
  <source src="../Frustrated/furstrated.mp4" type="video/mp4">
  Your browser does not support HTML5 video.
</video>

<br>

<button id="frustratedHD" onclick="playvid(this)">HD</button><button id="frustrated" onclick="playvid(this)">Regular</button>

<script>
// gets the video element
var video = document.getElementById("video");
// sets the extension / container we'll use
var vidType = "";

// identifies what type of video we can play, assuming this is an HTML5 supporting browser  
  if (video.canPlayType) {
    if (video.canPlayType('video/mp4; codecs="avc1.42E01E"') == "probably") {
      vidType = "mp4"
    } else {
      if (video.canPlayType('video/ogg; codecs="theora"') == "probably") {
    vidType = "ogg"
        } else { if (video.canPlayType('video/webm; codecs="vp8, vorbis"') == "probably") {
          vidType = "webm"
        }
      }
    }
  }
  // you'll want to decide how to handle no supported video type...

  function playvid(vid) {
    // log selected item to confirm selection, can comment this line out
    console.log("../Frustrated/" + vid.id + "." + vidType)
    // set the video element source to selected content and correct type
    video.src = "../Frustrated/" + vid.id + "." + vidType
    video.play();
  }
  </script>

Upload the video in different qualities to your server, and play a different video depending on the quality the user has chosen. 将不同质量的视频上传到服务器,然后根据用户选择的质量播放不同的视频。

Even if it's possible to downgrade a video on the client side, it's pointless, because the client still has to download the HD video in order to convert it. 即使可以在客户端降级视频,也没有意义,因为客户端仍必须下载高清视频才能进行转换。

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

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