volume control

This commit is contained in:
Martin Bauer 2021-12-15 23:14:59 +01:00
parent ee632664e6
commit 1c406f8b4e
2 changed files with 24 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import serial_asyncio
from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig, from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig,
EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig, EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig,
EffectSwipeAndChange) EffectSwipeAndChange)
from host_driver import MusicMouseProtocol, RfidTokenRead from host_driver import MusicMouseProtocol, RfidTokenRead, RotaryEncoderEvent
from player import AudioPlayer from player import AudioPlayer
from glob import glob from glob import glob
import os import os
@ -16,6 +16,9 @@ rfid_token_map = {
bytes.fromhex("88041174e9"): "elefant", bytes.fromhex("88041174e9"): "elefant",
bytes.fromhex("8804ce7230"): "fuchs", bytes.fromhex("8804ce7230"): "fuchs",
bytes.fromhex("88040d71f0"): "eule", bytes.fromhex("88040d71f0"): "eule",
bytes.fromhex("88043c6ede"): "omnom",
bytes.fromhex("88040b78ff"): "eichhoernchen",
bytes.fromhex("8804bc7444"): "hund",
} }
playlists = { playlists = {
@ -52,7 +55,7 @@ def on_firmware_msg(protocol, message):
eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0)) eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0))
protocol.send_message(eff) protocol.send_message(eff)
audio_player.pause() audio_player.pause()
if isinstance(message, RfidTokenRead) and message.id in rfid_token_map: elif isinstance(message, RfidTokenRead) and message.id in rfid_token_map:
eff = EffectSwipeAndChange() eff = EffectSwipeAndChange()
eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0) eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0)
figure = rfid_token_map[message.id] figure = rfid_token_map[message.id]
@ -64,8 +67,16 @@ def on_firmware_msg(protocol, message):
eff.swipe.bell_curve_width_in_leds = 6 eff.swipe.bell_curve_width_in_leds = 6
protocol.send_message(eff) protocol.send_message(eff)
audio_player.set_playlist(playlists[figure]) print(figure)
audio_player.play_from_start() if figure in playlists:
audio_player.set_playlist(playlists[figure])
audio_player.play_from_start()
elif isinstance(message, RotaryEncoderEvent):
if audio_player.is_playing():
if message.direction == 2:
audio_player.change_volume(2)
elif message.direction == 1:
audio_player.change_volume(-2)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()

View File

@ -113,3 +113,12 @@ class AudioPlayer:
self.on_playlist_end_callback() self.on_playlist_end_callback()
#print("Callback from VLC", event, args, kwargs) #print("Callback from VLC", event, args, kwargs)
#print(event.meta_type, event.obj, event.type) #print(event.meta_type, event.obj, event.type)
def change_volume(self, amount=1):
vol = self.media_player.audio_get_volume() + amount
print("volume", vol)
if vol > 100:
vol = 100
if vol < 0:
vol = 0
self.media_player.audio_set_volume(vol)