Musik Player funktoiniert rudimentär + neue Infoangaben und Fixes für die Wetterangabe

This commit is contained in:
2026-01-24 21:48:29 +01:00
parent 493a271d0e
commit 31a10f5aeb
16 changed files with 370 additions and 76 deletions

87
music_control.py Normal file
View File

@@ -0,0 +1,87 @@
import vlc
import os
import threading
class MusicPlayer:
def __init__(self, base_path="/home/tino/Desktop/Abschlussprojekt/test assistant/cloneAssistantAllInOne/RasPi_Voice_Assistant--WIP/musik/"):
self.base_path = base_path
self.instance = vlc.Instance()
self.player = self.instance.media_player_new()
self.lock = threading.Lock()
self.files = []
self.current_index = 0
self.playing = False
self.paused = False
events = self.player.event_manager()
events.event_attach(
vlc.EventType.MediaPlayerEndReached,
self._song_ended
)
def load_genre(self, genre):
folder = os.path.join(self.base_path, genre)
if not os.path.isdir(folder):
return False
self.files = [
os.path.join(folder, f)
for f in os.listdir(folder)
if f.endswith((".mp3", ".wav"))
]
self.current_index = 0
return bool(self.files)
def _play_current(self):
with self.lock:
media = self.instance.media_new(self.files[self.current_index])
self.player.set_media(media)
self.player.play()
self.playing = True
def _song_ended(self, event):
self.next_song()
def play(self):
if not self.files:
return False
if self.paused:
return self.resume()
if not self.playing:
self._play_current()
return True
def pause(self):
if self.playing:
self.player.pause()
self.playing = False
self.paused = True
def resume(self):
if self.paused:
self.player.play()
self.playing = True
self.paused = False
return True
return False
def stop(self):
self.player.stop()
self.playing = False
self.paused = False
self.current_index = 0
def next_song(self):
with self.lock:
self.current_index = (self.current_index + 1) % len(self.files)
self._play_current()
def previous_song(self):
with self.lock:
self.current_index = (self.current_index - 1) % len(self.files)
self._play_current()