Skip to content

Commit 8742698

Browse files
Adedd FIRST_PLAYING status in PlaybackStatus.
1 parent 9de6f51 commit 8742698

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

utils/audio_player/bass_player.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self) -> None:
2020
self.volume: float = 0.5
2121
self.supported_extensions = ('.wav', '.mp3', '.ogg')
2222

23-
def load_audio(self, source: str) -> None:
23+
def load_audio(self, source: str, attempts: Optional[int] = 3) -> None:
2424
"""Loads an audio file or a URL for playback."""
2525

2626
# Stop and release the previous file
@@ -41,7 +41,10 @@ def load_audio(self, source: str) -> None:
4141
self.current_channel = bass.BASS_StreamCreateFile(False, source.encode('utf-8'), 0, 0, 0)
4242

4343
if not self.current_channel:
44-
raise RuntimeError("Failed to load audio file or URL")
44+
if attempts:
45+
print(f"Trying too load: {source}.")
46+
return self.load_audio(source, attempts - 1)
47+
raise RuntimeError("Failed to load audio file or URL: {}".format(source))
4548

4649
self.source = source
4750
self.set_volume(self.volume)
@@ -101,7 +104,7 @@ def get_playback_status(self) -> PlaybackStatus:
101104
return PlaybackStatus.STOPPED
102105

103106
status = bass.BASS_ChannelIsActive(self.current_channel)
104-
if status == PlaybackStatus.PLAYING.value:
107+
if status == PlaybackStatus.PLAYING.value or status == PlaybackStatus.FIRST_PLAYING.value:
105108
return PlaybackStatus.PLAYING
106109
elif status == PlaybackStatus.PAUSED .value:
107110
return PlaybackStatus.PAUSED

utils/audio_player/status.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
class PlaybackStatus(Enum):
44
STOPPED = 0
55
PLAYING = 1
6+
FIRST_PLAYING = 2
67
PAUSED = 3

0 commit comments

Comments
 (0)