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.