How to reset MediaPlayerElement?

Hong 1,121 Reputation points
2021-08-11T03:30:22.053+00:00

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"
                Stretch="UniformToFill"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"/>
</Grid>

The following C# code initializes and starts mpeVideo:

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

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