Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled preloading when switching streams #4246

Merged
merged 1 commit into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,9 @@ public void selectAndLoadVideo(final int sid, final String videoUrl, final Strin
return;
}
setInitialData(sid, videoUrl, title, queue);
if (player != null) {
player.disablePreloadingOfCurrentTrack();
}
startLoading(false, true);
}

Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/org/schabi/newpipe/player/BasePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,11 @@ public MediaSourceTag getCurrentMetadata() {
return currentMetadata;
}

@NonNull
public LoadController getLoadController() {
return (LoadController) loadControl;
}

@NonNull
public String getVideoUrl() {
return currentMetadata == null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,10 @@ public void hideSystemUIIfNeeded() {
}
}

public void disablePreloadingOfCurrentTrack() {
getLoadController().disablePreloadingOfCurrentTrack();
}

/**
* Measures width and height of controls visible on screen.
* It ensures that controls will be side-by-side with NavigationBar and notches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class LoadController implements LoadControl {

private final long initialPlaybackBufferUs;
private final LoadControl internalLoadControl;
private boolean preloadingEnabled = true;

/*//////////////////////////////////////////////////////////////////////////
// Default Load Control
Expand Down Expand Up @@ -41,6 +42,7 @@ private LoadController(final int initialPlaybackBufferMs,

@Override
public void onPrepared() {
preloadingEnabled = true;
internalLoadControl.onPrepared();
}

Expand All @@ -52,11 +54,13 @@ public void onTracksSelected(final Renderer[] renderers, final TrackGroupArray t

@Override
public void onStopped() {
preloadingEnabled = true;
internalLoadControl.onStopped();
}

@Override
public void onReleased() {
preloadingEnabled = true;
internalLoadControl.onReleased();
}

Expand All @@ -78,6 +82,9 @@ public boolean retainBackBufferFromKeyframe() {
@Override
public boolean shouldContinueLoading(final long bufferedDurationUs,
final float playbackSpeed) {
if (!preloadingEnabled) {
return false;
}
return internalLoadControl.shouldContinueLoading(bufferedDurationUs, playbackSpeed);
}

Expand All @@ -90,4 +97,8 @@ public boolean shouldStartPlayback(final long bufferedDurationUs, final float pl
.shouldStartPlayback(bufferedDurationUs, playbackSpeed, rebuffering);
return isInitialPlaybackBufferFilled || isInternalStartingPlayback;
}

public void disablePreloadingOfCurrentTrack() {
preloadingEnabled = false;
}
}