Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

Add selectable live rewind backend preference

David Nashashf3efa946a8f0
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
index 20eb89df..47b7ba73 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
@@ -649,9 +649,14 @@ class PlayerViewModel @Inject constructor(
viewModelScope.launch {
combine(
preferencesRepository.playerTimeshiftEnabled,
- preferencesRepository.playerTimeshiftDepthMinutes
- ) { enabled, depthMinutes ->
- TimeshiftConfig(enabled = enabled, depthMinutes = depthMinutes)
+ preferencesRepository.playerTimeshiftDepthMinutes,
+ preferencesRepository.playerTimeshiftBackend
+ ) { enabled, depthMinutes, backendPreference ->
+ TimeshiftConfig(
+ enabled = enabled,
+ depthMinutes = depthMinutes,
+ backendPreference = backendPreference
+ )
}.collect { config ->
timeshiftConfig = config
_timeshiftUiState.update { current ->
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
index 7b7e65af..e1fa7977 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
@@ -61,6 +61,7 @@ internal fun SettingsContentPane(
uiState = uiState,
viewModel = viewModel,
timeshiftDepthLabel = screenLabels.timeshiftDepthLabel,
+ timeshiftBackendLabel = screenLabels.timeshiftBackendLabel,
decoderModeLabel = screenLabels.decoderModeLabel,
playbackBufferModeLabel = screenLabels.playbackBufferModeLabel,
audioOutputPreferenceLabel = screenLabels.audioOutputPreferenceLabel,
@@ -86,6 +87,7 @@ internal fun SettingsContentPane(
lastSpeedTestSummary = screenLabels.lastSpeedTestSummary,
speedTestRecommendationLabel = screenLabels.speedTestRecommendationLabel,
onShowTimeshiftDepthDialogChange = { dialogState.showTimeshiftDepthDialog = it },
+ onShowTimeshiftBackendDialogChange = { dialogState.showTimeshiftBackendDialog = it },
onShowDecoderModeDialogChange = { dialogState.showDecoderModeDialog = it },
onShowPlaybackBufferModeDialogChange = { dialogState.showPlaybackBufferModeDialog = it },
onShowAudioOutputPreferenceDialogChange = { dialogState.showAudioOutputPreferenceDialog = it },
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
index d6f2f0eb..e2d8ae6b 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
@@ -35,6 +35,7 @@ internal fun LazyListScope.settingsPlaybackSection(
uiState: SettingsUiState,
viewModel: SettingsViewModel,
timeshiftDepthLabel: String,
+ timeshiftBackendLabel: String,
decoderModeLabel: String,
playbackBufferModeLabel: String,
audioOutputPreferenceLabel: String,
@@ -60,6 +61,7 @@ internal fun LazyListScope.settingsPlaybackSection(
lastSpeedTestSummary: String,
speedTestRecommendationLabel: String,
onShowTimeshiftDepthDialogChange: (Boolean) -> Unit,
+ onShowTimeshiftBackendDialogChange: (Boolean) -> Unit,
onShowDecoderModeDialogChange: (Boolean) -> Unit,
onShowPlaybackBufferModeDialogChange: (Boolean) -> Unit,
onShowAudioOutputPreferenceDialogChange: (Boolean) -> Unit,
@@ -264,8 +266,8 @@ internal fun LazyListScope.settingsPlaybackSection(
)
ClickableSettingsRow(
label = stringResource(R.string.settings_live_timeshift_backend),
- value = stringResource(R.string.settings_live_timeshift_backend_value),
- onClick = {}
+ value = timeshiftBackendLabel,
+ onClick = { onShowTimeshiftBackendDialogChange(true) }
)
Text(
text = stringResource(R.string.settings_live_timeshift_backend_subtitle),
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
index d0b26a34..4655a9f3 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
@@ -9,8 +9,9 @@ import com.streamvault.domain.model.AppTimeFormat
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.DecoderMode
import com.streamvault.domain.model.PlaybackBufferMode
-import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.PlayerSurfaceMode
+import com.streamvault.domain.model.TimeshiftBackendPreference
+import com.streamvault.domain.model.VodHttpProtocolMode
@Composable
internal fun SettingsPlayerPreferenceDialogs(
@@ -35,6 +36,8 @@ internal fun SettingsPlayerPreferenceDialogs(
onShowVodHttpProtocolDialogChange: (Boolean) -> Unit,
showTimeshiftDepthDialog: Boolean,
onShowTimeshiftDepthDialogChange: (Boolean) -> Unit,
+ showTimeshiftBackendDialog: Boolean,
+ onShowTimeshiftBackendDialogChange: (Boolean) -> Unit,
showDefaultStopTimerDialog: Boolean,
onShowDefaultStopTimerDialogChange: (Boolean) -> Unit,
showDefaultIdleTimerDialog: Boolean,
@@ -307,6 +310,32 @@ internal fun SettingsPlayerPreferenceDialogs(
}
}
+ if (showTimeshiftBackendDialog) {
+ val backendOptions = remember(context) {
+ listOf(
+ TimeshiftBackendPreference.AUTOMATIC to context.getString(R.string.settings_live_timeshift_backend_auto),
+ TimeshiftBackendPreference.STORAGE to context.getString(R.string.settings_live_timeshift_backend_storage),
+ TimeshiftBackendPreference.MEMORY to context.getString(R.string.settings_live_timeshift_backend_memory)
+ )
+ }
+ PremiumSelectionDialog(
+ title = stringResource(R.string.settings_select_live_timeshift_backend),
+ onDismiss = { onShowTimeshiftBackendDialogChange(false) }
+ ) {
+ backendOptions.forEachIndexed { index, option ->
+ LevelOption(
+ level = index,
+ text = option.second,
+ currentLevel = if (uiState.playerTimeshiftBackend == option.first) index else -1,
+ onSelect = {
+ viewModel.setPlayerTimeshiftBackend(option.first)
+ onShowTimeshiftBackendDialogChange(false)
+ }
+ )
+ }
+ }
+ }
+
if (showDefaultStopTimerDialog) {
PlaybackTimerPresetDialog(
title = stringResource(R.string.settings_default_stop_timer),
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
index b81cb9fc..70e0663a 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
@@ -46,6 +46,8 @@ internal fun SettingsPreferenceDialogs(
onShowVodHttpProtocolDialogChange: (Boolean) -> Unit,
showTimeshiftDepthDialog: Boolean,
onShowTimeshiftDepthDialogChange: (Boolean) -> Unit,
+ showTimeshiftBackendDialog: Boolean,
+ onShowTimeshiftBackendDialogChange: (Boolean) -> Unit,
showDefaultStopTimerDialog: Boolean,
onShowDefaultStopTimerDialogChange: (Boolean) -> Unit,
showDefaultIdleTimerDialog: Boolean,
@@ -103,6 +105,8 @@ internal fun SettingsPreferenceDialogs(
onShowVodHttpProtocolDialogChange = onShowVodHttpProtocolDialogChange,
showTimeshiftDepthDialog = showTimeshiftDepthDialog,
onShowTimeshiftDepthDialogChange = onShowTimeshiftDepthDialogChange,
+ showTimeshiftBackendDialog = showTimeshiftBackendDialog,
+ onShowTimeshiftBackendDialogChange = onShowTimeshiftBackendDialogChange,
showDefaultStopTimerDialog = showDefaultStopTimerDialog,
onShowDefaultStopTimerDialogChange = onShowDefaultStopTimerDialogChange,
showDefaultIdleTimerDialog = showDefaultIdleTimerDialog,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
index 02d755d2..3cec53dc 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
@@ -24,6 +24,7 @@ import com.streamvault.domain.model.VodVariantPreferenceMode
import com.streamvault.domain.model.PlayerSurfaceMode
import com.streamvault.domain.model.Provider
import com.streamvault.domain.model.RemoteShortcutPreferences
+import com.streamvault.domain.model.TimeshiftBackendPreference
enum class ProviderWarningAction {
EPG,
@@ -78,6 +79,7 @@ internal data class SettingsPreferenceSnapshot(
val ethernetMaxVideoHeight: Int?,
val playerTimeshiftEnabled: Boolean,
val playerTimeshiftDepthMinutes: Int,
+ val playerTimeshiftBackend: TimeshiftBackendPreference,
val defaultStopPlaybackTimerMinutes: Int,
val defaultIdleStandbyTimerMinutes: Int,
val lastSpeedTestMegabits: Double?,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
index 7a4b7488..dfa1d2eb 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
@@ -40,6 +40,7 @@ internal fun SettingsUiState.applyPreferenceSnapshot(snapshot: SettingsPreferenc
ethernetMaxVideoHeight = snapshot.ethernetMaxVideoHeight,
playerTimeshiftEnabled = snapshot.playerTimeshiftEnabled,
playerTimeshiftDepthMinutes = snapshot.playerTimeshiftDepthMinutes,
+ playerTimeshiftBackend = snapshot.playerTimeshiftBackend,
defaultStopPlaybackTimerMinutes = snapshot.defaultStopPlaybackTimerMinutes,
defaultIdleStandbyTimerMinutes = snapshot.defaultIdleStandbyTimerMinutes,
lastSpeedTest = snapshot.lastSpeedTestMegabits?.let {
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
index 74879b31..7074156a 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
@@ -35,6 +35,7 @@ internal class SettingsScreenDialogState(
private val showSurfaceModeDialogState: MutableState<Boolean>,
private val showVodHttpProtocolDialogState: MutableState<Boolean>,
private val showTimeshiftDepthDialogState: MutableState<Boolean>,
+ private val showTimeshiftBackendDialogState: MutableState<Boolean>,
private val showDefaultStopTimerDialogState: MutableState<Boolean>,
private val showDefaultIdleTimerDialogState: MutableState<Boolean>,
private val showControlsTimeoutDialogState: MutableState<Boolean>,
@@ -98,6 +99,7 @@ internal class SettingsScreenDialogState(
var showSurfaceModeDialog by showSurfaceModeDialogState
var showVodHttpProtocolDialog by showVodHttpProtocolDialogState
var showTimeshiftDepthDialog by showTimeshiftDepthDialogState
+ var showTimeshiftBackendDialog by showTimeshiftBackendDialogState
var showDefaultStopTimerDialog by showDefaultStopTimerDialogState
var showDefaultIdleTimerDialog by showDefaultIdleTimerDialogState
var showControlsTimeoutDialog by showControlsTimeoutDialogState
@@ -229,6 +231,7 @@ internal fun rememberSettingsScreenDialogState(): SettingsScreenDialogState {
val showSurfaceModeDialogState = rememberSaveable { mutableStateOf(false) }
val showVodHttpProtocolDialogState = rememberSaveable { mutableStateOf(false) }
val showTimeshiftDepthDialogState = rememberSaveable { mutableStateOf(false) }
+ val showTimeshiftBackendDialogState = rememberSaveable { mutableStateOf(false) }
val showDefaultStopTimerDialogState = rememberSaveable { mutableStateOf(false) }
val showDefaultIdleTimerDialogState = rememberSaveable { mutableStateOf(false) }
val showControlsTimeoutDialogState = rememberSaveable { mutableStateOf(false) }
@@ -301,6 +304,7 @@ internal fun rememberSettingsScreenDialogState(): SettingsScreenDialogState {
showSurfaceModeDialogState = showSurfaceModeDialogState,
showVodHttpProtocolDialogState = showVodHttpProtocolDialogState,
showTimeshiftDepthDialogState = showTimeshiftDepthDialogState,
+ showTimeshiftBackendDialogState = showTimeshiftBackendDialogState,
showDefaultStopTimerDialogState = showDefaultStopTimerDialogState,
showDefaultIdleTimerDialogState = showDefaultIdleTimerDialogState,
showControlsTimeoutDialogState = showControlsTimeoutDialogState,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
index 97b56c7f..b75f8047 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
@@ -198,6 +198,8 @@ internal fun SettingsScreenDialogs(
onShowVodHttpProtocolDialogChange = { dialogState.showVodHttpProtocolDialog = it },
showTimeshiftDepthDialog = dialogState.showTimeshiftDepthDialog,
onShowTimeshiftDepthDialogChange = { dialogState.showTimeshiftDepthDialog = it },
+ showTimeshiftBackendDialog = dialogState.showTimeshiftBackendDialog,
+ onShowTimeshiftBackendDialogChange = { dialogState.showTimeshiftBackendDialog = it },
showDefaultStopTimerDialog = dialogState.showDefaultStopTimerDialog,
onShowDefaultStopTimerDialogChange = { dialogState.showDefaultStopTimerDialog = it },
showDefaultIdleTimerDialog = dialogState.showDefaultIdleTimerDialog,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
index dc88982d..78b4156d 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
@@ -15,6 +15,7 @@ import com.streamvault.domain.model.AppTimeFormat
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.LiveStreamFormatMode
import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.model.VodHttpProtocolMode
internal data class SettingsScreenLabels(
@@ -43,6 +44,7 @@ internal data class SettingsScreenLabels(
val wifiQualityLabel: String,
val ethernetQualityLabel: String,
val timeshiftDepthLabel: String,
+ val timeshiftBackendLabel: String,
val defaultStopTimerLabel: String,
val defaultIdleTimerLabel: String,
val lastSpeedTestLabel: String,
@@ -135,6 +137,9 @@ internal fun rememberSettingsScreenLabels(
val timeshiftDepthLabel = remember(uiState.playerTimeshiftDepthMinutes, context) {
formatTimeshiftDepthLabel(uiState.playerTimeshiftDepthMinutes, context)
}
+ val timeshiftBackendLabel = remember(uiState.playerTimeshiftBackend, context) {
+ formatTimeshiftBackendPreferenceLabel(uiState.playerTimeshiftBackend, context)
+ }
val defaultStopTimerLabel = remember(uiState.defaultStopPlaybackTimerMinutes, context) {
formatPlaybackTimerMinutesLabel(uiState.defaultStopPlaybackTimerMinutes, context)
}
@@ -204,6 +209,7 @@ internal fun rememberSettingsScreenLabels(
wifiQualityLabel = wifiQualityLabel,
ethernetQualityLabel = ethernetQualityLabel,
timeshiftDepthLabel = timeshiftDepthLabel,
+ timeshiftBackendLabel = timeshiftBackendLabel,
defaultStopTimerLabel = defaultStopTimerLabel,
defaultIdleTimerLabel = defaultIdleTimerLabel,
lastSpeedTestLabel = lastSpeedTestLabel,
@@ -305,6 +311,15 @@ internal fun formatPlaybackBufferModeLabel(
PlaybackBufferMode.LARGE -> context.getString(R.string.settings_live_buffer_large)
}
+internal fun formatTimeshiftBackendPreferenceLabel(
+ preference: TimeshiftBackendPreference,
+ context: Context
+): String = when (preference) {
+ TimeshiftBackendPreference.AUTOMATIC -> context.getString(R.string.settings_live_timeshift_backend_auto)
+ TimeshiftBackendPreference.STORAGE -> context.getString(R.string.settings_live_timeshift_backend_storage)
+ TimeshiftBackendPreference.MEMORY -> context.getString(R.string.settings_live_timeshift_backend_memory)
+}
+
internal fun formatLiveStreamFormatModeLabel(mode: LiveStreamFormatMode): String = when (mode) {
LiveStreamFormatMode.AUTO -> "Auto"
LiveStreamFormatMode.HLS -> "HLS (m3u8)"
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
index ba315195..aa597d10 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
@@ -18,6 +18,7 @@ import com.streamvault.domain.model.GroupedChannelLabelMode
import com.streamvault.domain.model.LiveChannelGroupingMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.VodVariantPreferenceMode
@@ -76,6 +77,7 @@ internal fun observeSettingsPreferenceSnapshot(
ethernetMaxVideoHeight = null,
playerTimeshiftEnabled = false,
playerTimeshiftDepthMinutes = 30,
+ playerTimeshiftBackend = TimeshiftBackendPreference.AUTOMATIC,
defaultStopPlaybackTimerMinutes = 0,
defaultIdleStandbyTimerMinutes = 0,
lastSpeedTestMegabits = null,
@@ -183,6 +185,8 @@ internal fun observeSettingsPreferenceSnapshot(
snapshot.copy(playerTimeshiftEnabled = enabled)
}.combine(preferencesRepository.playerTimeshiftDepthMinutes) { snapshot, depthMinutes ->
snapshot.copy(playerTimeshiftDepthMinutes = depthMinutes)
+ }.combine(preferencesRepository.playerTimeshiftBackend) { snapshot, backend ->
+ snapshot.copy(playerTimeshiftBackend = backend)
}.combine(preferencesRepository.defaultStopPlaybackTimerMinutes) { snapshot, minutes ->
snapshot.copy(defaultStopPlaybackTimerMinutes = minutes)
}.combine(preferencesRepository.defaultIdleStandbyTimerMinutes) { snapshot, minutes ->
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
index d3cca519..13f1e12f 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
@@ -34,6 +34,7 @@ import com.streamvault.domain.model.Provider
import com.streamvault.domain.model.RecordingItem
import com.streamvault.domain.model.RecordingStorageState
import com.streamvault.domain.model.RemoteShortcutPreferences
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.model.VodVariantPreferenceMode
data class CrashReportUiModel(
@@ -97,6 +98,7 @@ data class SettingsUiState(
val ethernetMaxVideoHeight: Int? = null,
val playerTimeshiftEnabled: Boolean = false,
val playerTimeshiftDepthMinutes: Int = 30,
+ val playerTimeshiftBackend: TimeshiftBackendPreference = TimeshiftBackendPreference.AUTOMATIC,
val defaultStopPlaybackTimerMinutes: Int = 0,
val defaultIdleStandbyTimerMinutes: Int = 0,
val lastSpeedTest: InternetSpeedTestUiModel? = null,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
index 2a096506..3eb28f22 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
@@ -62,6 +62,7 @@ import com.streamvault.domain.model.RemoteShortcutProfile
import com.streamvault.domain.model.RemoteShortcutSelection
import com.streamvault.domain.model.EpgResolutionSummary
import com.streamvault.domain.model.Result
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.model.VirtualCategoryIds
import com.streamvault.domain.model.VodVariantPreferenceMode
import com.streamvault.domain.usecase.ExportBackup
@@ -763,6 +764,12 @@ class SettingsViewModel @Inject constructor(
}
}
+ fun setPlayerTimeshiftBackend(preference: TimeshiftBackendPreference) {
+ viewModelScope.launch {
+ preferencesRepository.setPlayerTimeshiftBackend(preference)
+ }
+ }
+
fun setDefaultStopPlaybackTimerMinutes(minutes: Int) {
viewModelScope.launch {
preferencesRepository.setDefaultStopPlaybackTimerMinutes(minutes)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 50d6bcb6..d1129420 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -457,8 +457,12 @@
<string name="settings_live_timeshift_depth">Local Live Rewind Depth</string>
<string name="settings_live_timeshift_backend">Live Rewind Backend</string>
<string name="settings_live_timeshift_backend_value">Automatic</string>
- <string name="settings_live_timeshift_backend_subtitle">Prefers app storage for the local ring buffer and falls back to bounded memory when storage is unavailable.</string>
+ <string name="settings_live_timeshift_backend_subtitle">Choose whether local live rewind buffers to app storage or bounded memory. Automatic prefers storage and falls back to memory when the storage backend is constrained.</string>
+ <string name="settings_live_timeshift_backend_auto">Automatic</string>
+ <string name="settings_live_timeshift_backend_storage">Storage</string>
+ <string name="settings_live_timeshift_backend_memory">Memory</string>
<string name="settings_select_live_timeshift_depth">Select Local Live Rewind Depth</string>
+ <string name="settings_select_live_timeshift_backend">Select Live Rewind Backend</string>
<string name="settings_live_timeshift_depth_15">15 minutes</string>
<string name="settings_live_timeshift_depth_30">30 minutes</string>
<string name="settings_live_timeshift_depth_60">60 minutes</string>
diff --git a/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsTimeshiftBackendPreferenceTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsTimeshiftBackendPreferenceTest.kt
new file mode 100644
index 00000000..ca0321a1
--- /dev/null
+++ b/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsTimeshiftBackendPreferenceTest.kt
@@ -0,0 +1,36 @@
+package com.streamvault.app.ui.screens.settings
+
+import android.content.Context
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.app.R
+import com.streamvault.domain.model.TimeshiftBackendPreference
+import org.junit.Test
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.whenever
+
+class SettingsTimeshiftBackendPreferenceTest {
+
+ @Test
+ fun `settings ui state defaults timeshift backend to automatic`() {
+ assertThat(SettingsUiState().playerTimeshiftBackend)
+ .isEqualTo(TimeshiftBackendPreference.AUTOMATIC)
+ }
+
+ @Test
+ fun `formatTimeshiftBackendPreferenceLabel maps modes to settings labels`() {
+ val context: Context = mock()
+ whenever(context.getString(R.string.settings_live_timeshift_backend_auto)).thenReturn("Automatic")
+ whenever(context.getString(R.string.settings_live_timeshift_backend_storage)).thenReturn("Storage")
+ whenever(context.getString(R.string.settings_live_timeshift_backend_memory)).thenReturn("Memory")
+
+ assertThat(
+ formatTimeshiftBackendPreferenceLabel(TimeshiftBackendPreference.AUTOMATIC, context)
+ ).isEqualTo("Automatic")
+ assertThat(
+ formatTimeshiftBackendPreferenceLabel(TimeshiftBackendPreference.STORAGE, context)
+ ).isEqualTo("Storage")
+ assertThat(
+ formatTimeshiftBackendPreferenceLabel(TimeshiftBackendPreference.MEMORY, context)
+ ).isEqualTo("Memory")
+ }
+}
diff --git a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
index 3c90b294..ae6032c7 100644
--- a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
+++ b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
@@ -42,6 +42,7 @@ import com.streamvault.domain.model.RemoteShortcutPreferences
import com.streamvault.domain.model.RemoteShortcutProfile
import com.streamvault.domain.model.RemoteShortcutSelection
import com.streamvault.domain.model.SearchHistoryScope
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.manager.ParentalPinVerifier
import com.streamvault.domain.manager.ParentalControlSessionState
import com.streamvault.domain.manager.ParentalControlSessionStore
@@ -76,6 +77,10 @@ internal fun parsePlaybackBufferModePreference(saved: String?): PlaybackBufferMo
saved?.let { value -> PlaybackBufferMode.entries.firstOrNull { it.name == value } }
?: PlaybackBufferMode.AUTO
+internal fun parseTimeshiftBackendPreference(saved: String?): TimeshiftBackendPreference =
+ saved?.let { value -> TimeshiftBackendPreference.entries.firstOrNull { it.name == value } }
+ ?: TimeshiftBackendPreference.AUTOMATIC
+
@Singleton
class PreferencesRepository @Inject constructor(
@ApplicationContext private val context: Context,
@@ -173,6 +178,7 @@ class PreferencesRepository @Inject constructor(
val PLAYER_ETHERNET_MAX_VIDEO_HEIGHT = intPreferencesKey("player_ethernet_max_video_height")
val PLAYER_TIMESHIFT_ENABLED = booleanPreferencesKey("player_timeshift_enabled")
val PLAYER_TIMESHIFT_DEPTH_MINUTES = intPreferencesKey("player_timeshift_depth_minutes")
+ val PLAYER_TIMESHIFT_BACKEND = stringPreferencesKey("player_timeshift_backend")
val DEFAULT_STOP_PLAYBACK_TIMER_MINUTES = intPreferencesKey("default_stop_playback_timer_minutes")
val DEFAULT_IDLE_STANDBY_TIMER_MINUTES = intPreferencesKey("default_idle_standby_timer_minutes")
val LAST_SPEED_TEST_MEGABITS = stringPreferencesKey("last_speed_test_megabits")
@@ -441,6 +447,10 @@ class PreferencesRepository @Inject constructor(
}
}
+ val playerTimeshiftBackend: Flow<TimeshiftBackendPreference> = context.dataStore.data.map { preferences ->
+ parseTimeshiftBackendPreference(preferences[PreferencesKeys.PLAYER_TIMESHIFT_BACKEND])
+ }
+
val defaultStopPlaybackTimerMinutes: Flow<Int> = context.dataStore.data.map { preferences ->
sanitizePlaybackTimerMinutes(preferences[PreferencesKeys.DEFAULT_STOP_PLAYBACK_TIMER_MINUTES] ?: 0)
}
@@ -1061,6 +1071,12 @@ class PreferencesRepository @Inject constructor(
}
}
+ suspend fun setPlayerTimeshiftBackend(preference: TimeshiftBackendPreference) {
+ context.dataStore.edit { preferences ->
+ preferences[PreferencesKeys.PLAYER_TIMESHIFT_BACKEND] = preference.name
+ }
+ }
+
suspend fun setDefaultStopPlaybackTimerMinutes(minutes: Int) {
context.dataStore.edit { preferences ->
preferences[PreferencesKeys.DEFAULT_STOP_PLAYBACK_TIMER_MINUTES] = sanitizePlaybackTimerMinutes(minutes)
diff --git a/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryTimeshiftBackendPreferenceTest.kt b/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryTimeshiftBackendPreferenceTest.kt
new file mode 100644
index 00000000..0fa96984
--- /dev/null
+++ b/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryTimeshiftBackendPreferenceTest.kt
@@ -0,0 +1,28 @@
+package com.streamvault.data.preferences
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.TimeshiftBackendPreference
+import org.junit.Test
+
+class PreferencesRepositoryTimeshiftBackendPreferenceTest {
+
+ @Test
+ fun `parseTimeshiftBackendPreference defaults to automatic when missing`() {
+ assertThat(parseTimeshiftBackendPreference(null))
+ .isEqualTo(TimeshiftBackendPreference.AUTOMATIC)
+ }
+
+ @Test
+ fun `parseTimeshiftBackendPreference defaults to automatic when saved value is invalid`() {
+ assertThat(parseTimeshiftBackendPreference("RAMDISK"))
+ .isEqualTo(TimeshiftBackendPreference.AUTOMATIC)
+ }
+
+ @Test
+ fun `parseTimeshiftBackendPreference restores saved mode`() {
+ assertThat(parseTimeshiftBackendPreference("STORAGE"))
+ .isEqualTo(TimeshiftBackendPreference.STORAGE)
+ assertThat(parseTimeshiftBackendPreference("MEMORY"))
+ .isEqualTo(TimeshiftBackendPreference.MEMORY)
+ }
+}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 1e7bdf73..0f2f84d7 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -2,6 +2,12 @@
All notable product changes are recorded in this document.
+## [1.0.16] - 2026-06-19
+
+### Added
+
+- Added a selectable Local Live Rewind backend preference with `Automatic`, `Storage`, and `Memory` modes, so users can control whether live rewind prefers app storage or stays memory-backed when troubleshooting storage-wear or device-compatibility concerns.
+
## [1.0.15] - 2026-06-13
### Fixed
diff --git a/domain/src/main/java/com/streamvault/domain/model/TimeshiftBackendPreference.kt b/domain/src/main/java/com/streamvault/domain/model/TimeshiftBackendPreference.kt
new file mode 100644
index 00000000..222a755a
--- /dev/null
+++ b/domain/src/main/java/com/streamvault/domain/model/TimeshiftBackendPreference.kt
@@ -0,0 +1,7 @@
+package com.streamvault.domain.model
+
+enum class TimeshiftBackendPreference {
+ AUTOMATIC,
+ STORAGE,
+ MEMORY
+}
diff --git a/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftManager.kt b/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftManager.kt
index dd0e8daa..afb44fae 100644
--- a/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftManager.kt
+++ b/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftManager.kt
@@ -3,6 +3,7 @@ package com.streamvault.player.timeshift
import android.content.ComponentCallbacks2
import android.content.Context
import android.content.res.Configuration
+import com.streamvault.domain.model.TimeshiftBackendPreference
import com.streamvault.domain.model.StreamInfo
import com.streamvault.domain.model.StreamType
import com.streamvault.player.playback.applyUnsafeTlsBypass
@@ -133,14 +134,39 @@ internal class DefaultLiveTimeshiftManager @Inject constructor(
)
return@withLock
}
- val backend = chooseBackend()
- val sessionDir = File(context.cacheDir, "timeshift/${channelKey.hashCode()}-${System.currentTimeMillis()}").apply { mkdirs() }
+ val sessionRoot = context.cacheDir?.takeIf {
+ (it.exists() || it.mkdirs()) && it.canWrite()
+ } ?: run {
+ _state.value = LiveTimeshiftState(
+ enabled = true,
+ supported = false,
+ status = LiveTimeshiftStatus.FAILED,
+ message = "App storage is unavailable for local live rewind."
+ )
+ return@withLock
+ }
+ val sessionDir = File(
+ sessionRoot,
+ "timeshift/${channelKey.hashCode()}-${System.currentTimeMillis()}"
+ ).apply { mkdirs() }
// Crash-safe cleanup: delete all stale timeshift dirs from previous crashes/exits.
diskManager.cleanupStaleDirectories(activeSessionDir = sessionDir)
+ val backend = chooseBackend(config)
+ if (backend == null) {
+ sessionDir.deleteRecursively()
+ _state.value = LiveTimeshiftState(
+ enabled = true,
+ supported = false,
+ status = LiveTimeshiftStatus.FAILED,
+ message = backendUnavailableMessage(config.backendPreference)
+ )
+ return@withLock
+ }
+
// Global budget guard: evict LRU stale dirs if needed, then hard-fail if still over.
- if (!diskManager.isWithinBudget()) {
+ if (backend == LiveTimeshiftBackend.DISK && !diskManager.isWithinBudget()) {
diskManager.evictLruUntilWithinBudget(activeSessionDir = sessionDir)
if (!diskManager.isWithinBudget()) {
sessionDir.deleteRecursively()
@@ -239,13 +265,37 @@ internal class DefaultLiveTimeshiftManager @Inject constructor(
activeSession = null
}
- private fun chooseBackend(): LiveTimeshiftBackend {
+ private fun chooseBackend(config: TimeshiftConfig): LiveTimeshiftBackend? =
+ resolveLiveTimeshiftBackend(
+ preference = config.backendPreference,
+ snapshotStorageAvailable = isSnapshotStorageAvailableForTimeshift(),
+ diskStorageAvailable = isDiskStorageAvailableForTimeshift()
+ )
+
+ private fun backendUnavailableMessage(preference: TimeshiftBackendPreference): String = when (preference) {
+ TimeshiftBackendPreference.STORAGE ->
+ "The storage backend is unavailable for local live rewind right now."
+
+ TimeshiftBackendPreference.AUTOMATIC,
+ TimeshiftBackendPreference.MEMORY ->
+ "App storage is unavailable for local live rewind."
+ }
+
+ private fun isSnapshotStorageAvailableForTimeshift(): Boolean {
+ return try {
+ context.cacheDir?.takeIf { (it.exists() || it.mkdirs()) && it.canWrite() } != null
+ } catch (_: Throwable) {
+ false
+ }
+ }
+
+ private fun isDiskStorageAvailableForTimeshift(): Boolean {
+ if (!isSnapshotStorageAvailableForTimeshift()) return false
return try {
- context.cacheDir?.takeIf { (it.exists() || it.mkdirs()) && it.canWrite() }
- ?.let { LiveTimeshiftBackend.DISK }
- ?: LiveTimeshiftBackend.MEMORY
+ context.cacheDir.usableSpace >= MIN_FREE_DISK_BYTES &&
+ diskManager.isWithinBudget()
} catch (_: Throwable) {
- LiveTimeshiftBackend.MEMORY
+ false
}
}
@@ -558,7 +608,7 @@ internal class DefaultLiveTimeshiftManager @Inject constructor(
currentCoroutineContext().ensureActive()
if (remoteSegment.mediaSequence <= lastProcessedSequence) return@forEach
lastProcessedSequence = remoteSegment.mediaSequence
- checkDiskAndBudget()
+ if (backend == LiveTimeshiftBackend.DISK) checkDiskAndBudget()
val retained = retainHlsSegment(remoteSegment)
val windowDuration = segmentMutex.withLock {
runningSegmentDurationMs += retained.durationMs
@@ -796,7 +846,7 @@ internal class DefaultLiveTimeshiftManager @Inject constructor(
// Download init segment once (identified by URL; seenSegments deduplicates it).
parsed.initSegmentUrl?.let { initUrl ->
if (seenSegments.add("__init__:$initUrl")) {
- checkDiskAndBudget()
+ if (backend == LiveTimeshiftBackend.DISK) checkDiskAndBudget()
val retained = retainSegment(RemoteHlsSegment(initUrl, 0L), isInit = true)
segmentMutex.withLock { segments += retained }
}
@@ -805,7 +855,7 @@ internal class DefaultLiveTimeshiftManager @Inject constructor(
parsed.mediaSegments.forEach { remote ->
currentCoroutineContext().ensureActive()
if (!seenSegments.add(remote.uri)) return@forEach
- checkDiskAndBudget()
+ if (backend == LiveTimeshiftBackend.DISK) checkDiskAndBudget()
val retained = retainSegment(remote, isInit = false)
val windowDuration = segmentMutex.withLock {
runningSegmentDurationMs += retained.durationMs
diff --git a/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftModels.kt b/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftModels.kt
index a839f881..01af2bcb 100644
--- a/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftModels.kt
+++ b/player/src/main/java/com/streamvault/player/timeshift/LiveTimeshiftModels.kt
@@ -1,8 +1,11 @@
package com.streamvault.player.timeshift
+import com.streamvault.domain.model.TimeshiftBackendPreference
+
data class TimeshiftConfig(
val enabled: Boolean = false,
- val depthMinutes: Int = 30
+ val depthMinutes: Int = 30,
+ val backendPreference: TimeshiftBackendPreference = TimeshiftBackendPreference.AUTOMATIC
) {
val depthMs: Long = depthMinutes.coerceIn(15, 60) * 60_000L
@@ -23,6 +26,24 @@ enum class LiveTimeshiftBackend {
MEMORY
}
+internal fun resolveLiveTimeshiftBackend(
+ preference: TimeshiftBackendPreference,
+ snapshotStorageAvailable: Boolean,
+ diskStorageAvailable: Boolean
+): LiveTimeshiftBackend? {
+ if (!snapshotStorageAvailable) return null
+
+ return when (preference) {
+ TimeshiftBackendPreference.AUTOMATIC ->
+ if (diskStorageAvailable) LiveTimeshiftBackend.DISK else LiveTimeshiftBackend.MEMORY
+
+ TimeshiftBackendPreference.STORAGE ->
+ LiveTimeshiftBackend.DISK.takeIf { diskStorageAvailable }
+
+ TimeshiftBackendPreference.MEMORY -> LiveTimeshiftBackend.MEMORY
+ }
+}
+
enum class LiveTimeshiftStatus {
DISABLED,
UNSUPPORTED,
diff --git a/player/src/test/java/com/streamvault/player/timeshift/LiveTimeshiftBackendSelectionTest.kt b/player/src/test/java/com/streamvault/player/timeshift/LiveTimeshiftBackendSelectionTest.kt
new file mode 100644
index 00000000..9f43b658
--- /dev/null
+++ b/player/src/test/java/com/streamvault/player/timeshift/LiveTimeshiftBackendSelectionTest.kt
@@ -0,0 +1,77 @@
+package com.streamvault.player.timeshift
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.TimeshiftBackendPreference
+import org.junit.Test
+
+class LiveTimeshiftBackendSelectionTest {
+
+ @Test
+ fun `automatic prefers disk when storage is available`() {
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.AUTOMATIC,
+ snapshotStorageAvailable = true,
+ diskStorageAvailable = true
+ )
+ ).isEqualTo(LiveTimeshiftBackend.DISK)
+ }
+
+ @Test
+ fun `automatic falls back to memory when disk capture is unavailable but snapshots can still be written`() {
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.AUTOMATIC,
+ snapshotStorageAvailable = true,
+ diskStorageAvailable = false
+ )
+ ).isEqualTo(LiveTimeshiftBackend.MEMORY)
+ }
+
+ @Test
+ fun `all backends return null when snapshot storage is unavailable`() {
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.AUTOMATIC,
+ snapshotStorageAvailable = false,
+ diskStorageAvailable = false
+ )
+ ).isNull()
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.STORAGE,
+ snapshotStorageAvailable = false,
+ diskStorageAvailable = false
+ )
+ ).isNull()
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.MEMORY,
+ snapshotStorageAvailable = false,
+ diskStorageAvailable = false
+ )
+ ).isNull()
+ }
+
+ @Test
+ fun `storage returns null when disk capture is unavailable`() {
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.STORAGE,
+ snapshotStorageAvailable = true,
+ diskStorageAvailable = false
+ )
+ ).isNull()
+ }
+
+ @Test
+ fun `memory ignores disk capture availability when snapshots can still be written`() {
+ assertThat(
+ resolveLiveTimeshiftBackend(
+ preference = TimeshiftBackendPreference.MEMORY,
+ snapshotStorageAvailable = true,
+ diskStorageAvailable = false
+ )
+ ).isEqualTo(LiveTimeshiftBackend.MEMORY)
+ }
+}