0

Hi there guys just wondering if it is possible to click a video in HTML5 for it to play?

What I mean is, on the video not a separate button to stop and play the video, like on you tube for example.

Cheers

Here is my code..

<div style="text-align:center"> 
  <button onclick="playPause()">Play/Pause</button> 
  <button onclick="makeBig()">Big</button>
  <button onclick="makeSmall()">Small</button>
  <button onclick="makeNormal()">Normal</button>
  <br> 
  <video id="video1" width="1250">
    <source src="pjds.mp4" type="video/mp4">
    <source src="pjds.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
</div> 

<script> 
var myVideo = document.getElementById("video1"); 

function playPause() { 
    if (myVideo.paused) 
        myVideo.play(); 
    else 
        myVideo.pause(); 
} 

function makeBig() { 
    myVideo.width = 1250; 
} 

function makeSmall() { 
    myVideo.width = 420; 
} 

function makeNormal() { 
    myVideo.width = 560; 
} 
</script> 
Samantha
  • 3
  • 4

3 Answers3

0

register the click event on the video:

myVideo.addEventListener('click', playPause);

in this case, every click will call the playPause() function.

dreamlab
  • 3,321
  • 20
  • 23
0

This link may be useful

simple video player

HTML

<div class="mediaplayer">
        <video poster="http://corrupt-system.de/assets/media/sintel/sintel-trailer.jpg" controls preload="none">
            <source src="http://corrupt-system.de/assets/media/sintel/sintel-trailer.m4v" type="video/mp4" />
            <source src="http://corrupt-system.de/assets/media/sintel/sintel-trailer.webm" type="video/webm" />
        </video>
</div>
Hamix
  • 1,323
  • 7
  • 18
0

This can be achieved without javascript just plain HTML5

<html> 
<body> 

<div style="text-align:center"> 
  <video id="video1" width="420" controls>
    <source src="pjds.mp4" type="video/mp4">
    <source src="pjds.ogg" type="video/ogg">
    Your browser does not support HTML5 video.
  </video>
</div> 
</body> 
</html>
user3811714
  • 286
  • 2
  • 8
  • 21