Turn off volume control and mute button in HTML5 video

孤街醉人 提交于 2019-12-01 09:56:22

Super easy:

Your html should be something like:

<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

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.

This has worked:

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

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

Remove the controls attribute from the video element completely.

Try Here: http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video_controls. Remove the "controls" attribute and the bar will disappear.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!