Why do we need to use terms like"src" and "audio.ogg" in audio element? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why do we need to use terms like"src" and "audio.ogg" in audio element?

<audio controls> <source src="http://www.sololearn.com/uploads/audio.mp3" type="audio/mpeg"> <source src="http://www.sololearn.com/uploads/audio.ogg" type="audio/ogg"> </audio>

6th Jul 2020, 11:08 AM
Josh
Josh - avatar
4 Answers
+ 3
src is used to put your source, the audio name for example, or a link, ogg is just a type of audio, like mp3 for example, you don't need to use it, but you can just in case a browser doesn't support mp3 for some reason and supports ogg.
6th Jul 2020, 4:46 PM
Karak10
Karak10 - avatar
+ 3
There are two ways to put audio. The first is used if you only want to put one type of audio, like this: <audio src="music.mp3" type="music/mpeg" controls> The second way is used to put multiple types of audio, the browser will play the first supported audio it reads: <audio controls> <source src="music.mp3" type="audio/mpeg"> <source src="music.ogg" type="audio/ogg"> </audio> You can add more audio types, ogg and mp3 are just two examples.
6th Jul 2020, 4:51 PM
Karak10
Karak10 - avatar
+ 1
We do that to specify the source of the audio file to play.
6th Jul 2020, 11:10 AM
Arnesh
Arnesh - avatar
0
Jyothsna Sri src attribute is for the source(location - much like address) of the file, so that the page can load the file. And type is to let the computer know what the file type is or which file format so to unpack(or read ) the file in a correct manner.
6th Jul 2020, 11:14 AM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar