Video

Video playing.

// Video are rendered inside a Canvas,
// so first, you need to create a Canvas
var c = new Canvas(640, 360);

// The Canvas must be initialized with a 2d context
c.getContext("2d");

// And added to the root canvas, so we can see it
document.canvas.add(c);

// Then create the video with a reference to the Canvas
var video = new Video(c);

// Open the video file
video.open("big_buck_bunny_480p_h264.mov");

// And play it !
video.play();
var c = new Canvas(640, 360);
c.getContext("2d");
document.canvas.add(c);

var video = new Video(c);
video.open("big_buck_bunny_480p_h264.mov");

video.on("ready", function() {
    var dsp = Audio.getContext();

    var source = video.getAudioNode();
    if (!source) {
        console.log("Video does not have an audio channel");
        return;
    }

    var target = dsp.createNode("target", 2, 0);

    dsp.connect(source.output[0], target.input[0]);
    dsp.connect(source.output[1], target.input[1]);
});

video.play();

new Video(canvas)

Create a new Video instance.

Arguments:
canvas (Canvas)

The canvas parent. This must be a 2d Canvas

getAudioNode()

Get the audio node associated to the video.

This method will return null if it's called before the ready event of the video.

Returns: AudioNode | null

The audio node instance associated to the video or null if the video does not have any audio stream

bitrate(readonly)

  • Type: Integer

The bitrate of the Video in samples per buffer.

duration(readonly)

  • Type: Integer

The duration of the Video in seconds.

height(readonly)

  • Type: Integer

The height of the video.

metadata(readonly)

  • Type: Object

An object with metadata that belong to this Video stream.

var dsp = Audio.getContext();
var src = dsp.createNode("source", 0, 2);
src.open("path/to/file.mp3");
        for (var k in src.metadata) {
    console.log("Metadata : " + k + "=" + src.metadata[k]);
}

position

  • Type: Integer

The current position in the Video in seconds. Can also be used to set the position to a certain time.

var dsp = Audio.getContext();
var src = dsp.createNode("source", 0, 2);
src.open("path/to/file.mp3");
        console.log(src.position); // display the current position in the source
src.position += 5; // seek 5 seconds forwards

width(readonly)

  • Type: Integer

The width of the video.

Event: buffering(event)

Event fired when the source is buffering data.

Parameters:
event (Object)

Event object

filesize (Integer)

The size of the file in bytes

startByte (Integer)

The start position of the buffered data.

bufferedBytes (Integer)

The number of bytes buffered.

Event: end(dummy)

Event fired when the source reached the end of the file.

Parameters:
dummy (Any)

Empty parameter, set to 'undefined'

Event: error(event)

Event fired when the source fails to be opened or if a read error happens while playing the media file.

Parameters:
event (Object)

Event object

code (Integer)

The error code

error (String)

Description of the errorcode

Event: frame(video)

Event fired when a new video frame is drawn.

Parameters:
video (Video)

Video instance

Event: pause(dummy)

Event fired when the source is put on pause.

Parameters:
dummy (Any)

Empty parameter, set to 'undefined'

Event: play(dummy)

Event fired when the source is put on play.

Parameters:
dummy (Any)

Empty parameter, set to 'undefined'

Event: ready(dummy)

Event fired when the source is opened and ready to be played.

Parameters:
dummy (Any)

Empty parameter, set to 'undefined'


Caught a mistake or want to contribute to the documentation? Edit this page on GitHub!