hlovbeyond
hlovbeyond

Reputation: 49

How to Play a protected video using mediaElement or mediaPlayerElement

What's the proper way to play a video which requires authentication?

The video is hosted on a server which uses basic authentication, the credentials have to be passed on a cookie on the header.

I have tried AdaptiveMediaSource but I got an error that the server doesn't support the protocol.

I have tried this https://github.com/kiewic/MediaElementWithHttpClient/tree/master/MediaElementWithHttpClient but I got an error that Range is not supported.

Any help will be greatly appreciate it.

I'm targeting Windows 10 anniversary edition

Cheers H

Upvotes: 0

Views: 211

Answers (2)

kiewic
kiewic

Reputation: 16420

As noted by heroboy in this issue, the Range header request is not mandatory in the initial response, so you can try removing the following check from HttpRandomAccessStream.cs:

if (!response.Headers.ContainsKey("Accept-Ranges"))
{
    throw new Exception(String.Format(
        "HTTP server does not support range requests: {0}",
        "http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.5"));
}

But the server will still need to support range requests.

There is also a version of the sample for MediaPlayerElement.

Upvotes: 0

Sunteen Wu
Sunteen Wu

Reputation: 10627

I have replied your same case in MSDN.https://social.msdn.microsoft.com/Forums/windowsapps/en-US/dea09e8e-dd85-48dd-8edb-59ef150f442e/how-to-play-a-protected-video-using-mediaelement-or-mediaplayerelement?forum=wpdevelop

You can try to use WebView control to see if it can meet your requirements. The official sample: https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/XamlWebView

I have tried AdaptiveMediaSource but I got an error that the server doesn't support the protocol.

According to the official document, https://msdn.microsoft.com/en-us/windows/uwp/audio-video-camera/adaptive-streaming The Adaptive Streaming feature currently supports playback of Http Live Streaming (HLS) and Dynamic Streaming over HTTP (DASH) content. For a list of supported HLS protocol tags, see HLS tag support. If your server doesn't support these protocol you cannot use the Adaptive streaming feature.

I have tried this https://github.com/kiewic/MediaElementWithHttpClient/tree/master/MediaElementWithHttpClient but I got an error that Range is not supported.

Please see the Note in the Readme.md file of the demo. Note: The server must support HTTP Range headers. If your server doesn't support HTTP range headers you cannot directly use the demo.

Upvotes: 1

Related Questions