Skip to content

Commit 1b9c2b3

Browse files
Robinlitetex
authored andcommitted
Use Android11+ extractors
1 parent eae1f8b commit 1b9c2b3

4 files changed

Lines changed: 68 additions & 30 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,12 @@
177177
import org.schabi.newpipe.player.resolver.VideoPlaybackResolver;
178178
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHelper;
179179
import org.schabi.newpipe.player.seekbarpreview.SeekbarPreviewThumbnailHolder;
180-
import org.schabi.newpipe.util.StreamTypeUtil;
181180
import org.schabi.newpipe.util.DeviceUtils;
182181
import org.schabi.newpipe.util.ListHelper;
183182
import org.schabi.newpipe.util.NavigationHelper;
184183
import org.schabi.newpipe.util.PicassoHelper;
185184
import org.schabi.newpipe.util.SerializedCache;
185+
import org.schabi.newpipe.util.StreamTypeUtil;
186186
import org.schabi.newpipe.util.external_communication.KoreUtils;
187187
import org.schabi.newpipe.util.external_communication.ShareUtils;
188188
import org.schabi.newpipe.views.ExpandableSurfaceView;

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

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package org.schabi.newpipe.player.helper;
22

33
import android.content.Context;
4+
import android.os.Build;
45

56
import androidx.annotation.NonNull;
67

8+
import com.google.android.exoplayer2.source.MediaParserExtractorAdapter;
79
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
810
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
11+
import com.google.android.exoplayer2.source.chunk.MediaParserChunkExtractor;
912
import com.google.android.exoplayer2.source.dash.DashMediaSource;
1013
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
1114
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
15+
import com.google.android.exoplayer2.source.hls.MediaParserHlsMediaChunkExtractor;
1216
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource;
1317
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
1418
import 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() {

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
package org.schabi.newpipe.player.helper;
22

3+
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
4+
import static com.google.android.exoplayer2.Player.REPEAT_MODE_OFF;
5+
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
6+
import static org.schabi.newpipe.player.Player.IDLE_WINDOW_FLAGS;
7+
import static org.schabi.newpipe.player.Player.PLAYER_TYPE;
8+
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS;
9+
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER;
10+
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI;
11+
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
12+
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
13+
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
14+
import static java.lang.annotation.RetentionPolicy.SOURCE;
15+
316
import android.annotation.SuppressLint;
417
import android.content.Context;
518
import android.content.Intent;
@@ -57,19 +70,6 @@
5770
import java.util.Set;
5871
import java.util.concurrent.TimeUnit;
5972

60-
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ALL;
61-
import static com.google.android.exoplayer2.Player.REPEAT_MODE_OFF;
62-
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;
63-
import static java.lang.annotation.RetentionPolicy.SOURCE;
64-
import static org.schabi.newpipe.player.Player.IDLE_WINDOW_FLAGS;
65-
import static org.schabi.newpipe.player.Player.PLAYER_TYPE;
66-
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_ALWAYS;
67-
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER;
68-
import static org.schabi.newpipe.player.helper.PlayerHelper.AutoplayType.AUTOPLAY_TYPE_WIFI;
69-
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_BACKGROUND;
70-
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_NONE;
71-
import static org.schabi.newpipe.player.helper.PlayerHelper.MinimizeMode.MINIMIZE_ON_EXIT_MODE_POPUP;
72-
7373
public final class PlayerHelper {
7474
private static final StringBuilder STRING_BUILDER = new StringBuilder();
7575
private static final Formatter STRING_FORMATTER
@@ -312,7 +312,7 @@ public static int getPlaybackStartBufferMs() {
312312
return 500;
313313
}
314314

315-
public static TrackSelection.Factory getQualitySelector() {
315+
public static ExoTrackSelection.Factory getQualitySelector() {
316316
return new AdaptiveTrackSelection.Factory(
317317
1000,
318318
AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ default MediaSource maybeBuildLiveMediaSource(@NonNull final PlayerDataSource da
3535

3636
return null;
3737
}
38-
0
38+
3939
@NonNull
4040
default MediaSource buildLiveMediaSource(@NonNull final PlayerDataSource dataSource,
4141
@NonNull final String sourceUrl,

0 commit comments

Comments
 (0)