I have a Windows Store app (C#/XAML) which communicates with a REST service. At some point, I need to play a video stream provided by this service.
If I just assign the stream URI to the MediaElement.Source
property, it doesn't work, because the request needs to be authenticated. I need to customize the request sent by the MediaElement
control in order to add cookies, credentials and some other custom headers, but I can't find any method or property to do this.
How can I do it? Is it even possible?
OK, I got it working. Basically, the solution has 2 parts:
IRandomAccessStream
that implementsSeek
by making another request to the server, using theRange
header to specify which part of the stream I need.Here's the
RandomAccessStream
implementation:It can be used like this:
The user can seek to an arbitrary position in the video, and the stream will issue another request to get the stream at the specified position.
It's still more complex than I think it should be, but it works...
Note that the server must support the
Range
header in requests, and must issue theContent-Length
header in the initial response.