# Custom Video Player

## Objective

A branded player with your own controls and colours instead of default browser chrome.

A styled playback surface with custom transport controls layered over the app's existing video element.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Build on the existing video element and the app's Adaptive Media Source Component if it is present. Style and control what is already there rather than introducing a second playback path.
2. Ship the controls people use: play and pause, a scrub bar with buffered range, elapsed and total time, volume with mute, captions, playback rate, and fullscreen. Leave out anything you cannot support properly.
3. Wire every control to the app's existing Keyboard Interaction Primitives and Focus Ring System. Space and K toggle play, arrows seek and adjust volume, F enters fullscreen, M mutes, and every control shows a visible focus ring.
4. Surface caption tracks in the player rather than hiding them. If the app already produces transcripts through Voice Transcription, feed those tracks into this player instead of building a separate caption pipeline.
5. Do not remove the native controls until the custom ones are proven to work. A player whose custom chrome fails to initialise and has stripped the fallback leaves the viewer with a video they cannot pause.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Keyboard control is not optional. Play, seek, volume, captions, and fullscreen must all be operable without a mouse, with the shortcuts announced somewhere the user can find them.
- A live stream has no fixed duration, and its seekable range moves as it runs. Show a live indicator and a jump-to-live control instead of a progress bar that implies an ending, and handle the duration changing mid-playback.
- If a caption track, thumbnail sprite, or chapter file fails to load, the player must carry on without it. If the custom chrome itself fails to initialise, restore the native controls rather than leaving a bare video.
- Dragging the scrub bar fires continuously. Seek on release and preview on drag, or the player will issue a request for every pixel of movement and stall the connection it is trying to read from.
- Browsers block autoplay with sound. Detect the rejected play attempt, start muted if that is the intent, and show a clear unmute control rather than a video that appears to be broken.
- The player must reserve its aspect ratio before the video metadata loads, using the app's Media Aspect Ratio System, so the page does not jump when playback becomes ready.
- Fullscreen behaves differently on iOS, which may hand playback to the native full-screen player. Accept that and make sure state returns cleanly when the viewer exits.
- Controls must auto-hide during playback but reappear on any pointer movement, keyboard input, or touch, and must never auto-hide while a control has keyboard focus.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Play, seek, volume, mute, captions, rate, and fullscreen are all reachable by keyboard with visible focus.
- [ ] Live sources show a live state and a jump-to-live control rather than a fixed-duration progress bar.
- [ ] A failed caption or thumbnail resource degrades gracefully, and a failed player initialisation restores native controls.
- [ ] Scrubbing issues a single seek on release rather than a request per movement.
- [ ] Blocked autoplay produces a visible unmute prompt rather than an apparently broken video.
- [ ] The player reserves its aspect ratio before metadata loads and the page does not shift.
- [ ] Existing transcript and caption tracks are surfaced through this player, not a parallel one.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
