Personalized HTML5 video controls - Exclusively show mute button

Is there a way to customize the HTML5 video controls to show only the mute/unmute button in the top right corner of the video? I have found a solution by hiding other elements using "display: none;" in CSS for all other ids and buttons, but this might not be the most efficient method. Additionally, this customization only seems to work in Chrome. http://jsfiddle.net/pp6Wn/2/

<div id="video-container">
<video id="my_video" width="100%" height="100%" >
    <source src="http://romain-menard.fr/cours_html5/sitedemo/src/small.mp4"
    type="video/mp4" />
    <source src="video/movie.webm"
    type="video/webm" />
     </video>
<!-- Video Controls -->
<div id="video_controls_bar">
    <button id="playpausebtn"></button>

    <span id="curtimetext">00:00</span>
    <input id="seekslider" type="range" min="0" max="100" value="0" step="1"><span id="durtimetext">00:00</span>
    <button id="mutebtn">Mute</button>
    <input id="volumeslider" type="range" min="0" max="100" value="100" step="1">
    <button id="fullscreenbtn"></button>
  </div>
</div>

Answer №1

If you're looking for a solution, one approach could involve creating an additional button and incorporating some CSS to position it correctly. Then you can link this new button to a JavaScript function that handles muting:

To implement this:
Firstly, in your HTML code, create the new button outside of the "video_controls_bar" div but inside the "video-container" div:

</video>
<button id="mutebtn2">Mute</button>
<!-- Video Controls -->
<div id="video_controls_bar">

Next, in your JS file, make sure to assign the mute functionality by adding these lines within the "initializePlayer()" function:

mutebtn2 = document.getElementById("mutebtn2");
mutebtn2.addEventListener("click", vidmute2, false);

Don't forget to include the new function as well:

function vidmute2(){
    if(vid.muted){
        vid.muted = false;
        mutebtn2.innerHTML = "Mute";
    } else {
        vid.muted = true;
        mutebtn2.innerHTML = "Unmute";
    }
}

For styling purposes, use CSS to position the new button at the top-right corner of the video:

#mutebtn2 {
    position: absolute;
    top: 0px;
    right: 0px;
}

If you wish to hide the video controls, simply modify the relevant CSS code accordingly:

#video-container:hover #video_controls_bar {
    opacity: 0;
}

Finally, should you want to explore a live example, you can check out this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS is functioning properly on a local level, but fails to take effect once the "npm run build" command is executed in the React application's build

