CommunityToolkit / CommunityToolkit/Maui
[Proposal] API that allows developers to hook a media element event and know the full screen status.
- Dominant language
- C#
- Stars
- 2.7k
- Forks
- 500
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 7
Description
### Feature name
VideoPlayer_FullScreenStatusChanged
### Link to discussion
https://github.com/CommunityToolkit/Maui/discussions/1748#discussioncomment-9548965
### Progress tracker
- [x] Android Implementation
- [x] iOS Implementation
- [x] MacCatalyst Implementation
- [x] Windows Implementation
- [ ] Tizen Implementation
- [ ] Unit Tests
- [x] Samples
- [x] Documentation
### Summary
API that allows developers to hook a media element event and know the full screen status.
Is it full screen or normal ?
### Motivation
In Xamarin times, we already have something to control when the Full Screen status changed (first and third party) and now we have a very mature Media Element in MAUI is about time to start with this.
### Detailed Design
```cs
///
/// Backing store for the property.
///
public static readonly BindableProperty FullScreenProperty =
BindableProperty.Create(nameof(FullScreenState), typeof(MediaElementScreenState), typeof(MediaElement),
MediaElementScreenState.Default, propertyChanged: OnFullScreenPropertyChanged);
```
### Usage Syntax
```cs
public MediaElementPage(MediaElementViewModel viewModel, ILogger logger) : base(viewModel)
{
InitializeComponent();
MediaElement.FullScreenStateChanged += MediaElement_FullScreenStateChanged;
}
void MediaElement_FullScreenStateChanged(object? sender, FullScreenStateChangedEventArgs e) =>
logger.LogInformation("FullScreen State Changed. Old State: {PreviousState}, New State: {NewState}", e.PreviousState, e.NewState);
```
### Drawbacks
I don't see any reason to not do it :)
### Alternatives
Before I migrate to MAUI MediaElement I was using Xamarin with Xamarians/MediaPlayer [https://github.com/Xamarians/MediaPlayer] , looks simple enough from a use perspective:
```cs
public partial class SegnalesEnVivoPage : ContentPage
{
InitializeComponent();
BindingContext = new SegnalesEnVivoViewModel();
VideoPlayer.FullScreenStatusChanged += VideoPlayer_FullScreenStatusChanged;
}
private void VideoPlayer_FullScreenStatusChanged(object sender, bool value)
{
NavigationPage.SetHasNavigationBar(this, !value);
Shell.SetNavBarIsVisible(this, !value);
frmInformation.IsVisible = !value;
frmBackground.IsVisible = !value;
frmPlayer.Margin = value ? new Thickness(0, 0, 0, 0) : new Thickness(10, 20, 10, 10);
VideoPlayer.HeightRequest = value ? deviceScreenHeight : 240;
InvalidateMeasure();
}
}
```
### Unresolved Questions
Perhaps the above API is a good v1 if it works on all platforms?
And then we iterate on more functionality in later versions?
Contributor guide
Assessment
This issue has not been assessed yet.