Player quality + captions controls (piped-features)

- Quality button opens a modal picker over the video: Auto at the top plus
  every rung from the HLS master's variant list (parsed in the router;
  Piped videoStreams is unreliable), virtual-focus list like the rest of
  the dev player's chrome, OK applies / Back cancels, panel auto-sizes.
- Applying a quality rebuilds the /api/hls URL with the quality filter and
  restarts at the saved position (stop->stopped-edge->play), persists to
  playback.preferred_quality, keeps the retry URL list consistent.
- Captions button toggles globalCaptionMode On/Off (+ first-track fallback
  when the OS language match finds nothing); N/A when the video has none.
- Status line above the button row: 'Quality: Auto (1080p) | Captions: On'
  tracks streamingSegment while auto ramps.
- Fix: QualityLevelsFromPiped sort crashed the /streams converter (string
  vs AA compare); replaced by QualityLevelsFromHlsMaster.
- Seam tests for picker open/navigate/apply/cancel/clamp + captions toggle;
  ButtonRow specs updated for the 4-button row. Lib tag PIPED-LIB-26.
This commit is contained in:
spaghet committed 2026-11-24 21:50:41 -05:00
1 parent b7183f3603
commit 7577f89df6
19 files changed
+887 -23

No files matched your search

@@ -946,11 +946,13 @@ namespace Tests
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier, play/pause (leftmost)
m.top.callFunc("TestKey", RemoteKeys.Left, true) ' clamped at the left end
m.assertEqual(m.Snap().nudgeCount, 1)
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' -> quality
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' -> captions
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' -> minimize (rightmost)
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' clamped at the right end
snap = m.Snap()
m.assertEqual(snap.nudgeCount, 2)
m.assertEqual(snap.focusedButton, 1, "the clamp held the highlight at the end")
m.assertEqual(snap.focusedButton, 3, "the clamp held the highlight at the end")
end function
' Down at the bar tier (the bottom, and the default on reveal) is a no-op: consumed, no nudge.
@@ -1005,14 +1007,143 @@ namespace Tests
function _()
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' reveal -> bar tier (default)
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' highlight minimize
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' highlight quality
m.assertEqual(m.Snap().focusedButton, 1)
m.top.callFunc("TestKey", RemoteKeys.Play, true) ' must pause, not minimize
m.top.callFunc("TestKey", RemoteKeys.Play, true) ' must pause, not activate quality
snap = m.Snap()
m.assertEqual(snap.control, VideoControl.Pause, "Play paused the (playing) video")
m.assertEqual(snap.focusedButton, 1, "the highlight is untouched")
end function
' The quality button opens a modal picker over the video (virtual cursor, list not cycle):
' the seed's ladder [1080p,720p,480p] renders as auto/1080p/720p/480p rows, cursor starts on the
' applied rung (auto), Down moves it, OK applies + arms the stop->play switch, Back cancels.
@it("the quality button opens the picker and OK applies the highlighted rung")
function _()
m.top.callFunc("TestSeedPlaybackContent", ["1080p", "720p", "480p"], 1)
m.top.position = 42.0
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' reveal -> bar tier
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' highlight quality
m.assertEqual(m.Snap().focusedButton, 1)
m.top.callFunc("TestKey", RemoteKeys.Ok, true) ' open the picker
open = m.Snap()
m.assertTrue(open.pickerVisible, "the picker opened")
m.assertEqual(open.pickerRowCount, 4, "auto + the three seeded rungs")
m.assertEqual(open.pickerFocusedIndex, 0, "cursor starts on Auto (the applied rung)")
m.assertEqual(open.pickerAppliedIndex, 0, "Auto is marked applied")
m.assertFalse(open.chromeShown, "the HUD hides under the modal")
' the modal swallows transport keys: Left must not scrub
m.top.callFunc("TestKey", RemoteKeys.Left, true)
m.assertEqual(m.Snap().transportMode, TransportController.Mode.Idle, "Left swallowed")
' Down -> 1080p, OK applies: the switch arms (stop first) and the pick persists
m.top.callFunc("TestKey", RemoteKeys.Down, true)
m.assertEqual(m.Snap().pickerFocusedIndex, 1, "cursor moved to 1080p")
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
snap = m.Snap()
m.assertFalse(snap.pickerVisible, "the picker closed")
m.assertTrue(snap.qualitySwitchPending, "the switch armed")
m.assertEqual(snap.control, VideoControl.Stop, "the switch stopped the player")
m.assertEqual(m.top.preferences["playback.preferred_quality"], "1080p", "the pick persisted")
m.assertTrue(InStr(snap.buttonRowStatusText, "1080p") > 0, "the status line shows the new quality")
' the device completes the async stop -> the coordinator swaps the url and replays at position
m.top.callFunc("TestSetState", VideoState.Stopped)
after = m.Snap()
m.assertFalse(after.qualitySwitchPending, "the switch drained")
m.assertEqual(after.control, VideoControl.Play, "playback resumed on the new url")
m.assertTrue(InStr(after.contentUrl, "&quality=1080p") > 0, "the url carries the quality filter")
m.assertEqual(m.top.seek, 42.0, "resumed at the saved position")
' reopen: the cursor lands on the applied rung; Back cancels without switching
m.top.callFunc("TestSetState", VideoState.Playing)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Right, true)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
reopen = m.Snap()
m.assertTrue(reopen.pickerVisible)
m.assertEqual(reopen.pickerFocusedIndex, 1, "cursor reopens on 1080p")
m.assertEqual(reopen.pickerAppliedIndex, 1, "1080p is marked applied")
m.top.callFunc("TestKey", RemoteKeys.Back, true)
cancelled = m.Snap()
m.assertFalse(cancelled.pickerVisible, "Back closed the picker")
m.assertFalse(cancelled.qualitySwitchPending, "Back applied nothing")
m.assertEqual(m.top.preferences["playback.preferred_quality"], "1080p", "the pick unchanged")
' clamps: Up at the top rung stays on Auto (index 0), not a wrap
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Right, true)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' 1080p -> auto
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' clamped at auto
m.assertEqual(m.Snap().pickerFocusedIndex, 0, "the cursor clamps at the top")
m.top.callFunc("TestKey", RemoteKeys.Back, true)
end function
' The captions button (index 2): toggles globalCaptionMode; it is reported unavailable when the
' video has no captions (the coordinator still routes the press; the module no-ops).
@it("the captions button toggles the device caption mode")
function _()
m.top.callFunc("TestSeedPlaybackContent", ["1080p"], 2)
m.top.callFunc("TestSetState", VideoState.Playing)
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' reveal -> bar tier
m.top.callFunc("TestKey", RemoteKeys.Up, true) ' bar -> buttons tier
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' quality
m.top.callFunc("TestKey", RemoteKeys.Right, true) ' captions
m.assertEqual(m.Snap().focusedButton, 2)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
snap = m.Snap()
m.assertEqual(snap.captionMode, "On", "captions turned on")
m.assertTrue(InStr(snap.buttonRowStatusText, "On") > 0, "the status line shows Captions: On")
' the OS language pref matched nothing -> the module fell back to the first offered track.
m.assertEqual(m.top.subtitleTrack, "http://cc/0", "fell back to the first track")
m.top.callFunc("TestKey", RemoteKeys.Ok, true) ' toggle again
m.assertEqual(m.Snap().captionMode, "Off", "captions turned off")
end function
' No captions on this video: the toggle is inert and the status line says N/A.
@it("the captions button is a no-op when the video has no captions")
function _()
m.top.callFunc("TestSeedPlaybackContent", ["1080p"], 0)
m.top.callFunc("TestSetState", VideoState.Playing)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Up, true)
m.top.callFunc("TestKey", RemoteKeys.Right, true)
m.top.callFunc("TestKey", RemoteKeys.Right, true)
m.top.callFunc("TestKey", RemoteKeys.Ok, true)
snap = m.Snap()
m.assertEqual(snap.captionMode, "Off", "the mode never moved")
m.assertTrue(InStr(snap.buttonRowStatusText, "N/A") > 0, "the status line reports N/A")
end function
' The status line reflects the live ladder while Auto is selected: a streamingSegment edge updates
' the parenthetical (the auto-ramp readout the user asked for).
@it("the status line shows the auto-resolved height from streamingSegment")
function _()
m.top.callFunc("TestSeedPlaybackContent", ["1080p", "720p"], 0)
m.top.callFunc("TestSetState", VideoState.Playing)
m.top.streamingSegment = { segType: 0, height: 720, width: 1280 }
snap = m.Snap()
m.assertTrue(InStr(snap.buttonRowStatusText, "Auto (720p)") > 0, "the auto ramp shows in the status line")
m.top.streamingSegment = { segType: 0, height: 1080, width: 1920 }
m.assertTrue(InStr(m.Snap().buttonRowStatusText, "Auto (1080p)") > 0, "it tracks the ramp up")
end function
' Each arm is asserted: a state that silently failed to arm makes every row that follows vacuous.
function ArmRouterState(state as string) as void
m.top.callFunc("TestSetup")
@@ -1079,11 +1210,11 @@ namespace Tests
classified[name] = "dep"
end for
' controllers (plain .bs class instances).
for each name in ["transport", "sponsorblock", "playbackTelemetry"]
for each name in ["transport", "sponsorblock", "playbackTelemetry", "playbackControls"]
classified[name] = "controller"
end for
' cached child nodes / timers / animations / reusable helpers (structure, not state).
for each name in ["chrome", "titleLabel", "secondaryTitleLabel", "clock", "bifDisplay", "trickPlayBar", "spinner", "largePause", "buttonRow", "fullScreenHint", "autoHide", "transportTimer", "liveBadgeHold", "liveEdgeClock", "fullScreenHintTimer", "chromeFadeIn", "chromeFadeOut", "minimize", "nowDateTime"]
for each name in ["chrome", "titleLabel", "secondaryTitleLabel", "clock", "bifDisplay", "trickPlayBar", "spinner", "largePause", "buttonRow", "qualityPicker", "fullScreenHint", "autoHide", "transportTimer", "liveBadgeHold", "liveEdgeClock", "fullScreenHintTimer", "chromeFadeIn", "chromeFadeOut", "minimize", "nowDateTime"]
classified[name] = "node"
end for
' in-flight job handles.
@@ -1095,7 +1226,7 @@ namespace Tests
classified[name] = "axis"
end for
' flags / scratch — one-shot latches and counters with a single consuming path.
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "loadingSetSeekMs", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive"]
for each name in ["onCloseCalled", "ignoreNextFinished", "videoPlayedSuccessfully", "firstFrameSeen", "showFullScreenHint", "repauseAfterSeek", "loadingSetSeekMs", "watchTimeMarker", "reportWatchTime", "errorDialogNode", "lastCommitSeq", "lastFinishSeq", "liveAstSeconds", "liveFallbackEdgeMs", "liveFallbackAtSeconds", "liveBadgeHoldActive", "streamingSegmentTelemetryDone"]
classified[name] = "flag"
end for
' NOT coordinator state — node-scope + test-environment entries, pinned EXPLICITLY (no hidden