Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var position = 0;
- var playlist;
- var video;
- addClickHandlers();
- window.onload = function() {
- video = document.getElementById('video');
- addClickHandlers();
- video.src = "video/" + getFormatExtension();
- video.load();
- video.play();
- }
- function addClickHandlers() {
- var liElements = document.querySelectorAll("ul#videolist li");
- for (var i = 0; i < liElements.length; i++) {
- var li = liElements[i];
- li.onclick = handleVideoSelection;
- }
- }
- function clearAllSelections() {
- var liElements = document.querySelectorAll("ul#videolist li");
- for (var i = 0; i < liElements.length; i++) {
- var li = liElements[i];
- li.setAttribute("class", null);
- }
- }
- function handleVideoSelection(e) {
- clearAllSelections();
- e.target.setAttribute("class", "selected");
- var li = e.target;
- var src = li.getAttribute("data-src");
- var isSelected = li.getAttribute("class");
- if (isSelected === "selected") {
- if (video.paused) {
- video.play();
- }
- else if (video.ended) {
- video.load();
- video.play();
- }
- else {
- video.pause();
- }
- }
- else {
- video.src = src + getFormatExtension();
- video.load();
- video.play();
- }
- }
- function getFormatExtension() {
- if (video.canPlayType("video/mp4") != "") {
- return ".mp4";
- } else if (video.canPlayType("video/ogg") != "") {
- return ".ogg";
- } else if (video.canPlayType("video/webm") != "") {
- return ".webm";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment