Made countdown timer better support video playback speeds

This commit is contained in:
Ajay Ramachandran
2021-01-17 14:39:29 -05:00
parent e269b1aec6
commit 551355d21a
2 changed files with 16 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ export interface NoticeProps {
timed?: boolean, timed?: boolean,
idSuffix?: string, idSuffix?: string,
videoSpeed?: () => number,
fadeIn?: boolean, fadeIn?: boolean,
// Callback for when this is closed // Callback for when this is closed
@@ -19,7 +21,7 @@ export interface NoticeProps {
export interface NoticeState { export interface NoticeState {
noticeTitle: string, noticeTitle: string,
maxCountdownTime?: () => number, maxCountdownTime: () => number,
countdownTime: number, countdownTime: number,
countdownText: string, countdownText: string,
@@ -28,6 +30,8 @@ export interface NoticeState {
class NoticeComponent extends React.Component<NoticeProps, NoticeState> { class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
countdownInterval: NodeJS.Timeout; countdownInterval: NodeJS.Timeout;
intervalVideoSpeed: number;
idSuffix: string; idSuffix: string;
amountOfPreviousNotices: number; amountOfPreviousNotices: number;
@@ -154,7 +158,11 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
countdown(): void { countdown(): void {
if (!this.props.timed) return; if (!this.props.timed) return;
const countdownTime = this.state.countdownTime - 1; const countdownTime = Math.min(this.state.countdownTime - 1, this.state.maxCountdownTime());
if (this.props.videoSpeed && this.intervalVideoSpeed != this.props.videoSpeed()) {
this.setupInterval();
}
if (countdownTime <= 0) { if (countdownTime <= 0) {
//remove this from setInterval //remove this from setInterval
@@ -217,7 +225,11 @@ class NoticeComponent extends React.Component<NoticeProps, NoticeState> {
setupInterval(): void { setupInterval(): void {
if (this.countdownInterval) clearInterval(this.countdownInterval); if (this.countdownInterval) clearInterval(this.countdownInterval);
this.countdownInterval = setInterval(this.countdown.bind(this), 1000);
const intervalDuration = this.props.videoSpeed ? 1000 / this.props.videoSpeed() : 1000;
this.countdownInterval = setInterval(this.countdown.bind(this), intervalDuration);
if (this.props.videoSpeed) this.intervalVideoSpeed = this.props.videoSpeed();
} }
resetCountdown(): void { resetCountdown(): void {

View File

@@ -141,6 +141,7 @@ class SkipNoticeComponent extends React.Component<SkipNoticeProps, SkipNoticeSta
fadeIn={true} fadeIn={true}
timed={true} timed={true}
maxCountdownTime={this.state.maxCountdownTime} maxCountdownTime={this.state.maxCountdownTime}
videoSpeed={() => this.contentContainer().v?.playbackRate}
ref={this.noticeRef} ref={this.noticeRef}
closeListener={() => this.closeListener()}> closeListener={() => this.closeListener()}>