Last active
November 14, 2015 14:33
-
-
Save Xavka/ecde702b2ecabc61a72a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function() { | |
/* Variables */ | |
var videoPlayer = document.getElementById( 'video-player' ), | |
video = videoPlayer.getElementsByClassName( 'fullscreen-bg__video' )[0], | |
playlist = videoPlayer.getElementsByClassName( 'fullscreen-bg__playlist' )[0], | |
source = video.getElementsByTagName( 'source' ), | |
linkList = [], | |
videoDirectory = 'video/', | |
currentVideo = 0, | |
allLinks = playlist.children, | |
linkNumber = allLinks.length, | |
i, filename; | |
| |
/** | |
* Load and play video | |
* @param int index Video index | |
*/ | |
function playVideo( index ) { | |
allLinks[index].classList.add( 'current-video' ); | |
currentVideo = index; | |
| |
source[2].src = videoDirectory + linkList[index] + '.ogv'; | |
source[1].src = videoDirectory + linkList[index] + '.webm'; | |
source[0].src = videoDirectory + linkList[index] + '.mp4'; | |
| |
video.load(); | |
video.play(); | |
} | |
| |
// Save all video sources from playlist | |
for ( i = 0; i < linkNumber; i++ ) { | |
filename = allLinks[i].href; | |
linkList[i] = filename.match( /([^\/]+)(?=\.\w+$)/ )[0]; | |
} | |
| |
/** | |
* Play next video | |
*/ | |
video.addEventListener( 'ended', function () { | |
allLinks[currentVideo].classList.remove( 'current-video' ); | |
| |
nextVideo = currentVideo + 1; | |
if ( nextVideo >= linkNumber ) { | |
nextVideo = 0; | |
} | |
| |
playVideo( nextVideo ); | |
} ); | |
| |
} () ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment