Skip to content

Commit 1242a71

Browse files
committed
fix: Fix NaN and undefined initial states for rt player #292
1 parent b724eca commit 1242a71

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/backend/sources/PlayerState/RealtimePlayer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export abstract class RealtimePlayer {
1313
private clockTS: Dayjs = dayjs();
1414

1515
protected constructor(/* logger: Logger */) {
16-
//this.logger = childLogger(logger, `RT`);
16+
this.position = 0;
1717
const job = new SimpleIntervalJob({
1818
milliseconds: RT_TICK,
1919
runImmediately: true
@@ -27,7 +27,6 @@ export abstract class RealtimePlayer {
2727
}), { id: 'rt' });
2828
this.scheduler.addSimpleIntervalJob(job);
2929
this.scheduler.stop();
30-
this.position = 0;
3130
}
3231

3332
public play(position?: number) {
@@ -52,14 +51,18 @@ export abstract class RealtimePlayer {
5251
}
5352

5453
public getPosition(asSeconds: boolean = false) {
54+
if(this.position === 0 || this.position === undefined) {
55+
return 0;
56+
}
5557
return !asSeconds ? this.position : this.position / 1000;
5658
}
5759

5860
public setPosition(time?: number) {
5961
if(time === undefined) {
6062
this.position += Math.abs(dayjs().diff(this.clockTS, 'ms'));
63+
} else {
64+
this.position = time;
6165
}
62-
this.position = time;
6366
this.clockTS = dayjs();
6467
}
6568
}

0 commit comments

Comments
 (0)