How to make UWP MediaElement to be loop mode when casting to a TV?
Tom JD1 Xue
21
Reputation points
I find that when using UWP MediaElement
(component name: video), it works well to be in loop mode when set as below:
video.IsLooping = true; // method 1
video.MediaEnded -= Video_MediaEnded;
video.MediaEnded += Video_MediaEnded; // method 2
private void Video_MediaEnded(object sender, RoutedEventArgs e)
{
video.Position = new TimeSpan(0, 0, 1);
video.Play();
}
But when casting the source to a smart TV (DLNA), then the loop mode doesn't work at all.
private CastingConnection connection;
//Create a new casting connection to the device that's been selected
connection = (CastingDevice)castingDevicesList.SelectedItem).CreateCastingConnection();
//Register for events
connection.ErrorOccurred += Connection_ErrorOccurred;
connection.StateChanged += Connection_StateChanged;
//Cast the loaded video to the selected casting device.
CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(video?.GetAsCastingSource());
I add a timer to set the video.Position
after a period of time, e.g. 10s, but has no impact at all.
private void Timer_Tick(object sender, object e)
{
if (video.Position >= TimeSpan.FromSeconds(10))
{
video.Position = new TimeSpan(0, 0, 1);
}
}
Any advise?
Sign in to answer