Search code examples
wpfsilverlightwindows-runtimelive-streaming

Guidance on How to stream m38u files to Metro style app (WinRT)


I'm getting m38u files to stream to a live TV channel. I've tried to open these files (as they are just list of files with the media type "MPEG/TS") and build a playlist out of them. But the transitions between the videos are bad, it pauses for a second or two before starting the next video.

I don't mind writing some server side code to solve this, but I need some guidance.


Solution

  • I don't know how you set up your playlist, but I guess this is how you do this:

    1. You have a MediaElement
    2. You subscribe to MediaElement.MediaEnded event
    3. You parse the m38u file and set the fist stream from the list to MediaElement.Source.
    4. You handle MediaElement.MediaEnded and each time you just set next stream from the list.

    Is it true? If yes, then your issue is a step 4. Each time when you set new source - MediaElement requests the stream from server and buffers at least something to start show the video. I guess this is why you see 3 seconds transitions. This is how you need to solve this:

    1. You have the same MediaElement.
    2. You need to implement on your own IRandomAccessStream interface, which can download a stream to memory (if it is not really huge) or on disk, or just buffer stream with specific buffer size.
    3. You parse m38u file, initialize first your IRandomAccessStream and set it as a source.
    4. When for example first video on 90% time of it - you need to initialize second stream from playlist, start to download it with IRandomAccessStream.
    5. When MediaElement.MediaEnded will be fired - you will have buffered stream, which is ready for MediaElement, so you just need to set stream from step 4.