-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Disable video and text tracks in background player and prefer DASH manifests over HLS ones for livestreams #12601
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
base: dev
Are you sure you want to change the base?
Changes from all commits
afff985
1929785
e4a3185
ef47d6a
268ae39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
| * | ||
| * <p> | ||
| * 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. | ||
| * </p> | ||
| */ | ||
| 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<Period> periods) { | ||
| return super.buildMediaPresentationDescription( | ||
| AVAILABILITY_START_TIME_TO_USE, | ||
| durationMs, | ||
| minBufferTimeMs, | ||
| dynamic, | ||
| minUpdateTimeMs, | ||
| timeShiftBufferDepthMs, | ||
| suggestedPresentationDelayMs, | ||
| publishTimeMs, | ||
| programInformation, | ||
| utcTiming, | ||
| serviceDescription, | ||
| location, | ||
| periods); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -201,12 +201,13 @@ static MediaSource maybeBuildLiveMediaSource(final PlayerDataSource dataSource, | |
|
|
||
| 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()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment explaining that we prefer Dash over HLS because of the exoplayer bug (which I guess is the reason why you reordered here). |
||
| 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 @@ static MediaSource buildLiveMediaSource(final PlayerDataSource dataSource, | |
| 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(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| package org.schabi.newpipe.player.ui; | ||||||
|
|
||||||
| import androidx.annotation.NonNull; | ||||||
|
|
||||||
| import org.schabi.newpipe.player.Player; | ||||||
|
|
||||||
| /** | ||||||
| * This is not a real UI for the background player, it used to disable fetching video and text | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * tracks with it. | ||||||
| * | ||||||
| * <p> | ||||||
| * This allows reducing data usage for manifest sources with demuxed audio and video, | ||||||
| * such as livestreams. | ||||||
| * </p> | ||||||
| */ | ||||||
| public class BackgroundPlayerUi extends PlayerUi { | ||||||
|
|
||||||
| public BackgroundPlayerUi(@NonNull final Player player) { | ||||||
| super(player); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public void initPlayback() { | ||||||
| super.initPlayback(); | ||||||
|
|
||||||
| // Make sure to disable video and subtitles track types | ||||||
| player.useVideoAndSubtitles(false); | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason behind swapping
setRecovery()andreloadPlayQueueManager()here and above?