Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ExoPlayer settings page #8875

Merged
merged 5 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,13 @@
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player.PositionInfo;
import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.Tracks;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.text.CueGroup;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoSize;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
Expand All @@ -96,6 +94,7 @@
import org.schabi.newpipe.player.event.PlayerEventListener;
import org.schabi.newpipe.player.event.PlayerServiceEventListener;
import org.schabi.newpipe.player.helper.AudioReactor;
import org.schabi.newpipe.player.helper.CustomRenderersFactory;
import org.schabi.newpipe.player.helper.LoadController;
import org.schabi.newpipe.player.helper.PlayerDataSource;
import org.schabi.newpipe.player.helper.PlayerHelper;
Expand All @@ -115,7 +114,6 @@
import org.schabi.newpipe.player.ui.PopupPlayerUi;
import org.schabi.newpipe.player.ui.VideoPlayerUi;
import org.schabi.newpipe.util.DependentPreferenceHelper;
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PicassoHelper;
Expand Down Expand Up @@ -198,7 +196,7 @@ public final class Player implements PlaybackListener, Listener {

@NonNull private final DefaultTrackSelector trackSelector;
@NonNull private final LoadController loadController;
@NonNull private final RenderersFactory renderFactory;
@NonNull private final DefaultRenderersFactory renderFactory;

@NonNull private final VideoPlaybackResolver videoResolver;
@NonNull private final AudioPlaybackResolver audioResolver;
Expand Down Expand Up @@ -263,7 +261,16 @@ public Player(@NonNull final PlayerService service) {
final PlayerDataSource dataSource = new PlayerDataSource(context,
new DefaultBandwidthMeter.Builder(context).build());
loadController = new LoadController();
renderFactory = new DefaultRenderersFactory(context);

renderFactory = prefs.getBoolean(
context.getString(
R.string.always_use_exoplayer_set_output_surface_workaround_key), false)
? new CustomRenderersFactory(context) : new DefaultRenderersFactory(context);

renderFactory.setEnableDecoderFallback(
prefs.getBoolean(
context.getString(
R.string.use_exoplayer_decoder_fallback_key), false));

videoResolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver());
audioResolver = new AudioPlaybackResolver(context, dataSource);
Expand Down Expand Up @@ -520,16 +527,11 @@ private void initPlayer(final boolean playOnReady) {
// Setup UIs
UIs.call(PlayerUi::initPlayer);

// enable media tunneling
if (DEBUG && PreferenceManager.getDefaultSharedPreferences(context)
// Disable media tunneling if requested by the user from ExoPlayer settings
if (!PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.disable_media_tunneling_key), false)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I would make sure the preference does not get auto-created, and then use !DeviceUtils.shouldSupportMediaTunneling() instead of false as the value to use when the preference is not set.

Log.d(TAG, "[" + Util.DEVICE_DEBUG_INFO + "] "
+ "media tunneling disabled in debug preferences");
} else if (DeviceUtils.shouldSupportMediaTunneling()) {
trackSelector.setParameters(trackSelector.buildUponParameters()
.setTunnelingEnabled(true));
} else if (DEBUG) {
Log.d(TAG, "[" + Util.DEVICE_DEBUG_INFO + "] does not support media tunneling");
}
}
//endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.schabi.newpipe.player.helper;

import android.content.Context;
import android.os.Handler;

import androidx.annotation.Nullable;

import com.google.android.exoplayer2.mediacodec.MediaCodecAdapter;
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;
import com.google.android.exoplayer2.video.VideoRendererEventListener;

