From c06d61a83c5ab999a583c13ef0124bae03167abb Mon Sep 17 00:00:00 2001 From: J-Stutzmann <18075488+J-Stutzmann@users.noreply.github.com> Date: Mon, 31 Jul 2023 06:09:07 -0400 Subject: [PATCH] Made audio-focus calls respect mute state. --- .../main/java/org/schabi/newpipe/player/Player.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 1a8283590..1a323176c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1082,7 +1082,7 @@ public final class Player implements PlaybackListener, Listener { UIs.call(PlayerUi::onPrepared); - if (playWhenReady) { + if (playWhenReady && !isMuted()) { audioReactor.requestAudioFocus(); } } @@ -1223,6 +1223,11 @@ public final class Player implements PlaybackListener, Listener { public void toggleMute() { final boolean wasMuted = isMuted(); simpleExoPlayer.setVolume(wasMuted ? 1 : 0); + if (wasMuted) { + audioReactor.requestAudioFocus(); + } else { + audioReactor.abandonAudioFocus(); + } UIs.call(playerUi -> playerUi.onMuteUnmuteChanged(!wasMuted)); notifyPlaybackUpdateToListeners(); } @@ -1620,7 +1625,9 @@ public final class Player implements PlaybackListener, Listener { return; } - audioReactor.requestAudioFocus(); + if (!isMuted()) { + audioReactor.requestAudioFocus(); + } if (currentState == STATE_COMPLETED) { if (playQueue.getIndex() == 0) {