1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +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:
Till Mayer 2019-11-04 19:45:19 +01:00 committed by Andreas Kling
parent 2f13517a1a
commit 77f3c12dc9
7 changed files with 405 additions and 49 deletions

View file

@ -0,0 +1,59 @@
#pragma once
#include "PlaybackManager.h"
#include "SampleWidget.h"
#include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h>
#include <LibGUI/GSlider.h>
#include <LibGUI/GWidget.h>
class SoundPlayerWidget final : public GWidget {
C_OBJECT(SoundPlayerWidget)
public:
virtual ~SoundPlayerWidget() override;
private:
explicit SoundPlayerWidget(NonnullRefPtr<AClientConnection>, AWavLoader&);
void update_position(const int position);
void update_ui();
int normalize_rate(int) const;
int denormalize_rate(int) const;
class Slider final : public GSlider {
C_OBJECT(Slider)
public:
virtual ~Slider() override;
Function<void(int)> on_knob_released;
void set_value(int value)
{
if (!knob_dragging())
GSlider::set_value(value);
}
protected:
Slider(Orientation orientation, GWidget* parent)
: GSlider(orientation, parent)
{
}
virtual void mouseup_event(GMouseEvent& event) override
{
if (on_knob_released && is_enabled())
on_knob_released(value());
GSlider::mouseup_event(event);
}
};
PlaybackManager m_manager;
float m_sample_ratio;
RefPtr<GLabel> m_status;
RefPtr<GLabel> m_elapsed;
RefPtr<GLabel> m_remaining;
RefPtr<Slider> m_slider;
RefPtr<SampleWidget> m_sample_widget;
RefPtr<GraphicsBitmap> m_play_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/play.png") };
RefPtr<GraphicsBitmap> m_pause_icon { GraphicsBitmap::load_from_file("/res/icons/16x16/pause.png") };
RefPtr<GButton> m_play;
};