t = message.type
if t == gst.MESSAGE_EOS:
- log.info("End of stream")
self.eos_callback()
+ log.info("End of stream")
elif t == gst.MESSAGE_STATE_CHANGED:
- log.info("State changed: %s -> %s -> %s", old, new, pending)
old, new, pending = message.parse_state_changed()
+ log.info("State changed: %s -> %s -> %s", old, new, pending)
elif t == gst.MESSAGE_ERROR:
- log.critical( 'Error: %s %s', err, debug )
err, debug = message.parse_error()
+ log.critical( 'Error: %s %s', err, debug )
self.stop()
else:
log.info("? %s", message.type)
return self.items[self._current]
return None
+ def prev(self):
+ if self.has_prev():
+ self._current = self._current - 1
+ return self.items[self._current]
+ return None
+
def has_next(self):
return self._current < (len(self.items)-1)
+ def has_prev(self):
+ return self._current > 0
+
def current(self):
if self._current >= 0:
return self.items[self._current]
def current_index(self):
return self._current
- def __len__(self):
+ def size(self):
+ print type(self)
return len(self.items)
+ def __repr__(self):
+ return "Playlist(%s)"%(", ".join([str(item) for item in self.items]))
+
class Player(Playlist):
def __init__(self):
self.backend = PlayerBackend()
self.backend.set_eos_callback(self._on_eos)
- self.playlist = None
+ self.playlist = Playlist()
def play(self, playlist = None):
if playlist:
self.playlist = playlist
- if self.playlist is not None:
+ elif self.playlist is None:
+ self.playlist = Playlist()
+ if self.playlist.size():
if self.playlist.has_next():
entry = self.playlist.next()
log.debug("playing %s", entry)
self.stop()
def prev(self):
- pass
+ if self.playlist.has_prev():
+ entry = self.playlist.prev()
+ log.debug("playing %s", entry)
+ self.backend.play_url('mp3', entry.mp3_url())
def _on_eos(self):
log.debug("EOS!")
self.next()
+
+the_player = Player() # the player instance