@@ -36,79 +36,83 @@ public PlayerDataSource(@NonNull final Context context, @NonNull final String us
3636 }
3737
3838 public SsMediaSource .Factory getLiveSsMediaSourceFactory () {
39- return new SsMediaSource .Factory (new DefaultSsChunkSource .Factory (
40- cachelessDataSourceFactory ), cachelessDataSourceFactory )
39+ return new SsMediaSource .Factory (
40+ new DefaultSsChunkSource .Factory (cachelessDataSourceFactory ),
41+ cachelessDataSourceFactory
42+ )
4143 .setLoadErrorHandlingPolicy (
4244 new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ))
4345 .setLivePresentationDelayMs (LIVE_STREAM_EDGE_GAP_MILLIS );
4446 }
4547
4648 public HlsMediaSource .Factory getLiveHlsMediaSourceFactory () {
49+ final HlsMediaSource .Factory factory =
50+ new HlsMediaSource .Factory (cachelessDataSourceFactory )
51+ .setAllowChunklessPreparation (true )
52+ .setLoadErrorHandlingPolicy (
53+ new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
54+
4755 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
48- return new HlsMediaSource .Factory (cachelessDataSourceFactory )
49- .setExtractorFactory (MediaParserHlsMediaChunkExtractor .FACTORY )
50- .setAllowChunklessPreparation (true )
51- .setLoadErrorHandlingPolicy (
52- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
53- } else {
54- return new HlsMediaSource .Factory (cachelessDataSourceFactory )
55- .setAllowChunklessPreparation (true )
56- .setLoadErrorHandlingPolicy (
57- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
56+ factory .setExtractorFactory (MediaParserHlsMediaChunkExtractor .FACTORY );
5857 }
58+
59+ return factory ;
5960 }
6061
6162 public DashMediaSource .Factory getLiveDashMediaSourceFactory () {
63+ return new DashMediaSource .Factory (
64+ getDefaultDashChunkSourceFactory (cachelessDataSourceFactory ),
65+ cachelessDataSourceFactory
66+ )
67+ .setLoadErrorHandlingPolicy (
68+ new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
69+ }
70+
71+ private DefaultDashChunkSource .Factory getDefaultDashChunkSourceFactory (
72+ final DataSource .Factory dataSourceFactory
73+ ) {
6274 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
63- return new DashMediaSource . Factory ( new DefaultDashChunkSource .Factory (
75+ return new DefaultDashChunkSource .Factory (
6476 MediaParserChunkExtractor .FACTORY ,
65- cachelessDataSourceFactory , 1 ), cachelessDataSourceFactory )
66- .setLoadErrorHandlingPolicy (
67- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
68- } else {
69- return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
70- cachelessDataSourceFactory ), cachelessDataSourceFactory )
71- .setLoadErrorHandlingPolicy (
72- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
77+ dataSourceFactory ,
78+ 1
79+ );
7380 }
74- }
7581
76- public SsMediaSource .Factory getSsMediaSourceFactory () {
77- return new SsMediaSource .Factory (new DefaultSsChunkSource .Factory (
78- cacheDataSourceFactory ), cacheDataSourceFactory );
82+ return new DefaultDashChunkSource .Factory (dataSourceFactory );
7983 }
8084
8185 public HlsMediaSource .Factory getHlsMediaSourceFactory () {
82- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
83- return new HlsMediaSource .Factory (cacheDataSourceFactory )
84- .setExtractorFactory (MediaParserHlsMediaChunkExtractor .FACTORY );
85- } else {
86- return new HlsMediaSource .Factory (cacheDataSourceFactory );
86+ final HlsMediaSource .Factory factory = new HlsMediaSource .Factory (cacheDataSourceFactory );
87+
88+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .R ) {
89+ return factory ;
8790 }
91+
92+ // *** >= Android 11 / R / API 30 ***
93+ return factory .setExtractorFactory (MediaParserHlsMediaChunkExtractor .FACTORY );
8894 }
8995
9096 public DashMediaSource .Factory getDashMediaSourceFactory () {
91- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
92- return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
93- MediaParserChunkExtractor .FACTORY ,
94- cacheDataSourceFactory , 1 ), cacheDataSourceFactory );
95- } else {
96- return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
97- cacheDataSourceFactory ), cacheDataSourceFactory );
98- }
97+ return new DashMediaSource .Factory (
98+ getDefaultDashChunkSourceFactory (cacheDataSourceFactory ),
99+ cacheDataSourceFactory
100+ );
99101 }
100102
101103 public ProgressiveMediaSource .Factory getExtractorMediaSourceFactory () {
104+ final ProgressiveMediaSource .Factory factory ;
102105 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
103- return new ProgressiveMediaSource .Factory (cacheDataSourceFactory ,
104- MediaParserExtractorAdapter . FACTORY )
105- . setLoadErrorHandlingPolicy (
106- new DefaultLoadErrorHandlingPolicy ( EXTRACTOR_MINIMUM_RETRY ) );
106+ factory = new ProgressiveMediaSource .Factory (
107+ cacheDataSourceFactory ,
108+ MediaParserExtractorAdapter . FACTORY
109+ );
107110 } else {
108- return new ProgressiveMediaSource .Factory (cacheDataSourceFactory )
109- .setLoadErrorHandlingPolicy (
110- new DefaultLoadErrorHandlingPolicy (EXTRACTOR_MINIMUM_RETRY ));
111+ factory = new ProgressiveMediaSource .Factory (cacheDataSourceFactory );
111112 }
113+
114+ return factory .setLoadErrorHandlingPolicy (
115+ new DefaultLoadErrorHandlingPolicy (EXTRACTOR_MINIMUM_RETRY ));
112116 }
113117
114118 public SingleSampleMediaSource .Factory getSampleMediaSourceFactory () {
0 commit comments