Skip to content

playbackRate computation for slowdown seems to be wrong #230

@chrisguttandin

Description

@chrisguttandin

I think the playbackRate computation is wrong when the media element needs to slow down. It's at least not symmetric when compared to the speed up but maybe that's intentional.

Let's imagine the media element has a currentTime of 8.8 but it should be at the targetTime of 8.2. The diff computed as targetTime - currentTime is then -0.6. That means the following code ...

const rate = Math.max(
0,
((diff + this._correctionTime) / this._correctionTime) *
sourcePlaybackRate
);

... evaluates like this:

const rate = Math.max(0, ((-0,6 + 0,5) / 0,5) * sourcePlaybackRate);
const rate = Math.max(0, -0,2 * sourcePlaybackRate);
const rate = 0;

I guess when the media element has to slow down it should instead be something like the following:

const rate = sourcePlaybackRate / ((Math.abs(-0,6) + 0,5) / 0,5);
const rate = sourcePlaybackRate / 2.2;

What about changing the rate computation to something like this?

const rate = diff > 0
    ? ((diff + this._correctionTime) / this._correctionTime) * sourcePlaybackRate
    : sourcePlaybackRate / ((this._correctionTime - diff) / this._correctionTime);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions