Handle quick playback 'rebounces' in mpv

This commit is contained in:
Fabio Manganiello 2019-02-19 10:56:05 +01:00
parent 0336427386
commit c0513cade9

View file

@ -67,6 +67,8 @@ class MediaMpvPlugin(MediaPlugin):
self._player.register_event_callback(self._event_callback()) self._player.register_event_callback(self._event_callback())
def _event_callback(self): def _event_callback(self):
playback_rebounce_event = threading.Event()
def callback(event): def callback(event):
from mpv import MpvEventID as Event from mpv import MpvEventID as Event
self.logger.info('Received mpv event: {}'.format(event)) self.logger.info('Received mpv event: {}'.format(event))
@ -76,7 +78,8 @@ class MediaMpvPlugin(MediaPlugin):
return return
bus = get_bus() bus = get_bus()
if evt == Event.FILE_LOADED: if evt == Event.FILE_LOADED or evt == Event.START_FILE:
playback_rebounce_event.set()
self._mpv_stopped_event.clear() self._mpv_stopped_event.clear()
bus.post(NewPlayingMediaEvent(resource=self._get_current_resource())) bus.post(NewPlayingMediaEvent(resource=self._get_current_resource()))
bus.post(MediaPlayEvent(resource=self._get_current_resource())) bus.post(MediaPlayEvent(resource=self._get_current_resource()))
@ -84,9 +87,14 @@ class MediaMpvPlugin(MediaPlugin):
bus.post(MediaPauseEvent(resource=self._get_current_resource())) bus.post(MediaPauseEvent(resource=self._get_current_resource()))
elif evt == Event.UNPAUSE: elif evt == Event.UNPAUSE:
bus.post(MediaPlayEvent(resource=self._get_current_resource())) bus.post(MediaPlayEvent(resource=self._get_current_resource()))
# elif evt == Event.END_FILE or evt == Event.SHUTDOWN: elif evt == Event.END_FILE or evt == Event.SHUTDOWN:
elif evt == Event.SHUTDOWN: playback_rebounce_event.clear()
self._player = None playback_rebounced = playback_rebounce_event.wait(timeout=1)
if playback_rebounced:
return
if evt == Event.SHUTDOWN:
self._player = None
self._mpv_stopped_event.set() self._mpv_stopped_event.set()
bus.post(MediaStopEvent()) bus.post(MediaStopEvent())
return callback return callback