From 3fc67ceb2b3559b00f0b96599e639b8030ae9821 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 4 Jun 2024 02:55:13 +0200 Subject: [PATCH] Audio output --- sbapp/plyer/platforms/android/audio.py | 13 +++++++++++-- sbapp/plyer/platforms/linux/audio.py | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sbapp/plyer/platforms/android/audio.py b/sbapp/plyer/platforms/android/audio.py index b6421b4..3d40dc6 100644 --- a/sbapp/plyer/platforms/android/audio.py +++ b/sbapp/plyer/platforms/android/audio.py @@ -30,10 +30,13 @@ class AndroidAudio(Audio): self._check_thread = None self._finished_callback = None self._format = "opus" + self.is_playing = False def _check_playback(self): while self._player and self._player.isPlaying(): time.sleep(0.25) + + self.is_playing = False if self._finished_callback and callable(self._finished_callback): self._check_thread = None @@ -45,7 +48,7 @@ class AndroidAudio(Audio): if self._format == "aac": self._recorder.setAudioSource(AudioSource.DEFAULT) self._recorder.setAudioSamplingRate(48000) - self._recorder.setAudioEncodingBitRate(128000) + self._recorder.setAudioEncodingBitRate(64000) self._recorder.setAudioChannels(1) self._recorder.setOutputFormat(OutputFormat.MPEG_4) self._recorder.setAudioEncoder(AudioEncoder.AAC) @@ -53,7 +56,7 @@ class AndroidAudio(Audio): else: self._recorder.setAudioSource(AudioSource.DEFAULT) self._recorder.setAudioSamplingRate(48000) - self._recorder.setAudioEncodingBitRate(128000) + self._recorder.setAudioEncodingBitRate(16000) self._recorder.setAudioChannels(1) self._recorder.setOutputFormat(OutputFormat.OGG) self._recorder.setAudioEncoder(AudioEncoder.OPUS) @@ -74,11 +77,14 @@ class AndroidAudio(Audio): self._player.release() self._player = None + self.is_playing = False + def _play(self): self._player = MediaPlayer() self._player.setDataSource(self.file_path) self._player.prepare() self._player.start() + self.is_playing = True self._check_thread = threading.Thread(target=self._check_playback, daemon=True) self._check_thread.start() @@ -86,6 +92,9 @@ class AndroidAudio(Audio): def reload(self): self._stop() + def playing(self): + return self.is_playing + def instance(): return AndroidAudio() diff --git a/sbapp/plyer/platforms/linux/audio.py b/sbapp/plyer/platforms/linux/audio.py index 2cf3ec3..18ba9f2 100644 --- a/sbapp/plyer/platforms/linux/audio.py +++ b/sbapp/plyer/platforms/linux/audio.py @@ -15,10 +15,13 @@ class LinuxAudio(Audio): self._finished_callback = None self._loaded_path = None self.sound = None + self.is_playing = False def _check_playback(self): while self.sound != None and self.sound.state == "play": time.sleep(0.25) + + self.is_playing = False if self._finished_callback and callable(self._finished_callback): self._check_thread = None @@ -31,6 +34,7 @@ class LinuxAudio(Audio): def _stop(self): if self.sound != None and self.sound.state == "play": self.sound.stop() + self.is_playing = False def _play(self): if self.sound == None or self._loaded_path != self._file_path: @@ -46,6 +50,9 @@ class LinuxAudio(Audio): self._loaded_path = None self.sound = None + def playing(self): + return self.is_playing + def instance(): return LinuxAudio()