class M3U8::PlaybackStart

Overview

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:

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.

Included Modules

Extended Modules

Defined in:

m3u8/playback_start.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.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>

[View source]
def self.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>

[View source]

Class Method Detail

def self.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>

[View source]

Instance Method Detail

def precise : Bool | Nil #

An optional flag indicating whether the time offset is precise.


[View source]
def precise=(precise : Bool | Nil) #

An optional flag indicating whether the time offset is precise.


[View source]
def time_offset : Float64 #

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


[View source]
def time_offset=(time_offset : Float64) #

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


[View source]
def 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"

[View source]