De-duplicated PlayerDataSource-code

This commit is contained in:
litetex 2021-11-12 19:40:00 +01:00
parent 1b9c2b37c5
commit dd2cde3c1a
1 changed files with 51 additions and 47 deletions

View File

@ -36,79 +36,83 @@ public class PlayerDataSource {
} }
public SsMediaSource.Factory getLiveSsMediaSourceFactory() { public SsMediaSource.Factory getLiveSsMediaSourceFactory() {
return new SsMediaSource.Factory(new DefaultSsChunkSource.Factory( return new SsMediaSource.Factory(
cachelessDataSourceFactory), cachelessDataSourceFactory) new DefaultSsChunkSource.Factory(cachelessDataSourceFactory),
cachelessDataSourceFactory
)
.setLoadErrorHandlingPolicy( .setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY)) new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY))
.setLivePresentationDelayMs(LIVE_STREAM_EDGE_GAP_MILLIS); .setLivePresentationDelayMs(LIVE_STREAM_EDGE_GAP_MILLIS);
} }
public HlsMediaSource.Factory getLiveHlsMediaSourceFactory() { public HlsMediaSource.Factory getLiveHlsMediaSourceFactory() {
final HlsMediaSource.Factory factory =
new HlsMediaSource.Factory(cachelessDataSourceFactory)
.setAllowChunklessPreparation(true)
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return new HlsMediaSource.Factory(cachelessDataSourceFactory) factory.setExtractorFactory(MediaParserHlsMediaChunkExtractor.FACTORY);
.setExtractorFactory(MediaParserHlsMediaChunkExtractor.FACTORY)
.setAllowChunklessPreparation(true)
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY));
} else {
return new HlsMediaSource.Factory(cachelessDataSourceFactory)
.setAllowChunklessPreparation(true)
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY));
} }
return factory;
} }
public DashMediaSource.Factory getLiveDashMediaSourceFactory() { public DashMediaSource.Factory getLiveDashMediaSourceFactory() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { return new DashMediaSource.Factory(
return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory( getDefaultDashChunkSourceFactory(cachelessDataSourceFactory),
MediaParserChunkExtractor.FACTORY, cachelessDataSourceFactory
cachelessDataSourceFactory, 1), cachelessDataSourceFactory) )
.setLoadErrorHandlingPolicy( .setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY)); new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY));
} else {
return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(
cachelessDataSourceFactory), cachelessDataSourceFactory)
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(MANIFEST_MINIMUM_RETRY));
}
} }
public SsMediaSource.Factory getSsMediaSourceFactory() { private DefaultDashChunkSource.Factory getDefaultDashChunkSourceFactory(
return new SsMediaSource.Factory(new DefaultSsChunkSource.Factory( final DataSource.Factory dataSourceFactory
cacheDataSourceFactory), cacheDataSourceFactory); ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return new DefaultDashChunkSource.Factory(
MediaParserChunkExtractor.FACTORY,
dataSourceFactory,
1
);
}
return new DefaultDashChunkSource.Factory(dataSourceFactory);
} }
public HlsMediaSource.Factory getHlsMediaSourceFactory() { public HlsMediaSource.Factory getHlsMediaSourceFactory() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { final HlsMediaSource.Factory factory = new HlsMediaSource.Factory(cacheDataSourceFactory);
return new HlsMediaSource.Factory(cacheDataSourceFactory)
.setExtractorFactory(MediaParserHlsMediaChunkExtractor.FACTORY); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
} else { return factory;
return new HlsMediaSource.Factory(cacheDataSourceFactory);
} }
// *** >= Android 11 / R / API 30 ***
return factory.setExtractorFactory(MediaParserHlsMediaChunkExtractor.FACTORY);
} }
public DashMediaSource.Factory getDashMediaSourceFactory() { public DashMediaSource.Factory getDashMediaSourceFactory() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { return new DashMediaSource.Factory(
return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory( getDefaultDashChunkSourceFactory(cacheDataSourceFactory),
MediaParserChunkExtractor.FACTORY, cacheDataSourceFactory
cacheDataSourceFactory, 1), cacheDataSourceFactory); );
} else {
return new DashMediaSource.Factory(new DefaultDashChunkSource.Factory(
cacheDataSourceFactory), cacheDataSourceFactory);
}
} }
public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() { public ProgressiveMediaSource.Factory getExtractorMediaSourceFactory() {
final ProgressiveMediaSource.Factory factory;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory, factory = new ProgressiveMediaSource.Factory(
MediaParserExtractorAdapter.FACTORY) cacheDataSourceFactory,
.setLoadErrorHandlingPolicy( MediaParserExtractorAdapter.FACTORY
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY)); );
} else { } else {
return new ProgressiveMediaSource.Factory(cacheDataSourceFactory) factory = new ProgressiveMediaSource.Factory(cacheDataSourceFactory);
.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
} }
return factory.setLoadErrorHandlingPolicy(
new DefaultLoadErrorHandlingPolicy(EXTRACTOR_MINIMUM_RETRY));
} }
public SingleSampleMediaSource.Factory getSampleMediaSourceFactory() { public SingleSampleMediaSource.Factory getSampleMediaSourceFactory() {