text/plain
•
2.43 KB
•
87 lines
#pragma once
#include <stdbool.h>
#include "storage.h"
typedef enum {
PLAYLIST_MUSIC,
PLAYLIST_AUDIOBOOK,
} playlist_type_t;
typedef struct {
playlist_type_t type;
char path[STORAGE_MAX_PATH];
} playlist_entry_t;
typedef struct {
int index;
int count;
playlist_entry_t entries[PLAYLIST_MAX_ENTRIES];
} playlist_t;
extern playlist_t playlist;
// Load playlist from .onigiri/playlist.toml
void playlist_load(void);
// Save playlist to .onigiri/playlist.toml
void playlist_save(void);
// Add entry to end of playlist
void playlist_add(const char* path, playlist_type_t type);
// Clear all entries, reset index to 0
void playlist_clear(void);
// Return pointer to entry at current index (or NULL if empty)
playlist_entry_t* playlist_current(void);
// Advance to next entry. Returns false if at end.
bool playlist_next(void);
// Go to previous entry. Returns false if at beginning.
bool playlist_prev(void);
bool playlist_is_empty(void);
int playlist_count(void);
// Set current index
void playlist_set_index(int i);
// Call from main loop — periodically saves audiobook bookmark
void playlist_tick(void);
// --- High-level playback control (moved from now_playing_screen) ---
// Start playback of current playlist entry. Returns false on failure.
bool playlist_start(void);
// High-level next: saves bookmarks, advances to next entry, starts playback.
// Returns false if at end of playlist.
bool playlist_play_next(void);
// High-level prev: for music, restarts if >10s in; for audiobooks, always goes
// back. Returns false if already at beginning (music will restart instead).
bool playlist_play_prev(void);
// Save current audiobook bookmarks (position + chapter).
void playlist_save_bookmarks(void);
// Call from update loop. Handles auto-advance on playback completion.
// Returns true if playback ended and playlist was cleared (caller should
// navigate away).
bool playlist_check_advance(void);
// Apply pending bookmark seek when player becomes ready. Call each frame.
void playlist_apply_bookmark(void);
// Query chapter info for display. Returns false if not in directory audiobook
// mode.
bool playlist_get_chapter_info(int* current, int* total);
// Get the pending bookmark position (0 if none).
uint32_t playlist_get_bookmark_ms(void);
bool playlist_is_bookmark_applied(void);
// Sync internal state to match already-playing audio (e.g. when re-entering
// the now-playing screen while audio is already running).
void playlist_sync_state(void);