From 4f29cac7151eef1f9d4904a8d63fc21eeb7f899c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 7 Apr 2023 15:08:39 -0400 Subject: [PATCH] LibWeb: Set the media ready state to HAVE_ENOUGH_DATA after fetching Because we currently both fetch and process the media data in one chunk, we have enough data for playback immediately. --- Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index cca36aacac..f155456d16 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -503,6 +503,16 @@ WebIDL::ExceptionOr HTMLMediaElement::fetch_resource(AK::URL const& url_re queue_a_media_element_task([this, failure_callback = move(failure_callback)]() mutable { process_media_data(move(failure_callback)).release_value_but_fixme_should_propagate_errors(); + + // NOTE: The spec does not say exactly when to update the readyState attribute. Rather, it describes what + // each step requires, and leaves it up to the user agent to determine when those requirments are + // reached: https://html.spec.whatwg.org/multipage/media.html#ready-states + // + // Since we fetch the entire response at once, if we reach here with successfully decoded video + // metadata, we have satisfied the HAVE_ENOUGH_DATA requirements. This logic will of course need + // to change if we fetch or process the media data in smaller chunks. + if (m_ready_state == ReadyState::HaveMetadata) + set_ready_state(ReadyState::HaveEnoughData); }); };