-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();
|
onClose();
|
||||||
break;
|
break;
|
||||||
case ACTION_PLAY_PAUSE:
|
case ACTION_PLAY_PAUSE:
|
||||||
onVideoPlayPause();
|
onPlayPause();
|
||||||
break;
|
break;
|
||||||
case ACTION_REPEAT:
|
case ACTION_REPEAT:
|
||||||
onRepeatClicked();
|
onRepeatClicked();
|
||||||
|
|
|
@ -392,7 +392,7 @@ public abstract class BasePlayer implements
|
||||||
if (intent == null || intent.getAction() == null) return;
|
if (intent == null || intent.getAction() == null) return;
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
|
case AudioManager.ACTION_AUDIO_BECOMING_NOISY:
|
||||||
if (isPlaying()) onVideoPlayPause();
|
onPause();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -948,14 +948,11 @@ public abstract class BasePlayer implements
|
||||||
changeState(playWhenReady ? STATE_PLAYING : STATE_PAUSED);
|
changeState(playWhenReady ? STATE_PLAYING : STATE_PAUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onVideoPlayPause() {
|
public void onPlay() {
|
||||||
if (DEBUG) Log.d(TAG, "onVideoPlayPause() called");
|
if (DEBUG) Log.d(TAG, "onPlay() called");
|
||||||
|
if (audioReactor == null || playQueue == null || simpleExoPlayer == null) return;
|
||||||
|
|
||||||
if (!isPlaying()) {
|
|
||||||
audioReactor.requestAudioFocus();
|
audioReactor.requestAudioFocus();
|
||||||
} else {
|
|
||||||
audioReactor.abandonAudioFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getCurrentState() == STATE_COMPLETED) {
|
if (getCurrentState() == STATE_COMPLETED) {
|
||||||
if (playQueue.getIndex() == 0) {
|
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() {
|
public void onFastRewind() {
|
||||||
|
|
|
@ -49,7 +49,6 @@ import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.PlaybackParameters;
|
|
||||||
import com.google.android.exoplayer2.Player;
|
import com.google.android.exoplayer2.Player;
|
||||||
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
|
||||||
import com.google.android.exoplayer2.ui.SubtitleView;
|
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 (DEBUG) Log.d(TAG, "onResume() called");
|
||||||
if (playerImpl.getPlayer() != null && activityPaused && playerImpl.wasPlaying()
|
if (playerImpl.getPlayer() != null && activityPaused && playerImpl.wasPlaying()
|
||||||
&& !playerImpl.isPlaying()) {
|
&& !playerImpl.isPlaying()) {
|
||||||
playerImpl.onVideoPlayPause();
|
playerImpl.onPlay();
|
||||||
}
|
}
|
||||||
activityPaused = false;
|
activityPaused = false;
|
||||||
|
|
||||||
|
@ -188,7 +187,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
|
|
||||||
if (playerImpl != null && playerImpl.getPlayer() != null && !activityPaused) {
|
if (playerImpl != null && playerImpl.getPlayer() != null && !activityPaused) {
|
||||||
playerImpl.wasPlaying = playerImpl.isPlaying();
|
playerImpl.wasPlaying = playerImpl.isPlaying();
|
||||||
if (playerImpl.isPlaying()) playerImpl.onVideoPlayPause();
|
playerImpl.onPause();
|
||||||
}
|
}
|
||||||
activityPaused = true;
|
activityPaused = true;
|
||||||
}
|
}
|
||||||
|
@ -563,7 +562,7 @@ public final class MainVideoPlayer extends AppCompatActivity
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
super.onClick(v);
|
super.onClick(v);
|
||||||
if (v.getId() == playPauseButton.getId()) {
|
if (v.getId() == playPauseButton.getId()) {
|
||||||
onVideoPlayPause();
|
onPlayPause();
|
||||||
|
|
||||||
} else if (v.getId() == playPreviousButton.getId()) {
|
} else if (v.getId() == playPreviousButton.getId()) {
|
||||||
onPlayPrevious();
|
onPlayPrevious();
|
||||||
|
|
|
@ -618,7 +618,7 @@ public final class PopupVideoPlayer extends Service {
|
||||||
onClose();
|
onClose();
|
||||||
break;
|
break;
|
||||||
case ACTION_PLAY_PAUSE:
|
case ACTION_PLAY_PAUSE:
|
||||||
onVideoPlayPause();
|
onPlayPause();
|
||||||
break;
|
break;
|
||||||
case ACTION_REPEAT:
|
case ACTION_REPEAT:
|
||||||
onRepeatClicked();
|
onRepeatClicked();
|
||||||
|
@ -731,7 +731,7 @@ public final class PopupVideoPlayer extends Service {
|
||||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||||
if (DEBUG) Log.d(TAG, "onSingleTapConfirmed() called with: e = [" + e + "]");
|
if (DEBUG) Log.d(TAG, "onSingleTapConfirmed() called with: e = [" + e + "]");
|
||||||
if (playerImpl == null || playerImpl.getPlayer() == null) return false;
|
if (playerImpl == null || playerImpl.getPlayer() == null) return false;
|
||||||
playerImpl.onVideoPlayPause();
|
playerImpl.onPlayPause();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -424,7 +424,7 @@ public abstract class ServicePlayerActivity extends AppCompatActivity
|
||||||
player.onPlayPrevious();
|
player.onPlayPrevious();
|
||||||
|
|
||||||
} else if (view.getId() == playPauseButton.getId()) {
|
} else if (view.getId() == playPauseButton.getId()) {
|
||||||
player.onVideoPlayPause();
|
player.onPlayPause();
|
||||||
|
|
||||||
} else if (view.getId() == forwardButton.getId()) {
|
} else if (view.getId() == forwardButton.getId()) {
|
||||||
player.onPlayNext();
|
player.onPlayNext();
|
||||||
|
|
|
@ -62,12 +62,12 @@ public class BasePlayerMediaSession implements MediaSessionCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlay() {
|
public void onPlay() {
|
||||||
if (!player.isPlaying()) player.onVideoPlayPause();
|
player.onPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (player.isPlaying()) player.onVideoPlayPause();
|
player.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue