Skip to main content

smwebsdk.scene.startvideo

Home > @soulmachines/smwebsdk > Scene > startVideo

Scene.startVideo() method

Play the video element and return results. Different browsers have different restrictions on autoplay. Using this method can handle all the cases browsers can have on inital video playback.

Signature:

startVideo(videoElement?: HTMLVideoElement): Promise<{
video: boolean;
audio: boolean;
} | Error>;

Parameters

ParameterTypeDescription
videoElementHTMLVideoElement(Optional) Optional parameter specifying the video element hosting the Digital Person. If not specified the video element passed to the Scene constructor will be used.

Returns:

Promise<{ video: boolean; audio: boolean; } | Error>

Returns a promise which is fulfilled when the video playback is successful, with indication of video and audio status. If the video element is not defined or video play fails the promise is rejected with an Error object having the format:

{
message: string;
name: errorCode;
}

Where errorCode is one of: - noVideoElement - no HTMLVideoElement found from videoElement or Scene constructor - userInteractionRequired - cannot start media playback due to browser restriction; user interaction is required before playing again

Usage:

scene.startVideo()
.then(({ video, audio }) => {
if (!audio) {
//video is muted, ask user to unmute video
}
})
.catch((error) => {
if (error.name === 'userInteractionRequired') {
//ask user to interact with the UI
//unmute video and play again
video.muted = false;
video.play();
}
});