Skip to main content
SourceBuffer object

Represents a buffer that contains media data for a MediaSource object.

Important  This object is not supported in Internet Explorer 11 on Windows 7.

IE11

Syntax


var buffer = oMediaSource.addSourceBuffer("MIMEType"); 

DOM Information

Inheritance Hierarchy

The SourceBuffer does not inherit from any class or interface.

Members

The SourceBuffer object has these types of members:

Events

The SourceBuffer object has these events.

EventDescription
abort

Occurs when an append or remove operation is aborted by calling abort.

error

Occurs when an error happens during an append operation.

update

Occurs when an append or remove operation has completed successfully.

updateend

Occurs when the append or remove operation has ended.

updatestart

Occurs when the source buffer is updating.

 

Methods

The SourceBuffer object has these methods.

MethodDescription
abort

Aborts the processing of the current media segment.

addEventListener

Registers an event handler for the specified event type.

appendBuffer

Appends the specified media segment to the SourceBuffer.

appendStream

Appends the media segment data from the specified stream to the SourceBuffer.

dispatchEvent

Sends an event to the current element.

remove

Removes the media segments defined by the specified time range from the SourceBuffer.

removeEventListener

Removes an event handler that the addEventListener method registered.

 

Properties

The SourceBuffer object has these properties.

PropertyAccess typeDescription

appendWindowEnd

Read/write

Gets or sets the timestamp for the end of the append window.

appendWindowStart

Read/write

Gets or sets the timestamp for the start of the append window.

audioTracks

Read-only

Returns an AudioTrackList object with the audio tracks for a given video element.

buffered

Gets a collection of buffered time ranges.

timestampOffset

Read/write

Gets or sets the timestamp offset for media segments appended to the SourceBuffer.

updating

Read-only

Gets a value that specifies if appendBuffer, appendStream, or remove is in process.

 

Remarks

W3C Media Source Extensions spec.

Examples

This example gets a video object, creates a new mediaSource object, and assigns the MediaSource object to the src (source) of the video object. It then creates a videoSource buffer. See a complete example online.


// Create mediaSource and initialize video 
function setupVideo() {
  clearLog(); // Clear console log

  //  Create the media source 
  if (window.MediaSource) {
    mediaSource = new window.MediaSource();
   } else {
    log("mediasource or syntax not supported");
    return;
  }
  var url = URL.createObjectURL(mediaSource);
  videoElement.pause();
  videoElement.src = url;
  videoElement.width = width;
  videoElement.height = height;

  // Wait for event that tells us that our media source object is 
  //   ready for a buffer to be added.
  mediaSource.addEventListener('sourceopen', function (e) {
    try {
      videoSource = mediaSource.addSourceBuffer('video/mp4');
      initVideo(initialization, file);           
    } catch (e) {
      log('Exception calling addSourceBuffer for video', e);
      return;
    }
  },false);

See also

activeSourceBuffers
addSourceBuffer
sourceBuffers
Building a simple MPEG-DASH streaming player