Skip to content

Duration is not correct after live ended #1721

@KunXi-Fox

Description

@KunXi-Fox

Hi there,

I've noticed that we're having issue with calculate the correct duration for live stream with DVR window after live ended.

I'll trying to explain the issue with example below, let's say:

  • We have a live stream with DVR window, start at 10000
  • User is watching at 10050
  • User has 20 seconds buffered
  • Live stream ended at 10600

Based all those things, while right before live ended, the status should be:

  • videoElement.duration: math.pow(2,32)
  • minimumPosition: 10000
  • maximumPosition: 10600
  • position: 10050

In our codebase, we're calculate the current time and duration as:

currentTime: (position - minimumPosition) = 50
duration: (maximumPosition - minimumPosition) = 600

which is correct.

While live ended, we get:

  • videoElement.duration: 10070 (10050 + 20 which is maxBufferedEnd)
  • minimumPosition: 0
  • maximumPosition: 10070 (which is equal to videoElement.duration)
  • position: 10050

currentTime: (position - minimumPosition) = 10050
duration: (maximumPosition - minimumPosition) = 10070

All those value are totally incorrect, the expected value should be:

currentTime: 50
duration: 600

I've found a way to make current time to correct one, which is after live ended, I call videoElement.current = 50.1 to adjust the current time to correct one. But I can not do anything correct to make duration works fine unless I cache the last dynamic duration (I don't think it's a correct way)

From read code, I found the reason why duration is not correct:

We're change the duration to maxBufferredEnd here:

if (maxBufferedEnd < mediaSource.duration) {
try {
log.info("Init: Updating duration to what is currently buffered", maxBufferedEnd);
mediaSource.duration = maxBufferedEnd;
} catch (err) {
log.warn(
"Duration Updater: Can't update duration on the MediaSource.",
err instanceof Error ? err : "",
);
return MediaSourceDurationUpdateStatus.Failed;
}

and after live ended, we're return duration (wrong value) directly:

if (manifest !== null) {
if (!manifest.isDynamic && this.videoElement !== null) {
return this.videoElement.duration;
}
return getMaximumSafePosition(manifest);

Is there any other way to get it works? Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions