mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
VideoPlayer/LibVideo: Seek accurately when scrolling in the seek bar
Fast seeking does not work correctly when seeking in small increments, so it is necessary to use accurate seeking when using certain actions. The PlaybackManager has been changed to accept the seek mode as a parameter to `seek_to_timestamp` to facilitate this. This now means that it no longer has to track a seek mode preference.
This commit is contained in:
parent
1f650088a0
commit
b0db56cd39
4 changed files with 6 additions and 21 deletions
|
@ -56,7 +56,8 @@ ErrorOr<void> VideoPlayerWidget::setup_interface()
|
|||
auto progress = value / static_cast<double>(m_seek_slider->max());
|
||||
auto duration = m_playback_manager->duration().to_milliseconds();
|
||||
Time timestamp = Time::from_milliseconds(static_cast<i64>(round(progress * static_cast<double>(duration))));
|
||||
m_playback_manager->seek_to_timestamp(timestamp);
|
||||
auto seek_mode_to_use = m_seek_slider->knob_dragging() ? seek_mode() : Video::PlaybackManager::SeekMode::Accurate;
|
||||
m_playback_manager->seek_to_timestamp(timestamp, seek_mode_to_use);
|
||||
set_current_timestamp(m_playback_manager->current_playback_time());
|
||||
};
|
||||
|
||||
|
@ -100,7 +101,6 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -277,13 +277,6 @@ 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());
|
||||
}
|
||||
|
||||
ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
|
||||
{
|
||||
// File menu
|
||||
|
@ -303,9 +296,7 @@ ErrorOr<void> VideoPlayerWidget::initialize_menubar(GUI::Window& window)
|
|||
|
||||
// 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();
|
||||
});
|
||||
m_use_fast_seeking = GUI::Action::create_checkable("&Fast Seeking", [&](auto&) {});
|
||||
TRY(playback_menu->try_add_action(*m_use_fast_seeking));
|
||||
set_seek_mode(Video::PlaybackManager::DEFAULT_SEEK_MODE);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue