diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index 26dfe6740f..b3b8d10048 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -929,7 +929,7 @@ WebIDL::ExceptionOr HTMLMediaElement::pause_element() auto& realm = this->realm(); // 1. Fire an event named timeupdate at the element. - dispatch_event(DOM::Event::create(realm, HTML::EventNames::timeupdate).release_value_but_fixme_should_propagate_errors()); + dispatch_time_update_event().release_value_but_fixme_should_propagate_errors(); // 2. Fire an event named pause at the element. dispatch_event(DOM::Event::create(realm, HTML::EventNames::pause).release_value_but_fixme_should_propagate_errors()); @@ -973,6 +973,17 @@ void HTMLMediaElement::set_paused(bool paused) on_paused(); } +WebIDL::ExceptionOr HTMLMediaElement::dispatch_time_update_event() +{ + ScopeGuard guard { [this] { m_running_time_update_event_handler = false; } }; + m_running_time_update_event_handler = true; + + m_last_time_update_event_time = Time::now_monotonic(); + + dispatch_event(TRY(DOM::Event::create(realm(), HTML::EventNames::timeupdate))); + return {}; +} + // https://html.spec.whatwg.org/multipage/media.html#take-pending-play-promises JS::MarkedVector> HTMLMediaElement::take_pending_play_promises() { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h index 93c48fe05a..d5e958ef40 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include #include #include @@ -87,6 +88,8 @@ private: void set_paused(bool); void set_duration(double); + WebIDL::ExceptionOr dispatch_time_update_event(); + JS::MarkedVector> take_pending_play_promises(); void resolve_pending_play_promises(ReadonlySpan> promises); void reject_pending_play_promises(ReadonlySpan> promises, JS::NonnullGCPtr error); @@ -126,6 +129,9 @@ private: // https://html.spec.whatwg.org/multipage/media.html#media-data ByteBuffer m_media_data; + bool m_running_time_update_event_handler { false }; + Optional