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 / vlc-playback-engine

VLC playback engine and tracks

The playback engine gives the rest of Screenbox one media-player contract while VLC handles the actual media work. It turns a media source into a playback item with duration, tracks, subtitles, and chapters, then reports state changes to the queue, player view, and controls. See Media playback system, Play queue and playback controls, and Video rendering surface for the surrounding flows.

Playback engine

Media player contract

The IMediaPlayer contract presents playback as a set of stable actions and state changes. Higher-level services can play, pause, seek, change volume or speed, select chapters, and observe buffering or failure without depending on VLC types.

The contract also carries the active IPlaybackItem. This links player state to the media metadata and track choices that belong to the current item.

References: Screenbox.Core/…/IMediaPlayer.cs• L11-60

VLC player adapter

Screenbox.Core/…/VlcMediaPlayer.cs is the VLC-backed form of the media-player contract. It maps VLC events to common playback events and maps common actions back to VLC. This keeps VLC-specific behavior at the playback boundary while the rest of the application works with IMediaPlayer.

The adapter reports the states that user-facing playback needs, including opening, playing, paused, buffering, ended, and failed. It also exposes video size, seek support, position, duration, playback rate, audio delay, subtitle delay, and the selected chapter.

This diagram shows how a media source becomes VLC playback and how state returns to the application.

flowchart LR
    S[Media source] --> F[Player service]
    F --> I[VLC playback item]
    I --> P[VLC media player]
    P --> E[Playback events]
    E --> U[Queue, player, and controls]
    U --> A[Playback actions]
    A --> P

References: Screenbox.Core/…/IPlayerService.cs• L6-12 Screenbox.Core/…/PlayerService.cs• L58-71 Screenbox.Core/…/VlcMediaPlayer.cs• L16-35 Screenbox.Core/…/VlcMediaPlayer.cs• L213-250

Playback items

Playback item model

The IPlaybackItem model is the media unit that the player opens. It keeps the source and duration together with the selectable audio, video, and subtitle tracks and the read-only chapter list.

An item can wait for media parsing before its metadata is used. It can also expand child media when the source represents a container or playlist. These operations let the queue and track picker use one item shape for local files, URIs, and compound media.

References: Screenbox.Core/…/IPlaybackItem.cs• L11-28

VLC playback item

VlcPlaybackItem binds the common item model to a VLC media object. It creates the track lists and chapter list for that media, reports its known duration, and owns the lifetime of the VLC media resource.

The item loads track and chapter information as VLC makes it available. When the item is disposed, it detaches its track observers and releases the media resource so a later queue item does not receive stale updates.

References: Screenbox.Core/…/VlcPlaybackItem.cs• L13-35 Screenbox.Core/…/VlcPlaybackItem.cs• L41-59 Screenbox.Core/…/VlcPlaybackItem.cs• L100-118

Track lists

Media track values

MediaTrack is the shared description for an audio, video, or subtitle choice. Each track has an ID for the playback engine, a display label, and optional language information. Labels include the language when that adds useful context, so the UI can show a meaningful choice without knowing VLC metadata rules.

The concrete track types identify the role of each choice:

Track typeUser choice
AudioTrackThe sound stream used for playback
VideoTrackThe picture stream used for playback
SubtitleTrackThe text stream shown with the media

References: Screenbox.Core/…/MediaTrack.cs• L7-61 Screenbox.Core/…/AudioTrack.cs• L5-17 Screenbox.Core/…/VideoTrack.cs• L5-17 Screenbox.Core/…/SubtitleTrack.cs• L5-14

Single-selection track lists

SingleSelectTrackList<T> gives audio and video tracks one shared selection rule: the list contains zero or more choices and one selected index, or -1 when no choice is selected. A selection change raises an event so the active player can apply the new stream.

The public interfaces expose the list as a read-only collection with refresh support. This separates the track choices shown to the UI from the code that changes the active VLC stream.

References: Screenbox.Core/…/SingleSelectTrackList.cs• L8-49 Screenbox.Core/…/ISingleSelectMediaTrackList.cs• L6-9 Screenbox.Core/…/VlcMediaPlayer.cs• L445-495

VLC audio and video lists

The VLC audio and video lists translate VLC stream metadata into the common track values. They can fill at once when VLC already knows the streams, or fill after media parsing completes. Their selected index starts at the first track so the player has a normal default when tracks exist.

When a selection changes, the VLC player receives the track ID. The UI therefore selects a common track object while the adapter performs the engine-specific stream change.

References: Screenbox.Core/…/VlcAudioTrackList.cs• L5-49 Screenbox.Core/…/VlcVideoTrackList.cs• L5-49 Screenbox.Core/…/VlcMediaPlayer.cs• L462-482

VLC subtitle list

The subtitle list follows the same single-selection model but adds subtitle-specific behavior. It supports disabling subtitles, loading an external subtitle file, and tracking subtitles that VLC adds after playback starts.

External subtitles first appear as pending choices. Selecting one asks the player to add it to VLC, and the list updates the choice when VLC reports the new stream ID. The track picker also preloads matching subtitle files and can apply a saved language preference.

