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 / media-playback

Media playback system

The media playback system turns a selected media source into an active playback session. It builds and maintains a queue, gives the player a ready item, connects user and system controls to playback, and saves enough state to resume media later.

Playback lifecycle

Media selection and queue preparation

The queue service converts files, folders, playlists, or URIs into a QueueSession, which is the active ordered set of media items and its current position. The play queue coordinator makes that session the app-wide state and selects the item that the player must load.

Queue creation can expand playlists and other media collections. A single file can also retain a query for nearby files, so playback can move through its folder without loading the whole folder at once. Shuffle keeps a restore path to the original order, while repeat mode changes the allowed next and previous paths.

The queue buffer keeps playback items ready around the current position. This gives navigation a small working set without requiring every item in a large queue to stay loaded.

flowchart LR
    A[Selected file, folder, playlist, or URI] --> B[Queue session]
    B --> C[Current media item]
    B --> D[Nearby playback buffer]
    C --> E[Player playback item]
    E --> F[Playback]

References: Screenbox.Core/…/QueueService.cs• L42-160 Screenbox.Core/…/QueueSession.cs• L8-36 Screenbox.Core/…/PlayQueueBufferManager.cs• L17-25 Screenbox.Core/…/PlayQueueCoordinator.cs• L648-714

Player preparation and playback state

The player service creates the media player and turns a queue item into a playback item. The playback item is the bridge between an app media source and the player. It exposes duration, chapters, and available audio, video, and subtitle tracks.

The coordinator assigns the current playback item before it starts playback. The player then reports opening, buffering, playing, pause, position, media end, and failure changes. These events update the queue state and the visible player state.

The playback engine is described in VLC playback engine. This page covers only its role in the wider lifecycle.

References: Screenbox.Core/…/IPlayerService.cs• L6-13 Screenbox.Core/…/IPlaybackItem.cs• L11-27 Screenbox.Core/…/IMediaPlayer.cs• L11-60 Screenbox.Core/…/PlayQueueCoordinator.cs• L648-714

Player controls and track selection

Player controls send play, pause, seek, volume, rate, chapter, and track requests to the active player. The queue coordinator owns next and previous navigation, so controls use the same rules for normal order, shuffle, repeat, and nearby files.

Track selection belongs to the current playback item. Audio, video, and subtitle lists expose one selected track at a time, and a selection change is applied to the player. A dropped subtitle file is added to the current item and can become the selected subtitle.

The queue and control surface is described in Play queue and controls.

References: Screenbox.Core/…/PlaybackControlService.cs• L22-79 Screenbox.Core/…/PlayerControlsViewModel.cs• L141-170 Screenbox.Core/…/PlayerControlsViewModel.cs• L233-265 Screenbox.Core/…/SingleSelectTrackList.cs• L8-35 Screenbox.Core/…/PlayQueueCoordinator.cs• L977-1001

Playback progress and resume state

Playback progress links a media location to its last known position. The seek bar restores that position when the progress data is ready and updates it as playback moves. The tracker keeps a small recent set and saves it when the app suspends.

When media ends, the control service chooses the next item or the repeat action. Track repeat restarts the current item. List repeat returns to the first or last item as needed. Without a valid next item, playback stops at the end of the session.

References: Screenbox.Core/…/IPlaybackProgressTracker.cs• L6-50 Screenbox.Core/…/PlaybackProgressTracker.cs• L41-137 Screenbox.Core/…/SeekBarViewModel.cs• L110-169 Screenbox.Core/…/PlaybackControlService.cs• L60-79

System media integration

The system media service mirrors the active item and playback state to Windows system media controls. It supplies media details, play state, and a time range so outside controls can show and change the current playback position.

The coordinator connects system buttons and repeat-mode requests to the same queue and player actions used by the app controls. This keeps keyboard, in-app, and system media actions on one playback path.

References: Screenbox.Core/…/SystemMediaTransportControlsService.cs• L13-125 Screenbox.Core/…/PlayQueueCoordinator.cs• L123-125 Screenbox.Core/…/PlayQueueCoordinator.cs• L721-778 Screenbox.Core/…/PlayQueueCoordinator.cs• L1004-1019 Screenbox.Core/…/PlayerElementViewModel.cs• L446-498

Playback boundaries

Playback crosses four main boundaries. Each boundary has one primary responsibility, which keeps queue decisions separate from player state and from the view that renders the media.

BoundaryResponsibility
Media source to queueDescribe what can be played and turn a selection into ordered items.
Queue to playerSelect the current item and keep nearby items ready.
Player to controlsReport state, time, errors, chapters, and available tracks.
Player to systemPublish metadata, status, timeline, and external control actions.

Video output is a separate concern from playback state. The rendering path consumes the active player output and presents video in the app window. See Video rendering for that boundary.

References: Screenbox.Core/…/IMediaSource.cs• L1 Screenbox.Core/…/IMediaPlayer.cs• L11-60 Screenbox.Core/…/PlayQueueContext.cs• L10-60 Screenbox.VideoView/VideoView.cs• L1

Change checklist

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

  • Changes to queue order or current-item identity must preserve the link between QueueSession, PlayQueueContext, the playback buffer, and the player’s current item.
  • Changes to repeat or navigation rules must also update the enabled state of app and system next and previous controls.
  • Changes to media location or item replacement must keep resume progress keys and system media metadata aligned with the item that is playing.
  • Changes to track lists must keep selection changes synchronized with both the player and the visible control state.
  • Changes to player lifecycle events must preserve the handoff from native player callbacks to queue and UI state updates.

Important failure modes

TriggerConsequenceGuard
A media item cannot create a playback itemThe item cannot start and the user receives a media-load error.The buffer manager reports the failure and does not return a broken item.
Playback ends without a valid next itemThe session stops instead of advancing.Navigation checks the current index, neighboring-file query, and repeat mode.
A current queue item is replaced with a different object for the same fileThe queue can lose its current index and stop the active player.Neighbor expansion preserves the existing current-item object when locations match.
A native player event tries to change queue state directlyRe-entrant player calls or unsafe UI updates can freeze or corrupt playback.End and state events move work to a safe task or UI dispatcher.
Progress storage cannot loadPlayback starts without resume positions.Progress load failure is non-fatal and the tracker uses an empty state.

Key files

FileWhy to read it
Screenbox.Core/…/PlayQueueCoordinator.csMain owner of queue-to-player changes and playback lifecycle events.
Screenbox.Core/…/QueueService.csShows how user selections become queue sessions and how nearby files and shuffle work.
Screenbox.Core/…/QueueSession.csDefines the session state shared by queue and navigation decisions.
Screenbox.Core/…/PlayQueueBufferManager.csExplains how nearby media stays ready and how playback items are released.
Screenbox.Core/…/IMediaPlayer.csDefines the player contract for controls, state, time, tracks, and events.
Screenbox.Core/…/PlaybackControlService.csDefines next, previous, repeat, and end-of-media behavior.
Screenbox.Core/…/PlaybackProgressTracker.csDefines resume-position storage and app-suspend persistence.
Screenbox.Core/…/SystemMediaTransportControlsService.csDefines the Windows system media state and timeline surface.
Screenbox.Core/…/PlayerControlsViewModel.csShows how user actions reach playback and track selection.