Xspf Javascript Interface

Some of you have been asking for a way to control the Xspf Jukebox using Javascript, well here it is. A single line of code is all it takes to play, pause stop, switch between tracks, and toggle shuffle and repeat on/off. These are the only six functions available at this time, but I am open to suggestions for additional ones. The documentation has been updated for reference here.

25 thoughts on “Xspf Javascript Interface

  1. wow i am totally blown away by how awesome you are! :) i haven’t been able to get the js interface to work. the latest .swf file is dated jan 10. is that the one with the js stuff in it? thanks SO much for this!

  2. Great work Lacy! This opens up some new posibilities for the jukebox such as cross frame control. I have been trying to figure out the best way to embed the jukebox on a site so that you can browse around a site without interrupting the music. One solution I came up with is to use frames and have the jukebox in it’s own frame (I did this on this website – http://franticstate.com). Now with this new JavaScript interface another solution that would impact the page design less is to put the jukebox in a hidden frame and control it with JavaScript from the main page. The main drawback though is you would not be able to display the track information.

    On my site irishrockers.com I did not want to use frames so I went with an embedded juke box that you can undock into it’s own window and continue to navigate the site without interupting the music. This Javascript interface allows me to stop the music on the embedded player before launching the player in the popup.

    Thanks for all your work on continued improvements to XSPF Jukebox!

  3. This is off the topic of JavaScript interface but I’m just wondering if you or anyone else have come accross this one: The main issue I’m noticing now with the jukebox is an intermittant one – I set up my jukeboxes with autoload turned on and somtimes when I load up a page wuth the jukebox the display shows ‘Xspf Jukebox’ instead of the normal ‘Loading…’. Whenever this happens, pressing the play button does nothing and the only way to get the Jukebox to play a track is to refresh the page. This seems to happen at random approximately 10% of the time. The other strange thing about this is that I have changed the text for player_title and load_message but yet is displays ‘Xspf Jukebox’.

    Just wondering if anyone else noticed this problem or if anyone has any ideas what might be causing it?

  4. I cannot use the javascript functions on ie. i get the error: “object does’nt support this method or property”. i am using the same name for the id attribute (for object tag) and name attribute for embed tag. also it would be great if you could add a function for reseting the player to start from the first song in the play list. The jukebox is pretty useful.

  5. nice..ill have to check it out when I get a chance…two questions though…I already asked you about this..the crossfader fades in/out right now…any way to set it where the next song starts at 100% volume instead of fading in?

    Also..seems tracks shorter than 11 seconds wont crossfade to next track…any ideas why?

  6. This is a Flash error and not a Jukebox error. I have been doing a little research but there does not seem to be a definitive answer. All I can say is don’t put the tag inside a
    tag. Google is your friend.

  7. Lacy, I’ve posted this before but not had any response.. i’ve included “&statsurl=stats.php” in variables.txt but nothing happens… how do I collect stats? what am I doing wrong?

  8. Just started using xspf_jukebox. Easy to set up and get going, nice work! One suggestion I have for javascript control is a method allowing me to jump to a particular track in my playlist, so like switchToTrack(5) or somesuch. I have download links and it would be great to have them also control the track running in the player.

    In case it helps anyone else, I wanted to mention that when making calls from javascript, verify that you get an instance of the embed HTML element, not the object HTML element enclosing it. The embed is the movie, the object won’t know about any of the functions. So if you get “is not a function” console errors, check that.

    I tried to force a track selection by attempting to reset the player using Rewind, but got an NPObject error, which is consistent given that IsPlaying seems to always return false. My thinking was Rewind, skip, skip, would get me to track 3 but no dice. In any case a track selection function would be a very useful thing at least for me.

    On a separate note (so to speak) I noticed some issues in playback (like not getting sound) when crossFade is set to false or zero. I’m not completely averse to crossfading, but sometimes I actually want the silence between tracks. My guess is it may be tied to the buffering somehow, but that’s just a guess. Seemed worth mentioning.

    In any case thanks for pulling this together, it’s a great to have this capability for a site.

  9. Hello Lacy

    First thanks a lot for the great job you’re doing on the player!
    About javascript controls, I have a suggestion that would help me a lot for the use I make of the player :
    – the ability, with javascript control, to append a song to the currently playing playlist

    With this, I would be able to add new songs to the playing playlist, without reloading the player

    Tell me what you think about it

    Cheers

    Janfi, from France

  10. The player has been updated and your suggestion was included. Use the javascript function addTrack(id, location, title, creator, info url, purchase url, image url, annotation).
    More javascript functions will be available soon which use the id property but for now, it has no function.

  11. Hello everyone

    I can’t manage to use the javascript interface of the jukebox. Everytime I get a “is not a function” error in Firebug.

    Here’s the code of the very simple page I use to test :

    Play
    Shuffle
    Repeat

    When I test the flashObject object via this call :

    alert(window.document.flashObject);

    I get a :

    [object HTMLEmbedElement]

    which means I really get the embed element, like Eric Parker advices in his message.

    Can someone please help me?
    Cheers

  12. A new message with the code tag, sorry for the last one :)

    Hello everyone

    I can’t manage to use the javascript interface of the jukebox. Everytime I get a “is not a function” error in Firebug.

    Here’s the code of the very simple page I use to test :

    Play
    Shuffle
    Repeat

    When I test the flashObject object via this call :

    alert(window.document.flashObject);

    I get a :

    [object HTMLEmbedElement]

    which means I really get the embed element, like Eric Parker advices in his message.

    Can someone please help me?
    Cheers

  13. well, I just downloaded your new player and i get a js error that says object expected. I also get a popup message that says a script in the movie is causing it to run slowly. Lastly, I can’t scroll once I pick a song. It pretty much becomes diasabled once a song is chosen so I cant scroll to look at other songs. Any ideas?

  14. I fund what the problem was. It turned out that the javascript controls don’t work with local files. If I use my browser to see my web page localy, with the flash file also accesed localy, the javascript controls won’t work. But with the same page uploaded and accesed online, it works perfectly.

  15. I noticed that gotoTrack(track number) does not work when shuffle=ON, unfortunatley shuffle can only be toggled and not turned off with the Javascript Interface. I modified the .fla to turn off shuffle in the gotoTrack(track number) subroutine.

  16. I need to add(possibly delete) tracks to the playlist dynamically through the javascript API. I’ll even help out. I’m not familiar with Flash programming, but I am a programmer.

  17. Hi, is there a way to check whether a song or a play list is finish playing using JavaScript interface?

  18. Rico is right.
    gototrack(tracknumber)doesn’t work~
    in about line 394
    track_index = shuffle_array[shuffle_index];
    was miss typed
    correct it to this
    track_index = shuffle_array[track_index];
    make gototrack work properly.

    Anyway, Xspf Jukebox is a great mp3 player.

  19. and how can I use swfobject.js with google sites – where I can’t enter the header text?
    maybe its not possible. thanks

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>