Skip to content

Commit c670ad8

Browse files
AudricVStypox
authored andcommitted
Use DASH first instead of HLS and YouTube's DASH parser for lives
1 parent 077f34c commit c670ad8

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlayerDataSource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ public DashMediaSource.Factory getLiveDashMediaSourceFactory() {
129129
getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
130130
cachelessDataSourceFactory);
131131
}
132+
133+
public DashMediaSource.Factory getLiveYoutubeDashMediaSourceFactory() {
134+
return new DashMediaSource.Factory(
135+
getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
136+
cachelessDataSourceFactory)
137+
.setManifestParser(new YoutubeDashLiveManifestParser());
138+
}
132139
//endregion
133140

134141

app/src/main/java/org/schabi/newpipe/player/resolver/PlaybackResolver.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ static MediaSource maybeBuildLiveMediaSource(final PlayerDataSource dataSource,
201201

202202
try {
203203
final StreamInfoTag tag = StreamInfoTag.of(info);
204-
if (!info.getHlsUrl().isEmpty()) {
205-
return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag);
206-
} else if (!info.getDashMpdUrl().isEmpty()) {
204+
if (!info.getDashMpdUrl().isEmpty()) {
207205
return buildLiveMediaSource(
208206
dataSource, info.getDashMpdUrl(), C.CONTENT_TYPE_DASH, tag);
209207
}
208+
if (!info.getHlsUrl().isEmpty()) {
209+
return buildLiveMediaSource(dataSource, info.getHlsUrl(), C.CONTENT_TYPE_HLS, tag);
210+
}
210211
} catch (final Exception e) {
211212
Log.w(TAG, "Error when generating live media source, falling back to standard sources",
212213
e);
@@ -225,7 +226,11 @@ static MediaSource buildLiveMediaSource(final PlayerDataSource dataSource,
225226
factory = dataSource.getLiveSsMediaSourceFactory();
226227
break;
227228
case C.CONTENT_TYPE_DASH:
228-
factory = dataSource.getLiveDashMediaSourceFactory();
229+
if (metadata.getServiceId() == ServiceList.YouTube.getServiceId()) {
230+
factory = dataSource.getLiveYoutubeDashMediaSourceFactory();
231+
} else {
232+
factory = dataSource.getLiveDashMediaSourceFactory();
233+
}
229234
break;
230235
case C.CONTENT_TYPE_HLS:
231236
factory = dataSource.getLiveHlsMediaSourceFactory();

0 commit comments

Comments
 (0)