Support for media.vlc.play toggling paused state if called with no arguments, and MediaPlayRequestEvent should have player and plugin attributes set

This commit is contained in:
Fabio Manganiello 2021-02-28 01:40:29 +01:00
parent e0e3081eb1
commit d190560536

View file

@ -1,7 +1,7 @@
import os import os
import urllib.parse import urllib.parse
from platypush.context import get_bus, get_plugin from platypush.context import get_bus
from platypush.plugins.media import PlayerState, MediaPlugin from platypush.plugins.media import PlayerState, MediaPlugin
from platypush.message.event.media import MediaPlayEvent, MediaPlayRequestEvent, \ from platypush.message.event.media import MediaPlayEvent, MediaPlayRequestEvent, \
MediaPauseEvent, MediaStopEvent, MediaSeekEvent, MediaVolumeChangedEvent, \ MediaPauseEvent, MediaStopEvent, MediaSeekEvent, MediaVolumeChangedEvent, \
@ -135,11 +135,11 @@ class MediaVlcPlugin(MediaPlugin):
return callback return callback
@action @action
def play(self, resource, subtitles=None, fullscreen=None, volume=None): def play(self, resource=None, subtitles=None, fullscreen=None, volume=None):
""" """
Play a resource. Play a resource.
:param resource: Resource to play - can be a local file or a remote URL :param resource: Resource to play - can be a local file or a remote URL (default: None == toggle play).
:type resource: str :type resource: str
:param subtitles: Path to optional subtitle file :param subtitles: Path to optional subtitle file
@ -154,7 +154,10 @@ class MediaVlcPlugin(MediaPlugin):
:type fullscreen: bool :type fullscreen: bool
""" """
get_bus().post(MediaPlayRequestEvent(resource=resource)) if not resource:
return self.pause()
self._post_event(MediaPlayRequestEvent, resource=resource)
resource = self._get_resource(resource) resource = self._get_resource(resource)
if resource.startswith('file://'): if resource.startswith('file://'):