Skip to content

Commit d8236bb

Browse files
authored
Merge pull request #7406 from Redirion/usedefaultloadcontrol
Use DefaultLoadcontrol
2 parents 1de21fb + 9c9730b commit d8236bb

2 files changed

Lines changed: 5 additions & 76 deletions

File tree

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

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

33
import com.google.android.exoplayer2.DefaultLoadControl;
4-
import com.google.android.exoplayer2.LoadControl;
5-
import com.google.android.exoplayer2.Renderer;
6-
import com.google.android.exoplayer2.source.TrackGroupArray;
7-
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
8-
import com.google.android.exoplayer2.upstream.Allocator;
94

10-
public class LoadController implements LoadControl {
5+
public class LoadController extends DefaultLoadControl {
116

127
public static final String TAG = "LoadController";
13-
14-
private final long initialPlaybackBufferUs;
15-
private final LoadControl internalLoadControl;
168
private boolean preloadingEnabled = true;
179

18-
/*//////////////////////////////////////////////////////////////////////////
19-
// Default Load Control
20-
//////////////////////////////////////////////////////////////////////////*/
21-
22-
public LoadController() {
23-
this(PlayerHelper.getPlaybackStartBufferMs());
24-
}
25-
26-
private LoadController(final int initialPlaybackBufferMs) {
27-
this.initialPlaybackBufferUs = initialPlaybackBufferMs * 1000;
28-
29-
final DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder();
30-
builder.setBufferDurationsMs(
31-
DefaultLoadControl.DEFAULT_MIN_BUFFER_MS,
32-
DefaultLoadControl.DEFAULT_MAX_BUFFER_MS,
33-
initialPlaybackBufferMs,
34-
DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS);
35-
internalLoadControl = builder.build();
36-
}
37-
38-
/*//////////////////////////////////////////////////////////////////////////
39-
// Custom behaviours
40-
//////////////////////////////////////////////////////////////////////////*/
41-
4210
@Override
4311
public void onPrepared() {
4412
preloadingEnabled = true;
45-
internalLoadControl.onPrepared();
46-
}
47-
48-
@Override
49-
public void onTracksSelected(final Renderer[] renderers, final TrackGroupArray trackGroups,
50-
final ExoTrackSelection[] trackSelections) {
51-
internalLoadControl.onTracksSelected(renderers, trackGroups, trackSelections);
13+
super.onPrepared();
5214
}
5315

5416
@Override
5517
public void onStopped() {
5618
preloadingEnabled = true;
57-
internalLoadControl.onStopped();
19+
super.onStopped();
5820
}
5921

6022
@Override
6123
public void onReleased() {
6224
preloadingEnabled = true;
63-
internalLoadControl.onReleased();
64-
}
65-
66-
@Override
67-
public Allocator getAllocator() {
68-
return internalLoadControl.getAllocator();
69-
}
70-
71-
@Override
72-
public long getBackBufferDurationUs() {
73-
return internalLoadControl.getBackBufferDurationUs();
74-
}
75-
76-
@Override
77-
public boolean retainBackBufferFromKeyframe() {
78-
return internalLoadControl.retainBackBufferFromKeyframe();
25+
super.onReleased();
7926
}
8027

8128
@Override
@@ -85,21 +32,10 @@ public boolean shouldContinueLoading(final long playbackPositionUs,
8532
if (!preloadingEnabled) {
8633
return false;
8734
}
88-
return internalLoadControl.shouldContinueLoading(
35+
return super.shouldContinueLoading(
8936
playbackPositionUs, bufferedDurationUs, playbackSpeed);
9037
}
9138

92-
@Override
93-
public boolean shouldStartPlayback(final long bufferedDurationUs, final float playbackSpeed,
94-
final boolean rebuffering, final long targetLiveOffsetUs) {
95-
final boolean isInitialPlaybackBufferFilled
96-
= bufferedDurationUs >= this.initialPlaybackBufferUs * playbackSpeed;
97-
final boolean isInternalStartingPlayback = internalLoadControl
98-
.shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering,
99-
targetLiveOffsetUs);
100-
return isInitialPlaybackBufferFilled || isInternalStartingPlayback;
101-
}
102-
10339
public void disablePreloadingOfCurrentTrack() {
10440
preloadingEnabled = false;
10541
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,6 @@ public static long getPreferredFileSize() {
305305
return 2 * 1024 * 1024L; // ExoPlayer CacheDataSink.MIN_RECOMMENDED_FRAGMENT_SIZE
306306
}
307307

308-
/**
309-
* @return the number of milliseconds the player buffers for before starting playback
310-
*/
311-
public static int getPlaybackStartBufferMs() {
312-
return 500;
313-
}
314-
315308
public static ExoTrackSelection.Factory getQualitySelector() {
316309
return new AdaptiveTrackSelection.Factory(
317310
1000,

0 commit comments

Comments
 (0)