Skip to content

Commit

Permalink
Sound Notification: Fix Node Suspend on Idle (Bluetooth battery drain) (
Browse files Browse the repository at this point in the history
wbolster#74)

Enabling "Sound notification" seem to cause Bluetooth battery drain.

It seems the mic on/off sound state doesn't get reset after playback; audio source state is still "Running".

Fix resets playback at end-of-stream, so Pipewire can auto-suspend node (e.g. Bluetooth headset).

Co-authored-by: Kok-Yan Lo <[email protected]>
  • Loading branch information
klo2k and klo2k authored Oct 31, 2024
1 parent fdccdd3 commit 2f4a66e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ function init_sound(dir, name) {
const sink = Gst.ElementFactory.make("pulsesink", "sink");
playbin.set_property("audio-sink", sink);
playbin.set_volume(GstAudio.StreamVolumeFormat.LINEAR, 0.5);

// Fix audio node suspend-on-idle; stop playback at end-of-stream
const bus = playbin.get_bus();
bus.add_signal_watch();
bus.connect('message', (_bus, msg) => {
if (msg.type === Gst.MessageType.EOS)
playbin.set_state(Gst.State.NULL);
});

return playbin;
}

Expand Down

0 comments on commit 2f4a66e

Please sign in to comment.