Skip to content

Commit 8e67cdc

Browse files
MarcaDianoSumAtrIX
andauthored
feat(YouTube - Playback speed): Add option to show speed dialog button in video player (#3197)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent 32c5fa4 commit 8e67cdc

File tree

7 files changed

+117
-3
lines changed

7 files changed

+117
-3
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,12 @@ public final class app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch :
18401840
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
18411841
}
18421842

1843+
public final class app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch : app/revanced/patcher/patch/BytecodePatch {
1844+
public static final field INSTANCE Lapp/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch;
1845+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
1846+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
1847+
}
1848+
18431849
public final class app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch : app/revanced/patcher/patch/BytecodePatch {
18441850
public static final field INSTANCE Lapp/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch;
18451851
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V

src/main/kotlin/app/revanced/patches/youtube/video/speed/PlaybackSpeedPatch.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@ import app.revanced.patcher.data.BytecodeContext
44
import app.revanced.patcher.patch.BytecodePatch
55
import app.revanced.patcher.patch.annotation.CompatiblePackage
66
import app.revanced.patcher.patch.annotation.Patch
7+
import app.revanced.patches.youtube.video.speed.button.PlaybackSpeedButtonPatch
78
import app.revanced.patches.youtube.video.speed.custom.CustomPlaybackSpeedPatch
89
import app.revanced.patches.youtube.video.speed.remember.RememberPlaybackSpeedPatch
910

1011
@Patch(
1112
name = "Playback speed",
12-
description = "Adds options to customize available playback speeds and to remember the last playback speed selected.",
13-
dependencies = [CustomPlaybackSpeedPatch::class, RememberPlaybackSpeedPatch::class],
13+
description = "Adds options to customize available playback speeds, remember the last playback speed selected " +
14+
"and show a speed dialog button to the video player.",
15+
dependencies = [
16+
PlaybackSpeedButtonPatch::class,
17+
CustomPlaybackSpeedPatch::class,
18+
RememberPlaybackSpeedPatch::class,
19+
],
1420
compatiblePackages = [
1521
CompatiblePackage(
1622
"com.google.android.youtube",
@@ -42,4 +48,4 @@ object PlaybackSpeedPatch : BytecodePatch(emptySet()) {
4248
override fun execute(context: BytecodeContext) {
4349
// All patches this patch depends on succeed.
4450
}
45-
}
51+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package app.revanced.patches.youtube.video.speed.button
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.patch.BytecodePatch
5+
import app.revanced.patcher.patch.annotation.Patch
6+
import app.revanced.patches.all.misc.resources.AddResourcesPatch
7+
import app.revanced.patches.shared.misc.settings.preference.SwitchPreference
8+
import app.revanced.patches.youtube.misc.playercontrols.PlayerControlsBytecodePatch
9+
import app.revanced.patches.youtube.misc.settings.SettingsPatch
10+
import app.revanced.patches.youtube.video.speed.custom.CustomPlaybackSpeedPatch
11+
12+
@Patch(
13+
description = "Adds the option to display playback speed dialog button in the video player.",
14+
dependencies = [
15+
PlaybackSpeedButtonResourcePatch::class,
16+
CustomPlaybackSpeedPatch::class,
17+
PlayerControlsBytecodePatch::class,
18+
SettingsPatch::class,
19+
AddResourcesPatch::class,
20+
],
21+
)
22+
@Suppress("unused")
23+
object PlaybackSpeedButtonPatch : BytecodePatch(emptySet()) {
24+
private const val SPEED_BUTTON_CLASS_DESCRIPTOR =
25+
"Lapp/revanced/integrations/youtube/videoplayer/PlaybackSpeedDialogButton;"
26+
27+
override fun execute(context: BytecodeContext) {
28+
29+
AddResourcesPatch(this::class)
30+
31+
SettingsPatch.PreferenceScreen.PLAYER.addPreferences(
32+
SwitchPreference("revanced_playback_speed_dialog_button"),
33+
)
34+
35+
PlayerControlsBytecodePatch.initializeControl("$SPEED_BUTTON_CLASS_DESCRIPTOR->initializeButton(Landroid/view/View;)V")
36+
PlayerControlsBytecodePatch.injectVisibilityCheckCall("$SPEED_BUTTON_CLASS_DESCRIPTOR->changeVisibility(Z)V")
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package app.revanced.patches.youtube.video.speed.button
2+
3+
import app.revanced.patcher.data.ResourceContext
4+
import app.revanced.patcher.patch.ResourcePatch
5+
import app.revanced.patcher.patch.annotation.Patch
6+
import app.revanced.patches.youtube.misc.playercontrols.BottomControlsResourcePatch
7+
import app.revanced.util.ResourceGroup
8+
import app.revanced.util.copyResources
9+
10+
@Patch(
11+
dependencies = [BottomControlsResourcePatch::class],
12+
)
13+
internal object PlaybackSpeedButtonResourcePatch : ResourcePatch() {
14+
override fun execute(context: ResourceContext) {
15+
context.copyResources(
16+
"speedbutton",
17+
ResourceGroup(
18+
"drawable",
19+
"revanced_playback_speed_dialog_button.xml",
20+
),
21+
)
22+
23+
BottomControlsResourcePatch.addControls("speedbutton")
24+
}
25+
}

src/main/resources/addresources/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,11 @@
10651065
<string name="revanced_remember_video_quality_wifi">wifi</string>
10661066
<string name="revanced_remember_video_quality_toast">Changed default %1$s quality to: %2$s</string>
10671067
</patch>
1068+
<patch id="video.speed.button.PlaybackSpeedButtonPatch">
1069+
<string name="revanced_playback_speed_dialog_button_title">Show speed dialog button</string>
1070+
<string name="revanced_playback_speed_dialog_button_summary_on">Button is shown</string>
1071+
<string name="revanced_playback_speed_dialog_button_summary_off">Button is not shown</string>
1072+
</patch>
10681073
<patch id="video.speed.custom.CustomPlaybackSpeedPatch">
10691074
<string name="revanced_custom_playback_speeds_title">Custom playback speeds</string>
10701075
<string name="revanced_custom_playback_speeds_summary">Add or change the available playback speeds</string>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!--
2+
https://github.com/google/material-design-icons/blob/9beae745bb758f3ad56654fb377ea5cf62be4915/symbols/android/slow_motion_video/materialsymbolsoutlined/slow_motion_video_wght200gradN25_24px.xml
3+
The icon has been resized
4+
5+
6+
Copyright 2022 Google
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
-->
20+
21+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
22+
android:tint="#FFFFFF"
23+
android:width="24dp"
24+
android:height="24dp"
25+
android:viewportWidth="24"
26+
android:viewportHeight="24">
27+
<path
28+
android:fillColor="@android:color/white"
29+
android:pathData="M 6.0798492,16.70271 Q 5.3667836,15.77782 4.9972798,14.87317 4.6275665,13.96852 4.5,12.83942 h 0.7949215 q 0.1275665,0.9249 0.4677271,1.7656 0.3401706,0.8407 0.8797497,1.53346 z M 4.5,11.16058 Q 4.6373409,10.04469 5.002167,9.14154 5.3667836,8.2386 6.0798492,7.3137 L 6.6423983,7.87793 Q 6.1028192,8.5707 5.7626486,9.40308 5.422488,10.23568 5.2949215,11.16058 Z M 11.110466,19.5 Q 9.8992727,19.32286 9.0431213,18.95346 8.1871793,18.58406 7.2572507,17.89299 l 0.5627586,-0.57382 q 0.6818173,0.52458 1.5126748,0.89527 0.8308479,0.37047 1.7777819,0.49836 z M 7.8625281,6.66442 7.2899951,6.09059 Q 8.2197042,5.39953 9.0758557,5.03823 9.9320071,4.67714 11.152995,4.5 V 5.2872 Q 10.19861,5.41509 9.3677624,5.77746 8.5371243,6.13983 7.8625281,6.66442 Z M 10.32873,14.97101 V 9.02899 L 14.953488,12 Z M 12.827456,19.5 v -0.7872 q 2.53571,-0.36237 4.211668,-2.26097 1.675948,-1.89882 1.675948,-4.45183 0,-2.55301 -1.675948,-4.45183 Q 15.363166,5.64957 12.827456,5.2872 V 4.5 Q 15.70589,4.80844 17.60294,6.95069 19.5,9.09294 19.5,12 q 0,2.8964 -1.89706,5.04398 -1.89705,2.14758 -4.775484,2.45602 z"/>
30+
</vector>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yt="http://schemas.android.com/apk/res-auto" android:id="@+id/youtube_controls_bottom_ui_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layoutDirection="ltr">
3+
<com.google.android.libraries.youtube.common.ui.TouchImageView android:id="@+id/revanced_playback_speed_dialog_button" android:paddingLeft="12dp" android:paddingTop="22dp" android:paddingRight="12dp" android:paddingBottom="16dp" android:longClickable="false" android:layout_width="60dp" android:layout_height="60dp" android:src="@drawable/revanced_playback_speed_dialog_button" android:scaleType="center" yt:layout_constraintBottom_toTopOf="@+id/quick_actions_container" yt:layout_constraintRight_toLeftOf="@+id/fullscreen_button" style="@style/YouTubePlayerButton"/>
4+
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)