mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-30 06:34:28 +02:00
feat(YouTube - Playback speed): Add option to change 2x tap and hold speed (#4307)
This commit is contained in:
parent
220e9c78c1
commit
02fb26e945
@ -32,6 +32,11 @@ public class CustomPlaybackSpeedPatch {
|
|||||||
*/
|
*/
|
||||||
public static final float PLAYBACK_SPEED_MAXIMUM = 8;
|
public static final float PLAYBACK_SPEED_MAXIMUM = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tap and hold speed.
|
||||||
|
*/
|
||||||
|
private static final float TAP_AND_HOLD_SPEED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom playback speeds.
|
* Custom playback speeds.
|
||||||
*/
|
*/
|
||||||
@ -48,12 +53,27 @@ public class CustomPlaybackSpeedPatch {
|
|||||||
private static String[] preferenceListEntries, preferenceListEntryValues;
|
private static String[] preferenceListEntries, preferenceListEntryValues;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
final float holdSpeed = Settings.SPEED_TAP_AND_HOLD.get();
|
||||||
|
if (holdSpeed > 0 && holdSpeed <= PLAYBACK_SPEED_MAXIMUM) {
|
||||||
|
TAP_AND_HOLD_SPEED = holdSpeed;
|
||||||
|
} else {
|
||||||
|
showInvalidCustomSpeedToast();
|
||||||
|
Settings.SPEED_TAP_AND_HOLD.resetToDefault();
|
||||||
|
TAP_AND_HOLD_SPEED = Settings.SPEED_TAP_AND_HOLD.get();
|
||||||
|
}
|
||||||
|
|
||||||
loadCustomSpeeds();
|
loadCustomSpeeds();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void resetCustomSpeeds(@NonNull String toastMessage) {
|
/**
|
||||||
Utils.showToastLong(toastMessage);
|
* Injection point.
|
||||||
Settings.CUSTOM_PLAYBACK_SPEEDS.resetToDefault();
|
*/
|
||||||
|
public static float tapAndHoldSpeed() {
|
||||||
|
return TAP_AND_HOLD_SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showInvalidCustomSpeedToast() {
|
||||||
|
Utils.showToastLong(str("revanced_custom_playback_speeds_invalid", PLAYBACK_SPEED_MAXIMUM));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void loadCustomSpeeds() {
|
private static void loadCustomSpeeds() {
|
||||||
@ -74,17 +94,18 @@ public class CustomPlaybackSpeedPatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (speedFloat >= PLAYBACK_SPEED_MAXIMUM) {
|
if (speedFloat >= PLAYBACK_SPEED_MAXIMUM) {
|
||||||
resetCustomSpeeds(str("revanced_custom_playback_speeds_invalid", PLAYBACK_SPEED_MAXIMUM));
|
showInvalidCustomSpeedToast();
|
||||||
|
Settings.CUSTOM_PLAYBACK_SPEEDS.resetToDefault();
|
||||||
loadCustomSpeeds();
|
loadCustomSpeeds();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
customPlaybackSpeeds[i] = speedFloat;
|
customPlaybackSpeeds[i++] = speedFloat;
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.printInfo(() -> "parse error", ex);
|
Logger.printInfo(() -> "parse error", ex);
|
||||||
resetCustomSpeeds(str("revanced_custom_playback_speeds_parse_exception"));
|
Utils.showToastLong(str("revanced_custom_playback_speeds_parse_exception"));
|
||||||
|
Settings.CUSTOM_PLAYBACK_SPEEDS.resetToDefault();
|
||||||
loadCustomSpeeds();
|
loadCustomSpeeds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ public class Settings extends BaseSettings {
|
|||||||
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_WIFI = new IntegerSetting("revanced_video_quality_default_wifi", -2);
|
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_WIFI = new IntegerSetting("revanced_video_quality_default_wifi", -2);
|
||||||
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_MOBILE = new IntegerSetting("revanced_video_quality_default_mobile", -2);
|
public static final IntegerSetting VIDEO_QUALITY_DEFAULT_MOBILE = new IntegerSetting("revanced_video_quality_default_mobile", -2);
|
||||||
// Speed
|
// Speed
|
||||||
|
public static final FloatSetting SPEED_TAP_AND_HOLD = new FloatSetting("revanced_speed_tap_and_hold", 2.0f, true);
|
||||||
public static final BooleanSetting REMEMBER_PLAYBACK_SPEED_LAST_SELECTED = new BooleanSetting("revanced_remember_playback_speed_last_selected", FALSE);
|
public static final BooleanSetting REMEMBER_PLAYBACK_SPEED_LAST_SELECTED = new BooleanSetting("revanced_remember_playback_speed_last_selected", FALSE);
|
||||||
public static final BooleanSetting CUSTOM_SPEED_MENU = new BooleanSetting("revanced_custom_speed_menu", TRUE);
|
public static final BooleanSetting CUSTOM_SPEED_MENU = new BooleanSetting("revanced_custom_speed_menu", TRUE);
|
||||||
public static final FloatSetting PLAYBACK_SPEED_DEFAULT = new FloatSetting("revanced_playback_speed_default", -2.0f);
|
public static final FloatSetting PLAYBACK_SPEED_DEFAULT = new FloatSetting("revanced_playback_speed_default", -2.0f);
|
||||||
|
@ -662,6 +662,7 @@ public class app/revanced/patches/shared/misc/settings/preference/BasePreference
|
|||||||
|
|
||||||
public final class app/revanced/patches/shared/misc/settings/preference/InputType : java/lang/Enum {
|
public final class app/revanced/patches/shared/misc/settings/preference/InputType : java/lang/Enum {
|
||||||
public static final field NUMBER Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
public static final field NUMBER Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
||||||
|
public static final field NUMBER_DECIMAL Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
||||||
public static final field TEXT Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
public static final field TEXT Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
||||||
public static final field TEXT_CAP_CHARACTERS Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
public static final field TEXT_CAP_CHARACTERS Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
||||||
public static final field TEXT_MULTI_LINE Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
public static final field TEXT_MULTI_LINE Lapp/revanced/patches/shared/misc/settings/preference/InputType;
|
||||||
@ -1447,10 +1448,6 @@ public final class app/revanced/patches/youtube/video/speed/button/PlaybackSpeed
|
|||||||
public static final fun getPlaybackSpeedButtonPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
public static final fun getPlaybackSpeedButtonPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatchKt {
|
|
||||||
public static final fun getSpeedUnavailableId ()J
|
|
||||||
}
|
|
||||||
|
|
||||||
public final class app/revanced/patches/youtube/video/videoid/VideoIdPatchKt {
|
public final class app/revanced/patches/youtube/video/videoid/VideoIdPatchKt {
|
||||||
public static final fun getVideoIdPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
public static final fun getVideoIdPatch ()Lapp/revanced/patcher/patch/BytecodePatch;
|
||||||
public static final fun hookBackgroundPlayVideoId (Ljava/lang/String;)V
|
public static final fun hookBackgroundPlayVideoId (Ljava/lang/String;)V
|
||||||
|
@ -5,4 +5,5 @@ enum class InputType(val type: String) {
|
|||||||
TEXT_CAP_CHARACTERS("textCapCharacters"),
|
TEXT_CAP_CHARACTERS("textCapCharacters"),
|
||||||
TEXT_MULTI_LINE("textMultiLine"),
|
TEXT_MULTI_LINE("textMultiLine"),
|
||||||
NUMBER("number"),
|
NUMBER("number"),
|
||||||
|
NUMBER_DECIMAL("numberDecimal"),
|
||||||
}
|
}
|
@ -17,22 +17,26 @@ import app.revanced.patches.shared.misc.mapping.resourceMappings
|
|||||||
import app.revanced.patches.shared.misc.settings.preference.InputType
|
import app.revanced.patches.shared.misc.settings.preference.InputType
|
||||||
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
|
||||||
import app.revanced.patches.shared.misc.settings.preference.TextPreference
|
import app.revanced.patches.shared.misc.settings.preference.TextPreference
|
||||||
|
import app.revanced.patches.youtube.interaction.seekbar.disableFastForwardNoticeFingerprint
|
||||||
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch
|
||||||
import app.revanced.patches.youtube.misc.litho.filter.addLithoFilter
|
import app.revanced.patches.youtube.misc.litho.filter.addLithoFilter
|
||||||
import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch
|
import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch
|
||||||
|
import app.revanced.patches.youtube.misc.playservice.is_19_25_or_greater
|
||||||
|
import app.revanced.patches.youtube.misc.playservice.versionCheckPatch
|
||||||
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.addRecyclerViewTreeHook
|
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.addRecyclerViewTreeHook
|
||||||
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.recyclerViewTreeHookPatch
|
import app.revanced.patches.youtube.misc.recyclerviewtree.hook.recyclerViewTreeHookPatch
|
||||||
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
import app.revanced.patches.youtube.misc.settings.PreferenceScreen
|
||||||
import app.revanced.patches.youtube.misc.settings.settingsPatch
|
import app.revanced.patches.youtube.misc.settings.settingsPatch
|
||||||
import app.revanced.util.*
|
import app.revanced.util.*
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
|
import com.android.tools.smali.dexlib2.iface.instruction.NarrowLiteralInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
import com.android.tools.smali.dexlib2.iface.reference.FieldReference
|
||||||
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
import com.android.tools.smali.dexlib2.iface.reference.MethodReference
|
||||||
import com.android.tools.smali.dexlib2.immutable.ImmutableField
|
import com.android.tools.smali.dexlib2.immutable.ImmutableField
|
||||||
|
|
||||||
var speedUnavailableId = -1L
|
internal var speedUnavailableId = -1L
|
||||||
internal set
|
private set
|
||||||
|
|
||||||
private val customPlaybackSpeedResourcePatch = resourcePatch {
|
private val customPlaybackSpeedResourcePatch = resourcePatch {
|
||||||
dependsOn(resourceMappingPatch)
|
dependsOn(resourceMappingPatch)
|
||||||
@ -61,6 +65,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
|
|||||||
recyclerViewTreeHookPatch,
|
recyclerViewTreeHookPatch,
|
||||||
customPlaybackSpeedResourcePatch,
|
customPlaybackSpeedResourcePatch,
|
||||||
addResourcesPatch,
|
addResourcesPatch,
|
||||||
|
versionCheckPatch
|
||||||
)
|
)
|
||||||
|
|
||||||
execute {
|
execute {
|
||||||
@ -71,6 +76,12 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
|
|||||||
TextPreference("revanced_custom_playback_speeds", inputType = InputType.TEXT_MULTI_LINE),
|
TextPreference("revanced_custom_playback_speeds", inputType = InputType.TEXT_MULTI_LINE),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (is_19_25_or_greater) {
|
||||||
|
PreferenceScreen.VIDEO.addPreferences(
|
||||||
|
TextPreference("revanced_speed_tap_and_hold", inputType = InputType.NUMBER_DECIMAL),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Replace the speeds float array with custom speeds.
|
// Replace the speeds float array with custom speeds.
|
||||||
speedArrayGeneratorFingerprint.method.apply {
|
speedArrayGeneratorFingerprint.method.apply {
|
||||||
val sizeCallIndex = indexOfFirstInstructionOrThrow { getReference<MethodReference>()?.name == "size" }
|
val sizeCallIndex = indexOfFirstInstructionOrThrow { getReference<MethodReference>()?.name == "size" }
|
||||||
@ -166,5 +177,27 @@ internal val customPlaybackSpeedPatch = bytecodePatch(
|
|||||||
addLithoFilter(FILTER_CLASS_DESCRIPTOR)
|
addLithoFilter(FILTER_CLASS_DESCRIPTOR)
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
||||||
|
// region Custom tap and hold 2x speed.
|
||||||
|
|
||||||
|
if (is_19_25_or_greater) {
|
||||||
|
disableFastForwardNoticeFingerprint.method.apply {
|
||||||
|
val index = indexOfFirstInstructionOrThrow {
|
||||||
|
(this as? NarrowLiteralInstruction)?.narrowLiteral == 2.0f.toRawBits()
|
||||||
|
}
|
||||||
|
val register = getInstruction<OneRegisterInstruction>(index).registerA
|
||||||
|
|
||||||
|
addInstructions(
|
||||||
|
index + 1,
|
||||||
|
"""
|
||||||
|
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->tapAndHoldSpeed()F
|
||||||
|
move-result v$register
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1351,6 +1351,8 @@ Enabling this can unlock higher video qualities"</string>
|
|||||||
<string name="revanced_custom_playback_speeds_invalid">Custom speeds must be less than %s</string>
|
<string name="revanced_custom_playback_speeds_invalid">Custom speeds must be less than %s</string>
|
||||||
<string name="revanced_custom_playback_speeds_parse_exception">Invalid custom playback speeds</string>
|
<string name="revanced_custom_playback_speeds_parse_exception">Invalid custom playback speeds</string>
|
||||||
<string name="revanced_custom_playback_speeds_auto">Auto</string>
|
<string name="revanced_custom_playback_speeds_auto">Auto</string>
|
||||||
|
<string name="revanced_speed_tap_and_hold_title">Custom tap and hold speed</string>
|
||||||
|
<string name="revanced_speed_tap_and_hold_summary">Playback speed between 0-8</string>
|
||||||
</patch>
|
</patch>
|
||||||
<patch id="video.speed.remember.rememberPlaybackSpeedPatch">
|
<patch id="video.speed.remember.rememberPlaybackSpeedPatch">
|
||||||
<string name="revanced_remember_playback_speed_last_selected_title">Remember playback speed changes</string>
|
<string name="revanced_remember_playback_speed_last_selected_title">Remember playback speed changes</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user