diff options
author | Brendan Coles <bcoles@gmail.com> | 2020-11-01 06:19:49 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-11-01 10:33:57 +0100 |
commit | 90a30f694db94f7e2ac128e68983a0017b87ea39 (patch) | |
tree | 7bc99488846c7faf2da9c74185d55be75613abc1 | |
parent | 75dec15b43c0ea92dc0c22a2f73b9201f4bd8d85 (diff) | |
download | serenity-90a30f694db94f7e2ac128e68983a0017b87ea39.zip |
SoundPlayer: Optionally allow playback to loop indefinitely
-rw-r--r-- | Applications/SoundPlayer/PlaybackManager.cpp | 10 | ||||
-rw-r--r-- | Applications/SoundPlayer/PlaybackManager.h | 2 | ||||
-rw-r--r-- | Applications/SoundPlayer/main.cpp | 8 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Applications/SoundPlayer/PlaybackManager.cpp b/Applications/SoundPlayer/PlaybackManager.cpp index 551544c022..ce616ff71c 100644 --- a/Applications/SoundPlayer/PlaybackManager.cpp +++ b/Applications/SoundPlayer/PlaybackManager.cpp @@ -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; diff --git a/Applications/SoundPlayer/PlaybackManager.h b/Applications/SoundPlayer/PlaybackManager.h index e07f8b4667..da6adf8cd3 100644 --- a/Applications/SoundPlayer/PlaybackManager.h +++ b/Applications/SoundPlayer/PlaybackManager.h @@ -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 }; diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp index 63b71f81cb..7b249d1ed7 100644 --- a/Applications/SoundPlayer/main.cpp +++ b/Applications/SoundPlayer/main.cpp @@ -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); |