title: Play MediaRecorder chunks in MediaSource HTML5 -- video frozen
body: <p>I have this simple code to get chunks of video stream and play them in MediaSource. I see video, but sometimes it stops. It may work for few seconds or for few minutes. But finally it stops at some moment. chrome://media-internals/ shows no errors.</p>
  
  <p>What is wrong here?</p>
  
  <pre><code>    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
  var mediaSource = new MediaSource();
  var constraints = {
      "audio": true,
      "video": {
          "mandatory": {
              "minWidth": 320, "maxWidth": 320,
              "minHeight": 240, "maxHeight": 240
          }, "optional": []
      }
  };
  window.mediaSource = mediaSource;
  var sourceBuffer;
  var video = document.querySelector('#video');
  window.video = video;
  video.src = window.URL.createObjectURL(mediaSource);
  mediaSource.addEventListener('sourceopen', function (e) {
      console.log("sourceopen");
      sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
      window.sourceBuffer = sourceBuffer;
  }, false);
  mediaSource.addEventListener('error', function (e) {
      console.log("error", e)
  }, false);
  var stack = [];
  
  video.play();
  navigator.getUserMedia(constraints, function (stream) {
      console.log("stream", stream);
      mediaRecorder = new MediaRecorder(stream);
      mediaRecorder.ondataavailable = function (e) {
          var reader = new FileReader();
          reader.addEventListener("loadend", function () {
              var arr = new Uint8Array(reader.result);
              sourceBuffer.appendBuffer(arr);
          });
          reader.readAsArrayBuffer(e.data);
      };
      mediaRecorder.start(100);
  }, function (e) {
      console.log(e)
  });
  </code></pre>
  
  <p>Here is JSFIDDLE which is going to try to do it:
      <a href="https://jsfiddle.net/stivyakovenko/fkt89cLu/6/" rel="noreferrer">https://jsfiddle.net/stivyakovenko/fkt89cLu/6/</a>
  I am using Chrome as my main target.</p>