none
Streaming video of unknown filesize

    General discussion

  • Here's the basic scenario:

    1. MediaElement is playing a video from a webserver

    2. The webserver is transparently using ffmpeg to encode the video in a way that MediaElement can play it

    3. Because it's being encoded the size of the file is unknown and it can take a while to receive the entire video

    The video works; MediaElement starts playing and all is well.

    However after 100 seconds the connection to the webserver times out and once the buffered video is played out the video stops playing.

    I've been trying to fix this problem a few ways but have yet to find a solution that works; I'm hoping you guys will be able to help.

    1. Use WebClient with MediaElement.SetSource to play the video

    Doesn't work because WebClient tries to download the entire video first and is subject to the 100 seconds timeout.

    2. Use HttpWebRequest with MediaElement.SetSource to play the video

    I really thought this would work but because the ResponseStream doesn't support seeking MediaElement throws a DRM exception.

    3. Change the timeout of WebRequests for video

    If there's a way to do this I have yet to find it.

    4. Write a custom HTTP stream and give that to MediaElement.SetSource

    This one works... kind of. Since the size of the file is unknown you have to return -1 or something similar to fool the MediaElement. Everything goes fine until MediaElement reads the end of the file at which point it throws the MediaFailed event and stops playback immediately - if I could get this method to continue playing until the buffer is empty I'd be happy.

    So, Silverlight people, how do I solve this problem?

    Monday, July 18, 2011 12:46 AM

All replies