Blank page/white screen when navigating back from a "Video page"

Topics: Windows 8 Xaml
Aug 21, 2013 at 5:08 PM
I experience a very strange issue which seems to happen at random.

Let's assume I've got a page with a button. If i click the button another page opens. The only content of this new page is a back button and the MediaPlayer. The MediaPlayer starts playing a video via internet (progressive download).

When I click on the back button while the video is streaming I sometimes (3 times out of 2) end up at a white screen. After some random time (~ 10 secons) the content shows up. But if I tap on the screen while I experience the white screen, the previous page shows immediately.

Any ideas how to avoid this annoying bug?
What I've tried is to set the Source of my MediaElement to null in my OnNavigatedFrom method. Didn't help.

Any Ideas?
Coordinator
Aug 22, 2013 at 12:58 AM
I'm not sure what would cause the symptoms you are seeing but one thing to check is to make sure you are calling MediaPlayer.Dispose() instead of setting Source = null. Disposing the MediaPlayer will internally set Source = null and do many other things to ensure everything is cleaned up and there are no memory leaks.
Aug 22, 2013 at 6:54 AM
Thanks for your input, this seems to work if I only use the back button to navigate back.

But I want to support another case where I subscribe to the PlayerStateChanged event. If the NewState equals "Ending", I also want to go back.

These are the methods, that are relevant:
protected override void GoBack(object sender, RoutedEventArgs e)
        {
            VideoPlayer.PlayerStateChanged -= StratosVideo_PlayerStateChanged;

            if (VideoPlayer.Source != null)
            {
                VideoPlayer.Dispose();
            }

            base.GoBack(sender, e);
        }

        private void StratosVideo_PlayerStateChanged(object sender, RoutedPropertyChangedEventArgs<Microsoft.PlayerFramework.PlayerState> e)
        {
            if (e.NewValue == Microsoft.PlayerFramework.PlayerState.Ending)
            {
                VideoPlayer.PlayerStateChanged -= StratosVideo_PlayerStateChanged;
                VideoPlayer.Dispose();
                this.GoBack(VideoPlayer, new RoutedEventArgs());
            }
        }
I now end up all the time with the white page when the video is ending, but only sometimes if I click the back button. I am confused and frustrated...
Aug 26, 2013 at 6:15 AM
Let me add that this issue only displays on a touch-display with a SSD. It doesn't happen on my developer PC with no touch monitor or SSD.
A solution for this would be really great.
Coordinator
Aug 30, 2013 at 10:40 PM
Interesting about the touch and SSD only. I'm not sure why that would be related.

Can you please try using the MediaEnded event instead? This event is the last thing that occurs when the media plays to the very end.

If this still doesn't work I have 1 crazy thing to try as a last ditch effort...
Try both disposing and navigating back from a dispatcher callback.
For example:
void player_MediaEnded(object sender, MediaPlayerActionEventArgs e)
{
    Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
        player.Dispose();
        Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            this.GoBack();
        });
    });
}
The idea is that this will give the app time to finish what it was doing before you tell it to do something new.

You shouldn't need this but it could be useful to tell us more about the origin of the issue and unblock you in the meantime.
Nov 13, 2013 at 1:04 PM
Edited Nov 13, 2013 at 2:18 PM
I am quite desperate because this issue is still happening. I've tried your suggestion but without any positive result.
I might build a demo application that shows the bug and will film and upload it.

Edit: I've found that it is not 100 % related to touch monitors and ssd only. Happens on my desktop-pc as well sometimes.
Edit2: I can also upload a demo-App that shows the bug if needed.