stream.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!./bin/python3
  2. from handler import BaseHandler
  3. from handler.lib.pymplb import MPlayer
  4. class StreamHandler(BaseHandler):
  5. def __init__(self, config, display):
  6. super().__init__(config, display)
  7. self._mplayer = None
  8. def setPlaylistItem(self, item):
  9. '''
  10. Called with the selected item.
  11. '''
  12. super().setPlaylistItem(item)
  13. if self._mplayer is None:
  14. self._mplayer = MPlayer()
  15. self._mplayer.loadfile(self.item["url"])
  16. def update(self, text=None, highlight=-1, title=None, img=None):
  17. '''
  18. Called when the handler should update the display.
  19. '''
  20. super().update(title=[
  21. "",
  22. "Stream:",
  23. self.item["name"]
  24. ], img=self.item.get("img"))
  25. def stop(self):
  26. '''
  27. Called when the handler should stop.
  28. '''
  29. if self._mplayer is not None:
  30. self._mplayer.quit()
  31. self._mplayer = None
  32. def emitEvent(self, event):
  33. '''
  34. Called when an event has happened.
  35. '''
  36. super().emitEvent(event)