Javascript DOM HTML Audio currentSrc Property get

Introduction

Get the URL of the current audio:

var x = document.getElementById("myAudio").currentSrc;

Click the button to get the URL of the current audio.

View in separate window

<!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>/*from   w  w w  . j  ava2 s.c o  m*/
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myAudio").currentSrc;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The currentSrc property returns the URL of the audio file.

If no audio is set, currentSrc property returns an empty string.

This property is read-only.




PreviousNext

Related