Skip to content

Commit

Permalink
fix(embed-process.ts): player no longer paused when first loop ends
Browse files Browse the repository at this point in the history
close #21
  • Loading branch information
aidenlx committed May 12, 2021
1 parent 0d8dbbf commit d0f8e24
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/modules/embed-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ export function injectTimestamp(player: Player, timeSpan: TimeSpan): Player_TF {
}

// inject event handler to restrict play range

/**
* if current is out of range when start playing,
* move currentTime back to timeSpan.start
**/
const onplaying = (e: Event) => {
if (!playerTF.timeSpan) throw new Error("timeSpan not found");

Expand All @@ -201,6 +206,10 @@ export function injectTimestamp(player: Player, timeSpan: TimeSpan): Player_TF {
playerTF.currentTime = start;
}
};
/**
* if currentTime reaches end, pause video
* or play at start when loop is enabled
*/
const ontimeupdate = (e: Event) => {
if (!playerTF.timeSpan) throw new Error("timeSpan not found");

Expand All @@ -213,6 +222,9 @@ export function injectTimestamp(player: Player, timeSpan: TimeSpan): Player_TF {
playerTF.pause();
} else {
playerTF.currentTime = start;
// continue to play in loop
// if temporal fragment (#t=,2 at the end of src) paused the video
if(playerTF.paused) playerTF.play();
}
}
};
Expand Down

0 comments on commit d0f8e24

Please sign in to comment.