Making Video Player In HTML With Custom Controls In Javascript | letsbug

     Today we are making a simple video player in HTML with the help of javascript. We have default controls in HTML while adding a video in HTML with the controls attribute. But those default controls are default and we want customization we are  creating our own control box.

    To make it you need to know HTML and HTML5 and javascript. We are going to implement following functions in our player.

  1. Play
  2. Pause
  3. Repeat
  4. Seek
  5. Mute
    You are not limited to this only you can also add more functionality to it like progress bar. Or you can also add a explorer window to change the video. But for now let's focus on this.

 Custom Video Player In HTML and Javascript        

  For this we need three files linked with the html file which is style.css for a little styling and main.js for javascript which is going to be the backbone of this little project.    So you have to create index.html, style.css, main.js in you project folder.

    Then you can link that in index.html file. And open it in browser for viewing it.

code:

    index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Video Player</title>
    <link rel="stylesheet" href="./style.css">
    <script src="./main.js" defer async></script>
</head>

<body>
    <!-- video player -->
    <div class="video-player">
        <video id="video">
            <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
            <source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
            Your browser does not support the video tag.
        </video>

        <div class="control-box">
            <button class="play_pause">Play - pause</button>
            <button class="repeat">Repeat</button>
            <button class="mute">Mute</button>
            <button class="seek">Seek </button>
        </div>
    </div>
</body>

</html>

    style.css

body {
    display: grid;
    place-items: center;
}

* {
    box-sizing: border-box;
    padding: 0;
    margin: 0;
}

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

.video-player {
    width: 70vh;
    height: auto;
}

.control-box {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 1.5rem;
    background: hsl(199, 100%, 93%);
}

.control-box button {
    background-color: hsl(197, 100%, 33%);
    color: white;
    padding: .5rem;
    border: none;
    cursor: pointer;
    border-radius: .3rem;
}

    main.js

const video = document.querySelector('video');

const play_pause = document.querySelector('.play_pause');
const repeat = document.querySelector('.repeat');
const mute = document.querySelector('.mute');
const seek = document.querySelector('.seek');

let isPlaying = false
play_pause.addEventListener('click', () => {
    if (isPlaying === false) {
        video.play()
        isPlaying = true
    } else {
        video.pause()
        isPlaying = false
    }
});

repeat.addEventListener('click', () => {
    video.currentTime = 0
});

mute.addEventListener("click", () => {
    if (video.muted === false) {
        video.muted = true
    } else {
        video.muted = false
    }
})

seek.addEventListener('click', () => {
    video.currentTime += 10
})

output: 


video player | letsbug.com
output


Comments

Categories

Big Data Analytics Binary Search Binary Search Tree Binary To Decimal binary tree Breadth First Search Bubble sort C Programming c++ Chemical Reaction and equation class 10 class 10th Class 9 Climate Complex Numbers computer network counting sort CSS Cyber Offenses Cyber Security Cyberstalking Data Science Data Structures Decimal To Binary Development diamond pattern Digital Marketing dust of snow Economics Economics Lesson 4 Email Validation English fire and ice Food Security in India Footprints Without feet Forest And Wildlife Resources game Geography Geography lesson 6 glassmorphism Glossary Graph HackerRank Solution hindi HTML image previewer India-Size And Location Insertion Sort Internet Network Status Interview Questions Introduction to cyber crime and cyber security IT javascript tricks json to CSV converter lesson 2 lesson 1 lesson 2 Lesson 3 Lesson 6 lesson 7 Life lines of National Economy life processes Linear Search Linked List lowest common ancestor Machine Learning MCQs median in array Merge sort min and max of two numbers Moment Money and Credit My Childhood Natural Vegetation and Wildlife NCERT Network connectivity devices Network Models Network Security No Men Are foreign Node.js operator overloading P5.js PHP Physical features of India Population Prime Numbers python Quick sort R language Rain on the roof Regular Expression Resources and development reversing array saakhi science Searching Algorithm Selection sort Social Media Marketing social science Software Engineering Software Testing Sorting Algorithm Stacks staircase pattern System Concepts Text Recognition The last Leaf time converter Time Passed From A Date Todo List App Tree Trending Technologies Understanding Economic Development username and password video player Visualization water resources Wired And Wireless LAN साखी
Show more

Popular Posts

Big Data MCQs(multiple choice questions) with answers - letsbug

Digital Marketing MCQ(Multiple Choice Questions) with Answers | part 1 | letsbug

Software Engineering MCQs questions with answers - letsbug