-
Notifications
You must be signed in to change notification settings - Fork 477
Add support for local files and package resources to MediaElement #2502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Updated `PlatformUpdateSource` to be asynchronous, re-implemented `SetPoster` method for robustness, and replaced `MetadataArtworkUrl` with `MetadataArtworkSource` across the project. - Replaced `MetadataArtworkUrl` with `MetadataArtworkSource` in `MediaElementPage.xaml` and related files. - Introduced `loadCustomMediaSource` constant and `saveDirectory` string in `MediaElementPage.xaml.cs`. - Updated `ChangeSourceClicked` method to handle new media source and artwork property. - Added file handling methods: `Savefile`, `GetFileName`, and `PickAndShow`. - Updated `IMediaElement` and `MediaElement` class to use `MetadataArtworkSource`. - Modified `SetMetadata` in `Metadata.macios.cs` for new artwork property. - Removed `Metadata` class from `Metadata.windows.cs`. - Enhanced `MediaManager.android.cs` to handle new artwork property and fetch image data. - Added `BlankByteArray` method and `PlaybackState` class in `MediaManager.android.cs`. - Made `PlatformUpdateSource` in `MediaManager.macios.cs` asynchronous, updated `Dispose` method. - Added `GetArtwork` struct for fetching artwork in `MediaManager.macios.cs`. - Updated `MediaManager.windows.cs` to handle new artwork property and added `ArtworkUrl` method. - Updated `MediaElementTests` for new artwork property.
Simplified `SetMetadata` in `Metadata.macios.cs` by removing a null check for `artwork` before checking if it is a `UIImage`. Cleaned up `Dispose` in `MediaManager.android.cs` by removing redundant empty lines. Streamlined `StopService` in `MediaManager.android.cs` by removing `HttpClient` usage and `GetBytesFromMetadataArtworkUrl` method. Updated `Dispose` in `MediaManager.macios.cs` to change `SetPoster` return type from `Task` to `ValueTask`. Refactored `UpdateMetadata` in `MediaManager.windows.cs` to handle different `MetadataArtworkSource` types explicitly and removed redundant `ArtworkUrl` method. Cleaned up `OnPlaybackSessionPlaybackStateChanged` in `MediaManager.windows.cs` by removing the now redundant `ArtworkUrl` method.
… into MetaDataSource
69936ec to
9347a3a
Compare
… into MetaDataSource
Added "Load from File" option to MediaElementPage for local file playback. Refactored metadata artwork handling for Android and Windows to support file, resource, and URI sources. Unified MediaItem metadata creation on Android and improved artwork path resolution on Windows. Removed obsolete Metadata.windows.cs and integrated its logic. Includes minor bug fixes and code cleanups.
Refactored GetSource in MediaManager.macios.cs to use a switch statement with pattern matching for improved readability and maintainability. Removed the unused LoadBitmapImageAsync helper from MediaManager.windows.cs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 16 comments.
src/CommunityToolkit.Maui.MediaElement/Primitives/Metadata.macios.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementTests.cs
Show resolved
Hide resolved
Introduce isAndroidForegroundServiceEnabled to track service state. Update CreatePlatformView to accept and set this flag. Ensure notifications and service startup only occur when the foreground service is enabled, preventing unnecessary operations.
Removed unnecessary trace message in UpdateNotifications; now the method returns silently if the notification service is not running. This reduces log noise and streamlines error handling.
Refactored PlatformUpdateSource to call MediaElement.MediaOpened() only when there is no PlayerError, and to update notifications only when the Android foreground service is enabled. This improves clarity and ensures notifications are updated independently of media errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 7 comments.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
Refactored file and memory stream usage to use 'using' statements for proper disposal. Replaced synchronous CopyTo with asynchronous CopyToAsync for non-blocking I/O. Removed redundant byte array conversions by returning the result directly.
- Change GetSource to internal and remove XML docs. - Wrap ResourceMediaSource file access in try-catch; log warning if not found. - Only set thumbnail/poster if stream and uri are valid. - Always update system media controls metadata. - Clean up and reorganize redundant updater code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 13 comments.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementTests.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementTests.cs
Show resolved
Hide resolved
…ows.cs Co-authored-by: Copilot <[email protected]>
…ows.cs Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 9 comments.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementTests.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.UnitTests/Views/MediaElement/MediaElementTests.cs
Show resolved
Hide resolved
src/CommunityToolkit.Maui.MediaElement/Primitives/Metadata.macios.cs
Outdated
Show resolved
Hide resolved
- Add foreground service enabled check to Android StopService - Make GetMauiAssetBytes cancellable via CancellationToken - Log and handle missing/empty sources in Windows media update - Always set DisplayUpdater.Type to Music in Windows metadata
GetArtworkFromMediasource and its helper methods now accept an optional CancellationToken parameter, enabling cancellation of asynchronous operations for improved responsiveness and resource management.
Co-authored-by: Copilot <[email protected]>
Renamed the MetadataArtworkUrl method and all its references to MetadataArtworkMediaSource to better reflect that it operates on a MediaSource, not just a URL. This improves code clarity and intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs
Outdated
Show resolved
Hide resolved
Refactored MetadataArtworkMediaSource to use a switch statement for improved readability and maintainability. Updated CreateMediaItem in MediaManager.android.cs to accept a CancellationToken, enabling cancellation during asynchronous artwork retrieval.
[Proposal] Add support for local files and package resources to MediaElement #2151
Description of Change
Add support for file and resource file types to
MediaElement.MetadataArtworkSource. This will allow developers to set artwork usingMediaSourceclass.Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
Summary
Add support for local files and package resources as a source for
MediaElement.MetadataArtworkUrl. This will add the missing support for all types of files on all device for artwork images.Motivation
Allow developer more options to add images from more locations to use as artwork for player.
Detailed Design
API Design:
Usage Syntax
XAML:
Code Behind: