How to update MediaPlayerElement's buffer in realtime?

后端 未结 1 1943
我寻月下人不归
我寻月下人不归 2021-01-26 18:35

I\'m creating Twitch player using MediaPlayerElement and I want to update MediaPlayerElement\'s buffer in real-time but I don\'t know how.

I tried to do it like this:

相关标签:
1条回答
  • 2021-01-26 19:05

    I figured this out. I have to use MseStreamSource.

    First I need to create MseStreamSource with event like this:

    streamSource = new MseStreamSource();
    streamSource.Opened += (_, __) =>
    {
        if (buffer is null)
        {
            // it will create buffer where I can write data
            buffer = streamSource.AddSourceBuffer("video/MP2T");
            buffer.Mode = MseAppendMode.Sequence;
        }
    };
    

    Then set the source:

    StreamMediaPlayer.Source = MediaSource.CreateFromMseStreamSource(streamSource);
    

    And if I want to add video I have to do it like this:

    buffer.AppendBuffer(reader.ReadBytes(20 * 1024 * 1024).AsBuffer());
    

    I have to make sure that buffer is not updating. This information provides IsUpdating property.

    0 讨论(0)
提交回复
热议问题