Skip to content

Commit

Permalink
Trigger ended event when end = duration (#722)
Browse files Browse the repository at this point in the history
* Trigger ended event when end = duration

* Use player.duration() in place of duration in Manifest for ended event trigger
  • Loading branch information
Dananji authored Nov 11, 2024
1 parent 7ab894d commit 7da6347
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/components/MediaPlayer/VideoJS/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,14 @@ function VideoJSPlayer({
}
}

/**
* Set structStart variable in the updated player to update the progressBar with the
* correct time when using StructuredNavigation to switch between canvases.
* Set this before loadedmetadata event, because progress-bar uses this value in the
* update() function before that event emits.
*/
player.structStart = currentTimeRef.current;

playerLoadedMetadata(player);
};

Expand Down Expand Up @@ -392,11 +400,6 @@ function VideoJSPlayer({
}

isEndedRef.current ? player.currentTime(0) : player.currentTime(currentTimeRef.current);
/**
* Set structStart variable in the updated player to update the progressBar with the
* correct time when using StructuredNavigation to switch between canvases
*/
player.structStart = currentTimeRef.current;

if (isEndedRef.current || isPlayingRef.current) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class CustomSeekBar extends SeekBar {
if (!el_ || !player || !canvasTargetsRef.current) {
return;
}
const { start, end, duration } = canvasTargetsRef.current[srcIndexRef.current ?? 0];
const { start, end } = canvasTargetsRef.current[srcIndexRef.current ?? 0];

// Restrict access to the intended range in the media file
if (curTime < start) {
Expand All @@ -452,9 +452,14 @@ class CustomSeekBar extends SeekBar {
if (curTime >= end && !player.paused() && !player.isDisposed()) {
// Trigger ended event when playable range < duration of the
// full media. e.g. clipped playlist items
if (end < duration) {
if (end < player.duration()) {
player.trigger('ended');
}
// Reset progress-bar played range
document.documentElement.style.setProperty(
'--range-progress', `calc(${0}%)`
);
this.removeClass('played-range');

// On the next play event set the time to start or a seeked time
// in between the 'ended' event and 'play' event
Expand Down

0 comments on commit 7da6347

Please sign in to comment.