From 3d3828b6c529f15934c8e74dd095dcdf1dab60a5 Mon Sep 17 00:00:00 2001 From: Ben Raymond Date: Sat, 14 Oct 2023 21:35:04 +1100 Subject: [PATCH] fix clip transitions when they are not time-ordered v0.20.0 --- DESCRIPTION | 2 +- R/playlists.R | 5 ++++- inst/extdata/js/vid.js | 2 +- inst/extdata/js/vid2.js | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d9126f3..91535c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ovideo Title: Volleyball Video Utilities -Version: 0.19.7 +Version: 0.20.0 Authors@R: c(person(given = "Ben", family = "Raymond", role = c("aut", "cre"), email = "ben@untan.gl"), person(given = "Adrien", family = "Ickowicz", role = "aut"), person("openvolley.org", role = "org")) diff --git a/R/playlists.R b/R/playlists.R index e0a8c76..672a1fd 100644 --- a/R/playlists.R +++ b/R/playlists.R @@ -212,7 +212,10 @@ match_id_from_meta <- function(z) { add_seamless_timings <- function(x) { x <- mutate(x, end_time = .data$start_time + .data$duration) - x <- mutate(group_by(x, .data$video_src), overlap = .data$start_time <= lag(.data$end_time), + x <- mutate(group_by(x, .data$video_src), + ## a clip overlaps with its preceding one if the start time of clip i sits within the time period of clip (i-1) + ## but if clip i starts *before* clip (i-1) then they do not overlap (cannot be played seamlessly) - maybe a randomly-ordered playlist + overlap = dplyr::n() > 1 & .data$start_time <= lag(.data$end_time) & .data$start_time > lag(.data$start_time), overlap = case_when(is.na(.data$overlap) ~ FALSE, TRUE ~ .data$overlap), ## TRUE means that this event overlaps with previous ## may be better to calculate overlap in terms of point_id and/or team_touch_id? seamless_start_time = pmin(.data$video_time, case_when(is.na(lag(.data$end_time)) ~ .data$start_time, TRUE ~ (lag(.data$end_time) + .data$start_time)/2)), diff --git a/inst/extdata/js/vid.js b/inst/extdata/js/vid.js index 83dbdb5..d61770c 100644 --- a/inst/extdata/js/vid.js +++ b/inst/extdata/js/vid.js @@ -380,7 +380,7 @@ function dvjs_video_manage() { if (this_seamless && dvjs_video_controller.current >= 0 && dvjs_video_controller.current < (dvjs_video_controller.queue.length - 1)) { var item = dvjs_video_controller.queue[dvjs_video_controller.current]; var next_item = dvjs_video_controller.queue[dvjs_video_controller.current+1]; - this_seamless = item.video_src == next_item.video_src && next_item.start_time <= (item.start_time + item.duration) + this_seamless = item.video_src == next_item.video_src && next_item.start_time <= (item.start_time + item.duration) && next_item.start_time > item.start_time; } dvjs_video_next(this_seamless) } else { diff --git a/inst/extdata/js/vid2.js b/inst/extdata/js/vid2.js index 5c40056..b2cdefa 100644 --- a/inst/extdata/js/vid2.js +++ b/inst/extdata/js/vid2.js @@ -531,7 +531,7 @@ function dvjs_controller(id, type, seamless = true) { if (this_seamless && that.video_controller.current >= 0 && that.video_controller.current < (that.video_controller.queue.length - 1)) { var item = that.video_controller.queue[that.video_controller.current]; var next_item = that.video_controller.queue[that.video_controller.current+1]; - this_seamless = item.video_src == next_item.video_src && next_item.start_time <= (item.start_time + item.duration); + this_seamless = item.video_src == next_item.video_src && next_item.start_time <= (item.start_time + item.duration) && next_item.start_time > item.start_time; } that.video_next(this_seamless); } else {