summaryrefslogtreecommitdiff
path: root/Userland/Applications/VideoPlayer
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-04-08 19:18:38 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-09 23:55:05 +0200
commit3591a13e85ffd76682e26888ff5f0bc27b87aa2c (patch)
tree138df9f6d0f93768ed7e1ba0b18437bd1520414f /Userland/Applications/VideoPlayer
parent0f2b863c01989d7eee89f30607ef82d7e811be98 (diff)
downloadserenity-3591a13e85ffd76682e26888ff5f0bc27b87aa2c.zip
LibVideo+VideoPlayer: Convert playback event handler to callbacks
To pass events from LibVideo's PlaybackManager to interested parties, we currently dispatch Core::Event objects that outside callers listen for. Dispatching events in this manner rely on a Core::EventLoop. In order to use PlaybackManager from LibWeb, change this mechanism to instead use a set of callbacks to inform callers of events.
Diffstat (limited to 'Userland/Applications/VideoPlayer')
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp51
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.h2
2 files changed, 23 insertions, 30 deletions
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index a3315fac00..db7bc3dd86 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -112,7 +112,7 @@ void VideoPlayerWidget::close_file()
void VideoPlayerWidget::open_file(StringView filename)
{
- auto load_file_result = Video::PlaybackManager::from_file(*this, filename);
+ auto load_file_result = Video::PlaybackManager::from_file(filename);
if (load_file_result.is_error()) {
on_decoding_error(load_file_result.release_error());
@@ -121,9 +121,30 @@ void VideoPlayerWidget::open_file(StringView filename)
m_path = filename;
update_title();
-
close_file();
+
m_playback_manager = load_file_result.release_value();
+
+ m_playback_manager->on_video_frame = [this](auto frame) {
+ m_video_display->set_bitmap(move(frame));
+ m_video_display->repaint();
+
+ update_seek_slider_max();
+ set_current_timestamp(m_playback_manager->current_playback_time());
+ };
+
+ m_playback_manager->on_playback_state_change = [this]() {
+ update_play_pause_icon();
+ };
+
+ m_playback_manager->on_decoder_error = [this](auto error) {
+ on_decoding_error(error);
+ };
+
+ m_playback_manager->on_fatal_playback_error = [this](auto) {
+ close_file();
+ };
+
update_seek_slider_max();
resume_playback();
}
@@ -240,32 +261,6 @@ void VideoPlayerWidget::set_time_label(Time timestamp)
m_timestamp_label->set_text(string_builder.string_view());
}
-void VideoPlayerWidget::event(Core::Event& event)
-{
- if (event.type() == Video::EventType::DecoderErrorOccurred) {
- auto& error_event = static_cast<Video::DecoderErrorEvent&>(event);
- on_decoding_error(error_event.error());
- error_event.accept();
- } else if (event.type() == Video::EventType::VideoFramePresent) {
- auto& frame_event = static_cast<Video::VideoFramePresentEvent&>(event);
-
- m_video_display->set_bitmap(frame_event.frame());
- m_video_display->repaint();
-
- update_seek_slider_max();
- set_current_timestamp(m_playback_manager->current_playback_time());
-
- frame_event.accept();
- } else if (event.type() == Video::EventType::PlaybackStateChange) {
- update_play_pause_icon();
- event.accept();
- } else if (event.type() == Video::EventType::FatalPlaybackError) {
- close_file();
- }
-
- Widget::event(event);
-}
-
void VideoPlayerWidget::drop_event(GUI::DropEvent& event)
{
event.accept();
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
index b99e8a2fae..20fdaacc54 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
@@ -51,8 +51,6 @@ private:
void toggle_fullscreen();
- void event(Core::Event&) override;
-
virtual void drop_event(GUI::DropEvent&) override;
DeprecatedString m_path;