From cfba1b07c65cba3463c9b0aa2640d6bde65cb9d5 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 3 Feb 2023 13:49:43 +0100 Subject: [PATCH] Broadcast time left should never be negative (#10070) --- .../models/VoiceBroadcastPlayback.ts | 4 +++- .../models/VoiceBroadcastPlayback-test.tsx | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/voice-broadcast/models/VoiceBroadcastPlayback.ts b/src/voice-broadcast/models/VoiceBroadcastPlayback.ts index 94ccaac1fb..0a5442cb62 100644 --- a/src/voice-broadcast/models/VoiceBroadcastPlayback.ts +++ b/src/voice-broadcast/models/VoiceBroadcastPlayback.ts @@ -441,7 +441,9 @@ export class VoiceBroadcastPlayback } public get timeLeftSeconds(): number { - return Math.round(this.durationSeconds) - this.timeSeconds; + // Sometimes the meta data and the audio files are a little bit out of sync. + // Be sure it never returns a negative value. + return Math.max(0, Math.round(this.durationSeconds) - this.timeSeconds); } public async skipTo(timeSeconds: number): Promise { diff --git a/test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx b/test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx index ac4217e048..e7f4c8afcc 100644 --- a/test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx +++ b/test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx @@ -525,6 +525,20 @@ describe("VoiceBroadcastPlayback", () => { it("should update the time", () => { expect(playback.timeSeconds).toBe(11); + expect(playback.timeLeftSeconds).toBe(2); + }); + }); + + describe("and the chunk playback progresses across the actual time", () => { + // This can be the case if the meta data is out of sync with the actual audio data. + + beforeEach(() => { + chunk1Playback.clockInfo.liveData.update([15]); + }); + + it("should update the time", () => { + expect(playback.timeSeconds).toBe(15); + expect(playback.timeLeftSeconds).toBe(0); }); });