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-source-resolution

Media source resolution

Media source resolution turns a requested file, URI, or playlist into a stable media object that the library, queue, and player can use. It keeps the source identity separate from playback so the same request can support discovery, queue building, playlist expansion, and direct playback. It is the source layer below Media library, with file requests from Library indexing and files and queue consumers in Playlists and recent media and Search and content discovery.

Media source model

An IMediaSource is the common identity for playable media and media containers. It exposes a location, a display name, and a broad playback type. File sources add file access and type data. URI sources keep a network address. An expandable source marks a container that must first produce child media before it becomes a queue of playable items.

References: Screenbox.Core/…/IMediaSource.cs• L5-24 Screenbox.Core/…/IFileMediaSource.cs• L6-35 Screenbox.Core/…/IUriMediaSource.cs• L5-14 Screenbox.Core/…/IExpandableMediaSource.cs• L7-16

File sources

An IFileMediaSource represents a local or network file by its path. It can hold a ready StorageFile or resolve one later. This lets library records and playlist entries keep a usable path without requiring file access at creation time.

References: Screenbox.Core/…/FileMediaSource.cs• L10-63 Screenbox.Core/…/IFileMediaSource.cs• L6-35

URI sources

An IUriMediaSource represents a non-file address such as an HTTP, HTTPS, or RTSP URI. Its location stays the original URI and its name comes from the final URI segment. URI sources do not claim a file-based media type because the playable format may only be known when the stream is opened.

References: Screenbox.Core/…/UriMediaSource.cs• L7-25 Screenbox.Core/…/IUriMediaSource.cs• L5-14

Expandable sources

An IExpandableMediaSource is a container or playlist manifest rather than one direct stream. Expansion returns ExpandedMediaItem values that pair each child source with optional title and duration data. The queue can then treat the children as normal media while retaining the parent as the collection origin.

References: Screenbox.Core/…/IExpandableMediaSource.cs• L7-16 Screenbox.Core/…/ExpandedMediaItem.cs• L5-12 Screenbox.Core/…/QueueService.cs• L108-129

Factory selection

Screenbox.Core/…/MediaSourceFactory.cs is the single selection point for turning a StorageFile, Uri, or string into a source. The factory first separates file addresses from non-file URIs. It then recognizes .m3u and .m3u8 as playlist sources and uses ordinary file sources for other paths. This gives callers one contract while preserving the source capabilities needed later.

References: Screenbox.Core/…/MediaSourceFactory.cs• L7-52 Screenbox.Core/…/IMediaSourceFactory.cs• L6-13

The selection rules are:

Request formResulting sourceMain role
StorageFile with .m3u or .m3u8M3U playlist sourceExpand a playlist file
StorageFile with another supported typeFile sourcePlay a file
Absolute non-file URIURI sourcePlay a network or stream address
File URIFile sourceNormalize the URI to a file path
Path ending in .m3u or .m3u8M3U playlist sourceExpand a playlist path
Other pathFile sourcePlay a file path

M3U source expansion

M3uPlaylistMediaSource reads a playlist and converts each media entry into an ExpandedMediaItem. It resolves relative entries against the playlist directory, keeps absolute network entries as URIs, and sends every resolved target back through the factory. This means children follow the same file-versus-URI rules as any other request.

References: Screenbox.Core/…/M3uPlaylistMediaSource.cs• L11-25 Screenbox.Core/…/M3uPlaylistMediaSource.cs• L27-57 Screenbox.Core/…/M3uPlaylistMediaSource.cs• L67-140

The expansion flow is:

flowchart TD
    A[Playlist source] --> B[Read playlist text]
    B --> C{Adaptive stream manifest?}
    C -->|Yes| D[Return no child items]
    C -->|No| E[Read media entries]
    E --> F[Resolve relative paths]
    F --> G[Create child sources]
    G --> H[Attach optional title and duration]
    H --> I[Return expanded media items]

#EXTINF metadata can supply a child title and duration. Comment lines are ignored. Unreadable playlists, missing files, invalid entries, and entries that cannot be resolved do not create child items. An HLS manifest is left as one direct stream because its segments are not independent queue items.

References: Screenbox.Core/…/M3uPlaylistMediaSource.cs• L54-65 Screenbox.Core/…/M3uPlaylistMediaSource.cs• L83-137 Screenbox.Core.Tests/…/MediaSourceTests.cs• L98-147

Queue and playback handoff

Queue creation decides when an expandable source becomes a collection. A playlist with children is replaced by view models for those children. An empty expansion stays as the original item so a stream manifest or an unreadable playlist can still be offered to the player.

References: Screenbox.Core/…/QueueService.cs• L108-129 Screenbox.Core/…/QueueService.cs• L163-193

When playback receives an expandable item that was not expanded earlier, the queue coordinator expands it before selecting the current item. It replaces the placeholder with child items and keeps the collection origin. If expansion produces no items, it retries the same source as a direct playback item.

References: Screenbox.Core/…/PlayQueueCoordinator.cs• L456-471 Screenbox.Core/…/PlayQueueCoordinator.cs• L518-544

The player consumes file and URI sources through their native access form. A file with a resolved StorageFile uses the platform file access path. A lazy file uses its path. A URI uses its URI directly. This is the final handoff from source identity to the playback engine.

References: Screenbox.Core/…/PlayerService.cs• L65-104 Screenbox.Core/…/PlayerService.cs• L106-128

sequenceDiagram
    participant R as Request
    participant F as Source factory
    participant Q as Queue
    participant P as Player
    R->>F: Create file, URI, or playlist source
    F-->>Q: Return source identity
    alt Source is expandable
        Q->>F: Create child sources from entries
        F-->>Q: Return playable child items
    end
    Q->>P: Select playable source
    P-->>P: Open file path, StorageFile, or URI

Media view model identity

MediaViewModelFactory is the bridge between source resolution and library or queue state. It can create a new view model for a source or reuse a library item with the same location. For expanded playlist items, it applies the title and duration supplied by the playlist without changing the underlying source.

References: Screenbox.Core/…/MediaViewModelFactory.cs• L11-47 Screenbox.Core/…/MediaViewModelFactory.cs• L75-143

Location is the identity used for reuse. File URIs are compared as local paths, while network URIs remain URI strings. This keeps a file opened through different request forms from becoming two separate library items.

References: Screenbox.Core/…/MediaViewModelFactory.cs• L89-143 Screenbox.Core/…/MediaSourceFactory.cs• L20-47

Change checklist

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

  • Keep the factory rules aligned for StorageFile, Uri, and string inputs. A mismatch can turn the same location into different source kinds.
  • Preserve relative playlist resolution and file-URI normalization. Both affect whether expanded items point to a real file or to an unusable URI.
  • Keep empty expansion behavior aligned between queue creation and play-time expansion. HLS manifests and failed playlists depend on direct-play fallback.
  • Keep source locations stable when changing view-model reuse. Queue position and library identity use location matching.
  • Keep the player handoff able to consume every source kind that the factory can create.

Important failure modes

TriggerConsequenceGuard
Playlist file cannot be readExpansion returns no children and the original playlist may be tried as direct mediaPreserve the empty-result fallback in queue and play-time expansion
Relative playlist entry has no usable base pathThe entry is skippedRequire a resolvable playlist location before accepting relative entries
HLS manifest is treated as a static playlistStream segments appear as separate queue itemsDetect adaptive-stream manifest markers and keep the manifest direct
Factory creates a source kind that the player does not handlePlayback fails before the media engine opens the sourceUpdate factory and player source dispatch together
File URI and file path use different identity formsThe library can create duplicate view modelsNormalize file URIs to local paths before location matching

Key files

FileWhy to read it
Screenbox.Core/…/IMediaSource.csDefines the shared source identity used across library, queue, and playback.
Screenbox.Core/…/MediaSourceFactory.csShows how request forms become file, URI, or playlist sources.
Screenbox.Core/…/M3uPlaylistMediaSource.csShows playlist entry resolution and expansion into child media.
Screenbox.Core/…/QueueService.csShows how source expansion becomes a queue collection.
Screenbox.Core/…/PlayQueueCoordinator.csShows the play-time expansion path for a source selected directly.
Screenbox.Core/…/PlayerService.csShows the final conversion from source identity to player input.
Screenbox.Core/…/MediaViewModelFactory.csShows how resolved sources become reusable library and queue items.