Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
fix(YouTube - Video playback): Default video quality does not apply
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 authored and Francesco146 committed Jul 14, 2024
1 parent 6d2d33d commit 4c080ec
Showing 1 changed file with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public class VideoQualityPatch {
@NonNull
public static String videoId = "";

/**
* Injection point.
*/
public static void newVideoStarted(Object ignoredPlayerController) {
setVideoQuality(0);
}

/**
* Injection point.
*/
Expand All @@ -29,22 +36,28 @@ public static void newVideoStarted(@NonNull String newlyLoadedChannelId, @NonNul
return;
if (videoId.equals(newlyLoadedVideoId))
return;
Utils.runOnMainThreadDelayed(() -> videoId = newlyLoadedVideoId, 5000);
videoId = newlyLoadedVideoId;
setVideoQuality(Settings.SKIP_PRELOADED_BUFFER.get() ? 250 : 500);
}

/**
* Injection point.
*/
public static void userSelectedVideoQuality() {
Utils.runOnMainThreadDelayed(() ->
userSelectedVideoQuality(VideoInformation.getVideoQuality()),
300
);
}

private static void setVideoQuality(final long delayMillis) {
final int defaultQuality = Utils.getNetworkType() == Utils.NetworkType.MOBILE
? mobileQualitySetting.get()
: wifiQualitySetting.get();

if (defaultQuality == DEFAULT_YOUTUBE_VIDEO_QUALITY)
return;

long delayMillis;
if (Settings.SKIP_PRELOADED_BUFFER.get()) {
delayMillis = 250;
} else {
delayMillis = 500;
}

Utils.runOnMainThreadDelayed(() ->
VideoInformation.overrideVideoQuality(
VideoInformation.getAvailableVideoQuality(defaultQuality)
Expand All @@ -53,16 +66,6 @@ public static void newVideoStarted(@NonNull String newlyLoadedChannelId, @NonNul
);
}

/**
* Injection point.
*/
public static void userSelectedVideoQuality() {
Utils.runOnMainThreadDelayed(() ->
userSelectedVideoQuality(VideoInformation.getVideoQuality()),
300
);
}

private static void userSelectedVideoQuality(final int defaultQuality) {
if (!Settings.REMEMBER_VIDEO_QUALITY_LAST_SELECTED.get())
return;
Expand Down

0 comments on commit 4c080ec

Please sign in to comment.