mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:27:35 +00:00
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:
parent
fd3ffd88ce
commit
ceb7632862
2 changed files with 42 additions and 0 deletions
|
@ -101,6 +101,7 @@ void VideoPlayerWidget::open_file(StringView filename)
|
||||||
close_file();
|
close_file();
|
||||||
m_playback_manager = load_file_result.release_value();
|
m_playback_manager = load_file_result.release_value();
|
||||||
update_seek_slider_max();
|
update_seek_slider_max();
|
||||||
|
update_seek_mode();
|
||||||
resume_playback();
|
resume_playback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,8 +260,30 @@ void VideoPlayerWidget::update_title()
|
||||||
window()->set_title(string_builder.to_string());
|
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)
|
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");
|
auto& file_menu = window.add_menu("&File");
|
||||||
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
|
||||||
Optional<String> path = GUI::FilePicker::get_open_filepath(&window, "Open video file...");
|
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();
|
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");
|
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));
|
help_menu.add_action(GUI::CommonActions::make_about_action("Video Player", GUI::Icon::default_icon("app-video-player"sv), &window));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <AK/FixedArray.h>
|
#include <AK/FixedArray.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
#include <LibGUI/ActionGroup.h>
|
||||||
#include <LibGUI/Forward.h>
|
#include <LibGUI/Forward.h>
|
||||||
#include <LibGUI/Widget.h>
|
#include <LibGUI/Widget.h>
|
||||||
#include <LibGfx/Forward.h>
|
#include <LibGfx/Forward.h>
|
||||||
|
@ -30,6 +31,9 @@ public:
|
||||||
|
|
||||||
void update_title();
|
void update_title();
|
||||||
|
|
||||||
|
Video::PlaybackManager::SeekMode seek_mode();
|
||||||
|
void set_seek_mode(Video::PlaybackManager::SeekMode seek_mode);
|
||||||
|
|
||||||
void initialize_menubar(GUI::Window&);
|
void initialize_menubar(GUI::Window&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -40,6 +44,7 @@ private:
|
||||||
void set_current_timestamp(Time);
|
void set_current_timestamp(Time);
|
||||||
void set_time_label(Time);
|
void set_time_label(Time);
|
||||||
void on_decoding_error(Video::DecoderError const&);
|
void on_decoding_error(Video::DecoderError const&);
|
||||||
|
void update_seek_mode();
|
||||||
void display_next_frame();
|
void display_next_frame();
|
||||||
|
|
||||||
void cycle_sizing_modes();
|
void cycle_sizing_modes();
|
||||||
|
@ -63,6 +68,8 @@ private:
|
||||||
RefPtr<GUI::Action> m_cycle_sizing_modes_action;
|
RefPtr<GUI::Action> m_cycle_sizing_modes_action;
|
||||||
RefPtr<GUI::HorizontalSlider> m_volume_slider;
|
RefPtr<GUI::HorizontalSlider> m_volume_slider;
|
||||||
|
|
||||||
|
RefPtr<GUI::Action> m_use_fast_seeking;
|
||||||
|
|
||||||
OwnPtr<Video::PlaybackManager> m_playback_manager;
|
OwnPtr<Video::PlaybackManager> m_playback_manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue