Current section

Files

Jump to
rockbox_ffi src play.erl
Raw

src/play.erl

-module(play).
-compile([no_auto_import, nowarn_ignored, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-export([main/0]).
-export_type([charlist/0]).
-moduledoc(~" Play an audio source through the real output device.
The queue entry can be a local file, a remote `http(s)://` file, an
internet-radio stream, or an HLS (`.m3u8`) / MPEG-DASH (`.mpd`)
manifest — the engine detects each kind automatically.
Run: gleam run -m play [path-or-URL]
gleam run -m play hls # public HLS test stream
gleam run -m play dash # public MPEG-DASH test stream
The `Player` handle is a NIF resource freed by the BEAM garbage collector
(which stops playback) — no explicit close is needed. Ctrl-C twice opens
the BEAM break menu, which halts the VM and the output device with it.").
-type charlist() :: any().
-file("src/play.gleam", 53).
-spec poll(rockbox@player:player()) -> nil.
poll(P) ->
St = rockbox@player:status(P),
Pos = erlang:integer_to_binary(erlang:element(4, St) div 1000),
Clock = case erlang:element(5, St) of
0 ->
<<Pos/binary, "s / LIVE"/utf8>>;
_ ->
<<<<<<Pos/binary, "s / "/utf8>>/binary, (erlang:integer_to_binary(erlang:element(5, St) div 1000))/binary>>/binary, "s"/utf8>>
end,
gleam_stdlib:print(<<<<<<<<"\r["/utf8, (erlang:element(2, St))/binary>>/binary, "] "/utf8>>/binary, Clock/binary>>/binary, " "/utf8>>),
case (erlang:element(2, St) =:= ~"stopped") andalso (erlang:element(4, St) > 0) of
true ->
gleam_stdlib:println(~"\n✔ done");
false ->
timer:sleep(500),
poll(P)
end.
-file("src/play.gleam", 28).
-spec main() -> nil.
main() ->
Source = case gleam@list:map(init:get_plain_arguments(), fun unicode:characters_to_binary/1) of
[~"hls" | _] ->
~"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8";
[~"dash" | _] ->
~"https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
[Path | _] ->
Path;
[] ->
~"../../crates/rocksky/fixtures/08 - Internet Money - Speak(Explicit).m4a"
end,
P = rockbox@player:with_config(begin
_record = rockbox@player:default_config(),
{config, erlang:element(2, _record), erlang:element(3, _record), 0.8, erlang:element(5, _record), erlang:element(6, _record), erlang:element(7, _record), erlang:element(8, _record), erlang:element(9, _record), erlang:element(10, _record), erlang:element(11, _record), erlang:element(12, _record), erlang:element(13, _record), erlang:element(14, _record), erlang:element(15, _record), erlang:element(16, _record)}
end),
P@1 = begin
_pipe = P,
_pipe@1 = rockbox@player:set_queue(_pipe, [Source]),
_pipe@2 = rockbox@player:set_eq_preset(_pipe@1, bass_boost),
_pipe@3 = rockbox@player:set_bass(_pipe@2, 7),
_pipe@4 = rockbox@player:set_treble(_pipe@3, 4),
rockbox@player:play(_pipe@4)
end,
gleam_stdlib:println(<<"▶ playing "/utf8, Source/binary>>),
gleam_stdlib:println(~"eq: BassBoost preset, bass +7 dB, treble +4 dB"),
poll(P@1).