$(document).ready(function(){
var video = $('#myVideo');
video[0].removeAttribute("controls");
$('.control').fadeIn(500);
$('.caption').fadeIn(500);
video.on('loadedmetadata', function() {
$('.current').text(timeFormat(0));
$('.duration').text(timeFormat(video[0].duration));
setTimeout(startBuffer, 150);
$('.control').stop().fadeIn();
$('.caption').stop().fadeIn();
if(!volumeDrag && !timeDrag){
$('.control').stop().fadeOut();
$('.caption').stop().fadeOut();
.on('click', function() {
$('.btnPlay').find('.icon-play').addClass('icon-pause').removeClass('icon-play');
var startBuffer = function() {
var currentBuffer = video[0].buffered.end(0);
var maxduration = video[0].duration;
var perc = 100 * currentBuffer / maxduration;
$('.bufferBar').css('width',perc+'%');
if(currentBuffer < maxduration) {
setTimeout(startBuffer, 500);
video.on('timeupdate', function() {
var currentPos = video[0].currentTime;
var maxduration = video[0].duration;
var perc = 100 * currentPos / maxduration;
$('.timeBar').css('width',perc+'%');
$('.current').text(timeFormat(currentPos));
video.on('click', function() { playpause(); } );
$('.btnPlay').on('click', function() { playpause(); } );
var playpause = function() {
if(video[0].paused || video[0].ended) {
$('.btnPlay').addClass('paused');
$('.btnPlay').find('.icon-play').addClass('icon-pause').removeClass('icon-play');
$('.btnPlay').removeClass('paused');
$('.btnPlay').find('.icon-pause').removeClass('icon-pause').addClass('icon-play');
$('.btnFS').on('click', function() {
if($.isFunction(video[0].webkitEnterFullscreen)) {
video[0].webkitEnterFullscreen();
else if ($.isFunction(video[0].mozRequestFullScreen)) {
video[0].mozRequestFullScreen();
alert('Your browsers doesn\'t support fullscreen');
$('.sound').click(function() {
video[0].muted = !video[0].muted;
$(this).toggleClass('muted');
$('.volumeBar').css('width',0);
$('.volumeBar').css('width', video[0].volume*100+'%');
video.on('canplay', function() {
$('.loading').fadeOut(100);
var completeloaded = false;
video.on('canplaythrough', function() {
video.on('ended', function() {
$('.btnPlay').removeClass('paused');
video.on('seeking', function() {
$('.loading').fadeIn(200);
video.on('seeked', function() { });
video.on('waiting', function() {
$('.loading').fadeIn(200);
$('.progress').on('mousedown', function(e) {
$(document).on('mouseup', function(e) {
$(document).on('mousemove', function(e) {
var updatebar = function(x) {
var progress = $('.progress');
var maxduration = video[0].duration;
var position = x - progress.offset().left;
var percentage = 100 * position / progress.width();
$('.timeBar').css('width',percentage+'%');
video[0].currentTime = maxduration * percentage / 100;
$('.volume').on('mousedown', function(e) {
$('.sound').removeClass('muted');
$(document).on('mouseup', function(e) {
$(document).on('mousemove', function(e) {
var updateVolume = function(x, vol) {
var volume = $('.volume');
var position = x - volume.offset().left;
percentage = 100 * position / volume.width();
$('.volumeBar').css('width',percentage+'%');
video[0].volume = percentage / 100;
if(video[0].volume == 0){
$('.sound').removeClass('sound2').addClass('muted');
else if(video[0].volume > 0.5){
$('.sound').removeClass('muted').addClass('sound2');
$('.sound').removeClass('muted').removeClass('sound2');
var timeFormat = function(seconds){
var m = Math.floor(seconds/60)<10 ? "0"+Math.floor(seconds/60) : Math.floor(seconds/60);
var s = Math.floor(seconds-(m*60))<10 ? "0"+Math.floor(seconds-(m*60)) : Math.floor(seconds-(m*60));