forked from platypush/platypush
Added support for video events
This commit is contained in:
parent
84ab37e44e
commit
2fdb8c50da
2 changed files with 52 additions and 0 deletions
32
platypush/message/event/video/__init__.py
Normal file
32
platypush/message/event/video/__init__.py
Normal file
|
@ -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:
|
||||||
|
|
|
@ -11,6 +11,8 @@ from dbus.exceptions import DBusException
|
||||||
from omxplayer import OMXPlayer
|
from omxplayer import OMXPlayer
|
||||||
|
|
||||||
from platypush.message.response import Response
|
from platypush.message.response import Response
|
||||||
|
from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \
|
||||||
|
VideoStop, NewPlayingVideoEvent
|
||||||
|
|
||||||
from .. import Plugin
|
from .. import Plugin
|
||||||
|
|
||||||
|
@ -18,9 +20,11 @@ class VideoOmxplayerPlugin(Plugin):
|
||||||
def __init__(self, args=[], *argv, **kwargs):
|
def __init__(self, args=[], *argv, **kwargs):
|
||||||
self.args = args
|
self.args = args
|
||||||
self.player = None
|
self.player = None
|
||||||
|
self.cur_video = None
|
||||||
self.videos_queue = []
|
self.videos_queue = []
|
||||||
|
|
||||||
def play(self, resource):
|
def play(self, resource):
|
||||||
|
self.cur_video = resource
|
||||||
if resource.startswith('youtube:') \
|
if resource.startswith('youtube:') \
|
||||||
or resource.startswith('https://www.youtube.com/watch?v='):
|
or resource.startswith('https://www.youtube.com/watch?v='):
|
||||||
resource = self._get_youtube_content(resource)
|
resource = self._get_youtube_content(resource)
|
||||||
|
@ -29,6 +33,7 @@ class VideoOmxplayerPlugin(Plugin):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.player = OMXPlayer(resource, args=self.args)
|
self.player = OMXPlayer(resource, args=self.args)
|
||||||
|
self._init_player_handlers()
|
||||||
except DBusException as e:
|
except DBusException as e:
|
||||||
logging.warning('DBus connection failed: you will probably not ' +
|
logging.warning('DBus connection failed: you will probably not ' +
|
||||||
'be able to control the media')
|
'be able to control the media')
|
||||||
|
@ -44,6 +49,8 @@ class VideoOmxplayerPlugin(Plugin):
|
||||||
self.player.stop()
|
self.player.stop()
|
||||||
self.player.quit()
|
self.player.quit()
|
||||||
self.player = None
|
self.player = None
|
||||||
|
|
||||||
|
self.cur_video = None
|
||||||
return self.status()
|
return self.status()
|
||||||
|
|
||||||
def voldown(self):
|
def voldown(self):
|
||||||
|
@ -90,6 +97,19 @@ class VideoOmxplayerPlugin(Plugin):
|
||||||
'status': 'Not initialized'
|
'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):
|
def youtube_search_and_play(self, query):
|
||||||
self.videos_queue = self.youtube_search(query)
|
self.videos_queue = self.youtube_search(query)
|
||||||
url = self.videos_queue.pop(0)
|
url = self.videos_queue.pop(0)
|
||||||
|
|
Loading…
Reference in a new issue