Mute/unmute iframe video from another domain

Question:

I’ve implemented an iframe inside my webpage, the iframe points to another domain to catch the video content.

Nothing fancy inside my webpage, the iframe is standard aswell:

<iframe id='frame' src='domain.com/stream/324/index.m3u8' width='100%' allow='autoplay; encrypted media' frameborder='0' allowfullscreen></iframe>

I would like to add buttons outside the iframe to mute or unmute the video, even though the presence of the player’s controllers.

How can I achieve this?

Asked By: TerryMars

||

Answers:

Don’t use the <iframe> tag for videos. Instead, use the HTML5 <video> tag. With a <video> tag you can set the muted attribute. You can rewrite your <iframe> like this:

<video id="video" controls width="100%" src="domain.com/stream/324/index.m3u8"></video>

You can then create a button and add an event listener to mute and unmute the <video> tag. Like this:

<button onclick="document.getElementById('video').muted = true">Mute</button>
<button onclick="document.getElementById('video').muted = false">Unmute</button>
Answered By: Michael M.
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.