How to make UWP MediaElement to be loop mode when casting to a TV?

Tom JD1 Xue 21 Reputation points
2024-06-28T08:17:01.82+00:00

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?

Universal Windows Platform (UWP)
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,784 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,012 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.