Skip to content
Open
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
3 changes: 1 addition & 2 deletions app/src/main/java/org/schabi/newpipe/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -5620,7 +5620,7 @@ private void setupVideoSurface() {
cleanupVideoSurface();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // >=API23
surfaceHolderCallback = new SurfaceHolderCallback(context, simpleExoPlayer);
surfaceHolderCallback = new SurfaceHolderCallback(simpleExoPlayer);
binding.surfaceView.getHolder().addCallback(surfaceHolderCallback);
final Surface surface = binding.surfaceView.getHolder().getSurface();
// ensure player is using an unreleased surface, which the surfaceView might not be
Expand All @@ -5641,7 +5641,6 @@ private void cleanupVideoSurface() {
if (binding != null) {
binding.surfaceView.getHolder().removeCallback(surfaceHolderCallback);
}
surfaceHolderCallback.release();
surfaceHolderCallback = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.schabi.newpipe.player.playback;

import android.content.Context;
import android.view.SurfaceHolder;

import androidx.media3.common.Player;
import androidx.media3.exoplayer.video.PlaceholderSurface;

/**
* Prevent error message: 'Unrecoverable player error occurred'
* In case of rotation some users see this kind of an error which is preventable
* having a Callback that handles the lifecycle of the surface.
* <p>
* How?: In case we are no longer able to write to the surface eg. through rotation/putting in
* background we set set a DummySurface. Although it it works on API >= 23 only.
* background we clear the surface, and the player swaps in a placeholder one of its own.
* Result: we get a little video interruption (audio is still fine) but we won't get the
* 'Unrecoverable player error occurred' error message.
* <p>
Expand All @@ -24,12 +22,9 @@
*/
public final class SurfaceHolderCallback implements SurfaceHolder.Callback {

private final Context context;
private final Player player;
private PlaceholderSurface placeholderSurface;

public SurfaceHolderCallback(final Context context, final Player player) {
this.context = context;
public SurfaceHolderCallback(final Player player) {
this.player = player;
}

Expand All @@ -47,16 +42,6 @@ public void surfaceChanged(final SurfaceHolder holder,

@Override
public void surfaceDestroyed(final SurfaceHolder holder) {
if (placeholderSurface == null) {
placeholderSurface = PlaceholderSurface.newInstanceV17(context, false);
}
player.setVideoSurface(placeholderSurface);
}

public void release() {
if (placeholderSurface != null) {
placeholderSurface.release();
placeholderSurface = null;
}
player.setVideoSurface(null);
}
}