Party on with the Youtube JavaScript API
Spewing out Youtube videos on to your page has just become easier. Now you can load, control and search Youtube videos using nothing but JavaScript and a bit of patience. I know, I know. Your excitement is palpable through my DSL exchange.
So what can you do? You can embed two players onto your page:
- The chrome player - with all of Youtube’s standard controls
- The chromeless player - you guessed it, with no controls
For some, probably sane reason (although I’m yet to ascertain why), when using the chrome interface you cannot load new videos into the same player using the loadVideoById function, which is available to the chromeless player. Therefore if you would like to employ this highly useful method and be able to control playback, you have to build your own controls. Fortunately, the API methods make it rather easy.
Having nothing to do one rainy day, I decided to give it a go. My motivation was related to the fact that we go to a lot of parties but neither I nor my lazy friends are bothered to bring music and whine incessantly if we have to change a CD. Given the wealth of music videos on Youtube these days I thought that I could make a rudimentary jukebox so that you can play and cue music at will, even when plastered on tins of lager.
Naturally, it will play whatever video you feed it, but I don’t really want to watch some inane mashup of the Star Wars movies dubbed to a Linkin Park sountrack or other shit. One application that I thought might be rather splendid would be to create a playlist to join all the parts of a movie or TV episode. I am grateful to all the folk who take the time to splice and upload these treats but, by no fault of theirs, it’s a chore to click to the next part every nine minutes and twenty four seconds.
Here’s my first attempt. Of course I will excuse myself with the following:
- it’s alpha
- code review to come
- design change inevitable (maybe in the shape of a jukebox, that would be original)
- predictably, I couldn’t give a wet sock if it worked in IE6
- ideas for the future: saveable playlists, editable playlist order using sortable behaviour, auto-download of next video for smoother playback, fullscreen (or bigger at least), save /cache searches, tally favourites, plug into last.fm for recommendations, get artist data from musicbrainz, blah blah
At the very least, it’s great for listening to music at work.