/**
* A {@link MediaCodecVideoRenderer} which always enable the output surface workaround that
* ExoPlayer enables on several devices which are known to implement
* {@link android.media.MediaCodec#setOutputSurface(android.view.Surface)
* MediaCodec.setOutputSurface(Surface)} incorrectly.
*
* <p>
* See {@link MediaCodecVideoRenderer#codecNeedsSetOutputSurfaceWorkaround(String)} for more
* details.
* </p>
*
* <p>
* This custom {@link MediaCodecVideoRenderer} may be useful in the case a device is affected by
* this issue but is not present in ExoPlayer's list.
* </p>
*
* <p>
* This class has only effect on devices with Android 6 and higher, as the {@code setOutputSurface}
* method is only implemented in these Android versions and the method used as a workaround is
* always applied on older Android versions (releasing and re-instantiating video codec instances).
* </p>
*/
public final class CustomMediaCodecVideoRenderer extends MediaCodecVideoRenderer {

@SuppressWarnings({"checkstyle:ParameterNumber", "squid:S107"})
public CustomMediaCodecVideoRenderer(final Context context,
final MediaCodecAdapter.Factory codecAdapterFactory,
final MediaCodecSelector mediaCodecSelector,
final long allowedJoiningTimeMs,
final boolean enableDecoderFallback,
@Nullable final Handler eventHandler,
@Nullable final VideoRendererEventListener eventListener,
final int maxDroppedFramesToNotify) {
super(context, codecAdapterFactory, mediaCodecSelector, allowedJoiningTimeMs,
enableDecoderFallback, eventHandler, eventListener, maxDroppedFramesToNotify);
}

@Override
protected boolean codecNeedsSetOutputSurfaceWorkaround(final String name) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.schabi.newpipe.player.helper;

import android.content.Context;
import android.os.Handler;

import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
import com.google.android.exoplayer2.video.VideoRendererEventListener;

import java.util.ArrayList;

/**
* A {@link DefaultRenderersFactory} which only uses {@link CustomMediaCodecVideoRenderer} as an
* implementation of video codec renders.
*
* <p>
* As no ExoPlayer extension is currently used, the reflection code used by ExoPlayer to try to
* load video extension libraries is not needed in our case and has been removed. This should be
* changed in the case an extension is shipped with the app, such as the AV1 one.
* </p>
*/
public final class CustomRenderersFactory extends DefaultRenderersFactory {

public CustomRenderersFactory(final Context context) {
super(context);
}

@SuppressWarnings("checkstyle:ParameterNumber")
@Override
protected void buildVideoRenderers(final Context context,
@ExtensionRendererMode final int extensionRendererMode,
final MediaCodecSelector mediaCodecSelector,
final boolean enableDecoderFallback,
final Handler eventHandler,
final VideoRendererEventListener eventListener,
final long allowedVideoJoiningTimeMs,
final ArrayList<Renderer> out) {
out.add(new CustomMediaCodecVideoRenderer(context, getCodecAdapterFactory(),
mediaCodecSelector, allowedVideoJoiningTimeMs, enableDecoderFallback, eventHandler,
eventListener, MAX_DROPPED_VIDEO_FRAME_COUNT_TO_NOTIFY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.schabi.newpipe.settings;

import android.os.Bundle;

import androidx.annotation.Nullable;

public class ExoPlayerSettingsFragment extends BasePreferenceFragment {

@Override
public void onCreatePreferences(@Nullable final Bundle savedInstanceState,
@Nullable final String rootKey) {
addPreferencesFromResourceRegistry();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private SettingsResourceRegistry() {
add(PlayerNotificationSettingsFragment.class, R.xml.player_notification_settings);
add(UpdateSettingsFragment.class, R.xml.update_settings);
add(VideoAudioSettingsFragment.class, R.xml.video_audio_settings);
add(ExoPlayerSettingsFragment.class, R.xml.exoplayer_settings);
}

private SettingRegistryEntry add(
Expand Down
28 changes: 0 additions & 28 deletions app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,6 @@ public final class DeviceUtils {
private static Boolean isTV = null;
private static Boolean isFireTV = null;

/*
* Devices that do not support media tunneling
*/
// Formuler Z8 Pro, Z8, CC, Z Alpha, Z+ Neo
private static final boolean HI3798MV200 = Build.VERSION.SDK_INT == 24
&& Build.DEVICE.equals("Hi3798MV200");
// Zephir TS43UHD-2
private static final boolean CVT_MT5886_EU_1G = Build.VERSION.SDK_INT == 24
&& Build.DEVICE.equals("cvt_mt5886_eu_1g");
// Hilife TV
private static final boolean REALTEKATV = Build.VERSION.SDK_INT == 25
&& Build.DEVICE.equals("RealtekATV");
// Philips QM16XE
private static final boolean QM16XE_U = Build.VERSION.SDK_INT == 23
&& Build.DEVICE.equals("QM16XE_U");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmh, why are you removing this list completely? We know all these TVs don't work, so by default on such devices tunneling should be disabled. Then the user can go into settings and enable it, but at least it should be off by default.

Copy link
Member

@TobiGr TobiGr May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Someone needs to write a methid that sets a default value depeding on the device. Otherwise, NewPipe is going to stop working for some users and they certainly not search for a solution in the settings.


private DeviceUtils() {
}

Expand Down Expand Up @@ -211,18 +195,6 @@ public static int spToPx(@Dimension(unit = Dimension.SP) final int sp,
context.getResources().getDisplayMetrics());
}

/**
* Some devices have broken tunneled video playback but claim to support it.
* See https://github.com/TeamNewPipe/NewPipe/issues/5911
* @return false if affected device
*/
public static boolean shouldSupportMediaTunneling() {
return !HI3798MV200
&& !CVT_MT5886_EU_1G
&& !REALTEKATV
&& !QM16XE_U;
}

public static boolean isLandscape(final Context context) {
return context.getResources().getDisplayMetrics().heightPixels < context.getResources()
.getDisplayMetrics().widthPixels;
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@
<string name="detail_pinned_comment_view_description">تعليق مثبت</string>
<string name="leak_canary_not_available">LeakCanary غير متوفر</string>
<string name="progressive_load_interval_exoplayer_default">الافتراضي ExoPlayer</string>
<string name="progressive_load_interval_summary">تغيير حجم الفاصل الزمني للتحميل (حاليا %s). قد تؤدي القيمة الأقل إلى تسريع تحميل الفيديو الأولي. تتطلب التغييرات إعادة تشغيل المشغل</string>
<string name="settings_category_player_notification_summary">تكوين إشعار مشغل البث الحالي</string>
<string name="notifications">الإشعارات</string>
<string name="loading_stream_details">تحميل تفاصيل البث…</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-az/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@
<string name="hash_channel_description">Video fayl xülasəsi prosesi üçün bildirişlər</string>
<string name="on">Aç</string>
<string name="notification_scale_to_square_image_title">Miniatürü 1:1 görünüş nisbətinə kəs</string>
<string name="progressive_load_interval_summary">Yükləmə intervalı həcmini dəyişdir (hazırda %s). Daha aşağı dəyər ilkin video yükləməni sürətləndirə bilər. Dəyişikliklər oynadıcını yenidən başlatmağı tələb edir</string>
<string name="show_meta_info_summary">Yayım yaradıcısı, məzmunu və ya axtarış sorğusu haqqında əlavə məlumat olan üst məlumat qutularını gizlətmək üçün söndür</string>
<string name="auto_queue_summary">Əlaqəli yayımı əlavə etməklə (təkrarlanmayan) sonlanacaq oynatma növbəsini davam etdir</string>
<string name="remote_search_suggestions">Kənar axtarış təklifləri</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-bs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<string name="popup_remember_size_pos_summary">Zapamtite posljednju veličinu i položaj iskočnog prozora</string>
<string name="use_inexact_seek_title">Koristite brzo neprecizno premotavanje</string>
<string name="use_inexact_seek_summary">Neprecizno premotavanje dozvoljava pokretaču brže premotavanje s gorom preciznošću. Premotavanje za 5, 15 ili 25 sekundi ne radi s ovim</string>
<string name="progressive_load_interval_summary">Promijenite veličinu intervala za učitavanje (trenutačno %s). Niža vrijednost bi vam moglo ubrzat učitavanje videa. Trebate te ponovno učitati pokretač za promjenu.</string>
<string name="clear_queue_confirmation_summary">Prebacivanje sa jednog pokretača na drugi bi van moglo zamijeniti pokretni red</string>
<string name="show_comments_summary">Isključite da sakrijete komentare</string>
<string name="clear_queue_confirmation_title">Pitajte za potvrdu prije isčišćavanja reda</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-ckb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,6 @@
<string name="delete_downloaded_files_confirm">هەموو فایلە دابەزێنراوەکان لە دیسک بسڕدرێتەوە؟</string>
<string name="notifications_disabled">پەیامەکان ناکاراکراون</string>
<string name="get_notified">پەیامم بکە</string>
<string name="progressive_load_interval_summary">"قەبارەی نێوان بارکردنەکە بگۆڕە (لە ئێستادا %s) . بەهایەکی کەمتر لەوانەیە بارکردنی ڤیدیۆی سەرەتایی خێراتر بکات. گۆڕانکارییەکان پێویستیان بە داگیرساندنەوەی لێدەر هەیە"</string>
<string name="percent">لەسەدا</string>
<string name="semitone">نیمچەتەن</string>
<string name="progressive_load_interval_exoplayer_default">بنەڕەتی ExoPlayer</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-cs/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@
<string name="show_error_snackbar">Zobrazit krátké oznámení o chybě</string>
<string name="detail_pinned_comment_view_description">Připnutý komentář</string>
<string name="crash_the_player">Shodit přehrávač</string>
<string name="progressive_load_interval_summary">Změnit interval načítání (aktuálně %s). Menší hodnota může zrychlit počáteční načítání videa. Změna vyžaduje restart přehrávače</string>
<string name="leak_canary_not_available">LeakCanary není dostupné</string>
<string name="progressive_load_interval_exoplayer_default">Výchozí ExoPlayer</string>
<string name="settings_category_player_notification_summary">Nastavit oznámení o právě přehrávaném streamu</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-da/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@
<item quantity="one">Download fuldført</item>
<item quantity="other">%s downloads fuldført</item>
</plurals>
<string name="progressive_load_interval_summary">Ændr indlæsningsintervallets størrelse (som nu er på %s). En lavere værdi kan øge videoindlæsningshastigheden. Ændringer kræver en genstart af afspiller</string>
<string name="clear_queue_confirmation_description">Den aktive spilleliste bliver udskiftet</string>
<string name="clear_queue_confirmation_summary">Hvis du skifter fra en spiller til en anden, kan din kø blive erstattet</string>
<string name="show_meta_info_title">Vis metainformation</string>
Expand Down Expand Up @@ -731,4 +730,4 @@
<string name="duplicate_in_playlist">Playlists der er grået ud, indeholder allerede dette objekt.</string>
<string name="unset_playlist_thumbnail">Inaktiver permanent thumbnail</string>
<string name="msg_failed_to_copy">Fejlede at kopiere til udklipsholderen</string>
</resources>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@
\nBitte installiere einen Storage Access Framework kompatiblen Dateimanager</string>
<string name="detail_pinned_comment_view_description">Angehefteter Kommentar</string>
<string name="leak_canary_not_available">LeakCanary ist nicht verfügbar</string>
<string name="progressive_load_interval_summary">Ändern der Größe des Ladeintervalls (derzeit %s). Ein niedrigerer Wert kann das anfängliche Laden des Videos beschleunigen. Änderungen erfordern einen Neustart des Players</string>
<string name="progressive_load_interval_exoplayer_default">ExoPlayer Standard</string>
<string name="notifications">Benachrichtigungen</string>
<string name="streams_notification_channel_description">Benachrichtigen über neue abonnierbare Streams</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@
<string name="detail_pinned_comment_view_description">Καρφιτσωμένο σχόλιο</string>
<string name="leak_canary_not_available">Το LeakCanary δεν είναι διαθέσιμο</string>
<string name="progressive_load_interval_exoplayer_default">Εξ\' ορισμού ExoPlayer</string>
<string name="progressive_load_interval_summary">Αλλάξτε το μέγεθος του διαστήματος φόρτωσης (επί του παρόντος είναι %s). Μια χαμηλότερη τιμή μπορεί να επιταχύνει την αρχική φόρτωση βίντεο. Οι αλλαγές απαιτούν επανεκκίνηση της εφαρμογής</string>
<string name="notifications">Ειδοποιήσεις</string>
<plurals name="new_streams">
<item quantity="one">%s νέα ροή</item>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@
<string name="detail_pinned_comment_view_description">Comentario fijado</string>
<string name="leak_canary_not_available">LeakCanary no está disponible</string>
<string name="progressive_load_interval_exoplayer_default">ExoPlayer valor por defecto</string>
<string name="progressive_load_interval_summary">Cambie el tamaño del intervalo de carga (actualmente %s). Un valor más bajo puede acelerar la carga inicial de video. Los cambios requieren un reinicio del reproductor</string>
<string name="notifications">Notificaciones</string>
<string name="streams_notification_channel_name">Nuevos streams</string>
<string name="settings_category_player_notification_title">Notificación del reproductor</string>
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@
<string name="detail_pinned_comment_view_description">Esiletõstetud kommentaar</string>
<string name="leak_canary_not_available">LeakCanary pole saadaval</string>
<string name="progressive_load_interval_exoplayer_default">ExoPlayer\'i vaikimisi väärtused</string>
<string name="progressive_load_interval_summary">Muuda video laadimise välpa (hetkel %s). Väiksemast väärtusest võib abi olla, kui tahad et video esitamine algaks varem. Muudatuste jõustamine eeldab rakenduse uuesti käivitamist</string>
<string name="settings_category_player_notification_title">Meediamängija teavitused</string>
<string name="notifications_disabled">Teavitused pole kasutusel</string>
<string name="streams_notifications_interval_title">Kontrollimise sagedus</string>
Expand Down
Loading