sourceopen | onsourceopen event
Occurs when the media source is opened.
![]() ![]() |
Syntax
| HTML Attribute | <element onsourceopen = "handler(event)"> |
|---|---|
| Event Property | object.onsourceopen = handler; |
| addEventListener Method | object.addEventListener("sourceopen", handler, useCapture) |
Event information
| Synchronous | No |
|---|---|
| Bubbles | No |
| Cancelable | No |
Event handler parameters
- handler [in]
-
Type: function
Event handler object.
Standards information
Remarks
This event is often used to monitor when to add a buffer to the MediaSource object.
This event occurs when the readyState changes from either:
- closed to open
- ended to open
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.
// 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

