From c670ad80ee563e670b274f7a3c137a318d176218 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sat, 5 Jul 2025 20:33:37 +0200 Subject: [PATCH] Use DASH first instead of HLS and YouTube's DASH parser for lives --- .../newpipe/player/helper/PlayerDataSource.java | 7 +++++++ .../newpipe/player/resolver/PlaybackResolver.java | 13 +++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java index 0530d56e9..506b643fe 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java @@ -129,6 +129,13 @@ public class PlayerDataSource { getDefaultDashChunkSourceFactory(cachelessDataSourceFactory), cachelessDataSourceFactory); } + + public DashMediaSource.Factory getLiveYoutubeDashMediaSourceFactory() { + return new DashMediaSource.Factory( + getDefaultDashChunkSourceFactory(cachelessDataSourceFactory), + cachelessDataSourceFactory) + .setManifestParser(new YoutubeDashLiveManifestParser()); + } //endregion diff --git a/app/src/main/java/org/schabi/newpipe/player/resolver/PlaybackResolver.java b/app/src/main/java/org/schabi/newpipe/player/resolver/PlaybackResolver.java index e204b8372..33a007597 100644 --- a/app/src/main/java/org/schabi/newpipe/player/resolver/PlaybackResolver.java +++ b/app/src/main/java/org/schabi/newpipe/player/resolver/PlaybackResolver.java @@ -201,12 +201,13 @@ public interface PlaybackResolver extends Resolver { try { final StreamInfoTag tag = StreamInfoTag.of(info); - if (!info.getHlsUrl().isEmpty()) { - return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag); - } else if (!info.getDashMpdUrl().isEmpty()) { + if (!info.getDashMpdUrl().isEmpty()) { return buildLiveMediaSource( dataSource, info.getDashMpdUrl(), C.CONTENT_TYPE_DASH, tag); } + if (!info.getHlsUrl().isEmpty()) { + return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag); + } } catch (final Exception e) { Log.w(TAG, "Error when generating live media source, falling back to standard sources", e); @@ -225,7 +226,11 @@ public interface PlaybackResolver extends Resolver { factory = dataSource.getLiveSsMediaSourceFactory(); break; case C.CONTENT_TYPE_DASH: - factory = dataSource.getLiveDashMediaSourceFactory(); + if (metadata.getServiceId() == ServiceList.YouTube.getServiceId()) { + factory = dataSource.getLiveYoutubeDashMediaSourceFactory(); + } else { + factory = dataSource.getLiveDashMediaSourceFactory(); + } break; case C.CONTENT_TYPE_HLS: factory = dataSource.getLiveHlsMediaSourceFactory();