POMSD

Welcome

OR

Create Account

Quick Actions


Publisher Studio

Overview

Total Posts 0
Total Views 0
Latest Post None
Publisher Profile User

Manage My Posts

Post Title Date Published Views Security Actions

Create New Post

Profile Settings

How to Add Video Playback Speed Controller HTML CSS JS



 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Player</title>
<style>
    body {
        font-family: Arial, sans-serif;
        margin: 0;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        background-color: #f0f0f0;
    }

    .video-container {
        max-width: 600px;
        width: 100%;
        margin: 0 auto;
    }

    video {
        width: 100%;
        height: auto;
    }

    .speed-controls {
        text-align: center;
        margin-top: 20px;
    }

    button {
        padding: 10px 20px;
        cursor: pointer;
        border: none;
        background-color: #007bff;
        color: #fff;
        border-radius: 5px;
        margin: 0 5px;
    }

    .speed-display {
        margin-top: 10px;
        font-size: 16px;
    }
</style>
</head>
<body>
<div class="video-container">
    <video controls>
        <source src="sample_video.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>
</div>
<div class="speed-controls">
    <button id="decreaseSpeed">-</button>
    <button id="increaseSpeed">+</button>
    <button id="resetSpeed">Normal</button>
    <div class="speed-display" id="speedDisplay">Playback Speed: 1x</div>
</div>
<script>
    var speedDisplay = document.getElementById('speedDisplay');

    document.getElementById('increaseSpeed').addEventListener('click', function() {
        changeSpeed(0.25); // Increase speed by 0.25
    });

    document.getElementById('decreaseSpeed').addEventListener('click', function() {
        changeSpeed(-0.25); // Decrease speed by 0.25
    });

    document.getElementById('resetSpeed').addEventListener('click', function() {
        resetSpeed(); // Reset speed to 1x
    });

    function changeSpeed(speedChange) {
        var video = document.querySelector('video');
        if (!video.playbackRate) {
            video.playbackRate = 1.0;
        }
        video.playbackRate += speedChange; // Change playback speed
        speedDisplay.textContent = 'Playback Speed: ' + video.playbackRate.toFixed(2) + 'x';
    }

    function resetSpeed() {
        var video = document.querySelector('video');
        video.playbackRate = 1.0; // Reset speed to 1x
        speedDisplay.textContent = 'Playback Speed: 1x';
    }
</script>
</body>
</html>

Contact Us!

Comment Box

0 Comments