volume control
This commit is contained in:
parent
ee632664e6
commit
1c406f8b4e
|
@ -3,7 +3,7 @@ import serial_asyncio
|
|||
from led_cmds import (ColorRGBW, ColorHSV, EffectStaticConfig,
|
||||
EffectRandomTwoColorInterpolationConfig, EffectAlexaSwipeConfig,
|
||||
EffectSwipeAndChange)
|
||||
from host_driver import MusicMouseProtocol, RfidTokenRead
|
||||
from host_driver import MusicMouseProtocol, RfidTokenRead, RotaryEncoderEvent
|
||||
from player import AudioPlayer
|
||||
from glob import glob
|
||||
import os
|
||||
|
@ -16,6 +16,9 @@ rfid_token_map = {
|
|||
bytes.fromhex("88041174e9"): "elefant",
|
||||
bytes.fromhex("8804ce7230"): "fuchs",
|
||||
bytes.fromhex("88040d71f0"): "eule",
|
||||
bytes.fromhex("88043c6ede"): "omnom",
|
||||
bytes.fromhex("88040b78ff"): "eichhoernchen",
|
||||
bytes.fromhex("8804bc7444"): "hund",
|
||||
}
|
||||
|
||||
playlists = {
|
||||
|
@ -52,7 +55,7 @@ def on_firmware_msg(protocol, message):
|
|||
eff = EffectStaticConfig(ColorRGBW(0, 0, 0, 0))
|
||||
protocol.send_message(eff)
|
||||
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.swipe.primary_color = ColorRGBW(1, 1, 0, 0)
|
||||
figure = rfid_token_map[message.id]
|
||||
|
@ -64,8 +67,16 @@ def on_firmware_msg(protocol, message):
|
|||
eff.swipe.bell_curve_width_in_leds = 6
|
||||
|
||||
protocol.send_message(eff)
|
||||
audio_player.set_playlist(playlists[figure])
|
||||
audio_player.play_from_start()
|
||||
print(figure)
|
||||
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()
|
||||
|
|
|
@ -113,3 +113,12 @@ class AudioPlayer:
|
|||
self.on_playlist_end_callback()
|
||||
#print("Callback from VLC", event, args, kwargs)
|
||||
#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)
|
||||
|
|
Loading…
Reference in New Issue