Find out if the audio has a media controller:
var x = document.getElementById("myAudio").controller;
Click the button to check if the audio has a media controller.
<!DOCTYPE html> <html> <body> <audio id="myAudio" controls> <source src="sound.ogg" type="audio/ogg"> <source src="sound.mp3" type="audio/mpeg"> Your browser does not support the audio element. </audio>/* ww w.j av a2 s . co m*/ <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myAudio").controller; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The controller
property returns the current media controller of the audio.
By default the <audio> element does not have a media controller.
If a media controller is specified, the controller
property returns a MediaController
object.
MediaController Object properties/methods:
Value | Meaning |
---|---|
buffered | the buffered ranges of the audio |
seekable | the seekable ranges of the audio |
duration | the duration of the audio |
currentTime | get or set the current playback position of the audio |
paused | check if the audio is paused |
play() | play the audio |
pause() | pause the audio |
played | check if the audio has been played |
defaultPlaybackRate | get or set the default playback rate of the audio |
playbackRate | get or set the current playback rate of the audio |
volume | get or set the volume of the audio |
muted | get or set if the audio is muted |