Refactor AudioPlayer initialization and update audio file path handling in main
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
# Alarm Clock IoT Application
|
|
||||||
@@ -2,12 +2,17 @@ import subprocess
|
|||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
class AudioPlayer:
|
class AudioPlayer:
|
||||||
|
file_path: str
|
||||||
|
loop: bool
|
||||||
|
current_stop_function: Callable[[], None] | None = None
|
||||||
def __init__(self, file_path: str, loop: bool = False):
|
def __init__(self, file_path: str, loop: bool = False):
|
||||||
|
self.file_path = file_path
|
||||||
|
self.loop = loop
|
||||||
self.current_stop_function: Callable[[], None] | None = None
|
self.current_stop_function: Callable[[], None] | None = None
|
||||||
def play(self, file_path: str, loop: bool = False):
|
def play(self):
|
||||||
"""Play the specified audio file, stopping any currently playing audio."""
|
"""Play the specified audio file, stopping any currently playing audio."""
|
||||||
self.stop() # Stop any currently playing audio
|
self.stop() # Stop any currently playing audio
|
||||||
self.current_stop_function = play_audio(file_path, loop)
|
self.current_stop_function = play_audio(self.file_path, self.loop)
|
||||||
def stop(self):
|
def stop(self):
|
||||||
"""Stop any currently playing audio."""
|
"""Stop any currently playing audio."""
|
||||||
if self.current_stop_function:
|
if self.current_stop_function:
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ from .config import SHELLY_DEVICE_ID
|
|||||||
from .shelly import ShellyDevice
|
from .shelly import ShellyDevice
|
||||||
from .audio import AudioPlayer
|
from .audio import AudioPlayer
|
||||||
from .alarm_clock import AlarmClock
|
from .alarm_clock import AlarmClock
|
||||||
|
from os import path
|
||||||
|
|
||||||
shellyDevice = ShellyDevice(SHELLY_DEVICE_ID)
|
shellyDevice = ShellyDevice(SHELLY_DEVICE_ID)
|
||||||
audio_player = AudioPlayer('./boxing_bell_multiple.wav', loop=True)
|
|
||||||
|
audioFileAbsolutePath = path.abspath('./boxing_bell_multiple.wav')
|
||||||
|
audio_player = AudioPlayer(audioFileAbsolutePath, loop=True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Reference in New Issue
Block a user