diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 241cf4a3..b8460066 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -3,7 +3,7 @@ plugins { id("org.jetbrains.kotlin.plugin.compose") } /** The release's build number: versionCode is this x 10 plus the edition's channel. */ -val ORBIT_BUILD = 53 +val ORBIT_BUILD = 54 android { namespace = "tv.orbit.classic" compileSdk = 36 diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index f97e1698..c60af90c 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -477,6 +477,19 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea delay(60 * 60_000L) } } + // Files noted as unplayable only because the connection failed (before 1.0 RC3-12) are given another go, once. + LaunchedEffect(session) { + val active = session ?: return@LaunchedEffect + withContext(Dispatchers.IO) { runCatching { + val log = scheduleStore.unplayable() + val lost = log.all().filterValues { it.optString("reason") == unplayableReason("IO_NETWORK_CONNECTION_FAILED") }.keys + if (lost.isNotEmpty()) { + scheduleStore.saveFailed(active.accountId, scheduleStore.loadFailed(active.accountId) - lost) + lost.forEach(log::remove) + android.util.Log.i("OrbitSchedule", "unplayable cleared=${lost.size} reason=connection") + } + } } + } // The library read now, when asked for from adb ([CatalogueNow]); off the main thread, one at a time. LaunchedEffect(session) { val active = session ?: return@LaunchedEffect diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt index 6cacfe87..80754186 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt @@ -37,6 +37,13 @@ import kotlinx.coroutines.withContext /** A decoder fault normally repeats on the same file, so one more try is enough. */ private const val MAX_PLAYER_RETRIES = 1 +internal const val CONNECTION_RETRY_MS = 15_000L +internal const val CONNECTION_LOST = "The connection to your server dropped. Orbit tries again every 15 seconds and picks the programme up where it is now." + +/** A player error that's the connection's, not the file's: the network failing or timing out. */ +internal fun isConnectionError(code: Int) = code == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED || + code == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT || code == PlaybackException.ERROR_CODE_TIMEOUT || + code == PlaybackException.ERROR_CODE_IO_UNSPECIFIED /** * The box's audio clock can go wrong deep into a long film (seen 3 November on Godzilla's TrueHD passthrough, about @@ -95,6 +102,9 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl fun showInfo() { infoVisible = true; lastInteraction = SystemClock.elapsedRealtime() } var handedBack by remember { mutableStateOf(false) } var playerRetries by remember { mutableIntStateOf(0) } + // The connection dropping isn't the programme's fault (16 November 2026: The Lost Boys was marked unplayable when the + // living room box's Wi-Fi failed): say so, keep trying, and never note the file as one that won't play. + var connectionWaits by remember { mutableIntStateOf(0) } var audioRetries by remember { mutableIntStateOf(0) } var audioClockResets by remember { mutableIntStateOf(0) } var audioChosen by remember { mutableStateOf(false) } @@ -195,6 +205,14 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl player.prepare() } } + LaunchedEffect(connectionWaits) { + if (connectionWaits > 0 && scheduled != null) { + delay(CONNECTION_RETRY_MS) + failure = null + player.seekTo(scheduled.programme.offsetAt(scheduled.nowMs())) + player.prepare() + } + } LaunchedEffect(numberEntry) { if (numberEntry != null) { delay(10_000); numberEntry = null; numberProblem = null } } // Closes by itself, so a stray press doesn't leave it over the programme. LaunchedEffect(trackMenu, trackCursor) { if (trackMenu != null) { delay(10_000); trackMenu = null } } @@ -245,6 +263,12 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl audioRetries++ return } + if (scheduled != null && isConnectionError(error.errorCode)) { + failure = if (tvOnline(context)) CONNECTION_LOST else TV_OFFLINE + ready = false + connectionWaits++ + return + } // A decoder can also be taken away by a quick channel change, so a channel tries once more before giving up. if (scheduled != null && playerRetries < MAX_PLAYER_RETRIES) { ready = false diff --git a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt index 66cd1c78..bb89bf82 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -119,6 +119,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC neighbours.forEach { TuneAhead.warm(session, it) } } val prepareMutex = remember(channel) { Mutex() } + val tuneContext = androidx.compose.ui.platform.LocalContext.current val handedNow = handed?.takeIf { it.available && it.channelNumber == channel.number } var prepared by remember(channel) { mutableStateOf(handedNow?.plan) } var preparedSlot by remember(channel) { mutableStateOf(handedNow?.startMs) } @@ -131,7 +132,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC // Waiting on a slow server (1.0 RC3): after a few seconds the tuning screen says so; when it doesn't answer at all, Orbit // tries again every 30 seconds by itself. var serverRetry by remember(channel) { mutableIntStateOf(0) } - LaunchedEffect(serverRetry) { if (serverRetry > 0) { delay(30_000); if (problem == SERVER_NOT_ANSWERING) { problem = null; retryAttempt++ } } } + LaunchedEffect(serverRetry) { if (serverRetry > 0) { delay(30_000); if (problem == SERVER_NOT_ANSWERING || problem == TV_OFFLINE) { problem = null; retryAttempt++ } } } var waitingOnServer by remember(channel, current.startMs) { mutableStateOf(false) } LaunchedEffect(channel, current.startMs, retryAttempt) { waitingOnServer = false; delay(8_000); waitingOnServer = true } // Kids on a channel during a grown-up takeover: it's asleep, and nothing of it is opened. @@ -167,7 +168,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } catch (cancelled: CancellationException) { throw cancelled } // The server not answering at all (13 November 2026: Emby froze for six minutes during its scan) isn't this programme's // fault: say so plainly, and try again by itself every 30 seconds rather than give the slot up. - catch (failure: ServerNotAnswering) { problem = SERVER_NOT_ANSWERING; serverRetry++ } + catch (failure: ServerNotAnswering) { problem = if (tvOnline(tuneContext)) SERVER_NOT_ANSWERING else TV_OFFLINE; serverRetry++ } catch (failure: EmbyCheckException) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else failure.message } catch (_: Exception) { problem = if (channel is ScheduledChannel) "This programme isn't available right now. Orbit moves on at ${clock(current.endMs)}." else "This scheduled programme could not be opened. Return to the guide and try again." } } @@ -284,7 +285,15 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } } } -internal const val SERVER_NOT_ANSWERING = "Your server isn't answering right now. Orbit tries again every 30 seconds; nothing is wrong with this TV." +internal const val SERVER_NOT_ANSWERING = "Orbit can't reach your server right now. It tries again every 30 seconds. If other apps on this TV are slow too, it's this TV's connection." +/** When the TV itself has no working connection (16 November 2026: the living room box's Wi-Fi dropped, and Orbit blamed the server). */ +internal const val TV_OFFLINE = "This TV has lost its internet connection. Orbit tries again every 30 seconds and carries on once it's back." + +/** Whether this TV has a connection Android has checked reaches the internet. */ +internal fun tvOnline(context: android.content.Context): Boolean = runCatching { + val cm = context.getSystemService(android.net.ConnectivityManager::class.java) + cm.getNetworkCapabilities(cm.activeNetwork)?.hasCapability(android.net.NetworkCapabilities.NET_CAPABILITY_VALIDATED) == true +}.getOrDefault(true) @Composable internal fun ClassicTuningNumber(number: Int, modifier: Modifier = Modifier) { diff --git a/android/app/src/test/java/tv/orbit/classic/ConnectionLostTest.kt b/android/app/src/test/java/tv/orbit/classic/ConnectionLostTest.kt new file mode 100644 index 00000000..2e0d676c --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/ConnectionLostTest.kt @@ -0,0 +1,28 @@ +package tv.orbit.classic + +import androidx.media3.common.PlaybackException +import org.junit.Assert.* +import org.junit.Test + +/** 16 November 2026: the living room box's Wi-Fi dropped mid-film; Orbit marked The Lost Boys unplayable and blamed the server. */ +class ConnectionLostTest { + @Test fun theNetworkFailingIsntTheFilesFault() { + assertTrue(isConnectionError(PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED)) + assertTrue(isConnectionError(PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_TIMEOUT)) + assertTrue(isConnectionError(PlaybackException.ERROR_CODE_TIMEOUT)) + // A file that can't be read or decoded is still the file's. + assertFalse(isConnectionError(PlaybackException.ERROR_CODE_PARSING_CONTAINER_MALFORMED)) + assertFalse(isConnectionError(PlaybackException.ERROR_CODE_DECODER_INIT_FAILED)) + assertFalse(isConnectionError(PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS)) + } + + @Test fun theOldConnectionNotesAreRecognised() { + // What earlier builds wrote for any IO error; those entries are given another go. + assertEquals("The file couldn't be fetched from the server.", unplayableReason("IO_NETWORK_CONNECTION_FAILED")) + } + + @Test fun theMessagesDontBlameTheWrongEnd() { + assertFalse(SERVER_NOT_ANSWERING.contains("nothing is wrong with this TV")) + assertTrue(TV_OFFLINE.contains("This TV")) + } +}