From c23c3d84373f0fa52d680014100c4b7c3edf9b50 Mon Sep 17 00:00:00 2001 From: Astrid Smith Date: Sat, 17 Sep 2016 17:47:02 -0700 Subject: more things --- index.html | 75 +++++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index f1a4159..0276156 100644 --- a/index.html +++ b/index.html @@ -2,10 +2,8 @@ - - @@ -30,14 +28,15 @@ function onlyUnique(value, index, self) { // - s is a start time in decimal seconds // - e is an end time in decimal seconds function frag_make(cutlist) { - var vid_list = cutlist.map(function(x) {return x.id}).filter(onlyUnique); + var vid_list = cutlist.map(function(x) {return x.id}).concat([video_id]).filter(onlyUnique); var cuts = cutlist.map(function(x) { return {id: vid_list.indexOf(x.id), start: x.start, end: x.end}}); var frag = vid_list.join(",") + ":" + - cuts.map(function(x) { return [x.id, x.start, x.end].join("-") }).join(","); + cuts.map(function(x) { return [x.id, x.start, x.end].join("-") }).join(",") + ":" + + ($("#repeat-p")[0].checked ? "r" : ""); return frag; } @@ -45,10 +44,13 @@ function frag_make(cutlist) { // read a URL fragment string and turn it into a cutlist function frag_parse(frag) { var vc - vc = frag.split(":"); + vc = (frag + "::").split(":"); var vids = vc[0].split(","); var cuts = vc[1].split(","); + var flags = vc[2].split(""); + $("#repeat-p")[0].checked = (flags.indexOf("r") != -1); + var cutlist = cuts.map(function(x) { ise = x.split("-"); return {id:vids[+ise[0]], start:+ise[1], end:+ise[2]}; }) return cutlist; @@ -73,16 +75,18 @@ function frag_parse(frag) {
-
-
-
- - -
-
+ +
+ + + + + +
+ - +
Cut list (seconds)
startend
fromto
@@ -121,7 +125,6 @@ function load_video() { width: '640', events: { 'onReady': onPlayerReady, - 'onStateChange': onPlayerStateChange } }); } @@ -129,19 +132,13 @@ function load_video() { // 4. The API will call this function when the video player is ready. function onPlayerReady(event) { - player.loadVideoById(video_id); + player.cueVideoById(video_id); } // 5. The API calls this function when the player's state changes. -// The function indicates that when playing a video (state=1), -// the player should play for six seconds and then stop. -var done = false; function onPlayerStateChange(event) { } -function cutlist_cleanup() { -} - function cutlist_append_empty() { var row = ''; @@ -175,7 +172,7 @@ function b_grab() { return; } -function b_share() { +function cutlist_make() { var cutlist = $("#cutlist tr").get() .filter(function(x) { return $(x).find("input").size() != 0 }) .map(function(x) { @@ -187,12 +184,44 @@ function b_share() { }) .filter(function(x) { return x.start != x.end; }) + return cutlist; +} + +function b_share() { + var cutlist = cutlist_make(); var frag = frag_make(cutlist); history.pushState(null, "Video recut", "#" + frag); } +var pending_cutlist = []; function play_from_cutlist() { - + player.pauseVideo(); + pending_cutlist = cutlist_make(); + player.seekTo(0, false); + player.seekTo(pending_cutlist[0].start, true); + player.playVideo(); + playtime_check(0); +} + +function playtime_check(t_now) { + if (player.getCurrentTime() >= pending_cutlist[0].end) { + // time to change time + pending_cutlist.shift(); + + if (pending_cutlist.length == 0) { + if ($("#repeat-p")[0].checked) { + // again again + pending_cutlist = cutlist_make(); + } else { + // done playing + player.pauseVideo(); + return; + } + } + player.seekTo(pending_cutlist[0].start, true); + } + // wait for a bit and check the time + window.requestAnimationFrame(playtime_check); } function load_cutlist_from_url() { -- cgit v1.2.3