-
Notifications
You must be signed in to change notification settings - Fork 437
Update Media Element to use Media3 #2076
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Updated `CommunityToolkit.Maui.MediaElement.csproj` to replace `Xam.Plugins.Android.ExoPlayer` with `Xamarin.AndroidX.Media3` packages. In `MediaControlsService.android.cs`, updated drawable resources for media control actions to new icons. Replaced `StyledPlayerView` with `PlayerView` in `MauiMediaElement.android.cs`. Refactored `MediaManager.android.cs` to use `AndroidX.Media3` classes and interfaces, updating method signatures and interface implementations. Updated `MediaManager.shared.cs` to use `AndroidX.Media3.ExoPlayer.IExoPlayer` for Android. Aligned methods and properties with the new Media3 API, including playback state handling, error handling, and media session management. Refactored `OnPlaybackStateChanged` and `OnPlayerStateChanged` methods to handle new playback state values. Modified `InitializeMediaSession` to comment out `MediaSessionConnector` and adjust media session setup. Ensured compatibility with the new Media3 library across various methods.
Updated `CommunityToolkit.Maui.Camera.csproj` and `CommunityToolkit.Maui.MediaElement.csproj` to use newer versions of several Xamarin.AndroidX packages and added new package references. Refactored `MediaManager.android.cs`: - Removed unused imports and added new ones. - Replaced `MediaControllerCompat` and `MediaSessionCompat` with `MediaSession`. - Updated `OnPlaybackStateChanged` to use `PlaybackStateCompat` constants. - Removed `BroadcastUpdate` method and related calls. - Introduced `SetPlayerData` method for setting media metadata. - Removed `InitializeMediaSession` method and related calls. - Updated `StartService` to use the new `MediaSession`. - Removed `UIUpdateReceiver` class and related calls. - Updated method signatures to use new types from updated AndroidX libraries.
8 tasks
Removed AudioManager and related methods from MediaControlsService. Replaced Trace.WriteLine with Trace.TraceError for error logging. Removed OnSetupAudioServices method and its calls. Modified InitializeNotification to remove SetShowActionsInCompactView. Refactored OnSetContent and OnSetIntents methods. Added UIUpdateReceiver class to handle updates from MediaControlsService. Registered and unregistered UIUpdateReceiver in MediaManager. Added BroadcastUpdate methods for play and pause actions. Updated SetPlayerData to return MediaItem.Builder. Aligned method signatures with new MediaItem.Builder approach. Handled ACTION_PLAY, ACTION_PAUSE, ACTION_FASTFORWARD, and ACTION_REWIND in UIUpdateReceiver. Updated method names and parameters to match AndroidX Media3 conventions. Removed redundant or obsolete code and comments.
Updated `CommunityToolkit.Maui.Camera.csproj` and `CommunityToolkit.Maui.MediaElement.csproj`: - Removed `Xamarin.AndroidX.Lifecycle.LiveData`. - Downgraded several `Xamarin.AndroidX.Lifecycle` packages from `2.8.4` to `2.8.3.1`. - Downgraded `Xamarin.AndroidX.Activity.Ktx` from `1.9.1` to `1.9.0.4`. - Corrected `Xamarin.AndroidX.Media3.Ui` to `Xamarin.AndroidX.Media3.UI`. Enhanced `MediaManager.android.cs`: - Added `mediaSession` field to `MediaManager` class. - Updated `SetPlayerData` to set media ID using `mediaItem.SetMediaId(url)`. - Updated method signatures to use fully qualified names for `global::AndroidX.Media3.Common` types.
Refactored MediaManager.android.cs for improved readability and maintainability. Updated package references in CommunityToolkit.Maui.MediaElement.csproj, including the removal of Xamarin.AndroidX.Media3.Transformer and addition of new ExoPlayer packages. Enhanced method implementations and ensured compatibility with updated packages.
ne0rrmatrix
commented
Aug 2, 2024
Refactored `PlatformPause`, `PlatformSeek`, `PlatformStop`, and `PlatformUpdateSource` methods to streamline code and reduce potential issues: - Removed TODO comment in `PlatformPause`. - Simplified `PlatformSeek` by removing listener management and async handling. - Changed `PlatformStop` to a synchronous method, ensuring proper player stop without async seek. - Updated `PlatformUpdateSource` to set media items directly without modifying the listener.
Updated .NET to `net8.0` and Maui to `8.0.70` in `Directory.Build.props`. Removed old `Xamarin.AndroidX` packages and added `Xamarin.AndroidX.Collection.Jvm` and `Xamarin.AndroidX.Activity.Ktx` in `CommunityToolkit.Maui.MediaElement.csproj`. Introduced constants for playback states (`sTATE_IDLE`, `sTATE_BUFFERING`, `sTATE_READY`, `sTATE_ENDED`) and replaced `PlaybackStateCompat.StatePlaying` with `sTATE_READY` in `MediaManager.android.cs`. Added `Player.SetHandleAudioBecomingNoisy(true)` for handling audio interruptions and a `UIUpdateReceiver` for UI updates based on player state changes. Improved error handling in `PlatformSeek` method to avoid exceptions and ensure execution on the calling thread. Initialized `MediaItem.Builder` in `SetPlayerData` method. Updated `PlatformUpdateAspect` and `PlatformUpdateShouldLoopPlayback` methods to set properties based on `MediaElement` attributes.
* Modified `PlatformStop` to reset media position to start (0) and explicitly set `MediaElement.Position` to `TimeSpan.Zero`. * Added `MediaSession` release and disposal.
…at is compatible.
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.
Copilot reviewed 6 out of 16 changed files in this pull request and generated no comments.
Files not reviewed (10)
- samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCarouselViewPage.xaml: Language not supported
- samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementCollectionViewPage.xaml: Language not supported
- samples/CommunityToolkit.Maui.Sample/Platforms/Android/AndroidManifest.xml: Language not supported
- src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj: Language not supported
- src/CommunityToolkit.Maui.MediaElement/Primitives/AndroidMediaPermissions.android.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.android.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.MediaElement/Primitives/Metadata.macios.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.MediaElement/Primitives/Metadata.windows.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.android.cs: Evaluated as low risk
VladislavAntonyuk
previously approved these changes
Jan 10, 2025
src/CommunityToolkit.Maui.MediaElement/Services/SafeFireAndForgetExtensions.shared.cs
Show resolved
Hide resolved
TheCodeTraveler
previously approved these changes
Jan 14, 2025
TheCodeTraveler
approved these changes
Jan 14, 2025
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
breaking change
This label is used for PRs that include a breaking change
📽️ MediaElement
Issue/PR that has to do with MediaElement
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
Port Media Element to use Media 3 Binding from Xamarin AndroidX team. This will allow us to stop using deprecated methods and classes and move forward with adding new features to this media player.
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information
This is ready for testing and I encourage ppl to test and report any issues below. It is not yet ready for dotnet 9.x and will be updated as soon as toolkit main is updated to add support.