Skip to content

Uri media source http headers#3169

Open
Kaaybi wants to merge 12 commits intoCommunityToolkit:mainfrom
Kaaybi:uri-media-source-http-headers
Open

Uri media source http headers#3169
Kaaybi wants to merge 12 commits intoCommunityToolkit:mainfrom
Kaaybi:uri-media-source-http-headers

Conversation

@Kaaybi
Copy link

@Kaaybi Kaaybi commented Mar 20, 2026

Description of Change

Add HTTP headers support to MediaElement

Linked Issues

PR Checklist

Additional information

Thank you for reading through!

As documented, Tizen does not support custom HTTP headers.

I tested this on Windows with Mockoon. On HLS for instance, custom headers are propagated to both manifest and segments.
Feel free to test this by using the sample and setting custom headers.

screenshot2026-03-20 192916 screenshot2026-03-20 192949

@Kaaybi
Copy link
Author

Kaaybi commented Mar 20, 2026

@dotnet-policy-service agree

Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job, I've a few comments about your work

/// An <see cref="IRandomAccessStream"/> implementation backed by HTTP Range requests,
/// enabling progressive streaming of media content with custom HTTP headers without buffering the entire file in memory.
/// </summary>
sealed partial class HttpRandomAccessStream : IRandomAccessStream
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this class should live inside Views

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either.. Though it's an internal sealed class exclusively used by MediaManager.windows.cs. I can move it elsewhere if needed!

@Kaaybi
Copy link
Author

Kaaybi commented Mar 21, 2026

Thank you pictos for your detailed review, I will address your points asap!
edit: Done!

@Kaaybi Kaaybi requested a review from pictos March 21, 2026 08:49
@TheCodeTraveler TheCodeTraveler requested review from Copilot and removed request for pictos March 21, 2026 14:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for supplying custom HTTP request headers when MediaElement loads media from a UriMediaSource, enabling scenarios like authenticated streaming (Fixes #1889, #3154).

Changes:

  • Introduces UriMediaSource.HttpHeaders and a new MediaSource.FromUri(Uri?, IDictionary<string,string>?) overload.
  • Implements header propagation on Android (Media3), iOS/macCatalyst (AVUrlAsset options), and Windows (AdaptiveMediaSource + stream fallback).
  • Updates the sample page UI to let users define headers, and adds unit tests for the new API surface.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test-output.txt Adds captured test runner output (appears to be a local artifact).
test-error.txt Adds captured test crash output (appears to be a local artifact).
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/UriMediaSourceTests.cs Adds unit tests for HttpHeaders and the new FromUri overload.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs Applies headers on Windows using AdaptiveMediaSource and a stream fallback.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.macios.cs Applies headers for iOS/macCatalyst via AVUrlAsset options.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs Applies headers on Android by configuring a DefaultHttpDataSource.Factory.
src/CommunityToolkit.Maui.MediaElement/Views/HttpRandomAccessStream.windows.cs New Windows stream implementation used for header-enabled URI fallback.
src/CommunityToolkit.Maui.MediaElement/MediaSource/UriMediaSource.shared.cs Adds the HttpHeaders property to UriMediaSource.
src/CommunityToolkit.Maui.MediaElement/MediaSource/MediaSource.shared.cs Adds FromUri(Uri?, IDictionary<string,string>?) overload.
samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs Adds logic to capture/apply custom headers in the sample.
samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml Adds UI controls for entering custom headers in the sample.

@Kaaybi Kaaybi requested a review from TheCodeTraveler March 21, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants