captainserial
captainserial

Reputation: 57

UWP C# app that runs in fullscreen mode switches to windowed mode after viewing video fullscreen

I have an app that runs in fullscreen mode on a touchscreen kiosk. There is a MediaPlayerElement that plays videos from Youtube on a loop on my MainPage.

I want users to be able to switch to fullscreen playback for a video, then return to the MainPage. If I enable the TransportControls, fullscreen video playback works fine, but when exiting fullscreen the entire app switches to windowed mode.

Is there any way to change this behavior without subscribing to the SizeChanged event for the page, then switching back to fullscreen when I detect windowed mode?

Upvotes: 2

Views: 1057

Answers (1)

sramekpete
sramekpete

Reputation: 3208

You are looking for DependencyObject.RegisterPropertyChangedCallback method listening to changes on MediaPlayerElement.IsFullWindowProperty.

long token;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    token = mediaPlayer.RegisterPropertyChangedCallback(MediaPlayerElement.IsFullWindowProperty, OnMediaPlayerFullWindowChanged);
    base.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    mediaPlayer.UnregisterPropertyChangedCallback(MediaPlayerElement.IsFullWindowProperty, token);
}

Then you want to implement callback method that will take care of switching back to fullscreen.

private void OnMediaPlayerFullWindowChanged(DependencyObject sender, DependencyProperty dp)
{
    MediaPlayerElement mpe = (MediaPlayerElement)sender;

    if (mpe != null && dp == MediaPlayerElement.IsFullWindowProperty && !mpe.IsFullWindow)
    {
        ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
    }  
}

Related resource:

MediaPlayerElement Class example implementing RegisterPropertyChangedCallback

UWP Windows 10 App, Windows startup size and full screen

Upvotes: 4

Related Questions