first try with vlc
This commit is contained in:
parent
4fbd7f0f1b
commit
f4e31176a9
|
@ -4,36 +4,39 @@ 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
|
||||||
|
from player import AudioPlayer
|
||||||
|
from glob import glob
|
||||||
|
import os
|
||||||
|
|
||||||
|
MUSIC_FOLDER = "/home/martin/code/musicmouse/espmusicmouse/host_driver/music"
|
||||||
|
|
||||||
|
audio_player = AudioPlayer()
|
||||||
|
|
||||||
rfid_token_map = {
|
rfid_token_map = {
|
||||||
bytes.fromhex("0000000000"): "None",
|
bytes.fromhex("0000000000"): "None",
|
||||||
bytes.fromhex("88041174e9"): "Elephant",
|
bytes.fromhex("88041174e9"): "elefant",
|
||||||
bytes.fromhex("8804ce7230"): "Fox",
|
bytes.fromhex("8804ce7230"): "fuchs",
|
||||||
bytes.fromhex("88040d71f0"): "Owl",
|
bytes.fromhex("88040d71f0"): "eule",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def on_firmware_msg(protocol, message):
|
def on_firmware_msg(protocol, message):
|
||||||
print("Got message", message)
|
print("Got message", message)
|
||||||
if isinstance(message, RfidTokenRead) and message.id in rfid_token_map:
|
if isinstance(message, RfidTokenRead) and message.id in rfid_token_map:
|
||||||
if rfid_token_map[message.id] == "Elephant":
|
if rfid_token_map[message.id] == "None":
|
||||||
print("Elephant")
|
|
||||||
eff = EffectStaticConfig(ColorRGBW(0, 0, 1, 0))
|
|
||||||
protocol.send_message(eff)
|
|
||||||
elif rfid_token_map[message.id] == "Fox":
|
|
||||||
print("Fox")
|
|
||||||
eff = EffectRandomTwoColorInterpolationConfig()
|
|
||||||
protocol.send_message(eff)
|
|
||||||
elif rfid_token_map[message.id] == "Owl":
|
|
||||||
print("Owl")
|
|
||||||
eff = EffectSwipeAndChange()
|
|
||||||
eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0)
|
|
||||||
protocol.send_message(eff)
|
|
||||||
elif rfid_token_map[message.id] == "None":
|
|
||||||
eff = EffectAlexaSwipeConfig()
|
eff = EffectAlexaSwipeConfig()
|
||||||
eff.forward = False
|
eff.forward = False
|
||||||
print("Nothing")
|
print("Nothing")
|
||||||
protocol.send_message(eff)
|
protocol.send_message(eff)
|
||||||
|
audio_player.pause()
|
||||||
|
else:
|
||||||
|
eff = EffectSwipeAndChange()
|
||||||
|
eff.swipe.primary_color = ColorRGBW(1, 1, 0, 0)
|
||||||
|
protocol.send_message(eff)
|
||||||
|
figure = rfid_token_map[message.id]
|
||||||
|
glob_result = glob(os.path.join(MUSIC_FOLDER, figure, "*.mp3"))
|
||||||
|
audio_player.set_file(glob_result[0])
|
||||||
|
audio_player.play()
|
||||||
|
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import vlc
|
||||||
|
|
||||||
|
|
||||||
|
class AudioPlayer:
|
||||||
|
def __init__(self):
|
||||||
|
self.instance = vlc.Instance()
|
||||||
|
self.mediaplayer = self.instance.media_player_new()
|
||||||
|
|
||||||
|
def set_file(self, filename):
|
||||||
|
media = self.instance.media_new(filename)
|
||||||
|
self.mediaplayer.set_media(media)
|
||||||
|
|
||||||
|
def play(self):
|
||||||
|
self.mediaplayer.play()
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.mediaplayer.pause()
|
Loading…
Reference in New Issue