Skip to content

Bug in discardCuesBeforeTimeUs() in ReplacingCuesResolver.java #1939

Closed
@wischnow

Description

Version

Media3 1.5.0

More version details

Tested with version 1.5.0, but this is a very long standing bug.

Devices that reproduce the issue

The bug is device-independent.

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

I have had a small patch for exoplayer/media3 which adds support for Vobsub subtitles. Evene though there I create CuesWithTiming objects with a durationUs of 5 seconds, the subtitles were never removed from display. I finally found the time to dig deeper and find the bug. Look at discardCuesBeforeTimeUs() in ReplacingCuesResolver.java:

  public void discardCuesBeforeTimeUs(long timeUs) {
    int indexToDiscardTo = getIndexOfCuesStartingAfter(timeUs);
    if (indexToDiscardTo > 0) {
      cuesWithTimingList.subList(0, indexToDiscardTo).clear();
    }
  }

Since getIndexOfCuesStartingAfter() only looks at startTimeUs (as the name implies), this will also remove cues whose endTimeUs has not been reached yet, so that reaching that time will not trigger removing the subtitle.

To fix this, I admit, I was lazy:

  public void discardCuesBeforeTimeUs(long timeUs) {
    int indexToDiscardTo = getIndexOfCuesStartingAfter(timeUs);

    if (indexToDiscardTo > 1) {
      cuesWithTimingList.subList(0, indexToDiscardTo - 1).clear();
    }
  }

A more thorough implementation would check whether the endTimeUs of that cue is in the past or not, but since getPreviousCueChangeTimeUs() and getNextCueChangeTimeUs() check the times correctly, being lazy works in this case.

It may well be that this bug is never triggered for the types of subtitles supported by media3 out of the box, but that code is still wrong.

Expected result

See the description above.

Actual result

See the description above.

Media

None available

Bug Report

  • You will email the zip file produced by adb bugreport to [email protected] after filing this issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions