/* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package androidx.media3.extractor.text.webvtt; import android.text.TextUtils; import androidx.annotation.Nullable; import androidx.media3.common.Format; import androidx.media3.common.Format.CueReplacementBehavior; import androidx.media3.common.ParserException; import androidx.media3.common.util.Consumer; import androidx.media3.common.util.ParsableByteArray; import androidx.media3.common.util.UnstableApi; import androidx.media3.extractor.text.CuesWithTiming; import androidx.media3.extractor.text.LegacySubtitleUtil; import androidx.media3.extractor.text.SubtitleParser; import java.util.ArrayList; import java.util.List; /** * A {@link SubtitleParser} for WebVTT. * *
See the WebVTT specification.
*/
@UnstableApi
public final class WebvttParser implements SubtitleParser {
/**
* The {@link CueReplacementBehavior} for consecutive {@link CuesWithTiming} emitted by this
* implementation.
*/
public static final @CueReplacementBehavior int CUE_REPLACEMENT_BEHAVIOR =
Format.CUE_REPLACEMENT_BEHAVIOR_MERGE;
private static final int EVENT_NONE = -1;
private static final int EVENT_END_OF_FILE = 0;
private static final int EVENT_COMMENT = 1;
private static final int EVENT_STYLE_BLOCK = 2;
private static final int EVENT_CUE = 3;
private static final String COMMENT_START = "NOTE";
private static final String STYLE_START = "STYLE";
private final ParsableByteArray parsableWebvttData;
private final WebvttCssParser cssParser;
public WebvttParser() {
parsableWebvttData = new ParsableByteArray();
cssParser = new WebvttCssParser();
}
@Override
public @CueReplacementBehavior int getCueReplacementBehavior() {
return CUE_REPLACEMENT_BEHAVIOR;
}
@Override
public void parse(
byte[] data,
int offset,
int length,
OutputOptions outputOptions,
Consumer