From 2fdb8c50da5a044389c74e6f24e9d2b37348601f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 19 Apr 2018 22:42:28 +0200 Subject: [PATCH] Added support for video events --- platypush/message/event/video/__init__.py | 32 +++++++++++++++++++++++ platypush/plugins/video/omxplayer.py | 20 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 platypush/message/event/video/__init__.py diff --git a/platypush/message/event/video/__init__.py b/platypush/message/event/video/__init__.py new file mode 100644 index 000000000..e0ef9d238 --- /dev/null +++ b/platypush/message/event/video/__init__.py @@ -0,0 +1,32 @@ +from platypush.message.event import Event + + +class VideoEvent(Event): + """ Base class for music events """ + + def __init__(self, status, track, *args, **kwargs): + super().__init__(*args, status=status, video=video, **kwargs) + + +class VideoPlayEvent(VideoEvent): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + +class VideoStopEvent(VideoEvent): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + +class VideoPauseEvent(VideoEvent): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + +class NewPlayingVideoEvent(VideoEvent): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + +# vim:sw=4:ts=4:et: + diff --git a/platypush/plugins/video/omxplayer.py b/platypush/plugins/video/omxplayer.py index 21ffb68e0..05d151284 100644 --- a/platypush/plugins/video/omxplayer.py +++ b/platypush/plugins/video/omxplayer.py @@ -11,6 +11,8 @@ from dbus.exceptions import DBusException from omxplayer import OMXPlayer from platypush.message.response import Response +from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \ + VideoStop, NewPlayingVideoEvent from .. import Plugin @@ -18,9 +20,11 @@ class VideoOmxplayerPlugin(Plugin): def __init__(self, args=[], *argv, **kwargs): self.args = args self.player = None + self.cur_video = None self.videos_queue = [] def play(self, resource): + self.cur_video = resource if resource.startswith('youtube:') \ or resource.startswith('https://www.youtube.com/watch?v='): resource = self._get_youtube_content(resource) @@ -29,6 +33,7 @@ class VideoOmxplayerPlugin(Plugin): try: self.player = OMXPlayer(resource, args=self.args) + self._init_player_handlers() except DBusException as e: logging.warning('DBus connection failed: you will probably not ' + 'be able to control the media') @@ -44,6 +49,8 @@ class VideoOmxplayerPlugin(Plugin): self.player.stop() self.player.quit() self.player = None + + self.cur_video = None return self.status() def voldown(self): @@ -90,6 +97,19 @@ class VideoOmxplayerPlugin(Plugin): 'status': 'Not initialized' })) + def _init_player_handlers(self): + if not self.player: + return + + self.player.playEvent += lambda _: \ + self.bus.post(VideoPlayEvent(video=self.cur_video)) + + self.player.pauseEvent += lambda _: \ + self.bus.post(VideoPauseEvent(video=self.cur_video)) + + self.player.stopEvent += lambda _: \ + self.bus.post(VideoStopEvent()) + def youtube_search_and_play(self, query): self.videos_queue = self.youtube_search(query) url = self.videos_queue.pop(0)