简体   繁体   English

关闭 HTML5 视频中的音量控制和静音按钮

[英]Turn off volume control and mute button in HTML5 video

We have some videos playing great in our HTML mobile app.我们有一些视频在我们的 HTML 移动应用程序中播放效果很好。 However, our videos don't have sound, just subtitles, so we need to remove the volume slider and mute button but keep the timer bar.但是,我们的视频没有声音,只有字幕,所以我们需要移除音量滑块和静音按钮,但保留计时器栏。

Can this be done or toggled with HTML or CSS?这可以用 HTML 或 CSS 完成或切换吗? Or is some javascript required to do this?或者是否需要一些 javascript 来执行此操作?

At the moment the setting within our html tag is just: controls="controls"<\/em>目前我们的 html 标签中的设置只是: controls="controls"<\/em>

"

This has worked: 这已经起作用了:

video::-webkit-media-controls-volume-slider {
display:none;
}

video::-webkit-media-controls-mute-button {
display:none;
}

Super easy: 超级简单:

Your html should be something like: 您的html应该是这样的:

<video id="Video1">
  <source src="..." type="video/mp4">
  <source src="..." type="video/ogg">
  Your browser does not support HTML5 video.
</video>

Add then a customized button to play the video: 然后添加一个自定义按钮来播放视频:

<button id="play" onclick="vidplay()">&gt;</button>

Finally a progress bar: 最后是进度条:

<progress id="progressbar" value="0" max="100"></progress>

Then in javascript add a button to play 然后在javascript中添加一个按钮来播放

var video = document.getElementById("Video1");

function vidplay() {

       var button = document.getElementById("play");
       if (video.paused) {
          video.play();
          button.textContent = "||";
       } else {
          video.pause();
          button.textContent = ">";
       }
    }

And a listener to update the progress bar: 还有一个监听器来更新进度条:

video.addEventListener('timeupdate', updateProgressBar, false);


function updateProgressBar() { 
var progressBar = document.getElementById('progressbar'); 
var percentage = Math.floor((100 / mediaPlayer.duration) * mediaPlayer.currentTime);
 progressBar.value = percentage; progressBar.innerHTML = percentage + '% played'; 
}

So basically remove the "standard controls" and create your own ones. 因此,基本上删除 “标准控件”并创建自己的控件。

If you wanted to achieve more complicated results, I would recommend you another option. 如果您想获得更复杂的结果,我建议您使用另一种选择。 This could be using a more configurable setting such as video.js . 这可能使用了更可配置的设置,例如video.js

This is the list of pseudo elements of video:这是视频的伪元素列表:

video::-webkit-media-controls-panel视频::-webkit-media-controls-panel

video::-webkit-media-controls-play-button视频::-webkit-media-controls-play-button

video::-webkit-media-controls-volume-slider-container视频::-webkit-media-controls-volume-slider-container

video::-webkit-media-controls-volume-slider视频::-webkit-media-controls-volume-slider

video::-webkit-media-controls-mute-button视频::-webkit-media-controls-mute-button

video::-webkit-media-controls-timeline视频::-webkit-media-controls-timeline

video::-webkit-media-controls-current-time-display视频::-webkit-media-controls-current-time-display

video::-webkit-full-page-media::-webkit-media-controls-panel视频::-webkit-full-page-media::-webkit-media-controls-panel

video::-webkit-media-controls-timeline-container视频::-webkit-media-controls-timeline-container

video::-webkit-media-controls-time-remaining-display视频::-webkit-media-controls-time-remaining-display

video::-webkit-media-controls-seek-back-button视频::-webkit-media-controls-seek-back-button

video::-webkit-media-controls-seek-forward-button视频::-webkit-media-controls-seek-forward-button

video::-webkit-media-controls-fullscreen-button视频::-webkit-media-controls-fullscreen-button

video::-webkit-media-controls-rewind-button视频::-webkit-media-controls-rewind-button

video::-webkit-media-controls-return-to-realtime-button视频::-webkit-media-controls-return-to-realtime-button

video::-webkit-media-controls-toggle-closed-captions-button视频::-webkit-media-controls-toggle-closed-captions-button

In this referente there also pseudo-elements of audio, radio and several inputs.. Reference: Reference在这个参考中,还有音频、收音机和几个输入的伪元素。参考:参考

Remove the controls attribute from the video element completely. 从视频元素中完全删除控件属性。

Try Here: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video_controls . 在这里尝试: http : //www.w3schools.com/tags/tryit.asp ?filename= tryhtml5_video_controls Remove the "controls" attribute and the bar will disappear. 删除“控件”属性,该条将消失。

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

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