-Fixed main player paused video not abandoning audio focus after navigating away from activity during interruption, when resume on focus regain is enabled.
-Separated onPause and onPlay functions from onPlayPause. -Renamed onVideoPlayPause to onPlayPause.
This commit is contained in:
parent
8b60397f06
commit
72eaff148c
6 changed files with 33 additions and 19 deletions
|
@ -486,7 +486,7 @@ public final class BackgroundPlayer extends Service {
|
|||
onClose();
|
||||
break;
|
||||
case ACTION_PLAY_PAUSE:
|
||||
onVideoPlayPause();
|
||||
onPlayPause();
|
||||
break;
|
||||
case ACTION_REPEAT:
|
||||
onRepeatClicked();
|
||||
|
|
|
@ -392,7 +392,7 @@ public abstract class BasePlayer implements
|
|||
if (intent == null || intent.getAction() == null) return;
|
||||
switch (intent.getAction()) {
|
||||
case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
|
||||
if (isPlaying()) onVideoPlayPause();
|
||||
onPause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -948,14 +948,11 @@ public abstract class BasePlayer implements
|
|||
changeState(playWhenReady ? STATE_PLAYING : STATE_PAUSED);
|
||||
}
|
||||
|
||||
public void onVideoPlayPause() {
|
||||
if (DEBUG) Log.d(TAG, "onVideoPlayPause() called");
|
||||
public void onPlay() {
|
||||
if (DEBUG) Log.d(TAG, "onPlay() called");
|
||||
if (audioReactor == null || playQueue == null || simpleExoPlayer == null) return;
|
||||
|
||||
if (!isPlaying()) {
|
||||
audioReactor.requestAudioFocus();
|
||||
} else {
|
||||
audioReactor.abandonAudioFocus();
|
||||
}
|
||||
|
||||
if (getCurrentState() == STATE_COMPLETED) {
|
||||
if (playQueue.getIndex() == 0) {
|
||||
|
@ -965,7 +962,25 @@ public abstract class BasePlayer implements
|
|||
}
|
||||
}
|
||||
|
||||
simpleExoPlayer.setPlayWhenReady(!isPlaying());
|
||||
simpleExoPlayer.setPlayWhenReady(true);
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
if (DEBUG) Log.d(TAG, "onPause() called");
|
||||
if (audioReactor == null || simpleExoPlayer == null) return;
|
||||
|
||||
audioReactor.abandonAudioFocus();
|
||||
simpleExoPlayer.setPlayWhenReady(false);
|
||||
}
|
||||
|
||||
public void onPlayPause() {
|
||||
if (DEBUG) Log.d(TAG, "onPlayPause() called");
|
||||
|
||||
if (!isPlaying()) {
|
||||
onPlay();
|
||||
} else {
|
||||
onPause();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFastRewind() {
|
||||
|
|
|
@ -49,7 +49,6 @@ import android.widget.SeekBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||
import com.google.android.exoplayer2.ui.SubtitleView;
|
||||
|
@ -153,7 +152,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||
if (DEBUG) Log.d(TAG, "onResume() called");
|
||||
if (playerImpl.getPlayer() != null && activityPaused && playerImpl.wasPlaying()
|
||||
&& !playerImpl.isPlaying()) {
|
||||
playerImpl.onVideoPlayPause();
|
||||
playerImpl.onPlay();
|
||||
}
|
||||
activityPaused = false;
|
||||
|
||||
|
@ -188,7 +187,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||
|
||||
if (playerImpl != null && playerImpl.getPlayer() != null && !activityPaused) {
|
||||
playerImpl.wasPlaying = playerImpl.isPlaying();
|
||||
if (playerImpl.isPlaying()) playerImpl.onVideoPlayPause();
|
||||
playerImpl.onPause();
|
||||
}
|
||||
activityPaused = true;
|
||||
}
|
||||
|
@ -563,7 +562,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
|||
public void onClick(View v) {
|
||||
super.onClick(v);
|
||||
if (v.getId() == playPauseButton.getId()) {
|
||||
onVideoPlayPause();
|
||||
onPlayPause();
|
||||
|
||||
} else if (v.getId() == playPreviousButton.getId()) {
|
||||
onPlayPrevious();
|
||||
|
|
|
@ -618,7 +618,7 @@ public final class PopupVideoPlayer extends Service {
|
|||
onClose();
|
||||
break;
|
||||
case ACTION_PLAY_PAUSE:
|
||||
onVideoPlayPause();
|
||||
onPlayPause();
|
||||
break;
|
||||
case ACTION_REPEAT:
|
||||
onRepeatClicked();
|
||||
|
@ -731,7 +731,7 @@ public final class PopupVideoPlayer extends Service {
|
|||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||
if (DEBUG) Log.d(TAG, "onSingleTapConfirmed() called with: e = [" + e + "]");
|
||||
if (playerImpl == null || playerImpl.getPlayer() == null) return false;
|
||||
playerImpl.onVideoPlayPause();
|
||||
playerImpl.onPlayPause();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -424,7 +424,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
|
|||
player.onPlayPrevious();
|
||||
|
||||
} else if (view.getId() == playPauseButton.getId()) {
|
||||
player.onVideoPlayPause();
|
||||
player.onPlayPause();
|
||||
|
||||
} else if (view.getId() == forwardButton.getId()) {
|
||||
player.onPlayNext();
|
||||
|
|
|
@ -62,12 +62,12 @@ public class BasePlayerMediaSession implements MediaSessionCallback {
|
|||
|
||||
@Override
|
||||
public void onPlay() {
|
||||
if (!player.isPlaying()) player.onVideoPlayPause();
|
||||
player.onPlay();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (player.isPlaying()) player.onVideoPlayPause();
|
||||
player.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue