From c7607136503a22e27274eb5f9b45d4b4ddca16d6 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Fri, 23 Jun 2023 19:44:03 -0500 Subject: [PATCH] LibWeb: Prioritize video duration when loading video element media Previously, an audio loader could succeed for an HTMLVideoElement that contains a video file, which caused the duration to be set to the bogus duration of the audio loader instead of the correct duration from the video container. Instead of setting the duration based on audio always, set it to the video duration if we are creating a video element. --- Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index c8a06734a2..eb6c2414d9 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -1141,12 +1141,12 @@ WebIDL::ExceptionOr HTMLMediaElement::process_media_data(Functionduration() : video_track->duration(); - set_duration(static_cast(duration.to_milliseconds()) / 1000.0); - // 5. For video elements, set the videoWidth and videoHeight attributes, and queue a media element task given the media element to fire an event // named resize at the media element. if (video_track && is(*this)) { + auto duration = video_track ? video_track->duration() : audio_track->duration(); + set_duration(static_cast(duration.to_milliseconds()) / 1000.0); + auto& video_element = verify_cast(*this); video_element.set_video_width(video_track->pixel_width()); video_element.set_video_height(video_track->pixel_height()); @@ -1154,6 +1154,9 @@ WebIDL::ExceptionOr HTMLMediaElement::process_media_data(Functionrealm(), HTML::EventNames::resize).release_value_but_fixme_should_propagate_errors()); }); + } else { + auto duration = audio_track ? audio_track->duration() : video_track->duration(); + set_duration(static_cast(duration.to_milliseconds()) / 1000.0); } // 6. Set the readyState attribute to HAVE_METADATA.