Skip to content

Use Windows.UI.Xaml.Controls.MediaPlayerElement with Windows.Web.Http.HttpClient.

License

Notifications You must be signed in to change notification settings

kiewic/MediaPlayerElementWithHttpClient

Repository files navigation

MediaPlayerElementWithHttpClient

TL;DR

Use Windows.UI.Xaml.Controls.MediaPlayerElement with Windows.Web.Http.HttpClient.

Docs

MediaPlayerElement is a control to play audio and video in Windows Universal/Store apps.

However, when the audio or video is served from an internet server, using HttpClient is a better choice to handle the request because you can provide:

  • Authentication credentials.
  • Custom headers.
  • Etc.

The HttpRandomAccessStream class is a wrapper on top of HttpClient that can stream content from the internet and can be consumed as an IRandomAcessStream or IRandomAccessStreamWithContentType.

Example

MediaPlayerElement mediaPlayerElement = new MediaPlayerElement();

HttpClient client = new HttpClient();

// Add custom headers, credentials, etc.
client.DefaultRequestHeaders.Add("Foo", "Bar");

Uri uri = new Uri("http://video.ch9.ms/ch9/70cc/83e17e76-8be8-441b-b469-87cf0e6a70cc/ASPNETwithScottHunter_high.mp4");

HttpRandomAccessStream stream = await HttpRandomAccessStream.CreateAsync(client, uri);

mediaPlayerElement.SetMediaPlayer(new MediaPlayer());
mediaPlayerElement.Source = MediaSource.CreateFromStream(stream, stream.ContentType);

Note: The server must support HTTP Range headers.

Feedback

Please give it a try and provide feedback.

About

Use Windows.UI.Xaml.Controls.MediaPlayerElement with Windows.Web.Http.HttpClient.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages