Add stream media source#3181
Conversation
There was a problem hiding this comment.
Pull request overview
This PR primarily adds Stream-backed playback to CommunityToolkit.Maui.MediaElement via a new StreamMediaSource, with platform implementations for Windows/Android/iOS(+macOS) and an explicit “not supported” path on Tizen. It also includes several related refactors and fixes across Popup/StateContainer, source-generator infrastructure, analyzers, tests, CI, and the sample app.
Changes:
- Add
StreamMediaSource+ platform-specific playback wiring (WindowsCreateFromStream, Android ExoPlayerIDataSource, iOS/macOSAVAssetResourceLoader). - Introduce Android MediaElement foreground-service configuration plumbing (options, generator/test projects) and update initialization call sites.
- Assorted toolkit fixes/refactors (Popup close edge-cases, StateContainer defaults/validation, AppThemeResource lookup) with corresponding unit tests.
Reviewed changes
Copilot reviewed 117 out of 126 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | Refines popup close edge-case detection and default-value converters. |
| src/CommunityToolkit.Maui/Views/Popup/Popup.shared.cs | Adjusts popup defaults initialization and makes popup exceptions public/documented. |
| src/CommunityToolkit.Maui/Services/PopupService.shared.cs | Refactors popup content resolution to avoid extra DI constructions. |
| src/CommunityToolkit.Maui/Primitives/StateContainerDefaults.shared.cs | Removes shared static default StateViews instance. |
| src/CommunityToolkit.Maui/Primitives/BindablePropertySourceGeneratorPrimitives/BindablePropertyDiagnostics.shared.cs | Adds public diagnostic ID constants for generator attributes. |
| src/CommunityToolkit.Maui/Primitives/BindablePropertySourceGeneratorPrimitives/BindablePropertyAttribute.shared.shared.cs | Adds runtime BindablePropertyAttribute (experimental) for generator use. |
| src/CommunityToolkit.Maui/Primitives/BindablePropertySourceGeneratorPrimitives/AttachedBindablePropertyAttribute.shared.cs | Adds runtime AttachedBindablePropertyAttribute<T> (experimental) for generator use. |
| src/CommunityToolkit.Maui/Primitives/BindablePropertySourceGeneratorPrimitives/AccessModifier.shared.cs | Adds AccessModifier enum used by generators. |
| src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.shared.cs | Tweaks navigation bar default color creation. |
| src/CommunityToolkit.Maui/PlatformConfiguration/AndroidSpecific/NavigationBar.android.cs | Adds Android 35+ navigation bar overlay behavior and imports. |
| src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainerController.shared.cs | Moves to primary ctor, improves state lookup and error reporting. |
| src/CommunityToolkit.Maui/Layouts/StateContainer/StateContainer.shared.cs | Makes default StateViews a fresh list; enhances exception to support inner exception. |
| src/CommunityToolkit.Maui/Extensions/WeakReferenceExtensions.cs | Formatting-only adjustment. |
| src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs | Reworks property-name helper APIs (consolidates to IsOneOf). |
| src/CommunityToolkit.Maui/Extensions/AppThemeResourceExtension.shared.cs | Improves AppTheme resource lookup fallback (root resources / resource dictionaries). |
| src/CommunityToolkit.Maui/Converters/DateTimeOffsetConverter.shared.cs | Fixes offset handling and microseconds in DateTimeOffset conversions. |
| src/CommunityToolkit.Maui/Behaviors/Validators/MultiValidationBehavior.shared.cs | Whitespace/formatting adjustment. |
| src/CommunityToolkit.Maui.UnitTests/Views/Popup/PopupPageTests.cs | Adds tests for modal navigation stack edge-cases and blocked popup close behavior. |
| src/CommunityToolkit.Maui.UnitTests/Views/Popup/DefaultPopupSettingsTests.cs | Expands coverage for popup defaults and service-based popup creation. |
| src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaSourceTests.cs | Adds test for stream media source factory method. |
| src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementOptionsTests.cs | Adds tests for MediaElement options defaults and foreground service behavior. |
| src/CommunityToolkit.Maui.UnitTests/Services/PopupServiceTests.cs | Adds tests ensuring DI viewmodel is constructed once for popup service scenarios. |
| src/CommunityToolkit.Maui.UnitTests/Resources/Styles/AppThemeResourceDictionary.xaml.cs | Adds a ResourceDictionary code-behind for AppThemeResource tests. |
| src/CommunityToolkit.Maui.UnitTests/Resources/Styles/AppThemeResourceDictionary.xaml | Adds test XAML ResourceDictionary for AppThemeResource lookups. |
| src/CommunityToolkit.Maui.UnitTests/Layouts/StateContainerTests.cs | Adds tests for duplicate state keys and per-layout default state views uniqueness. |
| src/CommunityToolkit.Maui.UnitTests/Layouts/DockLayoutTests.cs | Whitespace/formatting adjustment. |
| src/CommunityToolkit.Maui.UnitTests/Extensions/AppThemeResourceExtensionTests.cs | Adds regression test for AppThemeResource dictionary loading. |
| src/CommunityToolkit.Maui.UnitTests/Extensions/AppBuilderExtensionsTests.cs | Updates tests for new MediaElement init signature and foreground service rules. |
| src/CommunityToolkit.Maui.UnitTests/Converters/DateTimeOffsetConverterTests.cs | Updates tests for new offset/microsecond logic and adds DST-oriented cases. |
| src/CommunityToolkit.Maui.UnitTests/Behaviors/BaseBehaviorTest.cs | Whitespace/formatting adjustment. |
| src/CommunityToolkit.Maui.UnitTests/BaseViewTest.cs | Registers additional popups used in expanded tests. |
| src/CommunityToolkit.Maui.UnitTests/BaseTest.cs | Restores default MediaElement options (incl. foreground service flag) on dispose. |
| src/CommunityToolkit.Maui.SourceGenerators/Models/BindablePropertyRecords.cs | Formatting adjustments to generated XML doc string templates. |
| src/CommunityToolkit.Maui.SourceGenerators/Generators/TextColorToGenerator.cs | Filters to public MAUI control types; minor formatting fix. |
| src/CommunityToolkit.Maui.SourceGenerators/Generators/BindablePropertyAttributeSourceGenerator.cs | Stops emitting attribute via post-init; tweaks default binding mode literal handling. |
| src/CommunityToolkit.Maui.SourceGenerators/Generators/AttachedBindablePropertyAttributeSourceGenerator.cs | Stops emitting attribute/enum via post-init (now provided by runtime primitives). |
| src/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.SourceGenerators/BindablePropertyDiagnostic.cs | Removes generator-side diagnostic constant (moved to runtime primitives). |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/TextColorToGeneratorTests/TextColorToGeneratorTests.cs | Adds generator test ensuring internal MAUI types don’t receive emitted code. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/CommunityToolkit.Maui.SourceGenerators.UnitTests.csproj | Updates package versions and project references for new generator setup. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/BindablePropertyAttributeSourceGeneratorTests/BindablePropertyAttributeSourceGenerator_IntegrationTests.cs | Updates expected output for binding mode literal changes. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/BindablePropertyAttributeSourceGeneratorTests/BaseBindablePropertyAttributeSourceGeneratorTest.cs | Removes expectation for post-init emitted attribute file. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/BaseTest.cs | Updates references to runtime primitives (attribute/enum) instead of Roslyn Accessibility. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/AttachedBindablePropertyAttributeSourceGeneratorTests/BaseAttachedBindablePropertyAttributeGeneratorTest.cs | Removes expectation for post-init emitted attribute/enum files. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/AttachedBindablePropertyAttributeSourceGeneratorTests/AttachedBindablePropertyAttributeSourceGenerator_ConstructorAttribute_CommonUsageTests.cs | Whitespace/formatting adjustment. |
| src/CommunityToolkit.Maui.SourceGenerators.UnitTests/AttachedBindablePropertyAttributeSourceGeneratorTests/AttachedBindablePropertyAttributeSourceGenerator_ClassAttribute_CommonUsageTests.cs | Whitespace/formatting adjustment. |
| src/CommunityToolkit.Maui.SourceGenerators.Benchmarks/Program.cs | Adds benchmark execution for Android MediaElement foreground-service configuration generator tests. |
| src/CommunityToolkit.Maui.SourceGenerators.Benchmarks/CommunityToolkit.Maui.SourceGenerators.Benchmarks.csproj | Adjusts project references for benchmark coverage. |
| src/CommunityToolkit.Maui.SourceGenerators.Benchmarks/AndroidMediaElementForegroundServiceConfigurationBenchmarks.cs | Adds benchmark wrapper over MediaElement foreground-service generator test suites. |
| src/CommunityToolkit.Maui.slnx | Adds MediaElement source generator projects and updates solution metadata. |
| src/CommunityToolkit.Maui.MediaElement/Views/StreamExtensions.windows.cs | Adds Windows stream MIME-type helper (currently generic default). |
| src/CommunityToolkit.Maui.MediaElement/Views/StreamAssetResourceLoader.macios.cs | Adds iOS/macOS AVAsset resource loader backed by a .NET Stream. |
| src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs | Wires stream source via WinMediaSource.CreateFromStream. |
| src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.tizen.cs | Throws NotSupportedException for stream sources on Tizen. |
| src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.macios.cs | Wires stream sources via AVUrlAsset + resource loader delegate; adds content-type sniffing. |
| src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs | Adds stream handling via custom data source; foreground service gating; lifecycle cleanup. |
| src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.android.cs | Fixes constructor availability/trim scenarios and updates Android namespace qualifiers. |
| src/CommunityToolkit.Maui.MediaElement/readme.txt | Updates usage to pass the new MediaElement initialization parameter. |
| src/CommunityToolkit.Maui.MediaElement/Platforms/Android/StreamDataSource.android.cs | Adds ExoPlayer IDataSource wrapper over .NET Stream. |
| src/CommunityToolkit.Maui.MediaElement/MediaSource/UriMediaSource.shared.cs | Replaces generator-backed property with explicit BindableProperty implementation. |
| src/CommunityToolkit.Maui.MediaElement/MediaSource/StreamMediaSource.shared.cs | Introduces new MediaSource type backed by a Stream (bindable property + operators). |
| src/CommunityToolkit.Maui.MediaElement/MediaSource/ResourceMediaSource.shared.cs | Replaces generator-backed property with explicit BindableProperty implementation. |
| src/CommunityToolkit.Maui.MediaElement/MediaSource/MediaSource.shared.cs | Adds MediaSource.FromStream(Stream) factory method. |
| src/CommunityToolkit.Maui.MediaElement/MediaSource/FileMediaSource.shared.cs | Replaces generator-backed property with explicit BindableProperty implementation. |
| src/CommunityToolkit.Maui.MediaElement/MediaElementOptions.shared.cs | Adds Android foreground service enable flag and update helper. |
| src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.android.cs | Passes foreground service enabled flag into platform view creation. |
| src/CommunityToolkit.Maui.MediaElement/Converters/MediaSourceConverter.shared.cs | Adds StreamMediaSource handling in converter output. |
| src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj | Packs MediaElement source generator analyzer; removes old generator reference. |
| src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs | Changes MediaElement initialization signature and applies foreground-service setting. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators/CommunityToolkit.Maui.MediaElement.SourceGenerators.csproj | Adds new MediaElement-specific source generator project. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/xunit.runner.json | Adds xUnit runner config for new generator unit test project. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/GlobalUsings.cs | Adds global usings for generator unit tests. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests.csproj | Adds MediaElement generator unit test project. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/BaseTest.cs | Adds generator testing base harness for MediaElement generator tests. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/AndroidMediaElementServiceConfigurationGeneratorTests/BaseAndroidMediaElementForegroundServiceConfigurationGeneratorTest.cs | Adds base test helper for foreground-service generator tests. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/AndroidMediaElementServiceConfigurationGeneratorTests/AndroidMediaElementForegroundServiceConfigurationGenerator_OutputTests.cs | Adds output/behavior tests for service configuration generator. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/AndroidMediaElementServiceConfigurationGeneratorTests/AndroidMediaElementForegroundServiceConfigurationGenerator_IntegrationTests.cs | Adds integration-style tests for service configuration generator. |
| src/CommunityToolkit.Maui.MediaElement.SourceGenerators.UnitTests/AndroidMediaElementServiceConfigurationGeneratorTests/AndroidMediaElementForegroundServiceConfigurationGenerator_EdgeCaseTests.cs | Adds edge-case tests for service configuration generator. |
| src/CommunityToolkit.Maui.MediaElement.Analyzers/Resources.resx | Updates resource file schema/contents. |
| src/CommunityToolkit.Maui.MediaElement.Analyzers/Resources.Designer.cs | Regenerates strongly-typed resources designer. |
| src/CommunityToolkit.Maui.MediaElement.Analyzers/CommunityToolkit.Maui.MediaElement.Analyzers.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes/CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.Core/Platform/StatusBar/StatusBar.android.cs | Adds Android 35+ overlay behavior and improves window selection logic. |
| src/CommunityToolkit.Maui.Core/Platform/KeyboardExtensions/KeyboardExtensions.shared.cs | Makes SoftKeyboardException public and documents it. |
| src/CommunityToolkit.Maui.Core/Extensions/WindowExtensions.android.cs | Updates window selection logic to prefer visible dialog windows. |
| src/CommunityToolkit.Maui.Core/Essentials/FolderPicker/FolderPickerImplementation.windows.cs | Temporarily comments SuggestedFolder usage pending Windows SDK support. |
| src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj | Updates WindowsAppSDK package version. |
| src/CommunityToolkit.Maui.Camera/CommunityToolkit.Maui.Camera.csproj | Removes old source generator reference block. |
| src/CommunityToolkit.Maui.Camera/CameraManager.windows.cs | Refactors initialization tracking and resets stream position after recording stop. |
| src/CommunityToolkit.Maui.Camera/CameraManager.shared.cs | Refactors initialization tracking fields and onLoaded callback storage. |
| src/CommunityToolkit.Maui.Camera.Analyzers/CommunityToolkit.Maui.Camera.Analyzers.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.Camera.Analyzers.CodeFixes/CommunityToolkit.Maui.Camera.Analyzers.CodeFixes.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.Analyzers/CommunityToolkit.Maui.Analyzers.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.Analyzers/AnalyzerReleases.Shipped.md | Formatting adjustments. |
| src/CommunityToolkit.Maui.Analyzers.UnitTests/UseCommunityToolkitMediaElementInitializationAnalyzerTests.cs | Updates analyzer unit test sources for new MediaElement init signature. |
| src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| src/CommunityToolkit.Maui.Analyzers.CodeFixes/CommunityToolkit.Maui.Analyzers.CodeFixes.csproj | Uses centralized $(CodeAnalysisVersion) for Roslyn packages. |
| samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ViewsGalleryViewModel.cs | Adds a new “MediaElement from Stream” entry to the gallery. |
| samples/CommunityToolkit.Maui.Sample/ViewModels/Views/MediaElement/MediaElementFromStreamViewModel.cs | Adds new ViewModel placeholder for the stream sample page. |
| samples/CommunityToolkit.Maui.Sample/ViewModels/Behaviors/StatusBarBehaviorViewModel.cs | Updates default slider values and reorganizes style/color properties. |
| samples/CommunityToolkit.Maui.Sample/Properties/launchSettings.json | Switches Windows launch profile from MsixPackage to Project. |
| samples/CommunityToolkit.Maui.Sample/Platforms/Android/SamsungBadgeProvider.cs | Adds fully-qualified Android URI usage. |
| samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml | Re-indents manifest and adds VIDEO_CAPTURE query intent. |
| samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs | Adds sample page demonstrating StreamMediaSource playback. |
| samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml | Adds UI for stream playback sample page. |
| samples/CommunityToolkit.Maui.Sample/Pages/Views/CameraView/CameraViewPage.xaml.cs | Adds Windows unpackaged microphone-permission handling and improves capture flow. |
| samples/CommunityToolkit.Maui.Sample/Pages/PlatformSpecific/NavigationBarPage.xaml | Adjusts layout and label formatting for navigation bar style selector. |
| samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml | Layout/formatting improvements for style selection UI. |
| samples/CommunityToolkit.Maui.Sample/MauiProgram.cs | Registers stream sample page/VM and updates MediaElement init call with new parameter. |
| samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj | Updates packages, analyzer refs, Windows packaging settings, and XAML compilation for new page. |
| samples/CommunityToolkit.Maui.Sample/AppShell.xaml.cs | Adds route mapping for stream sample page. |
| samples/CommunityToolkit.Maui.Sample.slnx | Adds MediaElement generator projects and adjusts deploy metadata. |
| Directory.Build.props | Adds CodeAnalysisVersion and updates MAUI package version / internals visibility. |
| .github/workflows/dotnet-build.yml | Builds new MediaElement generator project and runs its unit tests; bumps artifact action versions. |
| .github/workflows/benchmarks.yml | Bumps artifact action version. |
| .github/instructions/mobile-memory-leaks.instructions.md | Adds repo guidance on iOS/catalyst memory leak patterns. |
| .github/instructions/async.instructions.md | Adds repo guidance on async best practices. |
Files not reviewed (1)
- src/CommunityToolkit.Maui.MediaElement.Analyzers/Resources.Designer.cs: Language not supported
src/CommunityToolkit.Maui/Extensions/PropertyChangedEventArgsExtensions.shared.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaSourceTests.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/StreamAssetResourceLoader.macios.cs
Show resolved
Hide resolved
...les/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs
Outdated
Show resolved
Hide resolved
|
Thanks Matt! Could you rebase your branch against our |
Yeah sorry thought I'd done that...stand by |
5732b76 to
a1f72a4
Compare
|
@TheCodeTraveler I've done that now, I'll look at the copilot feedback next, but I think some of it is related to those earlier commits you mentioned. |
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaSourceTests.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/StreamAssetResourceLoader.macios.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/StreamAssetResourceLoader.macios.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.macios.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Platforms/Android/StreamDataSource.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
...les/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs
Show resolved
Hide resolved
samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/StreamAssetResourceLoader.macios.cs
Show resolved
Hide resolved
…e, and track stream position and gracefully fail the loading request on offset mismatch.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Platforms/Android/StreamDataSource.android.cs
Outdated
Show resolved
Hide resolved
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/ViewsGalleryViewModel.cs
Outdated
Show resolved
Hide resolved
...les/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs
Outdated
Show resolved
Hide resolved
...les/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs
Show resolved
Hide resolved
...les/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementFromStreamPage.xaml.cs
Outdated
Show resolved
Hide resolved
…eaned up some other potential bugs.
…ng in MediaManager.android.cs
…rs in StreamDataSource.android.cs
…leryViewModel.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…os.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
@TheCodeTraveler I've addressed feedback from Copilot and tidied up a couple of other things that were blocking the build. There are some failing tests in the builds, but I've noticed these are affecting a few other PRs as well. I've done a bit of digging and I think these are coming form the bindable property source generators. Happy to keep digging and see if I can fix them up here (or another PR) but wanted to check with you first whether you're ok with me doing that. |
|
Thanks Matt!! Sure, yea, if you can solve the randomly failing unit tests in a new PR, that'd be a HUGE help! Those have been a pain in my side for a long time. |
Description of Change
Adds StreamMediaSource support to MediaElement so media can be played directly from a .NET Stream.
This is intended for scenarios where media should remain in memory or within the app sandbox, rather than being written out to a file or fetched from an external URL. It enables workflows such as capturing or generating media in-memory and previewing it before persisting it.
The change adds a new MediaSource subtype and wires it through the existing MediaElement pipeline on supported platforms:
The API follows the existing MediaSource patterns, including a MediaSource.FromStream(Stream) factory method and direct use of StreamMediaSource.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)Note: Has a linked discussion, not issue, however was discussed and approved by @TheCodeTraveler, @ne0rrmatrix and @VladislavAntonyuk on the standup today (see: https://www.youtube.com/watch?v=gF1YSJyxAB8)
mainat time of PRAdditional information
What Was Added
Core Class
StreamMediaSource.shared.cs: NewMediaSourcesubclass that wraps a .NETStreamStreambindable propertyMediaSource.FromStream(Stream)FileMediaSource,UriMediaSource, andResourceMediaSourcePlatform-Specific Implementations
Windows (
MediaManager.windows.cs)WinMediaSource.CreateFromStream()withIRandomAccessStreamWindowsRuntimeStreamExtensions.AsRandomAccessStream()to convert .NET streams to Windows Runtime streamsStreamExtensions.windows.cs- ProvidesGetMimeType()extension methodAndroid (
MediaManager.android.cs)StreamDataSourceimplementing ExoPlayer'sIDataSourceinterfaceProgressiveMediaSourceStreamDataSource.android.cs- ContainsStreamDataSourceandStreamDataSourceFactoryclassesiOS/macOS (
MediaManager.macios.cs)AVAssetResourceLoaderDelegateto provide custom data sourcestream://media) and usesAVAssetResourceLoaderto intercept loading requestsStreamAssetResourceLoader.macios.cs- Custom delegate that feeds stream data toAVPlayerAVPlayerarchitectureTizen (
MediaManager.tizen.cs)NotSupportedExceptionwith helpful messageUsage Examples
Files Modified
New Files
MediaSource/StreamMediaSource.shared.cs- Core classPlatforms/Android/StreamDataSource.android.cs- Android implementationViews/StreamAssetResourceLoader.macios.cs- iOS/macOS implementationViews/StreamExtensions.windows.cs- Windows helper extensionsModified Files
MediaSource/MediaSource.shared.cs- AddedFromStream()factory methodViews/MediaManager.android.cs- Added stream support via custom DataSourceViews/MediaManager.windows.cs- Added stream support viaCreateFromStream()Views/MediaManager.macios.cs- Added stream support viaAVAssetResourceLoaderViews/MediaManager.tizen.cs- Added NotSupportedException for streamsConverters/MediaSourceConverter.shared.cs- AddedStreamMediaSourcecaseTechnical Details
Android Implementation
The Android implementation uses ExoPlayer's extensibility model:
StreamDataSourceimplementsIDataSourceinterfaceStreamDataSourceFactorycreates instances for ExoPlayerProgressiveMediaSource.FactoryiOS/macOS Implementation
The iOS/macOS implementation uses Apple's official extension mechanism:
AVUrlAssetwith custom URL schemeAVAssetResourceLoaderDelegateintercepts resource loading requestsAVAssetResourceLoadingDataRequestWindows Implementation
The Windows implementation uses built-in .NET stream conversion:
IRandomAccessStreamusingAsRandomAccessStream()WinMediaSource.CreateFromStream()APIConsiderations
Stream Lifecycle
MIME Type Detection
"application/octet-stream"by default"video/mp4"assumptionPerformance
Future Enhancements
StreamMediaSourcefor MIME type hint