Sunday, April 10, 2011

YouTube Audio Player

While I was procrastinating on my essay for GSW, I’ve made a couple slight changes to
the YouTube
Audio Player
that should make it a little better.

Firstly, I’ve given you the
ability to allow YouTube to set cookies.  I’m not sure why anyone would be interested in doing this for a
Music player, but its there.  I guess the primary reason I set this is because youtube-nocookie wasn’t
working properly the other day, as I soon found out from a comment on my blog.  So if it isn’t showing up,
you should allow YouTube to collect cookies.

The second, and by far the more important
change is embedding the link (in the event that neither the object nor the embed shows) in a <noembed>
tag.  I’m not quite sure how I didn’t know about the existence of this tag, but I’ve gone ahead and
programmed it in properly, which should get rid of the annoying duplication some users have been seeing on
any players generated from this point forward.

And one last change I made while working
on this blog post, I created an API!  So now you can generate them on the fly if you want to and get just
the HTML for the player.  I’ll document the API below:

  • &q=

    • The URL to the YouTube Video or Playlist

  • &a=1

    • Only Add if you want the music to AutoPlay

  • &loop=1

    • Only Add if you want the music to Loop

  • &js=1

    • Only Add if you want to be able to use the
      JavaScript API with it

  • &s=on

    • Add if you want to enable the Progress Bar on the video.

    • &psize=
      This is the progress bar size, acceptable variables are below

      • s –
        Small, This will set the width of the video to 150px

      • m – Medium, This will
        set the width of the video to 187px

      • l – Large, This will set the width of
        the video to 224px

      • &tc =1

        • Only
          Add if you also want to show a timecode.  Only works with progress bar.  Changes the follow sizes to the
          corresponding pixels:

        • s – 225px

        • m – 262px

        • l – 299px

  • &invis=1

    • Add if you want to make the player
      invisible.  Note: People hate this.

  • &html5=1

    • Add if you want to use YouTube’s HTML5 player. You shouldn’t use this.  Its VERY buggy.

  • &cookie=1

    • Add if you’re okay with YouTube
      setting cookies on the user’s computer.

that’s all!  Enjoy!