summaryrefslogtreecommitdiff
path: root/Userland/Applications/VideoPlayer
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2022-11-11 07:55:20 -0600
committerLinus Groh <mail@linusgroh.de>2022-11-14 10:05:56 +0000
commit87aed17a46291f7ef8cc3eba6fb6adebb8aa2f2d (patch)
tree87d058474c5a0a129ac284c8aaefa5c1040807f6 /Userland/Applications/VideoPlayer
parent5925d3b26bd2972c5d18e5df123d4f216d28083c (diff)
downloadserenity-87aed17a46291f7ef8cc3eba6fb6adebb8aa2f2d.zip
VideoPlayer: Make PlaybackManager use OwnPtr
VideoPlayerWidget was keeping a reference to PlaybackManager when changing files, so the old and new managers would both send frames to be presented at the same time, causing it to flicker back and forth between the two videos. However, PlaybackManager no longer relies on event bubbling to pass events to its parent. By changing it to send events directly to an Object, it can avoid being ref counted, so that it will get destroyed with its containing object and stop sending events.
Diffstat (limited to 'Userland/Applications/VideoPlayer')
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp9
-rw-r--r--Userland/Applications/VideoPlayer/VideoPlayerWidget.h3
2 files changed, 10 insertions, 2 deletions
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
index 31d5972503..f4d53ca8c4 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp
@@ -69,9 +69,15 @@ VideoPlayerWidget::VideoPlayerWidget(GUI::Window& window)
m_volume_slider->set_fixed_width(100);
}
+void VideoPlayerWidget::close_file()
+{
+ if (m_playback_manager)
+ m_playback_manager = nullptr;
+}
+
void VideoPlayerWidget::open_file(StringView filename)
{
- auto load_file_result = Video::PlaybackManager::from_file(this, filename);
+ auto load_file_result = Video::PlaybackManager::from_file(*this, filename);
if (load_file_result.is_error()) {
on_decoding_error(load_file_result.release_error());
@@ -81,6 +87,7 @@ void VideoPlayerWidget::open_file(StringView filename)
m_path = filename;
update_title();
+ close_file();
m_playback_manager = load_file_result.release_value();
resume_playback();
}
diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
index e52f5e920c..9f3abe1ddc 100644
--- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
+++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h
@@ -22,6 +22,7 @@ class VideoPlayerWidget final : public GUI::Widget {
C_OBJECT(VideoPlayerWidget)
public:
+ void close_file();
void open_file(StringView filename);
void resume_playback();
void pause_playback();
@@ -59,7 +60,7 @@ private:
RefPtr<GUI::Action> m_cycle_sizing_modes_action;
RefPtr<GUI::HorizontalSlider> m_volume_slider;
- RefPtr<Video::PlaybackManager> m_playback_manager;
+ OwnPtr<Video::PlaybackManager> m_playback_manager;
};
}