Disable download button HTML5 Video

7

After updating Opera and Chrome, using the video tag, the option to download the video appears as below:

Doesanyoneknowhowtodisablethis?I'musingthefollowingcode:

<videowidth="800" height="600" controls>
          <source src="movie.mp4" type="video/mp4">
          Your browser does not support the video tag.
     </video>
    
asked by anonymous 27.12.2016 / 16:32

1 answer

3

Hiding the button with a Blob

When doing a blob of the video and then a parse for URL (using URL.createObjectURL ), Google Chrome automatically hides the button:

var video = document.querySelector('video');

var xml = new XMLHttpRequest(); // Objeto XML
xml.open("GET", '/aqui-seu-video'); // Get do vídeo 

xml.responseType = "blob"; // Mudando o tipo de resposta para Blob

xml.onload = function (){
    if(xml.readyState === 4){
        if(xml.status === 200 || xml.status == 0){
            // Fazer um parse da resposta em url e passar para o source do <video>
            video.src = URL.createObjectURL(xml.response); 
        }
    }
}
xml.send(); // termina a chamada

Hiding the button with CSS

This button belongs to DOM of the <video> element in HTML5 . When looking at your tree of elements and their respective styles, using Google DevTools (after enabling the "Show user agent shadow DOM" option), we have that the download button has, by default, 32px width:

Wealsoseetwodiv:-webkit-media-controls-paneland-webkit-media-controls-enclosure.Thesecondbeingtheparentofthefirst.

Sowejustassign...-enclosureaoverflow:hidden:

video::-webkit-media-controls-enclosure{overflow:hidden;}

Andthe...-panelawidth:calc(100%+32px):

video::-webkit-media-controls-panel{width:calc(100%+32px);/*+otamanhodobotão*/}

Example

Withthis,justassigntheabovestylestoaspecificclassandusewhenneeded:

video.non-downloadable::-webkit-media-controls-enclosure{
 overflow: hidden;
}
video.non-downloadable::-webkit-media-controls-panel{
  width: calc(100% + 32px);
}
<h1>Apparently Non-Downloadable</h1>

<video controls width="500" src="https://www.html5rocks.com/pt/tutorials/video/basics/Chrome_ImF.mp4"class="non-downloadable" >
</video>

<h1>Downloadable</h1>

<video controls width="500" src="https://www.html5rocks.com/pt/tutorials/video/basics/Chrome_ImF.mp4">
</video>

Note: Of course, anyone who really wants to download the video, besides having the context menu option, can change the style in DevTools, but for a first impression this is it.

    
27.12.2016 / 21:20