When we want to embed YouTube video in our blog or website, it’s super easy and doesn’t need any tutorial for it. The Share button gives you the tiny URL and you can embed the URL straight into your website or page or blog. Now, the twist comes in case of Audio files. There are many URL videos, which are basically audio files converted to videos with some random images, slideshows etc. What if you need to embed the audio part only? Embedding audio is not a straight method for YouTube because YouTube is a video streaming site and allows only videos to be embedded. Amit Agarwal, a software enthusiast has come up with a good solution. He has written a code which you can modify according to your requirement. The code is available on Github and with a little bit of changes, it helps you embed just the audio file out of the YouTube video. Check out the steps:
Steps to Embed The Audio From A YouTube Video
1. First open the YouTube video from which you want to extract the audio. In the URL of the video which is there in the address bar, there is an ID associated with each video. Note down the ID. For example, in my video, the ID is Rdw9R4cuJiI.
2. Now, add the snippet to your website’s HTML code. It should be like the following.
Replace VIDEO_ID by the actual ID that you have noted before. This will be something like this:
The audio can be played manually. If you want it to play automatically or on loop, then follow the modifications:
To play the audio automatically, set the value of ‘data-autoplay’ to 1.
To play the audio on loop, set ‘data-loop’ to 1.