Rockbox.Player (rockbox_ex_ffi v0.2.0)

Copy Markdown View Source

Queue-based player with native ReplayGain and Rockbox crossfade.

A player owns a live audio output device and a background engine thread, so it only works where an output device exists. The handle is a NIF resource, freed by the BEAM garbage collector (which stops playback).

ReplayGain mode here uses the player values: 0 off, 1 track, 2 album. Crossfade mode: 0 off, 1 auto-skip, 2 manual-skip, 3 shuffle, 4 shuffle-or-manual, 5 always. Mix mode: 0 crossfade, 1 mix.

Summary

Types

t()

Opaque player handle (a NIF resource).

Functions

Delete the resume file (forget the saved state).

Export the current queue to an .m3u8 file (atomic write).

Import an .m3u/.m3u8 playlist into the queue at position.

Insert file paths / URLs into the queue at position.

Replace the queue with an .m3u/.m3u8 playlist file.

Create a player on the default device with default settings.

Create a player with configuration overrides (see @default_config keys). sample_rate: 0 means the device default.

The current queue as a list of path/URL strings.

Restore the queue + exact position from the player's resume file (does NOT auto-play). Returns {:ok, %{tracks: [...], index: i, elapsed_ms: ms}} or {:error, :absent} when there is nothing to resume.

Persist the queue + exact position to the resume file now.

Replace the queue with a list of file paths.

A snapshot of the player's status as an atom-keyed map.

Types

t()

@opaque t()

Opaque player handle (a NIF resource).

Functions

clear_resume(p)

@spec clear_resume(t()) :: :ok

Delete the resume file (forget the saved state).

enqueue(p, path)

@spec enqueue(t(), Path.t()) :: :ok

export_m3u(p, path)

@spec export_m3u(t(), Path.t()) :: :ok | {:error, :export_failed}

Export the current queue to an .m3u8 file (atomic write).

import_m3u(p, path, position, index \\ 0)

@spec import_m3u(t(), Path.t(), Rockbox.InsertPosition.t() | 0..7, non_neg_integer()) ::
  {:ok, [String.t()]} | {:error, term()}

Import an .m3u/.m3u8 playlist into the queue at position.

Returns {:ok, [path, ...]} with the imported entries, or {:error, reason}. index is only used when position is :index (7).

insert(p, paths, position, index \\ 0)

@spec insert(t(), [Path.t()], Rockbox.InsertPosition.t() | 0..7, non_neg_integer()) ::
  :ok

Insert file paths / URLs into the queue at position.

position is a Rockbox.InsertPosition atom (or its integer code); index is only used when position is :index (7).

load_m3u(p, path)

@spec load_m3u(t(), Path.t()) :: {:ok, [String.t()]} | {:error, term()}

Replace the queue with an .m3u/.m3u8 playlist file.

Returns {:ok, [path, ...]} with the loaded entries, or {:error, reason}.

new()

@spec new() :: t() | nil

Create a player on the default device with default settings.

new(opts)

@spec new(keyword() | map()) :: t() | nil

Create a player with configuration overrides (see @default_config keys). sample_rate: 0 means the device default.

Pass resume_file: "/path/to/state.m3u8" (optionally with resume_save_interval_ms:) to enable automatic queue+position persistence; restore it later with resume/1.

next(p)

@spec next(t()) :: :ok

pause(p)

@spec pause(t()) :: :ok

play(p)

@spec play(t()) :: :ok

previous(p)

@spec previous(t()) :: :ok

queue(p)

@spec queue(t()) :: [String.t()]

The current queue as a list of path/URL strings.

resume(p)

@spec resume(t()) :: {:ok, map()} | {:error, :absent}

Restore the queue + exact position from the player's resume file (does NOT auto-play). Returns {:ok, %{tracks: [...], index: i, elapsed_ms: ms}} or {:error, :absent} when there is nothing to resume.

sample_rate(p)

@spec sample_rate(t()) :: non_neg_integer()

save_resume(p)

@spec save_resume(t()) :: :ok

Persist the queue + exact position to the resume file now.

seek_ms(p, ms)

@spec seek_ms(t(), non_neg_integer()) :: :ok

set_crossfade(p, mode, fo_delay_ms, fo_dur_ms, fi_delay_ms, fi_dur_ms, mix_mode)

@spec set_crossfade(t(), 0..5, integer(), integer(), integer(), integer(), 0..1) ::
  :ok

set_queue(p, paths)

@spec set_queue(t(), [Path.t()]) :: :ok

Replace the queue with a list of file paths.

set_replaygain(p, mode, preamp_db, prevent_clipping)

@spec set_replaygain(t(), 0..2, number(), boolean()) :: :ok

set_volume(p, vol)

@spec set_volume(t(), number()) :: :ok

skip_to(p, index)

@spec skip_to(t(), non_neg_integer()) :: :ok

status(p)

@spec status(t()) :: map()

A snapshot of the player's status as an atom-keyed map.

stop(p)

@spec stop(t()) :: :ok

toggle(p)

@spec toggle(t()) :: :ok

volume(p)

@spec volume(t()) :: float()