mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 22:58: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:
parent
2f13517a1a
commit
77f3c12dc9
7 changed files with 405 additions and 49 deletions
|
@ -1,11 +1,18 @@
|
|||
#include "SampleWidget.h"
|
||||
#include "SoundPlayerWidget.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibAudio/ABuffer.h>
|
||||
#include <LibAudio/AClientConnection.h>
|
||||
#include <LibAudio/AWavLoader.h>
|
||||
#include <LibCore/CTimer.h>
|
||||
#include <LibDraw/CharacterBitmap.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GApplication.h>
|
||||
#include <LibGUI/GBoxLayout.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GLabel.h>
|
||||
#include <LibGUI/GMenu.h>
|
||||
#include <LibGUI/GMenuBar.h>
|
||||
#include <LibGUI/GSlider.h>
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibGUI/GWindow.h>
|
||||
#include <stdio.h>
|
||||
|
@ -30,43 +37,24 @@ int main(int argc, char** argv)
|
|||
auto audio_client = AClientConnection::construct();
|
||||
audio_client->handshake();
|
||||
|
||||
auto app_menu = make<GMenu>("SoundPlayer");
|
||||
app_menu->add_action(GCommonActions::make_quit_action([&](auto&) {
|
||||
app.quit();
|
||||
}));
|
||||
|
||||
auto menubar = make<GMenuBar>();
|
||||
menubar->add_menu(move(app_menu));
|
||||
app.set_menubar(move(menubar));
|
||||
|
||||
auto window = GWindow::construct();
|
||||
window->set_title("SoundPlayer");
|
||||
window->set_rect(300, 300, 300, 200);
|
||||
|
||||
auto widget = GWidget::construct();
|
||||
window->set_main_widget(widget);
|
||||
|
||||
widget->set_fill_with_background_color(true);
|
||||
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||
widget->layout()->set_margins({ 2, 2, 2, 2 });
|
||||
|
||||
auto sample_widget = SampleWidget::construct(widget);
|
||||
|
||||
auto button = GButton::construct("Quit", widget);
|
||||
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||
button->set_preferred_size(0, 20);
|
||||
button->on_click = [&](auto&) {
|
||||
app.quit();
|
||||
};
|
||||
|
||||
auto next_sample_buffer = loader.get_more_samples();
|
||||
|
||||
auto timer = CTimer::construct(100, [&] {
|
||||
if (!next_sample_buffer) {
|
||||
sample_widget->set_buffer(nullptr);
|
||||
return;
|
||||
}
|
||||
bool enqueued = audio_client->try_enqueue(*next_sample_buffer);
|
||||
if (!enqueued)
|
||||
return;
|
||||
sample_widget->set_buffer(next_sample_buffer);
|
||||
next_sample_buffer = loader.get_more_samples(16 * KB);
|
||||
if (!next_sample_buffer) {
|
||||
dbg() << "Exhausted samples :^)";
|
||||
}
|
||||
});
|
||||
window->set_resizable(false);
|
||||
window->set_rect(300, 300, 350, 140);
|
||||
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/app-sound-player.png"));
|
||||
|
||||
auto player = SoundPlayerWidget::construct(audio_client, loader);
|
||||
window->set_main_widget(player);
|
||||
window->show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue