mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-26 12:10:09 +01:00
Fix PlayerService leakead by Binder instance
Also see https://stackoverflow.com/q/63787707
This commit is contained in:
parent
135f0f7249
commit
00257e969e
@ -31,6 +31,8 @@ import android.util.Log;
|
||||
import org.schabi.newpipe.player.mediasession.MediaSessionPlayerUi;
|
||||
import org.schabi.newpipe.util.ThemeHelper;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
|
||||
/**
|
||||
* One service for all players.
|
||||
@ -41,7 +43,7 @@ public final class PlayerService extends Service {
|
||||
|
||||
private Player player;
|
||||
|
||||
private final IBinder mBinder = new PlayerService.LocalBinder();
|
||||
private final IBinder mBinder = new PlayerService.LocalBinder(this);
|
||||
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
@ -134,14 +136,19 @@ public final class PlayerService extends Service {
|
||||
return mBinder;
|
||||
}
|
||||
|
||||
public class LocalBinder extends Binder {
|
||||
public static class LocalBinder extends Binder {
|
||||
private final WeakReference<PlayerService> playerService;
|
||||
|
||||
LocalBinder(final PlayerService playerService) {
|
||||
this.playerService = new WeakReference<>(playerService);
|
||||
}
|
||||
|
||||
public PlayerService getService() {
|
||||
return PlayerService.this;
|
||||
return playerService.get();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return PlayerService.this.player;
|
||||
return playerService.get().player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user