Javascript examples for DOM HTML Element:Audio
The mediaGroup property sets or gets the name of the media group where the audio is from.
A media group allow 2 or more <audio> elements to be kept synchronized.
Set the mediaGroup property with the following Values
Value | Description |
---|---|
group | Sets the media group of the audio |
A String, representing the media group of the audio
The following code shows how to set the media group for 2 <audio> elements:
<!DOCTYPE html> <html> <body> <audio id="myAudio1" controls> <source src="your.ogg" type="audio/ogg"> <source src="your.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>//from w w w . j a v a2 s . com <audio id="myAudio2" controls> <source src="your.ogg" type="audio/ogg"> <source src="your.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio><br> <button onclick="setMedGroup()" type="button">Set media group for audios</button> <button onclick="getMedGroup()" type="button">Get media group for audios</button> <script> var x = document.getElementById("myAudio1"); var y = document.getElementById("myAudio2"); function setMedGroup() { x.mediaGroup = "test"; y.mediaGroup = "test"; } function getMedGroup() { console.log("Audio 1 media group: " + x.mediaGroup + ". Audio 2 media group: " + y.mediaGroup); } </script> </body> </html>