Skip to content

Commit 8b63b43

Browse files
committed
Disable media tunneling if the device is known for not supporting it
Revert removing the Utils related to media tunneling.
1 parent 78e577d commit 8b63b43

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/settings/NewPipeSettings.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public static void initSettings(final Context context) {
7676

7777
saveDefaultVideoDownloadDirectory(context);
7878
saveDefaultAudioDownloadDirectory(context);
79+
80+
if (isFirstRun) { // NOSONAR: isFirstRun is never null
81+
setMediaTunneling(context);
82+
}
7983
}
8084

8185
static void saveDefaultVideoDownloadDirectory(final Context context) {
@@ -152,4 +156,18 @@ public static boolean showRemoteSearchSuggestions(final Context context,
152156
return showSearchSuggestions(context, sharedPreferences,
153157
R.string.show_remote_search_suggestions_key);
154158
}
159+
160+
/**
161+
* Check if device does not support media tunneling
162+
* and disable that exoplayer feature if necessary.
163+
* @see DeviceUtils#shouldSupportMediaTunneling()
164+
* @param context
165+
*/
166+
public static void setMediaTunneling(@NonNull final Context context) {
167+
if (!DeviceUtils.shouldSupportMediaTunneling()) {
168+
PreferenceManager.getDefaultSharedPreferences(context).edit()
169+
.putBoolean(context.getString(R.string.disable_media_tunneling_key), true)
170+
.apply();
171+
}
172+
}
155173
}

app/src/main/java/org/schabi/newpipe/settings/SettingMigrations.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ protected void migrate(@NonNull final Context context) {
128128
}
129129
};
130130

131+
private static final Migration MIGRATION_5_6 = new Migration(5, 6) {
132+
@Override
133+
protected void migrate(@NonNull final Context context) {
134+
// PR #8875 added a new settings page for exoplayer introducing a specific setting
135+
// to disable media tunneling. However, media tunneling should be disabled by default
136+
// for some devices, because they are known for not supporting media tunneling
137+
// which can result in a black screen while playing videos.
138+
NewPipeSettings.setMediaTunneling(context);
139+
}
140+
};
141+
131142
/**
132143
* List of all implemented migrations.
133144
* <p>
@@ -140,12 +151,13 @@ protected void migrate(@NonNull final Context context) {
140151
MIGRATION_2_3,
141152
MIGRATION_3_4,
142153
MIGRATION_4_5,
154+
MIGRATION_5_6,
143155
};
144156

145157
/**
146158
* Version number for preferences. Must be incremented every time a migration is necessary.
147159
*/
148-
private static final int VERSION = 5;
160+
private static final int VERSION = 6;
149161

150162

151163
public static void initMigrations(@NonNull final Context context, final boolean isFirstRun) {

app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ public final class DeviceUtils {
3636
private static Boolean isTV = null;
3737
private static Boolean isFireTV = null;
3838

39+
/*
40+
* Devices that do not support media tunneling
41+
*/
42+
43+
/**
44+
* Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo.
45+
*/
46+
private static final boolean HI3798MV200 = Build.VERSION.SDK_INT == 24
47+
&& Build.DEVICE.equals("Hi3798MV200");
48+
/**
49+
* Zephir TS43UHD-2.
50+
*/
51+
private static final boolean CVT_MT5886_EU_1G = Build.VERSION.SDK_INT == 24
52+
&& Build.DEVICE.equals("cvt_mt5886_eu_1g");
53+
/**
54+
* Hilife TV.
55+
*/
56+
private static final boolean REALTEKATV = Build.VERSION.SDK_INT == 25
57+
&& Build.DEVICE.equals("RealtekATV");
58+
/**
59+
* Philips QM16XE.
60+
*/
61+
private static final boolean QM16XE_U = Build.VERSION.SDK_INT == 23
62+
&& Build.DEVICE.equals("QM16XE_U");
63+
3964
private DeviceUtils() {
4065
}
4166

@@ -224,4 +249,20 @@ public static int getWindowHeight(@NonNull final WindowManager windowManager) {
224249
return point.y;
225250
}
226251
}
252+
253+
/**
254+
* Some devices have broken tunneled video playback but claim to support it.
255+
* See https://github.com/TeamNewPipe/NewPipe/issues/5911
256+
* @Note Add a new {@link org.schabi.newpipe.settings.SettingMigrations.Migration} which calls
257+
* {@link org.schabi.newpipe.settings.NewPipeSettings#setMediaTunneling(Context)}
258+
* when adding a new device to the method
259+
* @return {@code false} if affected device; {@code true} otherwise
260+
*/
261+
public static boolean shouldSupportMediaTunneling() {
262+
// Maintainers note: add a new SettingsMigration which calls
263+
return !HI3798MV200
264+
&& !CVT_MT5886_EU_1G
265+
&& !REALTEKATV
266+
&& !QM16XE_U;
267+
}
227268
}

0 commit comments

Comments
 (0)