How To Embed The Audio From A YouTube Video?
How To Embed The Audio From A YouTube Video?

How To Embed The Audio From A YouTube Video?

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.

more-features-right

2. Now, add the snippet to your website’s HTML code. It should be like the following.

</p> <div data-video="VIDEO_ID" data-autoplay="0" data-loop="1" id="youtube-audio"> </div> <p><script src="https://www.youtube.com/iframe_api"></script><br /> <script src="https://cdn.rawgit.com/labnol/files/master/yt.js"></script>

Replace VIDEO_ID by the actual ID that you have noted before. This will be something like this:

</p> <div data-video="Rdw9R4cuJiI" data-autoplay="0" data-loop="1" id="youtube-audio"> </div> <p><script src="https://www.youtube.com/iframe_api"></script><br /> <script src="https://cdn.rawgit.com/labnol/files/master/yt.js"></script>

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.

A blogger with a zeal for learning technology. Enchanted to connect with wonderful people like you.