mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 19:12:45 +01:00
fix race condition when returning to main player
This commit is contained in:
parent
afaba7ccdf
commit
e1cc006db7
@ -145,6 +145,10 @@ public abstract class BasePlayer implements
|
|||||||
|
|
||||||
@Nullable protected Toast errorToast;
|
@Nullable protected Toast errorToast;
|
||||||
|
|
||||||
|
/** Will remember the last playback state even if simpleExoPlayer ot destroyed */
|
||||||
|
private int lastPlaybackState;
|
||||||
|
private boolean lastPlayWhenReady;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Player
|
// Player
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
@ -273,6 +277,8 @@ public abstract class BasePlayer implements
|
|||||||
public void destroyPlayer() {
|
public void destroyPlayer() {
|
||||||
if (DEBUG) Log.d(TAG, "destroyPlayer() called");
|
if (DEBUG) Log.d(TAG, "destroyPlayer() called");
|
||||||
if (simpleExoPlayer != null) {
|
if (simpleExoPlayer != null) {
|
||||||
|
lastPlaybackState = simpleExoPlayer.getPlaybackState();
|
||||||
|
lastPlayWhenReady = simpleExoPlayer.getPlayWhenReady();
|
||||||
simpleExoPlayer.removeListener(this);
|
simpleExoPlayer.removeListener(this);
|
||||||
simpleExoPlayer.stop();
|
simpleExoPlayer.stop();
|
||||||
simpleExoPlayer.release();
|
simpleExoPlayer.release();
|
||||||
@ -1106,14 +1112,16 @@ public abstract class BasePlayer implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
final int state = simpleExoPlayer.getPlaybackState();
|
final int state = getLastPlaybackState();
|
||||||
return (state == Player.STATE_READY || state == Player.STATE_BUFFERING)
|
return (state == Player.STATE_READY || state == Player.STATE_BUFFERING)
|
||||||
&& simpleExoPlayer.getPlayWhenReady();
|
&& getLastPlayWhenReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Player.RepeatMode
|
@Player.RepeatMode
|
||||||
public int getRepeatMode() {
|
public int getRepeatMode() {
|
||||||
return simpleExoPlayer == null ? Player.REPEAT_MODE_OFF : simpleExoPlayer.getRepeatMode();
|
return simpleExoPlayer == null
|
||||||
|
? Player.REPEAT_MODE_OFF
|
||||||
|
: simpleExoPlayer.getRepeatMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepeatMode(@Player.RepeatMode final int repeatMode) {
|
public void setRepeatMode(@Player.RepeatMode final int repeatMode) {
|
||||||
@ -1179,4 +1187,22 @@ public abstract class BasePlayer implements
|
|||||||
if (DEBUG) Log.d(TAG, "Setting recovery, queue: " + queuePos + ", pos: " + windowPos);
|
if (DEBUG) Log.d(TAG, "Setting recovery, queue: " + queuePos + ", pos: " + windowPos);
|
||||||
playQueue.setRecovery(queuePos, windowPos);
|
playQueue.setRecovery(queuePos, windowPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sometimes the playbac kstate gets asked even though simpleExoPlayer got already destroyed.
|
||||||
|
* Therefore on destroying simpleExoPlayer the playback state will get asked once more, so
|
||||||
|
* you can retreve the last playback state here.
|
||||||
|
* @return the playback state of simpleExoPlayer even if got destroyed
|
||||||
|
*/
|
||||||
|
public int getLastPlaybackState() {
|
||||||
|
return simpleExoPlayer == null
|
||||||
|
? lastPlaybackState
|
||||||
|
: simpleExoPlayer.getPlaybackState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getLastPlayWhenReady() {
|
||||||
|
return simpleExoPlayer == null
|
||||||
|
? lastPlayWhenReady
|
||||||
|
: simpleExoPlayer.getPlayWhenReady();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user