0.83.0: Drive-In curtain intro, reusable, skippable, with Drive-In curtains and Reduce motion settings
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 3m0s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m36s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-03 10:10:01 +00:00
co-authored by Claude Opus 5.5
parent e1d2b77da5
commit 310d878ef3
12 changed files with 168 additions and 13 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 96
versionName = "0.82.0-selection-reasons"
versionCode = 97
versionName = "0.83.0-curtain-intro"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.82.0\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.83.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -321,7 +321,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
val booked = driveInPlan
val onScreen = remember(booked) { booked?.let(::driveInChannel) }
if (watchingDriveIn && onScreen != null) {
ScheduledChannelPlayer(liveSession, onScreen, 0, onClose = { watchingDriveIn = false }, onUnplayable = ::rememberUnplayable)
val intro = remember { OrbitSettings(appContext).let { introFor(CurtainIntro, it.driveInIntro, it.reduceMotion) } }
ScheduledChannelPlayer(liveSession, onScreen, 0, onClose = { watchingDriveIn = false }, onUnplayable = ::rememberUnplayable, intro = intro)
// Between shows there's nothing on, so the viewer comes back out to the lot.
LaunchedEffect(onScreen) { while (driveInAiring(onScreen.plan, System.currentTimeMillis())) delay(1000); watchingDriveIn = false }
}
@@ -331,6 +332,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
}
if ((mainGuide || mainHome) && liveSession != null && liveChannel != null) {
if (watchingChannel) ScheduledChannelPlayer(liveSession, liveChannel, channelClockOffset,
intro = remember { CurtainIntro.takeIf { IntroTrial.take() } },
onClose = { watchingChannel = false; channelClockOffset = 0 },
onStep = { step ->
val next = channelAfter(availableChannels.map { it.number }, selectedNumber, step)
@@ -43,7 +43,9 @@ private const val MAX_PLAYER_RETRIES = 1
internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPlan, onClose: () -> Unit, scheduled: ScheduledPlayback? = null,
onStep: (Int) -> Unit = {}, onLast: () -> Unit = {}, onNumber: (Int) -> Boolean = { false }, subtitlePreference: MutableState<String?>? = null, runningPlayer: ExoPlayer? = null, announce: Boolean = true, onHandBack: ((ExoPlayer) -> Boolean)? = null, onUnplayable: ((String) -> Unit)? = null, audioPreference: MutableState<String?>? = null,
/** Set while an ident covers the end of the show: drawn over everything, with the show itself quietened underneath. */
ident: (@Composable () -> Unit)? = null) {
ident: (@Composable () -> Unit)? = null,
/** Shown over the opening moments, with the programme playing silently beneath it at its proper place. */
intro: IntroPlayback? = null) {
val context = LocalContext.current
val logoSetting = remember { OrbitSettings(context).channelLogo }
var failure by remember { mutableStateOf<String?>(null) }
@@ -221,6 +223,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
if (ready) { delay(2_000); tuningNumberVisible = false }
}
val covered = ident != null
LaunchedEffect(player, intro?.showing) { if (intro != null) player.volume = if (intro.showing) 0f else 1f }
LaunchedEffect(player, covered) {
if (covered) {
repeat(10) { step -> player.volume = 1f - (step + 1) / 10f; delay(50) }
@@ -242,7 +245,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
LaunchedEffect(infoVisible, lastInteraction, playing, ready) {
if (infoVisible && playing && ready) { delay(5_000); infoVisible = false }
}
Dialog(onDismissRequest = { if (trackMenu != null) trackMenu = null else if (numberEntry != null) { numberEntry = null; numberProblem = null } else {
Dialog(onDismissRequest = { if (intro?.showing == true) intro.skip() else if (trackMenu != null) trackMenu = null else if (numberEntry != null) { numberEntry = null; numberProblem = null } else {
// Backing out keeps the stream running in the picture, without subtitles at that size.
if (ready && failure == null && foreground && onHandBack?.invoke(player) == true) {
handedBack = true
@@ -258,6 +261,11 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
setOnKeyListener { _, code, event ->
val isOk = code == KeyEvent.KEYCODE_DPAD_CENTER || code == KeyEvent.KEYCODE_ENTER
val typedDigit = if (code in KeyEvent.KEYCODE_0..KeyEvent.KEYCODE_9) code - KeyEvent.KEYCODE_0 else null
// OK skips the intro. Nothing else reaches the controls until it's gone.
if (intro?.showing == true) {
if (isOk && event.action == KeyEvent.ACTION_DOWN) intro.skip()
return@setOnKeyListener isOk
}
// Number keys and a held OK open the box. A short OK still shows the programme bar.
if (scheduled != null && event.action == KeyEvent.ACTION_DOWN) {
if (isOk && event.repeatCount > 0 && numberEntry == null && !okHeld) {
@@ -345,6 +353,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
if (infoVisible && failure == null && ready) ClassicProgrammeStrip(plan.item, playing,
Modifier.align(Alignment.BottomCenter).fillMaxWidth(.86f).padding(bottom = 26.dp), scheduled = scheduled)
ident?.invoke()
intro?.let { IntroOverlay(it) }
trackMenu?.let { TrackPanel(it, trackCursor, Modifier.align(Alignment.CenterEnd).padding(end = 28.dp)) }
trackProblem?.let { Text(it, Modifier.align(Alignment.TopCenter).padding(top = 44.dp).background(Navy.copy(alpha = .85f)).padding(horizontal = 14.dp, vertical = 8.dp), color = Color.White, fontSize = 16.sp) }
numberEntry?.let { ChannelNumberBox(it, numberProblem, Modifier.align(Alignment.TopCenter).padding(top = 44.dp)) }
@@ -50,6 +50,7 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
if (intent?.getBooleanExtra("orbit_intro_test", false) == true) IntroTrial.nextTune = true
// One typeface everywhere, matching the channel logos.
setContent { MaterialTheme { CompositionLocalProvider(androidx.tv.material3.LocalTextStyle provides androidx.compose.ui.text.TextStyle(fontFamily = Barlow)) { OrbitApp() } } }
}
@@ -0,0 +1,97 @@
package tv.orbit.classic
import android.content.Context
import android.os.SystemClock
import android.view.TextureView
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.media3.common.MediaItem
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.datasource.RawResourceDataSource
import androidx.media3.exoplayer.ExoPlayer
import kotlinx.coroutines.delay
/** A short film before a screening. A takeover would offer its own; the Drive-In's curtains are the default. */
internal class IntroSource(val name: String, val raw: Int)
internal val CurtainIntro = IntroSource("curtains", R.raw.drive_in_intro)
/** Longer than any intro should run. Past it, the intro gives way whatever it's doing. */
internal const val INTRO_LIMIT_MS = 9_000L
/** The intro to play, or none when it's switched off or motion is reduced. */
internal fun introFor(source: IntroSource?, enabled: Boolean, reduceMotion: Boolean): IntroSource? = source.takeIf { enabled && !reduceMotion }
/** Set from adb for a test run, so the intro can be checked on any channel without waiting for a screening. Used once, then cleared. */
internal object IntroTrial {
@Volatile var nextTune = false
fun take(): Boolean = nextTune.also { nextTune = false }
}
/**
* Plays over the screen while the programme opens underneath at its proper place. Anything wrong ends it at once,
* and the programme carries on as if there had been no intro.
*/
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
internal class IntroPlayback(context: Context, val source: IntroSource, private val onEnd: (String) -> Unit) {
var showing by mutableStateOf(true)
private set
private val startedAt = SystemClock.elapsedRealtime()
val player: ExoPlayer? = runCatching {
ExoPlayer.Builder(context).build().apply {
setMediaItem(MediaItem.fromUri(RawResourceDataSource.buildRawResourceUri(source.raw)))
addListener(object : Player.Listener {
override fun onPlaybackStateChanged(state: Int) { if (state == Player.STATE_ENDED) end("finished") }
override fun onPlayerError(error: PlaybackException) { end("error ${error.errorCodeName}") }
})
prepare(); playWhenReady = true
}
}.getOrNull()
init { if (player == null) end("could not open") }
fun end(reason: String) {
if (!showing) return
showing = false
runCatching { player?.release() }
onEnd("intro=${source.name} ended=$reason afterMs=${SystemClock.elapsedRealtime() - startedAt}")
}
fun skip() = end("skipped")
}
/** One intro for the whole visit, so it carries on unbroken while the screen beneath changes from tuning to the film. */
@Composable
internal fun rememberIntro(source: IntroSource?, onEnd: (String) -> Unit): IntroPlayback? {
val context = LocalContext.current
val intro = remember(source) { source?.let { IntroPlayback(context, it, onEnd) } } ?: return null
LaunchedEffect(intro) { delay(INTRO_LIMIT_MS); intro.end("timeout") }
val lifecycle = LocalLifecycleOwner.current.lifecycle
DisposableEffect(intro, lifecycle) {
// Leaving the app ends it, so coming back never finds an intro stuck halfway.
val observer = LifecycleEventObserver { _, event -> if (event == Lifecycle.Event.ON_STOP) intro.end("app left") }
lifecycle.addObserver(observer)
onDispose { lifecycle.removeObserver(observer); intro.end("closed") }
}
return intro
}
/** Drawn over everything else on the screen while the intro is showing. */
@Composable
internal fun IntroOverlay(intro: IntroPlayback) {
val player = intro.player ?: return
if (!intro.showing) return
Box(Modifier.fillMaxSize().background(Color.Black)) {
AndroidView(modifier = Modifier.fillMaxSize(), factory = { TextureView(it).also(player::setVideoTextureView) })
}
}
@@ -36,7 +36,9 @@ internal fun scheduledRuntimeMatches(openedMs: Long?, scheduledMs: Long) = opene
@Composable
internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleChannel, clockOffsetMs: Long,
onClose: () -> Unit, onStep: (Int) -> Unit = {}, onLast: () -> Unit = {}, onNumber: (Int) -> Boolean = { false }, handoff: LiveHandoff? = null, onUnplayable: ((String) -> Unit)? = null) {
onClose: () -> Unit, onStep: (Int) -> Unit = {}, onLast: () -> Unit = {}, onNumber: (Int) -> Boolean = { false }, handoff: LiveHandoff? = null, onUnplayable: ((String) -> Unit)? = null,
/** A short film over the start of this visit, such as the Drive-In's curtains. The programme opens underneath at its proper place. */
intro: IntroSource? = null) {
// Outlives each programme and channel, and ends when the viewer leaves full screen.
val settingsContext = androidx.compose.ui.platform.LocalContext.current
val subtitlePreference = remember { mutableStateOf(if (OrbitSettings(settingsContext).subtitlesOn) SUBTITLES_BY_DEFAULT else null) }
@@ -59,6 +61,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
val phase = if (identsHere) identPhase(current.startMs, current.endMs, now, identMs) else IdentPhase.None
// Each changeover in the playback notes, so a missing ident can be explained afterwards.
val notes = remember { java.io.File(settingsContext.noBackupFilesDir, "schedule") }
val introPlayback = rememberIntro(intro) { PlaybackNotes.add(notes, "channel=${channel.number} $it") }
LaunchedEffect(channel, current.startMs) {
PlaybackNotes.add(notes, "channel=${channel.number} programme start=${current.startMs} lengthMs=${current.endMs - current.startMs} nextFollows=${next.startMs == current.endMs} scheduled=${channel is ScheduledChannel} offset=$clockOffsetMs identsOn=$identsOn")
}
@@ -115,13 +118,13 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
SideEffect { announcedChannel[0] = channel.number }
EmbyPlaybackDialog(session, plan, onClose,
scheduled = ScheduledPlayback(channel, current, shows[1], clockOffsetMs), onStep = onStep, onLast = onLast, onNumber = onNumber, subtitlePreference = subtitlePreference, runningPlayer = loadedNow?.claim() ?: handed?.takeIf { it.plan === plan }?.claim(),
ident = if (phase == IdentPhase.Showing) { { IdentOverlay(session, channel, next, identMs, now - (current.endMs - identMs)) } } else null, announce = announce, onUnplayable = onUnplayable, audioPreference = audioPreference,
ident = if (phase == IdentPhase.Showing) { { IdentOverlay(session, channel, next, identMs, now - (current.endMs - identMs)) } } else null, intro = introPlayback, announce = announce, onUnplayable = onUnplayable, audioPreference = audioPreference,
onHandBack = { running ->
if (handoff != null && clockOffsetMs == 0L) { handoff.returned = LiveStream(channel.number, current.startMs, plan, running); true } else false
})
}
} else Dialog(onDismissRequest = onClose, properties = DialogProperties(usePlatformDefaultWidth = false,
decorFitsSystemWindows = false, securePolicy = SecureFlagPolicy.SecureOn)) {
} else Dialog(onDismissRequest = { if (introPlayback?.showing == true) introPlayback.skip() else onClose() }, properties = DialogProperties(usePlatformDefaultWidth = false,
decorFitsSystemWindows = false, securePolicy = SecureFlagPolicy.SecureOn)) { Box(Modifier.fillMaxSize()) {
if (problem == null) ChannelTuningBackdrop(channel.number) { ProgrammeArtwork(session, channel, current) }
else Box(Modifier.fillMaxSize().background(Navy)) {
Column(Modifier.align(Alignment.Center).widthIn(max = 620.dp).padding(32.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
@@ -135,7 +138,8 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC
OrbitButton("Return to TV guide", onClick = onClose)
}
}
}
introPlayback?.let { IntroOverlay(it) }
} }
}
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.82.0")
next.setRequestProperty("User-Agent", "OrbitTV/0.83.0")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
@@ -6,6 +6,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
@@ -54,6 +56,13 @@ internal class OrbitSettings(context: Context) {
var identSound: Boolean
get() = saved.getBoolean("ident_sound", true)
set(value) { saved.edit().putBoolean("ident_sound", value).apply() }
var driveInIntro: Boolean
get() = saved.getBoolean("drive_in_intro", true)
set(value) { saved.edit().putBoolean("drive_in_intro", value).apply() }
/** Turns off moving presentation such as the Drive-In's curtains. More screens will follow it as they gain motion. */
var reduceMotion: Boolean
get() = saved.getBoolean("reduce_motion", false)
set(value) { saved.edit().putBoolean("reduce_motion", value).apply() }
}
internal enum class SettingsSection(val label: String, val icon: Int) {
@@ -137,8 +146,10 @@ private fun ViewingDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Bo
var channelLogo by remember { mutableStateOf(settings.channelLogo) }
var idents by remember { mutableStateOf(settings.idents) }
var identSound by remember { mutableStateOf(settings.identSound) }
var driveInIntro by remember { mutableStateOf(settings.driveInIntro) }
var reduceMotion by remember { mutableStateOf(settings.reduceMotion) }
var confirming by remember { mutableStateOf(false) }
Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) {
Column(modifier.verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(8.dp)) {
SettingLine("Subtitles", "Turn on English subtitles whenever you tune in, if the programme has them. You can still change them while watching, by pressing right.") {
OrbitButton(if (subtitlesOn) "On" else "Off", Modifier.width(64.dp).focusRequester(firstSwitch), selected = subtitlesOn, onClick = { subtitlesOn = !subtitlesOn; settings.subtitlesOn = subtitlesOn })
}
@@ -151,6 +162,12 @@ private fun ViewingDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Bo
SettingLine("Ident sound", "Let Tots play its jingle, at most once every 30 minutes.") {
OrbitButton(if (identSound) "On" else "Off", Modifier.width(64.dp), selected = identSound, onClick = { identSound = !identSound; settings.identSound = identSound })
}
SettingLine("Drive-In curtains", "Play the curtain intro, with its fanfare, as you go into a screening. Back skips it.") {
OrbitButton(if (driveInIntro) "On" else "Off", Modifier.width(64.dp), selected = driveInIntro, onClick = { driveInIntro = !driveInIntro; settings.driveInIntro = driveInIntro })
}
SettingLine("Reduce motion", "Leave out moving presentation, such as the Drive-In's curtains.") {
OrbitButton(if (reduceMotion) "On" else "Off", Modifier.width(64.dp), selected = reduceMotion, onClick = { reduceMotion = !reduceMotion; settings.reduceMotion = reduceMotion })
}
if (totsOn) {
if (confirming) SettingLine(if (windingDown) "Go back to Tots' usual schedule now?" else "Start Wind Down on Tots?", if (windingDown) "The programme on Tots changes straight away." else "Calm shows begin when the current programme ends, and run until morning unless you stop them.") {
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
Binary file not shown.
@@ -0,0 +1,23 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
class PresentationIntroTest {
@Test fun introPlaysOnlyWhenWantedAndMotionIsAllowed() {
assertSame(CurtainIntro, introFor(CurtainIntro, enabled = true, reduceMotion = false))
assertNull(introFor(CurtainIntro, enabled = false, reduceMotion = false))
assertNull(introFor(CurtainIntro, enabled = true, reduceMotion = true))
assertNull(introFor(null, enabled = true, reduceMotion = false))
}
@Test fun aTrialIntroIsUsedOnce() {
IntroTrial.nextTune = true
assertTrue(IntroTrial.take())
assertFalse(IntroTrial.take())
}
@Test fun theLimitOutlastsTheCurtains() {
assertTrue(INTRO_LIMIT_MS > 7_000)
}
}
+2
View File
@@ -38,3 +38,5 @@ LIST
cp "$D/tots/tots_morning.mp4" "$OUT/ident_614_morning.mp4"
cp "$D/tots/tots_morning_roll.mp4" "$OUT/ident_614_morning_roll.mp4"
cp "$D/tots/tots_evening.mp4" "$OUT/ident_614_evening.mp4"
# The Drive-In's curtain intro keeps its fanfare, 5 dB down so it sits nearer a film's own level. Its source is depth-native/blender/drive-in.
ffmpeg -nostdin -y -loglevel error -i "$D/blender/drive-in/drive-in_blender_sound.mp4" -vf fps=30 -c:v libx264 -profile:v main -pix_fmt yuv420p -crf 30 -maxrate 1400k -bufsize 2800k -af volume=-5dB -c:a aac -b:a 96k -movflags +faststart "$OUT/drive_in_intro.mp4"