Learn how to turn the standard YouTube video player into an audio player and embed any YouTube video in your website as any other audio file.
You can embed YouTube videos into your website by copy and paste the embed code in text mode. How do you embed the audio portion of any YouTube video into your website? There is an easy option, you convert the YouTube video into an MP3 file and upload it to an audio hosting site. This method will work but due to copyright issues, you likely to have face the problem from YouTube.
In this tweak, i’ll show you a simpler approach that uses the official YouTube API and requires no file conversion. With this technique, you can embed any YouTube video in your web pages and visitors on your site will be able to play and pause the audio with a simple click. You can also use a YouTube video as background audio that runs in a loop.
How To Embed YouTube Audio
Open any YouTube video which do you want to embed in your web page and copy the YouTube video ID (a string of 11 characters). Now copy-paste the code given below anywhere on your website and replace VIDEO_ID with actual ID of your YouTube video.
You’re able to change the following parameter depending on requirement
data-autoplay : You want to play audio immediately on page load, change the value to “1”.
data-loop : Set data-loop to 1, the audio will play continuously in a never-ending loop until manually stopped.
This method work on both desktop and mobile browsers because YouTube video usage the IFRAME player.
Here’s the annotated version of the source code. It can be extended to embed YouTube playlists, the default playback volume can be changed or you even embed a part of the video.
Credit : http://www.labnol.org