How to make a button that changes video's playstate?

Viewed 37

I wanted to make a joke website and rickroll my friends, but I can only make a video autoplay with muted sounds. So I thought of making a fake cookie consent button that changes the video playstate (basically a button that plays the video)

1 Answers

function videoPlay() {
    var video = document.getElementById('myvideo');
    var btn = document.getElementById('playBtn');
    if (video.paused) {
        video.play();
        btn.innerHTML = "Pause"
    } else {
        video.pause();
        btn.innerHTML = "Play"
    }
}
<video id="myvideo" src="https://www.w3schools.com/html/mov_bbb.mp4"></video>
    <button id="playBtn" onclick="videoPlay()">Play</button>

Related