Codes for video player

+3 Ary kutex · January 11, 2015
Hi all,

Am new to the forum and i would like to get the codes for the video player for tutorials 29-34 or so.

Thanks.

Post a Reply

Replies

Oldest  Newest  Rating
0 Jason Finney · January 15, 2015
<!-- HTML -->
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="main.css">
<script src="bucky.js"></script>
</head>
<body style='margin: 0;'>
<section id="skin">
<video id="myMovie" width="640" height="360">
<!-- Make sure your video is in the same folder as your HTML folder -->
<source src="<!-- Your video goes here.mp4 -->" type="video/mp4">
</video>
<nav>
<div id="buttons">
<button type="button" id="playButton">Play</button>
</div>
<div id="defaultBar">
<div id="progressBar"></div>
</div>
<div style="clear:both"></div>
</nav>
<section>
</video>
</body>
</html>

/* CSS */

body{
text-align:center;
background:#F1F1F1;
}
header,section,footer,aside,nav,article,hgroup{
display:block;
}
#skin{
width:700px;
margin:10px auto;
padding:5px;
background:red;
border:4px solid black;
border-radius:10px;
}
nav{
margin:5px 0px;
}
#buttons{
float:left;
width:70px;
height:22px;
}
#defaultBar{
position:relative;
float:left;
width:600px;
height:16px;
padding:4px;
border:2px solid black;
background:yellow;
}
#progressBar{
position:absolute;
width:0px;
height:16px;
background:blue;
}

// Javascript

function doFirst(){
barSize=600;
myMovie=document.getElementById('myMovie');
playButton=document.getElementById('playButton');
bar=document.getElementById('defaultBar');
progressBar=document.getElementById('progressBar');

playButton.addEventListener('click', playOrPause, false);
bar.addEventListener('click', clickedBar, false);
}

function playOrPause(){
if(!myMovie.paused && !myMovie.ended){
myMovie.pause();
playButton.innerHTML='Play';
window.clearInterval(updateBar);
}else{
myMovie.play();
playButton.innerHTML='Pause';
updateBar=setInterval(update, 500);
}
}

function update(){
if(!myMovie.ended){
var size=parseInt(myMovie.currentTime*barSize/myMovie.duration);
progressBar.style.width=size+'px';
}else{
progressBar.style.width='0px';
playButton.innerHTML='Play';
window.clearInterval(updateBar);
}
}

function clickedBar(e){
if(!myMovie.paused && !myMovie.ended){
var mouseX=e.pageX-bar.offsetLeft;
var newtime=mouseX*myMovie.duration/barSize;
myMovie.currentTime=newtime;
progressBar.style.width=mouseX+'px';
}
if(!myMovie.play && !myMovie.ended){
var mouseX=e.pageX-bar.offsetLeft;
var newtime=mouseX*myMovie.duration/barSize;
myMovie.currentTime=newtime;
progressBar.style.width=mouseX+'px';
}
}

window.addEventListener('load',doFirst,false);
0 Jason Finney · January 15, 2015
I was going to make a youtube like website that why there's a #F1F1F1 in there
  • 1

HTML / CSS / Web Design

107,332 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators