mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Automatic playback continuation should only happen when it was not paused or stopped.
This commit is contained in:
parent
0ab52e8f4d
commit
189d855c3f
2 changed files with 21 additions and 5 deletions
|
@ -55,6 +55,7 @@ class MediaPlaybackService : Service() {
|
|||
private var _hasFocus: Boolean = false;
|
||||
private var _focusRequest: AudioFocusRequest? = null;
|
||||
private var _audioFocusLossTime_ms: Long? = null
|
||||
private var _playbackState = PlaybackStateCompat.STATE_NONE;
|
||||
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||
Logger.v(TAG, "onStartCommand");
|
||||
|
@ -306,10 +307,8 @@ class MediaPlaybackService : Service() {
|
|||
Logger.i(TAG, "Updating notification bitmap=${if (bitmap != null) "yes" else "no."} channelId=${channel.id} icon=${icon} video=${video?.name ?: ""} playWhenReady=${playWhenReady} session.sessionToken=${session.sessionToken}");
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
// For API 29 and above
|
||||
startForeground(MEDIA_NOTIF_ID, notif, ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK);
|
||||
} else {
|
||||
// For API 28 and below
|
||||
startForeground(MEDIA_NOTIF_ID, notif);
|
||||
}
|
||||
|
||||
|
@ -332,6 +331,8 @@ class MediaPlaybackService : Service() {
|
|||
|
||||
if(_focusRequest == null)
|
||||
setAudioFocus();
|
||||
|
||||
_playbackState = state;
|
||||
}
|
||||
|
||||
//TODO: (TBD) This code probably more fitting inside FutoVideoPlayer, as this service is generally only used for global events
|
||||
|
@ -379,14 +380,26 @@ class MediaPlaybackService : Service() {
|
|||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
|
||||
MediaControlReceiver.onPauseReceived.emit();
|
||||
_audioFocusLossTime_ms = System.currentTimeMillis()
|
||||
if (_playbackState != PlaybackStateCompat.STATE_PAUSED &&
|
||||
_playbackState != PlaybackStateCompat.STATE_STOPPED &&
|
||||
_playbackState != PlaybackStateCompat.STATE_NONE &&
|
||||
_playbackState != PlaybackStateCompat.STATE_ERROR) {
|
||||
_audioFocusLossTime_ms = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
Log.i(TAG, "Audio focus transient loss");
|
||||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK -> {
|
||||
Log.i(TAG, "Audio focus transient loss, can duck");
|
||||
}
|
||||
AudioManager.AUDIOFOCUS_LOSS -> {
|
||||
_audioFocusLossTime_ms = System.currentTimeMillis()
|
||||
if (_playbackState != PlaybackStateCompat.STATE_PAUSED &&
|
||||
_playbackState != PlaybackStateCompat.STATE_STOPPED &&
|
||||
_playbackState != PlaybackStateCompat.STATE_NONE &&
|
||||
_playbackState != PlaybackStateCompat.STATE_ERROR) {
|
||||
_audioFocusLossTime_ms = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
_hasFocus = false;
|
||||
MediaControlReceiver.onPauseReceived.emit();
|
||||
Log.i(TAG, "Audio focus lost");
|
||||
|
|
|
@ -573,7 +573,10 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
//PlaybackException.ERROR_CODE_IO_READ_POSITION_OUT_OF_RANGE,
|
||||
PlaybackException.ERROR_CODE_IO_UNSPECIFIED -> {
|
||||
_shouldPlaybackRestartOnConnectivity = true;
|
||||
_connectivityLossTime_ms = System.currentTimeMillis()
|
||||
if (playing) {
|
||||
_connectivityLossTime_ms = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
Logger.i(TAG, "IO error, set _shouldPlaybackRestartOnConnectivity=true _connectivityLossTime_ms=$_connectivityLossTime_ms");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue