summaryrefslogtreecommitdiffhomepage
path: root/src/player.h
blob: 5ff8d7ca2a50e02d95742d998a66b379241e3f7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

/* player.h — audio playback contract.
 *
 * Owns: loading MP3 files, play/pause/seek, time formatting,
 * music-stream updates, cleanup. */

#include "types.h"

/* Load an MP3 file into the player. Handles unloading any previously
 * loaded stream. Sets state->loaded, state->playing, state->duration,
 * state->filename. Returns true on success. */
bool player_load(PlayerState *state, const char *path);

/* Unload the current audio stream and reset loaded/playing flags. */
void player_unload(PlayerState *state);

/* Playback control. No-ops if nothing is loaded. */
void player_play(PlayerState *state);
void player_pause(PlayerState *state);

/* Seek to an absolute time (seconds), clamped to [0, duration]. */
void player_seek(PlayerState *state, float target);

/* Per-frame update: pumps the music stream and refreshes currentTime.
 * Call once per frame while state->loaded is true. */
void player_update(PlayerState *state);

/* Format a time in seconds as "H:MM:SS" or "M:SS" into buf. */
void player_format_time(float seconds, char *buf, int bufsize);