mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
Added setting to allow restarting playback after connectivity loss behavior to be changed.
This commit is contained in:
parent
0fd8ba28bb
commit
fc5888d57e
3 changed files with 28 additions and 1 deletions
|
@ -389,6 +389,10 @@ class Settings : FragmentedStorageFileJson() {
|
|||
@FormField(R.string.restart_after_audio_focus_loss, FieldForm.DROPDOWN, R.string.restart_playback_when_gaining_audio_focus_after_a_loss, 11)
|
||||
@DropdownFieldOptionsId(R.array.restart_playback_after_loss)
|
||||
var restartPlaybackAfterLoss: Int = 1;
|
||||
|
||||
@FormField(R.string.restart_after_connectivity_loss, FieldForm.DROPDOWN, R.string.restart_playback_when_gaining_connectivity_after_a_loss, 11)
|
||||
@DropdownFieldOptionsId(R.array.restart_playback_after_loss)
|
||||
var restartPlaybackAfterConnectivityLoss: Int = 1;
|
||||
}
|
||||
|
||||
@FormField(R.string.comments, "group", R.string.comments_description, 6)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package com.futo.platformplayer.views.video
|
||||
|
||||
import android.content.Context
|
||||
import android.media.session.PlaybackState
|
||||
import android.net.Uri
|
||||
import android.util.AttributeSet
|
||||
import android.widget.RelativeLayout
|
||||
import com.futo.platformplayer.Settings
|
||||
import com.futo.platformplayer.api.media.models.chapters.IChapter
|
||||
import com.futo.platformplayer.logging.Logger
|
||||
import com.futo.platformplayer.api.media.models.streams.VideoMuxedSourceDescriptor
|
||||
|
@ -16,6 +16,7 @@ import com.futo.platformplayer.api.media.platforms.js.models.sources.JSAudioUrlR
|
|||
import com.futo.platformplayer.api.media.platforms.js.models.sources.JSHLSManifestAudioSource
|
||||
import com.futo.platformplayer.api.media.platforms.js.models.sources.JSVideoUrlRangeSource
|
||||
import com.futo.platformplayer.constructs.Event1
|
||||
import com.futo.platformplayer.receivers.MediaControlReceiver
|
||||
import com.futo.platformplayer.states.StateApp
|
||||
import com.futo.platformplayer.video.PlayerManager
|
||||
import com.google.android.exoplayer2.*
|
||||
|
@ -54,6 +55,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
private var _lastSubtitleMediaSource: MediaSource? = null;
|
||||
private var _shouldPlaybackRestartOnConnectivity: Boolean = false;
|
||||
private val _referenceObject = Object();
|
||||
private var _connectivityLossTime_ms: Long? = null
|
||||
|
||||
private var _chapters: List<IChapter>? = null;
|
||||
|
||||
|
@ -152,7 +154,25 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
|
||||
val pos = position;
|
||||
val dur = duration;
|
||||
var shouldRestartPlayback = false
|
||||
if (_shouldPlaybackRestartOnConnectivity && abs(pos - dur) > 2000) {
|
||||
if (Settings.instance.playback.restartPlaybackAfterLoss == 1) {
|
||||
val lossTime_ms = _connectivityLossTime_ms
|
||||
if (lossTime_ms != null && System.currentTimeMillis() - lossTime_ms < 1000 * 30) {
|
||||
shouldRestartPlayback = true
|
||||
}
|
||||
} else if (Settings.instance.playback.restartPlaybackAfterLoss == 2) {
|
||||
val lossTime_ms = _connectivityLossTime_ms
|
||||
if (lossTime_ms != null && System.currentTimeMillis() - lossTime_ms < 1000 * 10) {
|
||||
shouldRestartPlayback = true
|
||||
}
|
||||
} else if (Settings.instance.playback.restartPlaybackAfterLoss == 3) {
|
||||
shouldRestartPlayback = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (shouldRestartPlayback) {
|
||||
Logger.i(TAG, "Playback ended due to connection loss, resuming playback since connection is restored.");
|
||||
exoPlayer?.player?.playWhenReady = true;
|
||||
exoPlayer?.player?.prepare();
|
||||
|
@ -519,6 +539,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
PlaybackException.ERROR_CODE_IO_UNSPECIFIED -> {
|
||||
Logger.i(TAG, "IO error, set _shouldPlaybackRestartOnConnectivity=true");
|
||||
_shouldPlaybackRestartOnConnectivity = true;
|
||||
_connectivityLossTime_ms = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,6 +381,8 @@
|
|||
<string name="review_the_current_and_past_changelogs">Review the current and past changelogs</string>
|
||||
<string name="restart_after_audio_focus_loss">Restart after audio focus loss</string>
|
||||
<string name="restart_playback_when_gaining_audio_focus_after_a_loss">Restart playback when gaining audio focus after a loss</string>
|
||||
<string name="restart_after_connectivity_loss">Restart after connectivity loss</string>
|
||||
<string name="restart_playback_when_gaining_connectivity_after_a_loss">Restart playback when gaining connectivity after a loss</string>
|
||||
<string name="chapter_update_fps_title">Chapter Update FPS</string>
|
||||
<string name="chapter_update_fps_description">Change accuracy of chapter updating, higher might cost more performance</string>
|
||||
<string name="set_automatic_backup">Set Automatic Backup</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue