Maui
Maui copied to clipboard
Fix MediaElement Layout for Android
- Bug fix
Description of Change
The primary changes to the MauiMediaElement
class involve a significant refactoring to enhance layout management and simplify the handling of fullscreen mode for the media player. The key modifications include transitioning to a RelativeLayout
for better flexibility in positioning the StyledPlayerView
, removing explicit player size management in favor of relying on layout parameters, and streamlining the process for entering and exiting fullscreen mode. These adjustments lead to a more readable and maintainable codebase, with improved centering and sizing of the player view.
Summary of Changes:
-
Refactoring to Use RelativeLayout: Transitioned the layout management of the
StyledPlayerView
from aCoordinatorLayout
to aRelativeLayout
for improved flexibility in positioning and sizing. This change allows for easier adjustments and better control over the player view's layout within the media element.-
Code Change: Refactored
MauiMediaElement
to incorporateRelativeLayout
.
-
Code Change: Refactored
-
Removal of Player Size Management: Eliminated the explicit management of the player's height and width variables, relying instead on the layout parameters of the
RelativeLayout
andStyledPlayerView
for size adjustments. This simplification removes unnecessary code and leverages the layout system for resizing.-
Code Change: Removed
playerHeight
andplayerWidth
variables and related size management code.
-
Code Change: Removed
-
Adjustments for Fullscreen Mode: Simplified the handling of fullscreen mode by adding the player view directly to the window's decor view in fullscreen, and leveraging the
RelativeLayout
for re-adding the player view when exiting fullscreen. This approach minimizes the need for manual layout parameter adjustments.-
Code Change: Updated fullscreen mode handling to use window's decor view and
RelativeLayout
.
-
Code Change: Updated fullscreen mode handling to use window's decor view and
-
Simplification of Layout Management: By using a
RelativeLayout
, the process of adding and removing the player view during fullscreen transitions has been streamlined, making the code more readable and the transitions smoother.- Code Change: Simplified layout management code for fullscreen transitions.
-
Enhanced Centering of Player View: Configured the
RelativeLayout
with layout parameters that ensure theStyledPlayerView
is centered within theMauiMediaElement
, particularly in fullscreen mode, by setting the gravity toGravityFlags.Center
.-
Code Change: Set
RelativeLayout
gravity to center theStyledPlayerView
.
-
Code Change: Set
These changes collectively enhance the layout management of the media player, making the codebase more maintainable and the player's behavior more predictable and consistent, especially in terms of handling fullscreen mode and player view positioning.
Linked Issues
- Fixes #1872
PR Checklist
- [x] Has a linked Issue, and the Issue has been
approved
(bug) orChampioned
(feature/proposal) - [ ] Has tests (if omitted, state reason in description)
- [ ] Has samples (if omitted, state reason in description)
- [x] Rebased on top of
main
at time of PR - [x] Changes adhere to coding standard
- [ ] Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls
Additional information
Fixes previous PR that I put out. My bad!
Sample Android 34.0
https://github.com/CommunityToolkit/Maui/assets/4167863/87ae1a01-da0e-433c-ba64-381d337f85ff
Sample Android 26.0
https://github.com/CommunityToolkit/Maui/assets/4167863/062285a7-1524-47af-a5e7-a13140272ee6