English
Appearance
English
Appearance
Related reference: Scene API / Video
The advanced Web API provides three kinds of video objects:
createVideo()createAlphaVideo()createKeyingVideo()Because of the browser's media autoplay restrictions, videos inside a scene may fail to play when playback is requested.
To handle this, Kivicube silently plays the audio and video media in the scene once when the user clicks the "Start Now" button on the landing page.
After that, playback can happen freely during the experience.
This solves the autoplay issue for audio and video objects that come with the scene. However, videos added dynamically through the API can still fail to autoplay.
For that case, the plugin provides the setVideoNum API so the application layer can tell the plugin how many videos it intends to add dynamically.
The plugin will then silently play more videos when the "Start Now" button is clicked. Later, when createVideo or similar APIs are called, they will automatically be matched to a video element that can autoplay, achieving the autoplay effect.
Note
This must be called before the user clicks the "Start Now" button, otherwise it has no effect.
// Tell the plugin how many videos the application layer will dynamically add
await api.setVideoNum(10);const video = await api.createVideo('https://your.domain.com/ar.mp4');
await api.add(video);const alphaVideo = await api.createAlphaVideo('/assets/glow.mp4');
await api.add(alphaVideo);const keyingVideo = await api.createKeyingVideo(
'/assets/green-screen.mp4',
{
// Key color to remove. Default is #00F400.
color: '#00F400',
// Color similarity (0~1). Default is 0.42.
similarity: 0.42,
// Smoothness (0~1). Default is 0.08.
smoothness: 0.08,
// Spill reduction speed (0~1). Default is 0.
spill: 0,
}
);
await api.add(keyingVideo);Although ArrayBuffer input is supported, video files are usually large and consume significant memory. Using URLs is generally the better choice.
await api.playVideo(video, {
loop: true, // Whether playback should loop
full_screen: false // Whether it should play fullscreen
});You can later change the loop setting with setVideoLoop().
await api.pauseVideo(video);
await api.stopVideo(video);
await api.playbackVideo(video, { loop: false });// Video duration
const duration = await api.getVideoDuration(video);
// Whether the video is paused
const paused = await api.getVideoPaused(video);
// Current playback position
const currentTime = await api.getVideoCurrentTime(video);
// Whether looping is enabled
const loop = await api.getVideoLoop(video);// Jump the video to a given time
await api.setVideoCurrentTime(video, 3.2);
// Set whether the video should loop
await api.setVideoLoop(video, true);play - fires when video playback startsfunction onPlay(event) {
const { type, target } = event;
}
await api.on('play', onPlay, video);pause - fires when playback pausesfunction onPause(event) {
const { type, target } = event;
}
await api.on('pause', onPause, video);ended - fires when playback finishes naturallyfunction onEnded(event) {
const { type, target } = event;
}
await api.on('ended', onEnded, video);replay - fires when playback restartsfunction onReplay(event) {
const { type, target } = event;
}
await api.on('replay', onReplay, video);Best for most regular flat-video playback scenarios.
Best when you already have a platform-supported alpha-video asset and want to overlay it directly into the scene.
Best for green-screen or blue-screen style keying, but the final visual quality depends heavily on source quality and keying configuration.
Note
All videos are rendered inside the 3D scene, not as regular HTML video elements on the page.
Browsers enforce strict autoplay rules. Even though Kivicube handles some compatibility issues internally, you should still pay close attention to these cases:
So before shipping any video-heavy content, always run a full regression pass on real target devices.