How can I pause a video?

Hello, good to everyone.

I have a problem and the truth is that if you would help me I would appreciate it a lot (I don’t know much about programming).

Here you have the link of the project : https://playcanvas.com/editor/scene/1040064

To see the video press play.The video is hosted on a server. And I don’t know how to access a pause.

If you want to access the project, tell me and I will give you access.

The truth is that I’ve been trying to pause the video for a whole day but I can’t. Or if you leave me a reference on how to do it or information, I would really appreciate it.

Greetings and thank you all very much.

PD: I’m sorry for my English

This page is probably best https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Video_and_audio_APIs

Ultimately, you call the pause() function on the video object.

sorry @yaustar
I don’t understand much about programming, and I don’t understand how to put it in the code I have about pause ()

thanks

Hello @RafaelLopera

Here is script for you…
This script will target 1st video element in playcanvas.

Add this script on Root entity. Press Space to Play and Pause Video.

:warning: Note: You may need to modify this script according to number of video source…

var VideoPlayPauseScript = pc.createScript('videoPlayPauseScript');

// initialize code called once per entity
VideoPlayPauseScript.prototype.initialize = function() {
    
};

// update code called every frame
VideoPlayPauseScript.prototype.update = function(dt) {
    
    var videoElement = document.getElementsByTagName('video')[0];
    
    if(videoElement !== undefined)
    {
        if (this.app.keyboard.wasPressed(pc.KEY_SPACE))
        {
            if(videoElement.paused === true)
            {
                videoElement.play();
            }
            else if(videoElement.paused === false)
            {
                videoElement.pause();
            }
        }
    }
    
};
3 Likes

Thank you very much for your help, it has worked perfectly. (I saw this message too late, sorry)

1 Like