This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
forked from inotia00/revanced-integrations
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Overlay Button - Always Repeat): Re-implement
pause after repeat
- Loading branch information
1 parent
94beab4
commit e7fd995
Showing
4 changed files
with
69 additions
and
3 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
27 changes: 27 additions & 0 deletions
27
app/src/main/java/app/revanced/integrations/youtube/patches/utils/AlwaysRepeatPatch.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 |
---|---|---|
@@ -1,10 +1,37 @@ | ||
package app.revanced.integrations.youtube.patches.utils; | ||
|
||
import android.content.Context; | ||
import android.media.AudioManager; | ||
import android.view.KeyEvent; | ||
|
||
import app.revanced.integrations.youtube.utils.ReVancedUtils; | ||
import app.revanced.integrations.youtube.settings.SettingsEnum; | ||
|
||
public class AlwaysRepeatPatch { | ||
|
||
public static boolean enableAlwaysRepeat(boolean original) { | ||
return !SettingsEnum.ALWAYS_REPEAT.getBoolean() && original; | ||
} | ||
|
||
public static void shouldRepeatAndPause() { | ||
Context context = ReVancedUtils.getContext(); | ||
if (context == null) | ||
return; | ||
|
||
pauseMedia(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PAUSE), context); | ||
pauseMedia(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PAUSE), context); | ||
|
||
AudioManager audioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE); | ||
|
||
if (audioManager == null) | ||
return; | ||
|
||
audioManager.requestAudioFocus(null, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); | ||
} | ||
|
||
public static void pauseMedia(KeyEvent keyEvent, Context context) { | ||
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON); | ||
intent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent); | ||
context.sendOrderedBroadcast(intent, null); | ||
} | ||
} |
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