mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:37:37 +00:00
SoundPlayer: Added playback controls
The playback of a file can now be paused, stopped, continued and the user can seek to any part of the file.
This commit is contained in:
parent
2f13517a1a
commit
77f3c12dc9
7 changed files with 405 additions and 49 deletions
48
Applications/SoundPlayer/PlaybackManager.h
Normal file
48
Applications/SoundPlayer/PlaybackManager.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Vector.h>
|
||||
#include <LibAudio/AClientConnection.h>
|
||||
#include <LibAudio/AWavLoader.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
|
||||
#define PLAYBACK_MANAGER_BUFFER_SIZE 64 * KB
|
||||
#define PLAYBACK_MANAGER_RATE 44100
|
||||
|
||||
class PlaybackManager final {
|
||||
public:
|
||||
PlaybackManager(NonnullRefPtr<AClientConnection>, AWavLoader&);
|
||||
~PlaybackManager();
|
||||
|
||||
void play();
|
||||
void stop();
|
||||
void pause();
|
||||
void seek(const int position);
|
||||
bool toggle_pause();
|
||||
|
||||
int last_seek() const { return m_last_seek; }
|
||||
bool is_paused() const { return m_paused; }
|
||||
float total_length() const { return m_total_length; }
|
||||
RefPtr<ABuffer> current_buffer() const { return m_current_buffer; }
|
||||
|
||||
NonnullRefPtr<AClientConnection> connection() const { return m_connection; }
|
||||
AWavLoader& loader() const { return m_loader; }
|
||||
|
||||
Function<void()> on_update;
|
||||
|
||||
private:
|
||||
void next_buffer();
|
||||
void set_paused(bool);
|
||||
void load_next_buffer();
|
||||
void remove_dead_buffers();
|
||||
|
||||
bool m_paused { true };
|
||||
int m_next_ptr { 0 };
|
||||
int m_last_seek { 0 };
|
||||
float m_total_length;
|
||||
AWavLoader& m_loader;
|
||||
NonnullRefPtr<AClientConnection> m_connection;
|
||||
RefPtr<ABuffer> m_next_buffer;
|
||||
RefPtr<ABuffer> m_current_buffer;
|
||||
Vector<RefPtr<ABuffer>> m_buffers;
|
||||
RefPtr<CTimer> m_timer;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue