ExHLS.Client (ExHLS v0.1.3)

View Source

Module providing functionality to read and demux HLS streams. It allows reading chunks from the stream, choosing variants, and managing media playlists.

Summary

Types

client()

@opaque client()

variant_description()

@type variant_description() :: %{
  id: integer(),
  name: String.t() | nil,
  frame_rate: number() | nil,
  resolution: {integer(), integer()} | nil,
  codecs: String.t() | nil,
  bandwidth: integer() | nil,
  uri: String.t() | nil
}

Functions

choose_variant(client, variant_id)

@spec choose_variant(client(), String.t()) :: client()

generate_stream(client)

@spec generate_stream(client()) :: Enumerable.t(ExHLS.Chunk.t())

get_skipped_segments_cumulative_duration_ms(client)

@spec get_skipped_segments_cumulative_duration_ms(client()) ::
  {:ok, non_neg_integer()} | no_return()

get_tracks_info(client)

@spec get_tracks_info(client()) ::
  {:ok, %{optional(integer()) => struct()}, client()}
  | {:error, reason :: any(), client()}

get_variants(client)

@spec get_variants(client()) :: %{optional(integer()) => variant_description()}

new(url, opts \\ [])

@spec new(String.t(), parent_process: pid(), how_much_to_skip_ms: non_neg_integer()) ::
  client()

Starts the ExHLS client with the given URL.

As options, you can pass :parent_process to specify the parent process that will be allowed to read media chunks when the HLS stream is in the Live mode. Parent process defaults to the process that created the client.

You can also pass :how_much_to_skip_ms option to specify how many milliseconds of the beginning of the stream should be skipped. This option is only supported when the HLS stream is in the VoD mode. Defaults to 0.

Note that there is no guarantee that exactly the specified amount of time will be skipped. The actual skipped duration may be slightly shorter, depending on the HLS segments durations. To get the actual skipped duration, you can use get_skipped_segments_cumulative_duration_ms/1 function.