@@ -62,19 +62,12 @@ private static void changeDefaultQuality(int defaultQuality) {
62
62
*/
63
63
public static int setVideoQuality (Object [] qualities , final int originalQualityIndex , Object qInterface , String qIndexMethod ) {
64
64
try {
65
- if (!(qualityNeedsUpdating || userChangedDefaultQuality ) || qInterface == null ) {
66
- return originalQualityIndex ;
67
- }
68
- qualityNeedsUpdating = false ;
65
+ final int preferredQuality = Utils .getNetworkType () == NetworkType .MOBILE
66
+ ? mobileQualitySetting .get ()
67
+ : wifiQualitySetting .get ();
69
68
70
- final int preferredQuality ;
71
- if (Utils .getNetworkType () == NetworkType .MOBILE ) {
72
- preferredQuality = mobileQualitySetting .get ();
73
- } else {
74
- preferredQuality = wifiQualitySetting .get ();
75
- }
76
69
if (!userChangedDefaultQuality && preferredQuality == AUTOMATIC_VIDEO_QUALITY_VALUE ) {
77
- return originalQualityIndex ; // nothing to do
70
+ return originalQualityIndex ; // Nothing to do.
78
71
}
79
72
80
73
if (videoQualities == null || videoQualities .size () != qualities .length ) {
@@ -87,7 +80,11 @@ public static int setVideoQuality(Object[] qualities, final int originalQualityI
87
80
}
88
81
}
89
82
}
90
- Logger .printDebug (() -> "videoQualities: " + videoQualities );
83
+
84
+ // After changing videos the qualities can initially be for the prior video.
85
+ // So if the qualities have changed an update is needed.
86
+ qualityNeedsUpdating = true ;
87
+ Logger .printDebug (() -> "VideoQualities: " + videoQualities );
91
88
}
92
89
93
90
if (userChangedDefaultQuality ) {
@@ -98,7 +95,12 @@ public static int setVideoQuality(Object[] qualities, final int originalQualityI
98
95
return userSelectedQualityIndex ;
99
96
}
100
97
101
- // find the highest quality that is equal to or less than the preferred
98
+ if (!qualityNeedsUpdating ) {
99
+ return originalQualityIndex ;
100
+ }
101
+ qualityNeedsUpdating = false ;
102
+
103
+ // Find the highest quality that is equal to or less than the preferred.
102
104
int qualityToUse = videoQualities .get (0 ); // first element is automatic mode
103
105
int qualityIndexToUse = 0 ;
104
106
int i = 0 ;
@@ -112,20 +114,18 @@ public static int setVideoQuality(Object[] qualities, final int originalQualityI
112
114
113
115
// If the desired quality index is equal to the original index,
114
116
// then the video is already set to the desired default quality.
115
- //
116
- // The method could return here, but the UI video quality flyout will still
117
- // show 'Auto' (ie: Auto (480p))
118
- // It appears that "Auto" picks the resolution on video load,
119
- // and it does not appear to change the resolution during playback.
120
- //
121
- // To prevent confusion, set the video index anyways (even if it matches the existing index)
122
- // As that will force the UI picker to not display "Auto" which may confuse the user.
117
+ final int qualityToUseFinal = qualityToUse ;
123
118
if (qualityIndexToUse == originalQualityIndex ) {
124
- Logger .printDebug (() -> "Video is already preferred quality: " + preferredQuality );
119
+ // On first load of a new video, if the UI video quality flyout menu
120
+ // is not updated then it will still show 'Auto' (ie: Auto (480p)),
121
+ // even though it's already set to the desired resolution.
122
+ //
123
+ // To prevent confusion, set the video index anyways (even if it matches the existing index)
124
+ // as that will force the UI picker to not display "Auto".
125
+ Logger .printDebug (() -> "Video is already preferred quality: " + qualityToUseFinal );
125
126
} else {
126
- final int qualityToUseLog = qualityToUse ;
127
- Logger .printDebug (() -> "Quality changed from: "
128
- + videoQualities .get (originalQualityIndex ) + " to: " + qualityToUseLog );
127
+ Logger .printDebug (() -> "Changing video quality from: "
128
+ + videoQualities .get (originalQualityIndex ) + " to: " + qualityToUseFinal );
129
129
}
130
130
131
131
Method m = qInterface .getClass ().getMethod (qIndexMethod , Integer .TYPE );
0 commit comments