This repository has been archived by the owner on Dec 11, 2024. It is now read-only.
forked from ReVanced/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube - Overlay buttons): Add
Mute Video
button (#22)
* feat(YouTube - Overlay buttons): Add minimal MuteVolume button * feat(YouTube - Overlay buttons): Swap icons when audio is muted or not * feat(YouTube - Overlay buttons): Update icon when user changes the volume * chore: Update button id and add to animation control --------- Co-authored-by: Aaron Veil <[email protected]>
- Loading branch information
1 parent
0d2fb8d
commit 4a9f4a6
Showing
7 changed files
with
144 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/src/main/java/app/revanced/integrations/youtube/patches/overlaybutton/MuteVolume.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package app.revanced.integrations.youtube.patches.overlaybutton; | ||
|
||
import android.content.IntentFilter; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import app.revanced.integrations.shared.utils.Logger; | ||
import app.revanced.integrations.youtube.settings.Settings; | ||
import app.revanced.integrations.youtube.utils.VideoUtils; | ||
import app.revanced.integrations.youtube.utils.VolumeChangeReceiver; | ||
|
||
import static app.revanced.integrations.shared.utils.Utils.getContext; | ||
import static app.revanced.integrations.youtube.utils.VideoUtils.isAudioMuted; | ||
|
||
@SuppressWarnings("unused") | ||
public class MuteVolume extends BottomControlButton { | ||
private static MuteVolume instance; | ||
static VolumeChangeReceiver volumeChangeReceiver = new VolumeChangeReceiver(); | ||
|
||
public MuteVolume(ViewGroup bottomControlsViewGroup) { | ||
super(bottomControlsViewGroup, | ||
"mute_volume_button", | ||
Settings.OVERLAY_BUTTON_MUTE_VOLUME, | ||
view -> { | ||
VideoUtils.toggleMuteVolume(); | ||
if (instance != null) | ||
instance.changeActivated(!isAudioMuted()); | ||
}, | ||
null | ||
); | ||
// Set the initial state of the button | ||
this.changeActivated(!isAudioMuted()); | ||
|
||
// Register the volume change receiver to update the button state when the volume is changed | ||
IntentFilter filter = new IntentFilter("android.media.VOLUME_CHANGED_ACTION"); | ||
getContext().registerReceiver(volumeChangeReceiver, filter); | ||
} | ||
|
||
public static void initialize(View ViewGroup) { | ||
try { | ||
if (ViewGroup instanceof ViewGroup bottomControlsViewGroup) { | ||
instance = new MuteVolume(bottomControlsViewGroup); | ||
} | ||
} catch (Exception e) { | ||
Logger.printException(() -> "initialize failure", e); | ||
} | ||
} | ||
|
||
public static void changeVisibility(boolean visible, boolean animation) { | ||
MuteVolume muteVolume = instance; | ||
if (muteVolume != null) | ||
muteVolume.setVisibility(visible, animation); | ||
} | ||
|
||
public static void changeVisibilityNegatedImmediate() { | ||
MuteVolume muteVolume = instance; | ||
if (muteVolume != null) | ||
muteVolume.setVisibilityNegatedImmediate(); | ||
} | ||
|
||
// not used | ||
public static void notifyVolumeChange() { | ||
// TODO: not sure if this is implementable | ||
// ideally we would want to change the button state when the volume is changed by the user | ||
// by calling this method on VolumeKeysController.handleVolumeKeyEvent(). However, that method | ||
// is not run if the volume is changed by the user in the YouTube app. A possible solution | ||
// would be to use a global listener to detect volume changes, but I'm not sure if that's possible. | ||
Logger.printInfo(() -> "Volume changed"); | ||
if (instance != null) | ||
instance.changeActivated(!isAudioMuted()); | ||
} | ||
|
||
public static void destroy() { | ||
Logger.printInfo(() -> "Destroying MuteVolume"); | ||
getContext().unregisterReceiver(volumeChangeReceiver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/app/revanced/integrations/youtube/utils/VolumeChangeReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package app.revanced.integrations.youtube.utils; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import app.revanced.integrations.youtube.patches.overlaybutton.MuteVolume; | ||
|
||
/** | ||
* Receiver to notify the MuteVolume button when the volume is changed | ||
*/ | ||
public class VolumeChangeReceiver extends BroadcastReceiver { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
final String action = intent.getAction(); | ||
if ("android.media.VOLUME_CHANGED_ACTION".equals(action)) { | ||
MuteVolume.notifyVolumeChange(); | ||
} | ||
} | ||
} |