Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

addSourceBuffer method

Creates a new SourceBuffer and adds it to the SourceBuffers property of the MediaSource.

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

IE11

Syntax

var retVal = MediaSource.addSourceBuffer(type);

Parameters

type [in]

Type: DOMString

The MIME type.

Return value

Type: SourceBuffer

The media source buffer.

Exceptions

ExceptionCondition
INVALID_ACCESS_ERR

If type is null or an empty string.

NOT_SUPPORTED_ERR

If type contains a MIME type that's not supported or a MIME type that's not supported by SourceBuffer.

QUOTA_EXCEEDED_ERR

If the mediaSource can't handle any more SourceBuffer objects.

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 waits for the sourceopen event to fire, and then creates a video SourceBuffer using addSourceBuffer.


 function setupVideo() {
	     // get htmlvideoelement
      var videoElement = document.getElementById("myVideo");  

      // create the media source 
      mediaSource = new (window.MediaSource || window.WebKitMediaSource)();
      var url = URL.createObjectURL(mediaSource);
      videoElement.src = url;
 
      //  add a source buffer when mediaSource is ready
      mediaSource.addEventListener('sourceopen', function (e) {
        try {
          videoSource = mediaSource.addSourceBuffer('video/mp4');
          initVideo(); // initialize things          
        } catch (e) {
          log('Exception calling addSourceBuffer for video', e);
          return;
        }
      });

See also

MediaSource
Building a simple MPEG-DASH streaming player

 

 

Show:
© 2014 Microsoft. All rights reserved.