Reputation: 2387
Context: WinRT, Universal Apps, XAML, C#
I am creating a video player application in which one of the requirements is that the video plays exclusively in fullscreen, and when the video returns from fullscreen, the video should be stopped and the user should be taken to a summary page. Currently I am using MediaElement.IsFullWindow and MediaElement.AreTransportControlsEnabled in order to play the video in fullscreen and it works perfectly well, when the video ends I grab the MediaEnded event and take the user back to the summary page, setting IsFullWindow to false and AreTransportControlsEnabled to false.
The only problem is that Transport Controls have a fullscreen button that takes the user back to the non-fullscreen layout and the video keeps on playing.
On most applications this would be great, but on this one, I need to stop the video when it happens.
Unfortunately, when this happens, IsFullWindow is not set to false, the SizeChanged event for the MediaElement is not fired and there seems to be no other notification that the user has decided to leave fullscreen mode.
So I am trapped in a situation in which I am unable to find out whether the video is truly playing in fullscreen or not.
If I pause the video and the user plays it again, since IsFullWindow is true, it will go back to fullscreen and if I let the video play to the end everything works fine and the user goes to the summary page.
Does anybody have any suggestions on how I may be able to detect this change in order to stop the video?
Upvotes: 2
Views: 830
Reputation: 1297
You can overcome this issue by binding, IFullWindow MediaElement property with "TwoWay" mode, and act accordingly to its value on set :)
Upvotes: 0
Reputation: 674
When changed IsFullWindow status fires SizeChanged of Window.Current instead of MediaElement. You just should attach to this event
Window.Current.SizeChanged += this.OnWindowSizeChanged;
and check IsFullWindow of MediaElement when it fired.
private void OnWindowSizeChanged(object sender, WindowSizeChangedEventArgs windowSizeChangedEventArgs)
{
if (!this.mediaElement.IsFullWindow)
{
}
else
{
}
}
Upvotes: 1
Reputation: 184
You may use a DispatcherTimer called every 100 ms, check the status of the IsFullWindow property, and if property value changes, fire an event or call your own function.
Upvotes: -1
Reputation: 2387
I ended up using the Microsoft Player Framework which gives me events and properties to control all I needed without having to write my own code and incur in design work for the video player control assets.
Upvotes: 0
Reputation: 9289
An alternative solution is not to use transport control provided by media element and create your own custom media controls .
See this MSDN link which explains how to create custom media transport controls
Upvotes: 1