@@ -107,15 +107,17 @@ public final class Mp3Extractor implements Extractor {
107107 public static final int FLAG_ENABLE_CONSTANT_BITRATE_SEEKING_ALWAYS = 1 << 1 ;
108108
109109 /**
110- * Flag to force index seeking, in which a time-to-byte mapping is built as the file is read.
110+ * Flag to enable index seeking, in which a time-to-byte mapping is built as the file is read. If
111+ * other seeking metadata (e.g., Xing, VBRI, MLLT) is present in the file, it will be preferred
112+ * for performance reasons. This flag allows index seeking to be used as a fallback in cases where
113+ * no other seeking metadata is available.
111114 *
112115 * <p>This seeker may require to scan a significant portion of the file to compute a seek point.
113116 * Therefore, it should only be used if one of the following is true:
114117 *
115118 * <ul>
116119 * <li>The file is small.
117- * <li>The bitrate is variable (or it's unknown whether it's variable) and the file does not
118- * provide precise enough seeking metadata.
120+ * <li>The bitrate is variable (or it's unknown whether it's variable).
119121 * </ul>
120122 */
121123 public static final int FLAG_ENABLE_INDEX_SEEKING = 1 << 2 ;
@@ -479,27 +481,23 @@ private Seeker computeSeeker(ExtractorInput input) throws IOException {
479481 }
480482
481483 @ Nullable Seeker resultSeeker = null ;
482- if ((flags & FLAG_ENABLE_INDEX_SEEKING ) != 0 ) {
483- long durationUs ;
484- long dataEndPosition = C .INDEX_UNSET ;
485- if (metadataSeeker != null ) {
486- durationUs = metadataSeeker .getDurationUs ();
487- dataEndPosition = metadataSeeker .getDataEndPosition ();
488- } else if (seekFrameSeeker != null ) {
489- durationUs = seekFrameSeeker .getDurationUs ();
490- dataEndPosition = seekFrameSeeker .getDataEndPosition ();
491- } else {
492- durationUs = getId3TlenUs (metadata );
493- }
494- resultSeeker =
495- new IndexSeeker (
496- durationUs , /* dataStartPosition= */ input .getPosition (), dataEndPosition );
497- } else if (metadataSeeker != null ) {
484+ if (metadataSeeker != null ) {
498485 resultSeeker = metadataSeeker ;
499486 } else if (seekFrameSeeker != null ) {
500487 resultSeeker = seekFrameSeeker ;
501488 }
502489
490+ if ((flags & FLAG_ENABLE_INDEX_SEEKING ) != 0
491+ && (resultSeeker == null || !resultSeeker .isSeekable ())) {
492+ long durationUs =
493+ resultSeeker != null ? resultSeeker .getDurationUs () : getId3TlenUs (metadata );
494+ long dataEndPosition =
495+ resultSeeker != null ? resultSeeker .getDataEndPosition () : C .INDEX_UNSET ;
496+ resultSeeker =
497+ new IndexSeeker (
498+ durationUs , /* dataStartPosition= */ input .getPosition (), dataEndPosition );
499+ }
500+
503501 if (resultSeeker != null
504502 && shouldFallbackToConstantBitrateSeeking (resultSeeker )
505503 && resultSeeker .getDurationUs () != C .TIME_UNSET
0 commit comments