I’m developing a Windows 8 Windows Store app (XAML/C#) in which I have a MediaElement control. The MediaElement control takes as a source either a Uri or a IRandomAccessStream.
In my case I have as input a URI pointing to a custom encoded resource (and the stream is endless, so I need to be able to read it whilst it’s downloading).
What I’d like to do is set the source of my MediaPlayer to my url, let the player handle the download, yet be called whenever it needs to read something so I can decode it on the fly.
In Silverlight, a MediaStreamSource would seem to be the way to go but it does not exist in WinRT (a light implementation sample does exist though).
What would be the best way to set that up?
Here’s the solution:
I started from Microsoft’s “MediaStreamSource media extension sample” and then implemented my own MediaStreamSource class in C#.
Yet, using a custom media stream source, I could not reuse the existing download mechanism so I created my own based on WinRT’s HttpClient class which worked great.
Final recipe is: