VideoPlayer: Add an option to enable fast seeking

The fast seeking toggle is in the new Playback menu, and when enabled
it makes the PlaybackManager immediately start playing after finding a
keyframe to decode.
This commit is contained in:
Zaggy1024 2022-11-13 21:21:29 -06:00 committed by Andreas Kling
parent fd3ffd88ce
commit ceb7632862
Notes: sideshowbarker 2024-07-17 04:06:11 +09:00
2 changed files with 42 additions and 0 deletions

View file

@ -101,6 +101,7 @@ void VideoPlayerWidget::open_file(StringView filename)
close_file();
m_playback_manager = load_file_result.release_value();
update_seek_slider_max();
update_seek_mode();
resume_playback();
}
@ -259,8 +260,30 @@ void VideoPlayerWidget::update_title()
window()->set_title(string_builder.to_string());
}
Video::PlaybackManager::SeekMode VideoPlayerWidget::seek_mode()
{
if (m_use_fast_seeking->is_checked())
return Video::PlaybackManager::SeekMode::Fast;
return Video::PlaybackManager::SeekMode::Accurate;
}
void VideoPlayerWidget::set_seek_mode(Video::PlaybackManager::SeekMode seek_mode)
{
m_use_fast_seeking->set_checked(seek_mode == Video::PlaybackManager::SeekMode::Fast);
}
void VideoPlayerWidget::update_seek_mode()
{
if (!m_playback_manager)
return;
m_playback_manager->set_seek_mode(seek_mode());
}
void VideoPlayerWidget::initialize_menubar(GUI::Window& window)
{
// FIXME: This should return ErrorOr and use try_... functions.
// File menu
auto& file_menu = window.add_menu("&File");
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> path = GUI::FilePicker::get_open_filepath(&window, "Open video file...");
@ -272,6 +295,18 @@ void VideoPlayerWidget::initialize_menubar(GUI::Window& window)
window.close();
}));
// Playback menu
auto& playback_menu = window.add_menu("&Playback");
// FIXME: Maybe seek mode should be in an options dialog instead. The playback menu may get crowded.
// For now, leave it here for convenience.
m_use_fast_seeking = GUI::Action::create_checkable("&Fast Seeking", [&](auto&) {
update_seek_mode();
});
playback_menu.add_action(*m_use_fast_seeking);
set_seek_mode(Video::PlaybackManager::DEFAULT_SEEK_MODE);
// Help menu
auto& help_menu = window.add_menu("&Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Video Player", GUI::Icon::default_icon("app-video-player"sv), &window));
}

View file

@ -8,6 +8,7 @@
#include <AK/FixedArray.h>
#include <AK/NonnullRefPtr.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Forward.h>
#include <LibGUI/Widget.h>
#include <LibGfx/Forward.h>
@ -30,6 +31,9 @@ public:
void update_title();
Video::PlaybackManager::SeekMode seek_mode();
void set_seek_mode(Video::PlaybackManager::SeekMode seek_mode);
void initialize_menubar(GUI::Window&);
private:
@ -40,6 +44,7 @@ private:
void set_current_timestamp(Time);
void set_time_label(Time);
void on_decoding_error(Video::DecoderError const&);
void update_seek_mode();
void display_next_frame();
void cycle_sizing_modes();
@ -63,6 +68,8 @@ private:
RefPtr<GUI::Action> m_cycle_sizing_modes_action;
RefPtr<GUI::HorizontalSlider> m_volume_slider;
RefPtr<GUI::Action> m_use_fast_seeking;
OwnPtr<Video::PlaybackManager> m_playback_manager;
};