From 32b1c54fbcd1f3f13a047d01a147167f85065ca6 Mon Sep 17 00:00:00 2001 From: Martin Bauer Date: Tue, 28 Dec 2021 11:42:39 +0100 Subject: [PATCH] wip --- espmusicmouse/host_driver/main.py | 21 +++++++++------------ espmusicmouse/host_driver/player.py | 25 +++++++++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/espmusicmouse/host_driver/main.py b/espmusicmouse/host_driver/main.py index 14d2f26..0201bed 100755 --- a/espmusicmouse/host_driver/main.py +++ b/espmusicmouse/host_driver/main.py @@ -110,6 +110,7 @@ class Controller: def handle_rfid_event(self, tagid): if tagid == bytes.fromhex("0000000000"): if self.audio_player.is_playing(): + print("Got 000 rfid -> playing off animation") self._run_off_animation() self.audio_player.pause() self.mmstate.figure_removed() @@ -142,10 +143,13 @@ class Controller: elif message.direction == 1: self.audio_player.change_volume(-volume_increment) elif isinstance(message, ButtonEvent): - if message.button == "left" and message.event == "pressed": - self.audio_player.previous() - elif message.button == "right" and message.event == "pressed": - self.audio_player.next() + btn = message.button + if btn == "left" and message.event == "pressed" and self.audio_player.is_playing(): + res = self.audio_player.previous() + print(f"Prev {res}") + elif btn == "right" and message.event == "pressed" and self.audio_player.is_playing(): + res = self.audio_player.nex() + print(f"Next {res}") elif message.button == "rotary" and message.event == "pressed": hass_service(self.hass, "light", "toggle", entity_id="light.kinderzimmer_fluter") elif isinstance(message, TouchButtonPress): @@ -174,14 +178,6 @@ class Controller: "turn_on", entity_id="light.kinderzimmer_fluter", **colors[message.touch_button]) - #if message.touch_button == TouchButton.RIGHT_FOOT: - # asyncio.create_task( - # self.hass.call_service("switch", "toggle", {"entity_id": "switch.tasmota06"})) - # asyncio.create_task( - # self.hass.call_service("light", "turn_on", {"entity_id": "light.arbeitszimmer_fluter"})) - #elif message.touch_button == TouchButton.LEFT_FOOT: - # asyncio.create_task( - # self.hass.call_service("light", "turn_off", {"entity_id": "light.arbeitszimmer_fluter"})) elif isinstance(message, TouchButtonRelease): figure = self.mmstate.current_figure @@ -216,6 +212,7 @@ class Controller: self.mmstate.mouse_led_effect(mouse_eff) def _run_off_animation(self): + print("Running off animation") ring_eff = EffectReverseSwipe() self.mmstate.led_ring_effect(ring_eff) diff --git a/espmusicmouse/host_driver/player.py b/espmusicmouse/host_driver/player.py index f5b3211..62eaea3 100644 --- a/espmusicmouse/host_driver/player.py +++ b/espmusicmouse/host_driver/player.py @@ -77,10 +77,10 @@ class AudioPlayer: evm = self.media_player.event_manager() evm.event_attach(vlc.EventType.MediaPlayerStopped, self._callback) - evm.event_attach(vlc.EventType.MediaListEndReached, self._callback) evm2 = self.media_list_player.event_manager() - evm2.event_attach(vlc.EventType.MediaListEndReached, self._callback) + evm2.event_attach(vlc.EventType.MediaListPlayerPlayed, self._callback) + evm2.event_attach(vlc.EventType.MediaListPlayerStopped, self._callback) self.on_playlist_end_callback = None @@ -91,16 +91,25 @@ class AudioPlayer: result = vlc.MediaList() for e in files: result.add_media(self.instance.media_new(e)) + + evm = result.event_manager() + evm.event_attach(vlc.EventType.MediaListEndReached, + lambda e: print("Ml CB", str(vlc.EventType(e.type)))) + evm.event_attach(vlc.EventType.MediaListItemAdded, + lambda e: print("Ml ia CB", str(vlc.EventType(e.type)))) + return result def set_playlist(self, media_list): self.media_list_player.set_media_list(media_list) + print("Setting media list of length ", media_list.count()) + self.media_list_player.set_playback_mode(vlc.PlaybackMode.default) def next(self): - self.media_list_player.next() + return self.media_list_player.next() def previous(self): - self.media_list_player.previous() + return self.media_list_player.previous() def play(self): self.media_list_player.play() @@ -115,10 +124,11 @@ class AudioPlayer: self.media_list_player.pause() def _callback(self, event, *args, **kwargs): - - if True: # event.type == vlc.EventType.MediaPlayerEndReached: - #print("End reached") + eventStr = str(vlc.EventType(event.type)) + print(f"Got vlc event type {event.type} {eventStr} , event {event}") + if event.type == vlc.EventType.MediaPlayerStopped: if self.on_playlist_end_callback: + print("Calling playlist end cb") self.on_playlist_end_callback() #print("Callback from VLC", event, args, kwargs) #print(event.meta_type, event.obj, event.type) @@ -128,7 +138,6 @@ class AudioPlayer: volume = self.volume_min if self.volume_max and volume > self.volume_max: volume = self.volume_max - print("volume", volume) self.media_player.audio_set_volume(volume) def set_volume_limits(self, vmin, vmax):