References: Screenbox.Core/…/ISubtitleTrackList.cs• L5-8 Screenbox.Core/…/VlcSubtitleTrackList.cs• L10-16 Screenbox.Core/…/VlcSubtitleTrackList.cs• L55-92 Screenbox.Core/…/VlcSubtitleTrackList.cs• L95-165 Screenbox.Core/…/CompositeTrackPickerViewModel.cs• L96-142

Track picker interface

The track picker turns the engine lists into user-facing audio, video, and subtitle choices. It adds a visible Disable entry for subtitles and uses a track number when a stream has no label. The picker converts its display index to the underlying selection index before it updates the playback item.

Audio and video use direct list indexes. Subtitle selection uses an offset because the first display entry means no subtitles. The picker also exposes timing offsets for audio and subtitles through the active playback session.

References: Screenbox/…/CompositeTrackPicker.xaml.cs• L25-40 Screenbox/…/CompositeTrackPicker.xaml.cs• L101-134 Screenbox.Core/…/CompositeTrackPickerViewModel.cs• L247-280 Screenbox.Core/…/CompositeTrackPickerViewModel.cs• L304-349

Chapter navigation

Chapter list

Chapters divide a media item into named or numbered time ranges. VlcChapterList reads VLC chapter descriptions after the player knows the media duration, converts them into ChapterCue values, and exposes them as a read-only list on the playback item.

The media player keeps the current chapter in sync with VLC. It can move to the next or previous chapter, while the seek and player controls use chapter changes to update progress and navigation state.

References: Screenbox.Core/…/VlcChapterList.cs• L11-61 Screenbox.Core/…/VlcMediaPlayer.cs• L351-360 Screenbox.Core/…/VlcMediaPlayer.cs• L549-565

VLC integration boundary

Media creation and resource access

PlayerService is the entry point that creates the VLC runtime, the player adapter, and VLC-backed playback items. It accepts file and URI sources and gives VLC the access form needed for each source. It also releases temporary access tokens when the media item closes.

The service sets VLC options needed by the application and connects VLC dialogs to application dialogs and notifications. This keeps source access, VLC setup, and resource cleanup outside the common player contract.

References: Screenbox.Core/…/PlayerService.cs• L14-21 Screenbox.Core/…/PlayerService.cs• L58-103 Screenbox.Core/…/PlayerService.cs• L131-185 Screenbox.Core/…/PlayerService.cs• L189-210 Screenbox/…/VlcDialogService.cs• L15-32

Playback session settings

The playback session holds values that apply to the active player rather than to one track choice. It keeps playback rate, audio timing offset, and subtitle timing offset, then applies them when the current player changes.

The track picker changes the timing offsets through this session. The session forwards the values to the player in the units expected by the common playback contract, so controls do not need to know VLC’s internal units.

References: Screenbox.Core/…/PlaybackSessionViewModel.cs• L13-43 Screenbox.Core/…/PlaybackSessionViewModel.cs• L46-67 Screenbox.Core/…/PlaybackSessionViewModel.cs• L80-122 Screenbox/…/CompositeTrackPicker.xaml.cs• L137-163

Change checklist

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

  • Keep IMediaPlayer and VlcMediaPlayer event and property contracts aligned. View models subscribe to the common contract and can silently stop updating if a VLC event is not mapped.
  • Keep track IDs and selected indexes consistent between SingleSelectTrackList<T>, the VLC track lists, and the stream-selection calls. Subtitle display indexes have a separate disable offset.
  • Preserve the parse and attach order for delayed VLC metadata. Track lists and chapters can be empty until VLC finishes parsing.
  • Keep external subtitle state synchronized with VLC-added stream IDs. A pending subtitle choice must become a real VLC track after selection.
  • Update media-resource cleanup with any change to source creation. File access tokens and VLC media objects must live for the same playback item lifetime.

Important failure modes

TriggerConsequenceGuard
VLC reports a stream before the media track list is populatedA selected subtitle may not map to a real streamDelay the subtitle selection and apply it when tracks arrive.
A subtitle display index is sent as the underlying indexThe wrong subtitle is selected or subtitles fail to disableConvert the picker index to -1 or the zero-based track index.
A playback item is replaced without detaching its track handlersOld media can change the new player stateRemove item handlers before registering the new item.
A VLC media object or access token is not releasedLater playback can leak resources or lose file access capacityDispose the playback item and release its source token together.
VLC cannot open or decode the sourcePlayback stops and the player reports failureObserve MediaFailed and return the player to a non-playing state.

Key files

FileWhy to read it
Screenbox.Core/…/IMediaPlayer.csDefines the playback contract used by the rest of the application.
Screenbox.Core/…/IPlaybackItem.csDefines the media unit and its track and chapter relationships.
Screenbox.Core/…/VlcMediaPlayer.csShows the VLC-to-application playback boundary.
Screenbox.Core/…/VlcPlaybackItem.csShows how one VLC media object exposes duration and media choices.
Screenbox.Core/…/VlcSubtitleTrackList.csShows the extra rules for external and delayed subtitles.
Screenbox.Core/…/VlcChapterList.csShows how VLC chapter data becomes application chapter data.
Screenbox.Core/…/PlayerService.csShows player creation, source handling, VLC setup, and cleanup.
Screenbox.Core/…/CompositeTrackPickerViewModel.csShows how user track choices reach the active playback item.
Screenbox/…/CompositeTrackPicker.xaml.csShows how common track lists become picker display lists.