From 077f34c922703a62b4144f43e1a73d3f2096e543 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sat, 5 Jul 2025 20:26:37 +0200 Subject: [PATCH] Add a YouTube DASH manifest parser to make live DASH manifests usable This is a hacky solution, a better one should be investigated and used. --- .../helper/YoutubeDashLiveManifestParser.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/src/main/java/org/schabi/newpipe/player/helper/YoutubeDashLiveManifestParser.java diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/YoutubeDashLiveManifestParser.java b/app/src/main/java/org/schabi/newpipe/player/helper/YoutubeDashLiveManifestParser.java new file mode 100644 index 000000000..00f5de071 --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/player/helper/YoutubeDashLiveManifestParser.java @@ -0,0 +1,68 @@ +package org.schabi.newpipe.player.helper; + +import android.net.Uri; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.google.android.exoplayer2.source.dash.manifest.DashManifest; +import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser; +import com.google.android.exoplayer2.source.dash.manifest.Period; +import com.google.android.exoplayer2.source.dash.manifest.ProgramInformation; +import com.google.android.exoplayer2.source.dash.manifest.ServiceDescriptionElement; +import com.google.android.exoplayer2.source.dash.manifest.UtcTimingElement; + +import java.util.List; + +/** + * A {@link DashManifestParser} fixing YouTube DASH manifests to allow starting playback from the + * newest period available instead of the earliest one in some cases. + * + *

+ * It changes the {@code availabilityStartTime} passed to a custom value doing the workaround. + * A better approach to fix the issue should be investigated and used in the future. + *

+ */ +public class YoutubeDashLiveManifestParser extends DashManifestParser { + + // Result of Util.parseXsDateTime("1970-01-01T00:00:00Z") + private static final long AVAILABILITY_START_TIME_TO_USE = 0; + + // There is no computation made with the availabilityStartTime value in the + // parseMediaPresentationDescription method itself, so we can just override methods called in + // this method using the workaround value + // Overriding parsePeriod does not seem to be needed + + @SuppressWarnings("checkstyle:ParameterNumber") + @NonNull + @Override + protected DashManifest buildMediaPresentationDescription( + final long availabilityStartTime, + final long durationMs, + final long minBufferTimeMs, + final boolean dynamic, + final long minUpdateTimeMs, + final long timeShiftBufferDepthMs, + final long suggestedPresentationDelayMs, + final long publishTimeMs, + @Nullable final ProgramInformation programInformation, + @Nullable final UtcTimingElement utcTiming, + @Nullable final ServiceDescriptionElement serviceDescription, + @Nullable final Uri location, + @NonNull final List periods) { + return super.buildMediaPresentationDescription( + AVAILABILITY_START_TIME_TO_USE, + durationMs, + minBufferTimeMs, + dynamic, + minUpdateTimeMs, + timeShiftBufferDepthMs, + suggestedPresentationDelayMs, + publishTimeMs, + programInformation, + utcTiming, + serviceDescription, + location, + periods); + } +}