class

M3U8::PlaybackStart

Inherits M3U8::Concern / Reference / Object

PlaybackStart represents the EXT-X-START tag used in HLS playlists.

The EXT-X-START tag specifies the preferred starting point for playback of a Media Playlist. It includes the following attributes:

  • TIME-OFFSET (required): A decimal number representing the offset (in seconds) from the beginning of the playlist where playback should start. A negative value indicates that playback should begin a certain time before the end of the playlist.
  • PRECISE (optional): A boolean value that indicates whether the time offset is precise. This attribute is represented as "YES" for true and "NO" for false.

According to RFC 8216, Section 4.3.5.2, the tag is formatted as follows:

#EXT-X-START:TIME-OFFSET=-12.9,PRECISE=YES

This class provides methods to parse an EXT-X-START tag from a text string, create a new instance using a NamedTuple of parameters, and output the tag as a properly formatted string.

Constructors

new(params : NamedTuple = NamedTuple.new)

Constructs a new PlaybackStart instance from a NamedTuple of parameters.

The NamedTuple can include:

  • time_offset (Float64 or convertible to Float64): The preferred start offset.
  • precise (Bool): The precision flag.

Example:

options = {
  time_offset: -12.9,
  precise:     true,
}
PlaybackStart.new(options)
# => #<M3U8::PlaybackStart:0x7a950cc56270 @precise=true, @time_offset=-12.9>
Source
new(time_offset, precise : Bool | Nil = nil)

Initializes a new PlaybackStart instance.

The time_offset is converted to a Float, and the precise flag is stored as provided.

Examples:

time_offset = -12.9
precise = true
PlaybackStart.new(time_offset)          # => #<M3U8::PlaybackStart:0x7a8a1a6fd240 @precise=nil, @time_offset=-12.9>
PlaybackStart.new(time_offset, precise) # => #<M3U8::PlaybackStart:0x7a8a1a6fd210 @precise=true, @time_offset=-12.9>
Source

Class methods

parse(text)

Parses a text string representing an EXT-X-START tag and returns a new PlaybackStart instance.

It extracts the TIME-OFFSET and PRECISE attributes from the tag line using the parse_attributes helper (defined in M3U8::Concern), converts them to the appropriate types (with precise parsed as a boolean), and creates a new instance.

Example:

text = "#EXT-X-START:TIME-OFFSET=-12.9,PRECISE=YES"
PlaybackStart.parse(text)
# => #<M3U8::PlaybackStart:0x7acbac72a2a0 @precise=true, @time_offset=-12.9>
Source

Instance methods

precise

An optional flag indicating whether the time offset is precise.

Source
precise=(precise : Bool | Nil)

An optional flag indicating whether the time offset is precise.

Source
time_offset

The time offset in seconds, indicating the preferred start point.

Source
time_offset=(time_offset : Float64)

The time offset in seconds, indicating the preferred start point.

Source
to_s

Returns the string representation of the EXT-X-START tag.

It assembles the formatted attributes and prefixes them with #EXT-X-START:.

Example:

options = {
  time_offset: -12.9,
  precise:     true,
}
PlaybackStart.new(options).to_s
# => "#EXT-X-START:TIME-OFFSET=-12.9,PRECISE=YES"

PlaybackStart.new(time_offset: -12.9).to_s
# => "#EXT-X-START:TIME-OFFSET=-12.9"
Source