7

I am trying to find out whether it is possible to play a video in a MediaElement from a stream which is still downloading, rather than waiting for it to finish? I have researched the topic pretty thoroughly, but found no definitive answer.

I am trying to implement playback on demand. I am currently playing the video by assigning the uri to the MediaElement's Source, and this works. I want to change this to play back by opening the uri in a Stream, and assigning the Stream to the MediaElement using SetSource.

I have written code which takes the uri, creates a WebClient, and uses OpenReadAsync to begin reading from it. I've set AllowReadStreamBuffering to false to allow me to get the stream from OpenReadComplete as soon as it's available (rather than waiting for it to finish downloading). As soon as I have a handle to the Stream, I assign it to the MediaElement and attempt playback.

This is currently resulting in a System.Exception: 2210 error. As I know the resource exists and is readable, I don't know whether it's my code that's wrong, or whether it's simply not possible for a MediaElement to play back from a stream that is incomplete.

If this is not possible using SetSource and a Stream, is it possible using SetSource and a MediaStreamSource class? I did look at MediaStreamSource for this task, but it seemed to require me to write code which parsed the incoming stream and extract a frame at a time from it, which sounded painful.

Cypher
  • 71
  • 3
  • 1
    This is possible, I'm doing this in several applications currently. If someone is still looking for an 'how-to', I could write a more detailed answer. – jv42 Nov 25 '11 at 09:29
  • @jv42: Hi, I'm trying to playback still-downloading stream in silverlight but so far without success. I tried to extend MemoryStream and lock access to read and wite methods (so as to allow to read subsequently downoaded bytes by MediaElement, and write data [continually received from a socket] always at the end of the stream). The stream plays back but only to the point in time that had already been downloaded upon starting playing. Could you please share with me the solution that you had mentioned ? – empi Jul 03 '12 at 13:07
  • Ah for that case... well, the best I've managed is to detect the end of the stream and restart playback from last position. This causes a small hitch, but allows continuous playback. – jv42 Jul 03 '12 at 14:11
  • @jv42 Would be very interested in a more detailed answer on how you solved this – Sami Rajala Feb 06 '13 at 12:35
  • @SamiRajala As I said above, the best I got is playing up to where it was downloaded on start of playback, not that good. – jv42 Feb 06 '13 at 12:53
  • It is more about the media host that you are using. For example, if your media source link is on IIS, it should be downloaded. But if you use streaming server(you can try it on Expression Encoder), mediaelement do not have to download all media file. Actually, smooth streaming is the best way to play video streams in different resolutions. – scetiner Jun 19 '13 at 13:50

0 Answers0