Problem streaming video using media source extensions

Wolf-Kun

I seem to have a very strange problem. I am trying to play a video which is being streamed live using a web browser. For this, I am looking at the MediaSource object. I have got it in a way so that the video is taken from a server in chunks to be played. The problem is that the first chunk plays correctly then playback stops.

To make this even more strange, if I put the computer to sleep after starting streaming, then wake it up andthe video will play as expected.

Some Notes:

  1. I am currently using chrome.
  2. I have tried both of them ,with and without calling MediaSource's endOfStream.

    var VF = 'video/webm; codecs="vp8,opus"';
    var FC = 0;
    alert(MediaSource.isTypeSupported(VF));
    
    var url = window.URL || window.webkitURL;
    var VSRC = new MediaSource();
    var VURL = URL.createObjectURL(VSRC);
    var bgi, idx = 1;
    var str, rec, dat = [], datb, brl;
    var sbx;
    
    //connect the mediasource to the <video> elment first.
    vid2.src = VURL;
    
    VSRC.addEventListener("sourceopen", function () {
        // alert(VSRC.readyState);
        //Setup the source only once.
        if (VSRC.sourceBuffers.length == 0) {
            var sb = VSRC.addSourceBuffer(VF);
            sb.mode = 'sequence';
            sb.addEventListener("updateend", function () {
                VSRC.endOfStream();
            });
            sbx = sb;
        }
    });
    
    
    //This function will be called each time we get more chunks from the stream.
    dataavailable = function (e) {
                //video is appended to the sourcebuffer, but does not play in video element
                //Unless the computer is put to sleep then awaken!?
                sbx.appendBuffer(e.result);
                FC += 1;
                //These checks behave as expected.
                len.innerHTML = "" + sbx.buffered.length + "|" + VSRC.duration;
                CTS.innerHTML = FC;
    };
    
user1390208

You are making two big mistakes:

  1. You can only call sbx.appendBuffer when sbx.updating property is false, otherwise appendBuffer will fail. So what you need to do in reality is have a queue of chunks, and add a chunk to the queue if sbx.updating is true:

    if (sbx.updating || segmentsQueue.length > 0)
        segmentsQueue.push(e.result);
    else
        sbx.appendBuffer(e.result);
    
  2. Your code explicitly says to stop playing after the very first chunk:

    sb.addEventListener("updateend", function () {
        VSRC.endOfStream();
            });
    

    Here is what you really need to do:

    sb.addEventListener("updateend", function () {
        if (!sbx.updating && segmentsQueue.length > 0) {
            sbx.appendBuffer(segmentsQueue.shift());
        }
    });
    

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Comparing Media Source Extensions (MSE) with WebRTC

分類Dev

Media Source Extensions(MSE)とWebRTCの比較

分類Dev

Media Source Extensions(MSE)とWebRTCの比較

分類Dev

モバイルの最初のフレームでミュートおよび自動再生がフリーズするHLS / Media Source Extensions <video>

分類Dev

DIY: Video Streaming Server

分類Dev

Live video streaming in 2017

分類Dev

RMTP video streaming in Android

分類Dev

Azure media streaming locators expiry

分類Dev

Hls video streaming on iOS/Safari

分類Dev

media streaming: when packaging take place

分類Dev

FabricJS Problem with clipPath on a video

分類Dev

Streaming frames from the screen, generating a video

分類Dev

Adobe Source Code Pro has two extensions?

分類Dev

Adobe Source Code Pro has two extensions?

分類Dev

Using AVPlayer for streaming is slow

分類Dev

Live streaming using FFMPEG

分類Dev

How to capture just the audio or video while streaming a video from a URL?

分類Dev

HTML5 video media fragments with Javascript

分類Dev

DOMException: Could not start video source

分類Dev

<video src = ""> </ video>と<video> <source> </ source> </ video>の違いは?

分類Dev

Google Cast Media Player Library - for streaming from Local Device

分類Dev

Using VSCode Extensions in Visual Studio

分類Dev

Using `find` for multiple file extensions

分類Dev

Android - m3u8 video streaming

分類Dev

How to embed streaming Video (rtmp protocol) in HTML web page?

分類Dev

If I'm streaming video: I'm the server or the client?

分類Dev

On Vimeo, does it make sense to use "HTTP Live Streaming" video file link if your video isn't live streaming?

分類Dev

Using Heroku for Django Media Files

分類Dev

iframe embed video with php variable as source not working

Related 関連記事

  1. 1

    Comparing Media Source Extensions (MSE) with WebRTC

  2. 2

    Media Source Extensions(MSE)とWebRTCの比較

  3. 3

    Media Source Extensions(MSE)とWebRTCの比較

  4. 4

    モバイルの最初のフレームでミュートおよび自動再生がフリーズするHLS / Media Source Extensions <video>

  5. 5

    DIY: Video Streaming Server

  6. 6

    Live video streaming in 2017

  7. 7

    RMTP video streaming in Android

  8. 8

    Azure media streaming locators expiry

  9. 9

    Hls video streaming on iOS/Safari

  10. 10

    media streaming: when packaging take place

  11. 11

    FabricJS Problem with clipPath on a video

  12. 12

    Streaming frames from the screen, generating a video

  13. 13

    Adobe Source Code Pro has two extensions?

  14. 14

    Adobe Source Code Pro has two extensions?

  15. 15

    Using AVPlayer for streaming is slow

  16. 16

    Live streaming using FFMPEG

  17. 17

    How to capture just the audio or video while streaming a video from a URL?

  18. 18

    HTML5 video media fragments with Javascript

  19. 19

    DOMException: Could not start video source

  20. 20

    <video src = ""> </ video>と<video> <source> </ source> </ video>の違いは?

  21. 21

    Google Cast Media Player Library - for streaming from Local Device

  22. 22

    Using VSCode Extensions in Visual Studio

  23. 23

    Using `find` for multiple file extensions

  24. 24

    Android - m3u8 video streaming

  25. 25

    How to embed streaming Video (rtmp protocol) in HTML web page?

  26. 26

    If I'm streaming video: I'm the server or the client?

  27. 27

    On Vimeo, does it make sense to use "HTTP Live Streaming" video file link if your video isn't live streaming?

  28. 28

    Using Heroku for Django Media Files

  29. 29

    iframe embed video with php variable as source not working

ホットタグ

アーカイブ