/.." is removed.
while (path.length !== (path = path.replace(SLASH_DOT_DOT_REGEX, "")).length) {} // eslint-disable-line no-empty
path = path.split("").reverse().join("");
while (path.indexOf("//") >= 0) {
path = path.replace("//", "/");
}
return path;
}
function navigateToArchive(archiveFileBase) {
console.log("going to archive:", archiveFileBase);
window.location = "?" + validOptions[0] + "=" + normalizePath(mediaBasePath + "/" + archiveFileBase);
}
function playFromMarker(markerInfo) {
videojsPlayer.currentTime(markerInfo.elapsedTimeSeconds);
if (videojsPlayer.paused()) {
videojsPlayer.play();
}
}
function playNextMarker() {
var nextMarkerNum = selectedMarkerDiv.markerNum + 1;
if (isNaN(nextMarkerNum) || nextMarkerNum >= markerArray.length) {
return false;
}
onMarkerClick.call(listElements[nextMarkerNum]);
return true;
}
function playPreviousMarker() {
var nextMarkerNum = selectedMarkerDiv.markerNum - 1;
if (isNaN(nextMarkerNum) || nextMarkerNum < 0) {
return false;
}
onMarkerClick.call(listElements[nextMarkerNum]);
return true;
}
function processMarkers(text) {
var lines = text.split("\n");
var lineX; // each line in markers file
var fields; // tab delimited fields in each line
lines.forEach(function(line, i) {
lineX = line;
fields = lineX.split("\t");
if (fields.length == 1) {
return;
}
var markerInfo = {
elapsedTime: fields[0].trim(),
clockTime: fields[1].trim(),
title: fields[2].trim(),
details: fields[3].trim(),
elapsedTimeSeconds: convertTimeFormatStringToSeconds(fields[0].trim())
};
markerArray.push(markerInfo);
renderMarker(markerArray[i], i === 0, i);
});
}
function processFileList(text) {
var lines = text.split("\n");
lines.forEach(function(line) {
if (line.startsWith("TITLE=")) {
setTitle(line.substr("TITLE=".length));
}
else if (line.startsWith("MP3=")) {
setAudioFilename(line.substr("MP3=".length));
}
else if (line.startsWith("NOTES=")) {
setMarkersFilename(line.substr("NOTES=".length));
}
});
}
function processArchiveList(text) {
var startWord = "Files=";
var titlesToken = "&Titles";
var endWord = "&";
if (text.startsWith(startWord)) {
text = text.substr(startWord.length);
} else {
console.error("Archive list data doesn`t begin with start sequence:", startWord);
return;
}
var archiveTitlesTextStart = text.indexOf(titlesToken);
if (archiveTitlesTextStart < 0) {
console.error("No titles section found in archive list");
return;
}
var archiveFilesText = text.substr(0, archiveTitlesTextStart);
var archiveTitlesText = text.substr(archiveTitlesTextStart + titlesToken.length + 1);
var archiveTitles = archiveTitlesText.split("|");
if (archiveTitles[archiveTitles.length -1] === endWord) {
archiveTitles.pop();
} else {
console.warn("Archive list titles data doesn`t end with end sequence:", endWord);
}
archiveTitles = archiveTitles.map(function(title) {
return escape(title);
});
archiveTitles.forEach(function(title) {
console.log("Title:", title);
});
var archiveFiles = archiveFilesText.split("|");
archiveFiles.pop();
archiveFiles = archiveFiles.map(function(file) {
return escape(file);
});
archiveFiles.forEach(function(file, index) {
console.log("File:", file);
renderArchive(file, archiveTitles[index]);
});
}
function setTitle(t) {
console.log("setTitle:", t);
title = t;
}
function setAudioFilename(filename) {
console.log("setAudioFilename:", filename);
audioFileName = filename;
}
function setMarkersFilename(filename) {
console.log("setMarkersFilename:", filename);
fileListFileName = filename + ".txt";
}
function loadMedia() {
var audioFile = getAbsoluteUrl(mediaBasePath + "/" + (audioFileName) + ".mp3");
console.log("Loading audio:", audioFile);
videojsPlayer.src(audioFile);
videojsPlayer.load();
}
function loadApplicationData() {
assertLoadingStageGreaterOrEqual("READY_TO_GO");
goToNextLoadingStage();
switch(loadingStage) {
case 0:
case 1:
break;
case 2:
getArchiveList(loadApplicationData);
break;
case 3:
getFileList(loadApplicationData);
break;
case 4:
getMarkers(loadApplicationData);
break;
}
}
function onArchiveLoaded() {
var playButton = document.querySelector(
"#" + playerId + " > button.vjs-big-play-button");
var controlsDiv = document.querySelector("#" + controlsId);
playButton.classList.add("force-hidden");
controlsDiv.classList.add("force-hidden");
isArchive = true;
goToNextLoadingStage(LoadingStagesEnum.indexOf("ALL_DONE"));
}
function getArchiveList(failedCallback) {
assertLoadingStageEqual("LOADING_ARCHIVE");
fetchRelativePath(mediaBasePath + "/" + archiveListFileName, function(text) {
onArchiveLoaded();
processArchiveList(text);
}, function(errorStatusCode) {
console.error("Failed loading archive list with status:" + errorStatusCode);
failedCallback();
});
}
function getFileList(failedCallback) {
assertLoadingStageEqual("LOADING_FILELIST");
fetchRelativePath(mediaBasePath + "/" + fileListFileName, function(text) {
processFileList(text);
loadMedia();
loadApplicationData();
}, function(errorStatusCode) {
console.error("Failed loading file list with status:" + errorStatusCode);
failedCallback();
});
}
function getMarkers(failedCallback) {
assertLoadingStageEqual("LOADING_MARKERS");
fetchRelativePath(mediaBasePath + "/" + fileListFileName, function(text) {
processMarkers(text);
goToNextLoadingStage();
}, function(errorStatusCode) {
console.error("Failed loading file list with status:" + errorStatusCode);
failedCallback();
});
}
function renderArchive(archiveFileBase, archiveTitle) {
var archiveHTML = ""
+ " " + unescape(archiveTitle)
+ "
";
var archiveLineDiv = document.createElement("div");
var link = document.createElement("a");
link.href = "#";
link.innerHTML = archiveHTML;
archiveLineDiv.appendChild(link);
archiveLineDiv.onclick = onArchiveClick;
archiveLineDiv.archiveFileBase = archiveFileBase;
archiveLineDiv.archiveTitle = archiveTitle;
listContainerElement.appendChild(archiveLineDiv);
listElements.push(archiveLineDiv);
}
function renderMarker(marker, selected, markerNum) {
var markerHTML = ""
+ "
"
//+ "▶"
+ ""
+ "
"
+ "
"
+ "" + marker.elapsedTime + ""
+ "" + marker.clockTime + ""
+ "" + marker.title + ""
+ "
"
+ "
";
var markerLineDiv = document.createElement("div"); // Create a for each line
var link = document.createElement("a");
link.href = "#";
link.innerHTML = markerHTML;
markerLineDiv.appendChild(link); // Append to the marker link
markerLineDiv.onclick = onMarkerClick;
markerLineDiv.markerNum = markerNum;
markerLineDiv.markerInfo = marker;
listContainerElement.appendChild(markerLineDiv); // Add marker to DOM
listElements.push(markerLineDiv);
if (selected) {
setSelectedMarker(markerLineDiv);
}
}
var SoniClear = window.SoniClear = window.SoniClear || {};
SoniClear.setup = setup;
SoniClear.loadApplicationData = loadApplicationData;
SoniClear.playNextMarker = playNextMarker;
SoniClear.playPreviousMarker = playPreviousMarker;
})(window, window.videojs);