Hi guys I'm trying to make a custom video player.
I'm trying to make a button pause or play the video but it is not able to do so.
Html code: index.html
<html>
<head>
<script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../js/player.js"></script>
<link rel="stylesheet" href="../css/style.css" />
<title></title>
</head>
<body>
<video id="main_video" src="../media/4k.mp4" controls autoplay></video>
<p>
<button onclick="play_pause()" type="button">PLAY/PAUSE</button>
</body>
</html>
Javascript code: player.js
var video_screen = document.getElementById('main_video');
var play_pause_status = "play";
function play_pause()
{
if (play_pause_status == "pause")
{
video_screen.play();
play_pause_status = "play";
}
else
{
video_screen.pause();
play_pause_status = "pause";
}
}
When I click the button this is the error shown:
Uncaught TypeError: Cannot read property 'pause' of null at play_pause
I want to keep my Javascript code into a separate file.
I'm not able to understand the error please help.