mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 10:39:57 +00:00
Fix cast.media.Media#getEstimatedTime
This commit is contained in:
@@ -75,7 +75,7 @@ export default class Media {
|
|||||||
#isActive = true;
|
#isActive = true;
|
||||||
#updateListeners = new Set<UpdateListener>();
|
#updateListeners = new Set<UpdateListener>();
|
||||||
#sendMediaMessageCallbacks = new Map<string, Callbacks>();
|
#sendMediaMessageCallbacks = new Map<string, Callbacks>();
|
||||||
#lastCurrentTime?: number;
|
#lastCurrentTime = 0;
|
||||||
|
|
||||||
#listener = onMessage(message => {
|
#listener = onMessage(message => {
|
||||||
if ((message as any).data._id !== this.#id) {
|
if ((message as any).data._id !== this.#id) {
|
||||||
@@ -194,12 +194,21 @@ export default class Media {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getEstimatedTime(): number {
|
public getEstimatedTime(): number {
|
||||||
if (this.currentTime === undefined
|
if (this.playerState === PlayerState.PLAYING) {
|
||||||
|| this.#lastCurrentTime === undefined) {
|
let estimatedTime = this.currentTime + (this.playbackRate * (
|
||||||
return 0;
|
Date.now() - this.#lastCurrentTime) / 1000);
|
||||||
|
|
||||||
|
// Enforce valid range
|
||||||
|
if (this.media?.duration && estimatedTime > this.media.duration) {
|
||||||
|
estimatedTime = this.media.duration;
|
||||||
|
} else if (estimatedTime < 0) {
|
||||||
|
estimatedTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return estimatedTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.currentTime + ((Date.now() / 1000) - this.#lastCurrentTime);
|
return this.currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStatus(
|
public getStatus(
|
||||||
|
|||||||
Reference in New Issue
Block a user