Introducing a new way to review your PRs.

Read the announcement

huynhsontung / screenbox

LibVLC-based media player for the Universal Windows Platform

View on GitHub

19 documents · Updated Nov 23, 2026

docs / casting

Casting media

Casting lets the player discover compatible playback targets on the local network and send the current media player output to one selected target. The feature keeps discovery state separate from the player view and exposes a small control surface from the player controls. See the external media integrations overview and the related Lively Wallpaper integration page.

Cast contexts

Cast state

The cast context is the shared source of truth for the current discovery watcher and active external target. It is shared by the cast view model and the rest of the core layer so the selected target remains tied to the app session rather than to one view instance.

References: Screenbox.Core/…/CastContext.cs• L7-14 Screenbox.Core/…/ServiceHelpers.cs• L59-64

Renderer model

A renderer is the app's user-facing model for an external playback target. It supplies the target name, type, icon, and audio/video capabilities, while its availability marks whether the target can still receive playback.

References: Screenbox.Core/…/Renderer.cs• L5-31

Casting service

Service contract

The cast service provides two operations: create a watcher for the current media player and set or clear its active renderer. This contract keeps target discovery and player configuration out of the view model while returning a success result for the change of target.

References: Screenbox.Core/…/ICastService.cs• L7-17

Player bridge

The current implementation connects casting to the VLC-backed media player. It creates a renderer watcher only for that player type and passes the selected renderer's native target to VLC; clearing the renderer returns playback to local output.

References: Screenbox.Core/…/CastService.cs• L8-22 Screenbox.Core/…/VlcMediaPlayer.cs• L16-17 Screenbox.Core/…/VlcMediaPlayer.cs• L264-268

Renderer discovery

The discovery flow uses the media engine's renderer discovery facility to track external targets as they appear and disappear. The watcher owns this short-lived process and reports changes through found and lost events.

flowchart LR
    A[Cast flyout opens] --> B[Create renderer watcher]
    B --> C[Start discovery]
    C --> D[Renderer found]
    D --> E[Add target to cast list]
    C --> F[Renderer lost]
    F --> G[Remove target from cast list]
    H[Cast flyout closes] --> I[Stop and dispose watcher]

Watcher lifecycle

The watcher starts discovery once and retains the active renderer models until it stops. Stopping releases the discovery resource and invalidates the renderer models, so a later session must discover targets again.

References: Screenbox.Core/…/RendererWatcher.cs• L11-30 Screenbox.Core/…/RendererWatcher.cs• L33-70

Target events

A found event adds a renderer to the available target set. A lost event removes the matching renderer and tells the consumer that the target is no longer usable.

References: Screenbox.Core/…/RendererWatcher.cs• L72-87 Screenbox.Core/…/RendererEventArgs.cs• L6-24

Cast-control view model

Discovery controls

The cast-control view model turns watcher events into an observable target list for the cast flyout. It starts discovery when the flyout opens and stops it when the flyout closes, which limits network discovery to the time when the user can act on its results.

References: Screenbox.Core/…/CastControlViewModel.cs• L14-53 Screenbox/…/CastControl.xaml.cs• L19-26

Cast selection

The view model permits casting only when the selected renderer is still available. A successful service call records the active renderer in the shared cast context and changes the view model to its casting state.

References: Screenbox.Core/…/CastControlViewModel.cs• L18-23 Screenbox.Core/…/CastControlViewModel.cs• L71-88

Cast stopping

Stopping casting clears the renderer on the current media player and in the shared context. The view model then returns to discovery so the user can choose another target.

References: Screenbox.Core/…/CastControlViewModel.cs• L90-99

Cast-control view

The cast flyout presents discovered renderer names and lets the user select one. During casting it replaces the discovery list with the active device and a stop action, so the view reflects the same state that the view model and context hold.

References: Screenbox/…/CastControl.xaml• L22-55 Screenbox/…/CastControl.xaml• L57-125 Screenbox/…/PlayerControls.xaml.cs• L66-70

Cast flow

The complete user flow connects the player controls, discovery watcher, service contract, and shared state as one path.

sequenceDiagram
    participant User
    participant Controls as Player controls
    participant VM as Cast-control view model
    participant Service as Cast service
    participant Player as VLC media player
    participant Target as External renderer

    User->>Controls: Open cast flyout
    Controls->>VM: Start discovery
    VM->>Service: Create watcher
    Service-->>VM: Renderer watcher
    VM->>Target: Discover available targets
    Target-->>VM: Found renderer
    User->>VM: Select target and cast
    VM->>Service: Set active renderer
    Service->>Player: Set renderer target
    Player->>Target: Send playback output
    User->>VM: Stop casting
    VM->>Service: Clear active renderer
    Service->>Player: Clear renderer target

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Renderer availability rules aligned with the watcher's lost-target events and the view model's cast command guard.
  • Keep ICastService behavior aligned with the media-player types accepted by CastService; a new player type needs both watcher creation and renderer selection support.
  • Keep flyout open and close behavior aligned with watcher ownership so discovery does not continue after the cast view is gone.
  • Keep successful renderer changes synchronized across the media player, CastContext.ActiveRenderer, and the view model's casting state.

Important failure modes

TriggerConsequenceGuard
No current media player exists when discovery startsThe cast list stays empty and no watcher is createdStartDiscovering returns until PlayerContext.MediaPlayer is available
The current player is not a VlcMediaPlayerWatcher creation throws, or renderer selection returns falseKeep casting tied to the supported player bridge
The selected renderer is no longer availableThe cast command cannot run, and a lost target is removed from the listRenderer.IsAvailable gates casting and lost events clear the selection
Renderer discovery cannot startNo targets are reported to the cast viewCheck the watcher start result when changing discovery behavior

Key files

FileWhy to read it
Screenbox.Core/…/CastContext.csShared active renderer and watcher state
Screenbox.Core/…/Renderer.csUser-facing target model and availability state
Screenbox.Core/…/RendererWatcher.csDiscovery lifecycle and target events
Screenbox.Core/…/ICastService.csCasting service contract
Screenbox.Core/…/CastService.csBridge from the service contract to the media player
Screenbox.Core/…/CastControlViewModel.csDiscovery, selection, cast, and stop behavior
Screenbox/Controls/CastControl.xamlCast flyout states and user actions
Screenbox/…/CastControl.xaml.csFlyout lifecycle and view-model binding
Screenbox/…/PlayerControls.xaml.csEntry point from the player controls