mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:27:35 +00:00
VideoPlayer: Port to GML
This commit is contained in:
parent
f0a33b2a8e
commit
f63ecc2763
7 changed files with 95 additions and 42 deletions
|
@ -4,11 +4,17 @@ serenity_component(
|
||||||
DEPENDS AudioServer
|
DEPENDS AudioServer
|
||||||
)
|
)
|
||||||
|
|
||||||
|
compile_gml(VideoPlayerWindow.gml VideoPlayerWindowGML.h videoplayer_window_gml)
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
main.cpp
|
main.cpp
|
||||||
VideoFrameWidget.cpp
|
VideoFrameWidget.cpp
|
||||||
VideoPlayerWidget.cpp
|
VideoPlayerWidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(GENERATED_SOURCES
|
||||||
|
VideoPlayerWindowGML.h
|
||||||
|
)
|
||||||
|
|
||||||
serenity_app(VideoPlayer ICON app-video-player)
|
serenity_app(VideoPlayer ICON app-video-player)
|
||||||
target_link_libraries(VideoPlayer PRIVATE LibVideo LibAudio LibCore LibGfx LibGUI LibMain)
|
target_link_libraries(VideoPlayer PRIVATE LibVideo LibAudio LibCore LibGfx LibGUI LibMain)
|
||||||
|
|
|
@ -9,10 +9,13 @@
|
||||||
|
|
||||||
#include "VideoFrameWidget.h"
|
#include "VideoFrameWidget.h"
|
||||||
|
|
||||||
|
REGISTER_WIDGET(VideoPlayer, VideoFrameWidget);
|
||||||
|
|
||||||
namespace VideoPlayer {
|
namespace VideoPlayer {
|
||||||
|
|
||||||
VideoFrameWidget::VideoFrameWidget()
|
VideoFrameWidget::VideoFrameWidget()
|
||||||
{
|
{
|
||||||
|
REGISTER_BOOL_PROPERTY("auto_resize", auto_resize, set_auto_resize);
|
||||||
set_auto_resize(true);
|
set_auto_resize(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ enum class VideoSizingMode : u8 {
|
||||||
Sentinel
|
Sentinel
|
||||||
};
|
};
|
||||||
|
|
||||||
class VideoFrameWidget : public GUI::Frame {
|
class VideoFrameWidget final : public GUI::Frame {
|
||||||
C_OBJECT(VideoFrameWidget)
|
C_OBJECT(VideoFrameWidget)
|
||||||
public:
|
public:
|
||||||
virtual ~VideoFrameWidget() override = default;
|
virtual ~VideoFrameWidget() override = default;
|
||||||
|
|
|
@ -15,29 +15,28 @@
|
||||||
#include <LibGUI/Toolbar.h>
|
#include <LibGUI/Toolbar.h>
|
||||||
#include <LibGUI/ToolbarContainer.h>
|
#include <LibGUI/ToolbarContainer.h>
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
#include <Userland/Applications/VideoPlayer/VideoPlayerWindowGML.h>
|
||||||
|
|
||||||
#include "VideoPlayerWidget.h"
|
#include "VideoPlayerWidget.h"
|
||||||
|
|
||||||
namespace VideoPlayer {
|
namespace VideoPlayer {
|
||||||
|
|
||||||
VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
ErrorOr<NonnullRefPtr<VideoPlayerWidget>> VideoPlayerWidget::try_create()
|
||||||
: m_window(window)
|
|
||||||
{
|
{
|
||||||
set_fill_with_background_color(true);
|
auto main_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) VideoPlayerWidget()));
|
||||||
|
TRY(main_widget->load_from_gml(videoplayer_window_gml));
|
||||||
|
|
||||||
set_layout<GUI::VerticalBoxLayout>();
|
TRY(main_widget->setup_interface());
|
||||||
|
|
||||||
m_video_display = add<VideoFrameWidget>();
|
return main_widget;
|
||||||
m_video_display->set_auto_resize(false);
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> VideoPlayerWidget::setup_interface()
|
||||||
|
{
|
||||||
|
m_video_display = find_descendant_of_type_named<VideoPlayer::VideoFrameWidget>("video_frame");
|
||||||
m_video_display->on_click = [&]() { toggle_pause(); };
|
m_video_display->on_click = [&]() { toggle_pause(); };
|
||||||
|
|
||||||
auto& player_controls_widget = add<GUI::Widget>();
|
m_seek_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("seek_slider");
|
||||||
player_controls_widget.set_layout<GUI::VerticalBoxLayout>();
|
|
||||||
player_controls_widget.set_max_height(50);
|
|
||||||
|
|
||||||
m_seek_slider = player_controls_widget.add<GUI::HorizontalSlider>();
|
|
||||||
m_seek_slider->set_fixed_height(20);
|
|
||||||
m_seek_slider->set_enabled(false);
|
|
||||||
m_seek_slider->on_change = [&](int value) {
|
m_seek_slider->on_change = [&](int value) {
|
||||||
if (!m_playback_manager)
|
if (!m_playback_manager)
|
||||||
return;
|
return;
|
||||||
|
@ -48,13 +47,9 @@ VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
||||||
set_current_timestamp(timestamp);
|
set_current_timestamp(timestamp);
|
||||||
m_playback_manager->seek_to_timestamp(timestamp);
|
m_playback_manager->seek_to_timestamp(timestamp);
|
||||||
};
|
};
|
||||||
m_seek_slider->set_jump_to_cursor(true);
|
|
||||||
|
|
||||||
auto& toolbar_container = player_controls_widget.add<GUI::ToolbarContainer>();
|
m_play_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv));
|
||||||
m_toolbar = toolbar_container.add<GUI::Toolbar>();
|
m_pause_icon = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv));
|
||||||
|
|
||||||
m_play_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/play.png"sv).release_value_but_fixme_should_propagate_errors();
|
|
||||||
m_pause_icon = Gfx::Bitmap::try_load_from_file("/res/icons/16x16/pause.png"sv).release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
m_play_pause_action = GUI::Action::create("Play", { Key_Space }, m_play_icon, [&](auto&) {
|
m_play_pause_action = GUI::Action::create("Play", { Key_Space }, m_play_icon, [&](auto&) {
|
||||||
toggle_pause();
|
toggle_pause();
|
||||||
|
@ -64,20 +59,12 @@ VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
|
||||||
cycle_sizing_modes();
|
cycle_sizing_modes();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_toolbar->add_action(*m_play_pause_action);
|
m_timestamp_label = find_descendant_of_type_named<GUI::Label>("timestamp");
|
||||||
m_toolbar->add<GUI::VerticalSeparator>();
|
m_volume_slider = find_descendant_of_type_named<GUI::HorizontalSlider>("volume_slider");
|
||||||
m_timestamp_label = m_toolbar->add<GUI::Label>();
|
find_descendant_of_type_named<GUI::Button>("playback")->set_action(*m_play_pause_action);
|
||||||
m_timestamp_label->set_autosize(true);
|
find_descendant_of_type_named<GUI::Button>("sizing")->set_action(*m_cycle_sizing_modes_action);
|
||||||
|
|
||||||
m_toolbar->add<GUI::Widget>(); // Filler widget
|
return {};
|
||||||
|
|
||||||
m_toolbar->add_action(*m_cycle_sizing_modes_action);
|
|
||||||
|
|
||||||
m_toolbar->add<GUI::VerticalSeparator>();
|
|
||||||
m_volume_slider = m_toolbar->add<GUI::HorizontalSlider>();
|
|
||||||
m_volume_slider->set_min(0);
|
|
||||||
m_volume_slider->set_max(100);
|
|
||||||
m_volume_slider->set_fixed_width(100);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoPlayerWidget::close_file()
|
void VideoPlayerWidget::close_file()
|
||||||
|
@ -176,7 +163,7 @@ void VideoPlayerWidget::on_decoding_error(Video::DecoderError const& error)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::MessageBox::show(&m_window, DeprecatedString::formatted(text_format, error.string_literal()), "Video Player encountered an error"sv);
|
GUI::MessageBox::show(window(), DeprecatedString::formatted(text_format, error.string_literal()), "Video Player encountered an error"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoPlayerWidget::update_seek_slider_max()
|
void VideoPlayerWidget::update_seek_slider_max()
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
namespace VideoPlayer {
|
namespace VideoPlayer {
|
||||||
|
|
||||||
class VideoPlayerWidget final : public GUI::Widget {
|
class VideoPlayerWidget final : public GUI::Widget {
|
||||||
C_OBJECT(VideoPlayerWidget)
|
C_OBJECT_ABSTRACT(VideoPlayerWidget)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<VideoPlayerWidget>> try_create();
|
||||||
|
virtual ~VideoPlayerWidget() override = default;
|
||||||
void close_file();
|
void close_file();
|
||||||
void open_file(StringView filename);
|
void open_file(StringView filename);
|
||||||
void resume_playback();
|
void resume_playback();
|
||||||
|
@ -37,8 +39,8 @@ public:
|
||||||
ErrorOr<void> initialize_menubar(GUI::Window&);
|
ErrorOr<void> initialize_menubar(GUI::Window&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VideoPlayerWidget(GUI::Window&);
|
VideoPlayerWidget() = default;
|
||||||
|
ErrorOr<void> setup_interface();
|
||||||
void update_play_pause_icon();
|
void update_play_pause_icon();
|
||||||
void update_seek_slider_max();
|
void update_seek_slider_max();
|
||||||
void set_current_timestamp(Time);
|
void set_current_timestamp(Time);
|
||||||
|
@ -51,15 +53,11 @@ private:
|
||||||
|
|
||||||
void event(Core::Event&) override;
|
void event(Core::Event&) override;
|
||||||
|
|
||||||
GUI::Window& m_window;
|
|
||||||
|
|
||||||
DeprecatedString m_path;
|
DeprecatedString m_path;
|
||||||
|
|
||||||
RefPtr<VideoFrameWidget> m_video_display;
|
RefPtr<VideoFrameWidget> m_video_display;
|
||||||
RefPtr<GUI::HorizontalSlider> m_seek_slider;
|
RefPtr<GUI::HorizontalSlider> m_seek_slider;
|
||||||
|
|
||||||
RefPtr<GUI::Toolbar> m_toolbar;
|
|
||||||
|
|
||||||
RefPtr<Gfx::Bitmap> m_play_icon;
|
RefPtr<Gfx::Bitmap> m_play_icon;
|
||||||
RefPtr<Gfx::Bitmap> m_pause_icon;
|
RefPtr<Gfx::Bitmap> m_pause_icon;
|
||||||
|
|
||||||
|
|
59
Userland/Applications/VideoPlayer/VideoPlayerWindow.gml
Normal file
59
Userland/Applications/VideoPlayer/VideoPlayerWindow.gml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
@GUI::Widget {
|
||||||
|
fill_with_background_color: true
|
||||||
|
layout: @GUI::VerticalBoxLayout {}
|
||||||
|
|
||||||
|
@VideoPlayer::VideoFrameWidget {
|
||||||
|
name: "video_frame"
|
||||||
|
auto_resize: false
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Widget {
|
||||||
|
max_height: 50
|
||||||
|
layout: @GUI::VerticalBoxLayout {}
|
||||||
|
|
||||||
|
@GUI::HorizontalSlider {
|
||||||
|
name: "seek_slider"
|
||||||
|
fixed_height: 20
|
||||||
|
enabled: false
|
||||||
|
jump_to_cursor: true
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::ToolbarContainer {
|
||||||
|
@GUI::Toolbar {
|
||||||
|
name: "toolbar"
|
||||||
|
|
||||||
|
@GUI::Button {
|
||||||
|
name: "playback"
|
||||||
|
icon: "/res/icons/16x16/play.png"
|
||||||
|
fixed_width: 24
|
||||||
|
button_style: "Coolbar"
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::VerticalSeparator {}
|
||||||
|
|
||||||
|
@GUI::Label {
|
||||||
|
name: "timestamp"
|
||||||
|
autosize: true
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::Layout::Spacer {}
|
||||||
|
|
||||||
|
@GUI::Button {
|
||||||
|
name: "sizing"
|
||||||
|
text: "..."
|
||||||
|
fixed_width: 24
|
||||||
|
button_style: "Coolbar"
|
||||||
|
}
|
||||||
|
|
||||||
|
@GUI::VerticalSeparator {}
|
||||||
|
|
||||||
|
@GUI::HorizontalSlider {
|
||||||
|
name: "volume_slider"
|
||||||
|
min: 0
|
||||||
|
max: 100
|
||||||
|
fixed_width: 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
window->resize(640, 480);
|
window->resize(640, 480);
|
||||||
window->set_resizable(true);
|
window->set_resizable(true);
|
||||||
|
|
||||||
auto main_widget = TRY(window->set_main_widget<VideoPlayer::VideoPlayerWidget>(window));
|
auto main_widget = TRY(window->set_main_widget<VideoPlayer::VideoPlayerWidget>());
|
||||||
main_widget->update_title();
|
main_widget->update_title();
|
||||||
TRY(main_widget->initialize_menubar(window));
|
TRY(main_widget->initialize_menubar(window));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue