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:
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.