Build an audio player with Ifa-Lang's Ohun (Audio) domain.
// Simple Audio Player
ayanmo playlist = Odi.akojopo("music/*.mp3");
ayanmo current = 0;
ayanmo playing = iro;
ese play_track(index) {
ti index >= 0 && index < Ogunda.len(playlist) {
ayanmo track = Ogunda.gba(playlist, index);
Ohun.play(track);
playing = otito;
Irosu.fo("Playing: " + track);
}
}
ese pause() {
Ohun.pause();
playing = iro;
}
ese next() {
current = current + 1;
ti current >= Ogunda.len(playlist) {
current = 0;
}
play_track(current);
}
ese previous() {
current = current - 1;
ti current < 0 {
current = Ogunda.len(playlist) - 1;
}
play_track(current);
}
// Start playing
play_track(0);
// Handle events
Ohun.on_complete(ese() {
next();
});
// Terminal UI for player
nigba otito {
Ose.clear();
Irosu.fo("=== Ifa Music Player ===");
Irosu.fo("Now: " + Ogunda.gba(playlist, current));
Irosu.fo("");
Irosu.fo("[P] Play/Pause [N] Next [B] Back [Q] Quit");
ayanmo key = Ose.getch();
yà n key {
"p" => ti playing { pause(); } bibẹkỠ{ play_track(current); }
"n" => next();
"b" => previous();
"q" => da;
}
}