Add feature to jump to marker (#471)

* Add options for setting marker and jumping to marker
* Correct "mute" to "muted"
This commit is contained in:
jacobcolbert
2019-05-06 00:41:16 -04:00
committed by Ilya Grigorik
parent e91b4c9cdb
commit d8965f644c
3 changed files with 30 additions and 9 deletions

View File

@@ -486,6 +486,10 @@
pauseSpeed(v, value); pauseSpeed(v, value);
} else if (action === 'muted') { } else if (action === 'muted') {
muted(v, value); muted(v, value);
} else if (action === 'mark') {
setMark(v);
} else if (action === 'jump') {
jumpToMark(v);
} }
} }
}); });
@@ -520,6 +524,16 @@
v.muted = v.muted !== true; v.muted = v.muted !== true;
} }
function setMark(v) {
v.vsc.mark = v.currentTime;
}
function jumpToMark(v) {
if (v.vsc.mark && typeof v.vsc.mark === "number") {
v.currentTime = v.vsc.mark;
}
}
function handleDrag(video, controller, e) { function handleDrag(video, controller, e) {
const shadowController = controller.shadowRoot.querySelector('#controller'); const shadowController = controller.shadowRoot.querySelector('#controller');

View File

@@ -100,4 +100,9 @@ select {
.customForce { .customForce {
display: none; display: none;
}
.customKey {
color: transparent;
text-shadow: 0 0 0 #000000;
} }

View File

@@ -102,6 +102,9 @@ function updateCustomShortcutInputText(inputItem, keyCode) {
inputItem.keyCode = keyCode; inputItem.keyCode = keyCode;
} }
// List of custom actions for which customValue should be disabled
var customActionsNoValues=["pause","muted","mark","jump"];
function add_shortcut() { function add_shortcut() {
var html = `<select class="customDo"> var html = `<select class="customDo">
<option value="slower">Decrease speed</option> <option value="slower">Decrease speed</option>
@@ -112,6 +115,8 @@ function add_shortcut() {
<option value="fast">Preferred speed</option> <option value="fast">Preferred speed</option>
<option value="muted">Mute</option> <option value="muted">Mute</option>
<option value="pause">Pause</option> <option value="pause">Pause</option>
<option value="mark">Set marker</option>
<option value="jump">Jump to marker</option>
</select> </select>
<input class="customKey" type="text" placeholder="press a key"/> <input class="customKey" type="text" placeholder="press a key"/>
<input class="customValue" type="text" placeholder="value (0.10)"/> <input class="customValue" type="text" placeholder="value (0.10)"/>
@@ -192,7 +197,7 @@ function restore_options() {
const dom = document.querySelector(".customs:last-of-type") const dom = document.querySelector(".customs:last-of-type")
dom.querySelector(".customDo").value = item["action"]; dom.querySelector(".customDo").value = item["action"];
if (item["action"] === "pause" || item["action"] === "muted") if (customActionsNoValues.includes(item["action"]))
dom.querySelector(".customValue").disabled = true; dom.querySelector(".customValue").disabled = true;
updateCustomShortcutInputText(dom.querySelector(".customKey"), item["key"]); updateCustomShortcutInputText(dom.querySelector(".customKey"), item["key"]);
@@ -262,14 +267,11 @@ document.addEventListener('DOMContentLoaded', function () {
}); });
document.addEventListener('change', (event) => { document.addEventListener('change', (event) => {
eventCaller(event, "customDo", function () { eventCaller(event, "customDo", function () {
switch (event.target.value) { if (customActionsNoValues.includes(event.target.value)) {
case "muted": event.target.nextElementSibling.nextElementSibling.disabled = true;
case "pause": event.target.nextElementSibling.nextElementSibling.value = 0;
event.target.nextElementSibling.nextElementSibling.disabled = true; } else {
event.target.nextElementSibling.nextElementSibling.value = 0; event.target.nextElementSibling.nextElementSibling.disabled = false;
break;
default:
event.target.nextElementSibling.nextElementSibling.disabled = false;
} }
}) })
}); });