javascript to trigger play/pause/prev/next in SSB

Need help? Post your questions here.

Moderator: moderators

javascript to trigger play/pause/prev/next in SSB

Postby stampedes » Wed Jun 23, 2010 12:02 am

Hey there-
I just discovered subsonic a few days ago, to my great delight- I'd just finally reached the breaking point with itunes that I was planning on taking an amateur crack at coding up something like subsonic. Glad to see I don't have to now! Thanks! As you'll see from the question I'm about to ask, I'm woefully unequipped for such a task, so you've saved me much effort.

Previously, I used global shortcut keys for prev/next/play/pause control of itunes. I'm working on replicating this using a site-specific browser (Fluid) and (hopefully) a small bit of javascript to control the player. I've just taken a brief look at the code, and I'm a bit lost.

Being pretty much stupid about javascript+flash, I'm a bit thrown by how the playlist control works. I've got prev/next working fine, and I can stop the player easily, but I can't figure out what code needs to be called to toggle a play/pause of the player. It looks like the events provided by JW-Player are inadequate (no "pause" event, best i can tell), and the dwr stuff looks to have some control, but I can't quite pin down the flow of code.

Can anyone chime in as to what the right direction would be in the sense of where to poke and prod to get the player to do what I want it to?
User avatar
stampedes
 
Posts: 2
Joined: Tue Jun 22, 2010 11:36 pm

Postby stampedes » Wed Jun 23, 2010 1:41 am

Well, that wasn't too hard at all, actually. Nevermind!

The jw-player object, in its docs, claims that sending a "PLAY" event will toggle, but this doesn't seem to be the case, so it must be accompanied by a boolean parameter. This gets toggles working fine. This, of course, only works with the web player mode, but I couldn't figure out play/pause without tweaking the flash object itself.

For the curious: I use Spark (http://www.shadowlab.org/Software/spark.php) to trigger these on keypress, but anything that you can set to execute javascript on a keypress (quicksilver, maybe launchbar, QSB, etc) will work. You've also got to use Fluidium (http://github.com/itod/fluidium), not fluid, to do this- Fluid lacks the needed "do Javascript" command.


Code: Select all
-- playback
tell application "Subsonic"
   do JavaScript "switch (parent.playlist.player.getConfig().state) {
   case 'PLAYING':
      parent.playlist.player.sendEvent('PLAY','false');
      break;
   case 'PAUSED':
      parent.playlist.player.sendEvent('PLAY','true');
      break;
   case 'IDLE':
      parent.playlist.skip(0);
      break;
   default:
   }"
end tell


Code: Select all
-- previous
tell application "Subsonic"
   do JavaScript "parent.playlist.onPrevious()"
end tell


Code: Select all
-- next
tell application "Subsonic"
   do JavaScript "parent.playlist.onNext()"
end tell


Again, thanks for making such a sweet little program!
User avatar
stampedes
 
Posts: 2
Joined: Tue Jun 22, 2010 11:36 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 22 guests