--- /dev/null
+import Actions
+import subprocess
+
+class Player(object):
+
+ def __init__(self):
+ pass
+
+ def _command(self,*command):
+ subprocess.call([ 'alsaplayer' ] + list(command))
+
+ def _get_status(self):
+ status = {}
+ for line in subprocess.Popen(['alsaplayer', '--status'], stdout=subprocess.PIPE).stdout:
+ if not ':' in line: continue
+ k, v = line.split(':',1)
+ status[k.strip()] = v.strip()
+ return status
+
+ def play(self):
+ self._command('--start')
+
+ def pause(self):
+ if self._get_status()['speed'] == '0%':
+ self.speed(1.0)
+ else:
+ self.speed(0.0)
+
+ def stop(self):
+ self._command('--stop')
+
+ def prev(self):
+ self._command('--prev')
+
+ def next(self):
+ self._command('--next')
+
+ def jump(self, n):
+ self._command('--jump', str(n))
+
+ def clear(self):
+ self._command('--clear')
+
+ def add(self, f):
+ self._command('--enqueue', str(f))
+
+ def speed(self, v):
+ self._command('--speed', str(v))
+
+
+class Action(Actions.Action):
+
+ def __init__(self, name, action, player, *args):
+ Actions.Action.__init__(self, name)
+ self._action = action
+ self._player = player
+ self._args = args
+
+ def __call__(self, binding):
+ getattr(self._player, self._action)(*self._args);
+
+class Dispatcher(object):
+
+ def __init__(self, action):
+ self._action = action
+
+ def __call__(self, name, *args):
+ return Action(name, self._action, *args)
+
+Play = Dispatcher('play')
+Pause = Dispatcher('pause')
+Stop = Dispatcher('stop')
+Toggle = Dispatcher('toggle')
+Prev = Dispatcher('prev')
+Next = Dispatcher('next')
+Jump = Dispatcher('jump')
+Clear = Dispatcher('clear')
+Add = Dispatcher('add')