From 9e61e48b318d53f85865b5206f4bb0e545f00990 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Sun, 5 Feb 2023 19:40:52 -0600 Subject: VideoPlayer: Pause while the user is dragging the seek bar --- .../Applications/VideoPlayer/VideoPlayerWidget.cpp | 18 +++++++++++++++--- Userland/Applications/VideoPlayer/VideoPlayerWidget.h | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp index ddc6040c82..61d15e69fe 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.cpp @@ -37,6 +37,18 @@ ErrorOr VideoPlayerWidget::setup_interface() m_video_display->on_click = [&]() { toggle_pause(); }; m_seek_slider = find_descendant_of_type_named("seek_slider"); + m_seek_slider->on_drag_start = [&]() { + if (!m_playback_manager) + return; + m_was_playing_before_seek = m_playback_manager->is_playing(); + m_playback_manager->pause_playback(); + }; + m_seek_slider->on_drag_end = [&]() { + if (!m_playback_manager || !m_was_playing_before_seek) + return; + m_was_playing_before_seek = false; + m_playback_manager->resume_playback(); + }; m_seek_slider->on_change = [&](int value) { if (!m_playback_manager) return; @@ -103,7 +115,7 @@ void VideoPlayerWidget::update_play_pause_icon() m_play_pause_action->set_enabled(true); - if (m_playback_manager->is_playing()) { + if (m_playback_manager->is_playing() || m_was_playing_before_seek) { m_play_pause_action->set_icon(m_pause_icon); m_play_pause_action->set_text("Pause"sv); } else { @@ -114,7 +126,7 @@ void VideoPlayerWidget::update_play_pause_icon() void VideoPlayerWidget::resume_playback() { - if (!m_playback_manager) + if (!m_playback_manager || m_seek_slider->knob_dragging()) return; m_playback_manager->resume_playback(); update_play_pause_icon(); @@ -122,7 +134,7 @@ void VideoPlayerWidget::resume_playback() void VideoPlayerWidget::pause_playback() { - if (!m_playback_manager) + if (!m_playback_manager || m_seek_slider->knob_dragging()) return; m_playback_manager->pause_playback(); update_play_pause_icon(); diff --git a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h index 61760387bf..bdc53cb630 100644 --- a/Userland/Applications/VideoPlayer/VideoPlayerWidget.h +++ b/Userland/Applications/VideoPlayer/VideoPlayerWidget.h @@ -68,6 +68,8 @@ private: RefPtr m_use_fast_seeking; OwnPtr m_playback_manager; + + bool m_was_playing_before_seek { false }; }; } -- cgit v1.2.3