/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include class PlaybackManager final { public: PlaybackManager(NonnullRefPtr); ~PlaybackManager() = default; void play(); void stop(); void pause(); void seek(int const position); void loop(bool); bool toggle_pause(); void set_loader(NonnullRefPtr&&); RefPtr loader() const { return m_loader; } bool is_paused() const { return m_paused; } float total_length() const { return m_total_length; } FixedArray const& current_buffer() const { return m_current_buffer; } NonnullRefPtr connection() const { return m_connection; } Function on_update; Function on_finished_playing; private: // Number of buffers we want to always keep enqueued. static constexpr size_t always_enqueued_buffer_count = 5; void next_buffer(); void set_paused(bool); bool m_paused { true }; bool m_loop = { false }; float m_total_length { 0 }; size_t m_samples_to_load_per_buffer { 0 }; RefPtr m_loader { nullptr }; NonnullRefPtr m_connection; FixedArray m_current_buffer; RefPtr m_timer; // Controls the GUI update rate. A smaller value makes the visualizations nicer. static constexpr u32 update_rate_ms = 50; // Number of milliseconds of audio data contained in each audio buffer static constexpr u32 buffer_size_ms = 100; };