I am trying to assign a HLS stream to a MediaElement
and then play it immediately but I'm failing to do so.
It's an UWP application (Windows 10).
Uri hlsUri = new Uri("http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8");
AdaptiveMediaSourceCreationResult hlsSource = await AdaptiveMediaSource.CreateFromUriAsync(hlsUri);
if (hlsSource .Status == AdaptiveMediaSourceCreationStatus.Success)
{
videoPlayer.SetMediaStreamSource(hlsSource .MediaSource);
videoPlayer.Play();
}
For some reason this thing doesn't work. The StreamSource is set, but for some reason the Play()
is executed before that.
I tried to wrap the CreateFromUriAsync
method in a Task
, like suggested here, to wait for the result first, but I couldn't make it work.
It works with await Task.Delay(TimeSpan.FromMilliseconds(400));
, but that looks to me like a ticking timebomb. However, it leads me to believe, that my problem is somewhere in the async
method.