[remote-playback] Pull Request: Add a remoting buffer state attribute to RemotePlayback

takumif has just submitted a new pull request for https://github.com/w3c/remote-playback:

== Add a remoting buffer state attribute to RemotePlayback ==
This PR proposes to add a remoting buffer state attribute to RemotePlayback, which will indicate the remote buffer state when using MSE / media remoting mode (as opposed to media/URL flinging).

Here is sample code showing how RemotePlayback may interact with MSE using the new enum:
```javascript
const video = document.querySelector('#my-video');
const mediaSource = new MediaSource();
let sourceBuffer;
let isBufferingSegments = false;
mediaSource.addEventListener('sourceopen', onMediaSourceOpen);
video.src = window.URL.createObjectURL(mediaSource);
video.remote.addEventListener('remotingstatechanged', onRemotingStateChanged);

function onRemotingStateChanged() {
  switch (video.remote.remotingBufferState) {
    case 'insufficient-data':
    case 'enough-data':
      startBufferingSegments();
      break;
    case 'too-much-data':
    case 'not-remoting':
      stopBufferingSegments();
      break;
  }
}

async function onMediaSourceOpen() {
  sourceBuffer = mediaSource.addSourceBuffer('video/mp4; codecs="avc1.4d401f"');
  await startBufferingSegments();
  video.play();
}

async function startBufferingSegments() {
  if (isBufferingSegments) {
    return;
  }
  isBufferingSegments = true;
  sourceBuffer.addEventListener('updateend', bufferNextSegment);
  await bufferNextSegment();
}

function stopBufferingSegments() {
  if (!isBufferingSegments) {
    return;
  }
  isBufferingSegments = false;
  sourceBuffer.removeEventListener('updateend', bufferNextSegment);
}

async function bufferNextSegment() {
  const videoChunk = await getNextVideoChunk();
  sourceBuffer.appendBuffer(new Uint8Array(videoChunk));
}

async function getNextVideoChunk() {
  // Fetches and returns a video chunk.
}

```

See https://github.com/w3c/remote-playback/pull/126

Received on Tuesday, 3 September 2019 22:50:25 UTC