11package org .schabi .newpipe .player .helper ;
22
33import android .content .Context ;
4+ import android .os .Build ;
45
56import androidx .annotation .NonNull ;
67
8+ import com .google .android .exoplayer2 .source .MediaParserExtractorAdapter ;
79import com .google .android .exoplayer2 .source .ProgressiveMediaSource ;
810import com .google .android .exoplayer2 .source .SingleSampleMediaSource ;
11+ import com .google .android .exoplayer2 .source .chunk .MediaParserChunkExtractor ;
912import com .google .android .exoplayer2 .source .dash .DashMediaSource ;
1013import com .google .android .exoplayer2 .source .dash .DefaultDashChunkSource ;
1114import com .google .android .exoplayer2 .source .hls .HlsMediaSource ;
15+ import com .google .android .exoplayer2 .source .hls .MediaParserHlsMediaChunkExtractor ;
1216import com .google .android .exoplayer2 .source .smoothstreaming .DefaultSsChunkSource ;
1317import com .google .android .exoplayer2 .source .smoothstreaming .SsMediaSource ;
1418import com .google .android .exoplayer2 .upstream .DataSource ;
@@ -40,17 +44,33 @@ public SsMediaSource.Factory getLiveSsMediaSourceFactory() {
4044 }
4145
4246 public HlsMediaSource .Factory getLiveHlsMediaSourceFactory () {
43- return new HlsMediaSource .Factory (cachelessDataSourceFactory )
44- .setAllowChunklessPreparation (true )
45- .setLoadErrorHandlingPolicy (
46- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
47+ 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 ));
58+ }
4759 }
4860
4961 public DashMediaSource .Factory getLiveDashMediaSourceFactory () {
50- return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
51- cachelessDataSourceFactory ), cachelessDataSourceFactory )
52- .setLoadErrorHandlingPolicy (
53- new DefaultLoadErrorHandlingPolicy (MANIFEST_MINIMUM_RETRY ));
62+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
63+ return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
64+ 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 ));
73+ }
5474 }
5575
5676 public SsMediaSource .Factory getSsMediaSourceFactory () {
@@ -59,18 +79,36 @@ public SsMediaSource.Factory getSsMediaSourceFactory() {
5979 }
6080
6181 public HlsMediaSource .Factory getHlsMediaSourceFactory () {
62- return new HlsMediaSource .Factory (cacheDataSourceFactory );
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 );
87+ }
6388 }
6489
6590 public DashMediaSource .Factory getDashMediaSourceFactory () {
66- return new DashMediaSource .Factory (new DefaultDashChunkSource .Factory (
67- cacheDataSourceFactory ), cacheDataSourceFactory );
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+ }
6899 }
69100
70101 public ProgressiveMediaSource .Factory getExtractorMediaSourceFactory () {
71- return new ProgressiveMediaSource .Factory (cacheDataSourceFactory )
72- .setLoadErrorHandlingPolicy (
73- new DefaultLoadErrorHandlingPolicy (EXTRACTOR_MINIMUM_RETRY ));
102+ 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 ));
107+ } else {
108+ return new ProgressiveMediaSource .Factory (cacheDataSourceFactory )
109+ .setLoadErrorHandlingPolicy (
110+ new DefaultLoadErrorHandlingPolicy (EXTRACTOR_MINIMUM_RETRY ));
111+ }
74112 }
75113
76114 public SingleSampleMediaSource .Factory getSampleMediaSourceFactory () {
0 commit comments