How to reset MediaPlayerElement?

Hong 1,121 Reputation points

An app can reuse a MediaPlayerElement in most cases but there is a problem with a certain type of video stream.
Here is the code in Xaml:

 <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
    <MediaPlayerElement  x:Name="mpeVideo"

The following C# code initializes and starts mpeVideo:

MpeVideo.Source = MediaSource.CreateFromMediaStreamSource(mediaStreamSourceVideo);
MpeVideo.MediaPlayer.RealTimePlayback = true;

If I call the initialization method with a different mediaStreamSourceVideo after stopping the previous one, it works fine in most cases, but fails with some. I can reliably reproduce this with an RTSP video stream. However, if the app exits the page and reenters the page, and runs the initialization again apparently with a new instance of MediaPlayerElement, everything will be fine.

Is there a way to reset MediaPlayerElement so that it will be like a new instance? MpeVideo.MediaPlayer.Dispose() does not work because the initialization will fail after its execution.

Universal Windows Platform (UWP)
{count} votes