Set the media group for 2 videos:
<!DOCTYPE html> <html> <body> <video id="myVideo1" width="100" height="100" controls> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support the video tag. </video>//www .j a v a2 s .c o m <video id="myVideo2" width="100" height="100" controls> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Your browser does not support the video tag. </video><br> <p id="demo"></p> <button onclick="setMedGroup()" type="button">Set media group for videos</button> <button onclick="getMedGroup()" type="button">Get media group for videos</button> <script> var x = document.getElementById("myVideo1"); var y = document.getElementById("myVideo2"); function setMedGroup() { x.mediaGroup = "test"; y.mediaGroup = "test"; } function getMedGroup() { document.getElementById("demo").innerHTML = "Video 1 media group: " + x.mediaGroup + ". Video 2 media group: " + y.mediaGroup; } </script> </body> </html>
The mediaGroup property sets or gets the name of the media group the video is a part of.
A media group allow 2 or more <video> elements to be kept synchronized.
Property Values
Value | Description |
---|---|
group | Specifies the media group of the video |
The mediaGroup property returns a String representing the media group of the video.