All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.alexeylapin.m3u8.parser.StartTimeOffsetAttribute Maven / Gradle / Ivy

The newest version!
package com.github.alexeylapin.m3u8.parser;

import com.github.alexeylapin.m3u8.model.StartTimeOffset;
import com.github.alexeylapin.m3u8.model.StartTimeOffset;

import java.util.Map;

import static com.github.alexeylapin.m3u8.parser.ParserUtils.YES;

/*
 * #EXT-X-START:
 */
enum StartTimeOffsetAttribute implements Attribute {
    TIME_OFFSET {
        @Override
        public void read(StartTimeOffset.Builder builder, String value) {
            builder.timeOffset(Double.parseDouble(value));
        }

        @Override
        public void write(StartTimeOffset value, TextBuilder textBuilder) {
            textBuilder.add(key(), String.valueOf(value.timeOffset()));
        }
    },

    PRECISE {
        @Override
        public void read(StartTimeOffset.Builder builder, String value) throws PlaylistParserException {
            builder.precise(ParserUtils.yesOrNo(value));
        }

        @Override
        public void write(StartTimeOffset value, TextBuilder textBuilder) {
            if (value.precise()) {
                textBuilder.add(name(), YES);
            }
        }
    };

    final static Map attributeMap = ParserUtils.toMap(values(), Attribute::key);

    static StartTimeOffset parse(String attributes, ParsingMode parsingMode) throws PlaylistParserException {
        StartTimeOffset.Builder builder = StartTimeOffset.builder();
        ParserUtils.readAttributes(attributeMap, attributes, builder, parsingMode);
        return builder.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy