SoundPlayer: Optionally allow playback to loop indefinitely

This commit is contained in:
Brendan Coles 2020-11-01 06:19:49 +00:00 committed by Andreas Kling
parent 75dec15b43
commit 90a30f694d
Notes: sideshowbarker 2024-07-19 01:36:16 +09:00
3 changed files with 19 additions and 1 deletions

View file

@ -73,6 +73,11 @@ void PlaybackManager::play()
set_paused(false);
}
void PlaybackManager::loop(bool loop)
{
m_loop = loop;
}
void PlaybackManager::seek(const int position)
{
if (!m_loader)
@ -166,7 +171,10 @@ void PlaybackManager::next_buffer()
if (!m_next_buffer) {
if (!m_connection->get_remaining_samples() && !m_paused) {
dbgln("Exhausted samples :^)");
stop();
if (m_loop)
seek(0);
else
stop();
}
return;

View file

@ -43,6 +43,7 @@ public:
void stop();
void pause();
void seek(const int position);
void loop(bool);
bool toggle_pause();
void set_loader(OwnPtr<Audio::WavLoader>&&);
@ -62,6 +63,7 @@ private:
void remove_dead_buffers();
bool m_paused { true };
bool m_loop = { false };
size_t m_next_ptr { 0 };
size_t m_last_seek { 0 };
float m_total_length { 0 };

View file

@ -90,6 +90,14 @@ int main(int argc, char** argv)
app->quit();
}));
auto& playback_menu = menubar->add_menu("Playback");
auto loop = GUI::Action::create_checkable("Loop", { Mod_Ctrl, Key_R }, [&](auto& action) {
player.manager().loop(action.is_checked());
});
playback_menu.add_action(move(loop));
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::Action::create("About", [&](auto&) {
GUI::AboutDialog::show("SoundPlayer", Gfx::Bitmap::load_from_file("/res/icons/32x32/app-sound-player.png"), window);