📜 ⬆️ ⬇️

jQuery plugin for playing music from youtube

As you know, youtube is the largest video hosting in the world.
Among other things, there is stored as a huge music videos, and just songs. The fact is that YouTube is very often used as a hosting for audio tracks, apparently because there is no specialized audio hosting on the Internet. Thus, the idea arose to make an audio player based on music videos from YouTube ...

Task


So, such a player must meet the following requirements:

Solution, functionality


The result was a fairly compact (less than 200 lines of code) and an easy-to-use plug-in. You only need to connect the two files swfobject.js and jquery.youtube.js , as well as initialize the plugin by simply calling $('#container').youtube();
After that, methods to control the player, such as "prev", "next", "toggleplay", etc., become available.
Example of use and instructions are available on the demo page.

Restrictions


Of course, the proposed solution has its drawbacks.
Firstly, youtube does not allow to receive only audio stream, because of which extra traffic and resources are spent on initializing a video player and hiding it. Fortunately, I did not notice any delays or lags: the player is initialized almost instantly, the tracks are also loaded quite quickly.
The second drawback is more significant: the player will be blocked by flashblock and cf browser for deferred loading of flash movies (like flash-to-click). How can I deal with this, I did not come up with :(

Total


Once again the link to the demo page
Link to download the plugin
')
I would be grateful for any comments and suggestions.

Source: https://habr.com/ru/post/142640/


All Articles