Reputation: 1649
So I have an iframe whose "src" points to the URL of some music. The iframe is hidden and it plays the music automatically. How do I add a button to mute the music?
<iframe hidden="true" frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86
src="http://urlofmusic"></iframe>
Note that the music is from an external website. Also the URL doesn't point to a particular file. It's simply an external link provided by the website.
Upvotes: 0
Views: 1524
Reputation: 356
The only way to mute a iframe is remove it from html. You can clone it for unmute later. But you cannot pause and resume, it like stop and play.
HTML
<div id = "iframe_contain">
<iframe width="0" height="0" hidden="hidden" id="iframe"
src="http://www.youtube.com/embed/y6120QOlsfU?autoplay=1&loop=1">
</iframe>
</div>
<a href="javascript:" id="mute">Mute</a><a href="javascript:" id="unmute">Unmute</a>
JS
(function(){
$("#mute").click(mute);
$("#unmute").click(unmute);
//backup iframe
var iframe_bk;
//play status
var status = 1;
function mute(){
if(status!=1) return;
var iframe = $("#iframe");
iframe_bk = iframe.clone();
iframe.remove();
status = 0;
}
function unmute(){
if(status!=0) return;
if(iframe_bk){
$("#iframe_contain").append(iframe_bk);
iframe_bk = null;
status = 1;
}
}
})();
I use jQuery and here working version in jsfiddle
Upvotes: 1
Reputation: 386
You want to use "controls" parameter inside the audio tag
<audio controls>
<source src="nameofsong.ogg" type="audio/ogg">
<source src="nameofsong.mp3" type="audio/mpeg">
audio tag not supported message optional
</audio>
You can substitute the filename for the URL of the song in the src
Upvotes: 1