stream.py 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 update(self):
  9. '''
  10. Called when the handler should update the display.
  11. '''
  12. self.display.update(title=[
  13. "",
  14. "Stream:",
  15. self.item["name"]
  16. ], img=self.item.get("img"))
  17. if self._mplayer is None:
  18. self._mplayer = MPlayer()
  19. self._mplayer.loadfile(self.item["url"])
  20. def stop(self):
  21. '''
  22. Called when the handler should stop.
  23. '''
  24. if self._mplayer is not None:
  25. self._mplayer.quit()
  26. self._mplayer = None
  27. def emitEvent(self, event):
  28. '''
  29. Called when an event has happened.
  30. '''
  31. super().emitEvent(event)