forked from platypush/platypush
MPV.Event.IDLE should also be treated as a player stop event
This commit is contained in:
parent
d6f251989c
commit
f378fa8832
1 changed files with 17 additions and 15 deletions
|
@ -38,6 +38,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
|
|
||||||
self.args = self._default_mpv_args
|
self.args = self._default_mpv_args
|
||||||
if args:
|
if args:
|
||||||
|
# noinspection PyTypeChecker
|
||||||
self.args.update(args)
|
self.args.update(args)
|
||||||
|
|
||||||
self._player = None
|
self._player = None
|
||||||
|
@ -55,7 +56,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
os.environ[k] = v
|
os.environ[k] = v
|
||||||
|
|
||||||
self._player = mpv.MPV(**mpv_args)
|
self._player = mpv.MPV(**mpv_args)
|
||||||
self._player.register_event_callback(self._event_callback())
|
self._player.event_callbacks += self._event_callback()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _post_event(evt_type, **evt):
|
def _post_event(evt_type, **evt):
|
||||||
|
@ -83,7 +84,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
self._post_event(MediaPauseEvent, resource=self._get_current_resource(), title=self._player.filename)
|
self._post_event(MediaPauseEvent, resource=self._get_current_resource(), title=self._player.filename)
|
||||||
elif evt == Event.UNPAUSE:
|
elif evt == Event.UNPAUSE:
|
||||||
self._post_event(MediaPlayEvent, resource=self._get_current_resource(), title=self._player.filename)
|
self._post_event(MediaPlayEvent, resource=self._get_current_resource(), title=self._player.filename)
|
||||||
elif evt == Event.SHUTDOWN or (
|
elif evt == Event.SHUTDOWN or evt == Event.IDLE or (
|
||||||
evt == Event.END_FILE and event.get('event', {}).get('reason') in
|
evt == Event.END_FILE and event.get('event', {}).get('reason') in
|
||||||
[EndFile.EOF_OR_INIT_FAILURE, EndFile.ABORTED, EndFile.QUIT]):
|
[EndFile.EOF_OR_INIT_FAILURE, EndFile.ABORTED, EndFile.QUIT]):
|
||||||
playback_rebounced = self._playback_rebounce_event.wait(timeout=0.5)
|
playback_rebounced = self._playback_rebounce_event.wait(timeout=0.5)
|
||||||
|
@ -267,6 +268,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
""" Toggle the fullscreen mode """
|
""" Toggle the fullscreen mode """
|
||||||
return self.toggle_property('fullscreen')
|
return self.toggle_property('fullscreen')
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def toggle_property(self, property):
|
def toggle_property(self, property):
|
||||||
"""
|
"""
|
||||||
|
@ -285,6 +287,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
setattr(self._player, property, value)
|
setattr(self._player, property, value)
|
||||||
return {property: value}
|
return {property: value}
|
||||||
|
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
@action
|
@action
|
||||||
def get_property(self, property):
|
def get_property(self, property):
|
||||||
"""
|
"""
|
||||||
|
@ -314,6 +317,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
@action
|
@action
|
||||||
def set_subtitles(self, filename, *args, **kwargs):
|
def set_subtitles(self, filename, *args, **kwargs):
|
||||||
""" Sets media subtitles from filename """
|
""" Sets media subtitles from filename """
|
||||||
|
# noinspection PyTypeChecker
|
||||||
return self.set_property(subfile=filename, sub_visibility=True)
|
return self.set_property(subfile=filename, sub_visibility=True)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
|
@ -339,13 +343,13 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
"""
|
"""
|
||||||
if not self._player:
|
if not self._player:
|
||||||
return self.play(resource, **args)
|
return self.play(resource, **args)
|
||||||
return self._player.loadfile(resource, mode='append-play', **args)
|
return self._player.loadfile(resource, mode='append-play')
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def mute(self):
|
def mute(self):
|
||||||
""" Toggle mute state """
|
""" Toggle mute state """
|
||||||
if not self._player:
|
if not self._player:
|
||||||
return (None, 'No mpv instance is running')
|
return None, 'No mpv instance is running'
|
||||||
mute = not self._player.mute
|
mute = not self._player.mute
|
||||||
self._player.mute = mute
|
self._player.mute = mute
|
||||||
return {'muted': mute}
|
return {'muted': mute}
|
||||||
|
@ -378,8 +382,7 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
'audio_channels': getattr(self._player, 'audio_channels'),
|
'audio_channels': getattr(self._player, 'audio_channels'),
|
||||||
'audio_codec': getattr(self._player, 'audio_codec_name'),
|
'audio_codec': getattr(self._player, 'audio_codec_name'),
|
||||||
'delay': getattr(self._player, 'delay'),
|
'delay': getattr(self._player, 'delay'),
|
||||||
'duration': getattr(self._player, 'playback_time', 0) +
|
'duration': getattr(self._player, 'playback_time', 0) + getattr(self._player, 'playtime_remaining', 0)
|
||||||
getattr(self._player, 'playtime_remaining', 0)
|
|
||||||
if getattr(self._player, 'playtime_remaining') else None,
|
if getattr(self._player, 'playtime_remaining') else None,
|
||||||
'filename': getattr(self._player, 'filename'),
|
'filename': getattr(self._player, 'filename'),
|
||||||
'file_size': getattr(self._player, 'file_size'),
|
'file_size': getattr(self._player, 'file_size'),
|
||||||
|
@ -410,5 +413,4 @@ class MediaMpvPlugin(MediaPlugin):
|
||||||
return ('file://' if os.path.isfile(self._player.stream_path)
|
return ('file://' if os.path.isfile(self._player.stream_path)
|
||||||
else '') + self._player.stream_path
|
else '') + self._player.stream_path
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue