Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Cut off broadcast time left at 0 seconds #10070

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/voice-broadcast/models/VoiceBroadcastPlayback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
14 changes: 14 additions & 0 deletions test/voice-broadcast/models/VoiceBroadcastPlayback-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down