The audio object property src used to set and retrieve the value of the src attribute of a audio. It specifies the location (URL) of the audio file. It returns a string that represents the url of the audio file.
1 <audio>.src
2 <audio>.src = <url>
audio : A audio element object to set and retrieve src property
url : It specifies the url of the audio file
Possible values
1. | absolute : It specifies url that can be either in same server or remote |
2. | relative : It specifies url that should be in the same server |
1 <html>
2 <style>
3 .container {
4 margin: 10px 0;
5 }
6 </style>
7 <body>
8 <h1>The Audio Object</h1>
9 <h2>Example</h2>
10
11 <div>
12 <audio id="audio" src="audio.mp3" controls >
13 Your browser does not support the audio tag.
14 </audio>
15 </div>
16 <p>
17 <button onclick="access()">Access</button>
18 </p>
19 <p id="result"></p>
20
21 <script>
22 function access() {
23 const audio = document.getElementById("audio");
24 const str = `The audio source url is : <b>${audio.src}</b>`;
25 document.getElementById("result").innerHTML = str;
26 }
27 </script>
28 </body>
29 </html>
Audio property src
Related options for your search