Audio and video tags | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Audio and video tags

Hi guys. I started learning HTML5 and have a question regard audio and video tags. In the exercises, there are always two lines of code, with the almost same content. For the audio: <audio controls> <source src="audio.mp3" type="audio/mpeg"> <source src="audio.ogg" type="audio/ogg"> </audio> And for video: <video controls> <source src="video.mp4" type="video/mp4"> <source src="video.ogg" type="video/ogg"> Video is not supported by your browser </video> I am not sure to understand why is that? Because of the format of the file? Or why? Something like an algorithm? If it is not audio/mpeg, then maybe is audio/ogg? If it is not too, then the other side will recieve the error that the file is not supported? Thanks very much :)

30th Jan 2018, 9:14 PM
Vladimir
Vladimir  - avatar
2 Answers
+ 3
Not all browsers support all audio/video formats. For example, open source browsers might not be able to play mp3 files because of patents and nonfree software requirements, so they would try to fall back to ogg (a patent-free open source format) or wav. It's basically the same with video. If you want your audio/video to be compatible with a wide variety of browsers, you should provide alternative file formats, so browsers can fall back to them. The browser will play the first supported file and ignore the others.
30th Jan 2018, 9:17 PM
SplittyDev
SplittyDev - avatar
+ 2
Okay, thank you very much. :)
30th Jan 2018, 9:25 PM
Vladimir
Vladimir  - avatar