I am attempting to override the CSS of Muidrawer-paper. It works locally after running "npm start", but it does not take effect when building the package. .css-12i7wg6-MuiPaper-root-MuiDrawer-paper { position: absolute !important; top: 50px !import ...

Check the date selected in the date picker against today's date

<div class="input-group" ng-init="d.expiredAt = toDate(d.expiredAt);"> <input type="text" class="form-control" uib-datepicker-popup="dd/MMM/yyyy" is-open="popup1.opened" ng-required="false" close-text="Close" ng-model="d.expiredAt" ng-readonly="! ...

jQuery doesn't bother holding its breath for the response of the function

After searching through numerous similar questions, I have yet to come across a suitable solution for my issue. The scenario is that I have two functions, one of which returns a boolean value. My objective is to execute a specific task only when the boolea ...

Exploring JQuery 3.1.1 in combination with the powerful CSS flexbox techniques

When utilizing the fade functions in JQuery, an element that initially has 'display: none' and is then faded out will have JQuery inject 'display: block' when faded in. In a flexbox layout, this can cause the element to wrap to the nex ...

Strong tags within MFC

Is it possible to create labels in MFC (Static text) that contain both bold and non-bold text? For instance, something like this: "I want my label to have a mix of styles like this" Any suggestions on how to achieve this? I am aware that I can change ...

Implement a slideshow feature that automatically changes a CSS attribute when preview images are shown

(Apologies for the perplexing title) My intention was to create a slideshow gallery, and I stumbled upon an example here: https://www.w3schools.com/howto/howto_js_slideshow_gallery.asp In this setup, you'll notice previews of images in a small bar b ...

Ways to implement a shared ng-model across multiple elements

Brand new to AngularJS here! I have a page with multiple input boxes where users can enter tracking numbers. The number of input boxes can vary from 1 to 10. I am struggling to fetch data from all input boxes as I am only able to retrieve data from the fi ...

What is the best way to control the amount of rows displayed in a textarea?

Does anyone know a simple solution for restricting the number of rows a user can input in a textarea with jquery/javascript? Appreciate any help! ...

Exploring the functionality of the jQuery.ajax() method within JSF

<h:outputScript library="js" name="jquery-1.11.0.min.js"></h:outputScript> <script> //<![CDATA[ function executeTask() { $.ajax({ type: "POST", url: "#{testBean.RunTask}", data: "{}", contentType: "application/json; cha ...

Boss declares, "Display the iFrame with no borders visible."

Good day to everyone, I am currently dealing with an issue on the page: It seems to be working perfectly in all of my browsers except for Internet Explorer. Since I don't have IE, I'm having trouble troubleshooting this. My boss mentioned somet ...

Using Jquery to assign negative values in CSS styling

Here is the jQuery code snippet I am working with: <script type="text/javascript" src="js/jquery.js"> </script> <script type="text/javascript"> $(document).ready(function() { get_font_size(); set_sidebar(); }); function get_f ...

How can I create a box-shaped outline using Three.js?

As someone new to threejs, I have been trying to figure out how to render a transparent box around a symbol in my canvas. The box should only display a border and the width of this border should be customizable. Currently, I am using wireframe to create a ...

Utilizing jQuery's .fadeOut and .fadeIn for seamless transitions in webpage designs

My issue involves using simple jquery to display images based on category selectors being clicked (subpar code snippet) $(".graphic-design-selector").click(function(){ $(".web-design, .photography").fadeOut(1000); $(".design").fadeIn(1000); }); ...

Acquire HTML content and save it in a MYSQL database: A Step-by-Step Guide

How can I effectively store an HTML page with CSS in a MYSQL database? Is this even feasible? What type of column should be used for storage? And how can I retrieve the stored formatted HTML and display it correctly using PHP? If the page contains imag ...

What are the best methods for creating a significant gap in a flexbox layout?

https://i.sstatic.net/iMkPt.png I created a menu using flexbox to have only two columns and vertical scrolling for multiple menus. However, I am facing spacing issues between the menus when one menu has many children. Here is the code snippet along with t ...

Leveraging Jquery to Retrieve the Value from a Button with an Embedded Span

Below is a button with some text: HTML: <button><span>fdsfsd</span>Result<span>aasd</span></button> Is there a way to retrieve the value of "Result" from the button above using jQuery? I need to be able to change thes ...

Clickability issue with Bootstrap collapsible navigation button

I've been working on implementing a collapsible menu on a website, but I'm running into issues with the toggle button. The button appears fine, but it's not responding when clicked. I must be overlooking something simple. Any assistance wou ...

Sorting table rows updates the row numbers in table-sorter

I am currently using tablesorter for my table functionality, but I have encountered an issue where the row numbers do not update when I sort the table. It seems to be a fixed ... $("#tablesorter-demo tr").click(function () { $('#tablesorter-demo ...

Changes made in the DropDownList selection are not being accurately captured on the server side

I have come across an issue with a dropdownlist in my asp.net web page. This dropdownlist is a server-side control. I am making an ajax call and within that call, I am adding a new item to the dropdownlist and setting it as selected. The new item displays ...

Place two divs in the center of a container, with one floating to the left and the other floating

I have attempted numerous techniques provided on this site, but none seem to be effective. My goal is to horizontally center two divs that are positioned to the left and right within a container with a 100% width. Here is the CSS snippet I am using: #bo ...