diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index e034a1e53d1..02ad329cd16 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -187,24 +187,21 @@ Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(StringView type) con
auto mime_type = MimeSniff::MimeType::parse(type);
if (mime_type.has_value() && mime_type->type() == "video"sv) {
- if (mime_type->subtype() == "webm"sv)
+ if (supported_video_subtypes.contains_slow(mime_type->subtype()))
return Bindings::CanPlayTypeResult::Probably;
return Bindings::CanPlayTypeResult::Maybe;
}
if (mime_type.has_value() && mime_type->type() == "audio"sv) {
- if (mime_type->subtype() == "flac"sv)
- return Bindings::CanPlayTypeResult::Probably;
- if (mime_type->subtype() == "mp3"sv)
- return Bindings::CanPlayTypeResult::Probably;
+ auto result = Bindings::CanPlayTypeResult::Maybe;
+ if (supported_audio_subtypes.contains_slow(mime_type->subtype()))
+ result = Bindings::CanPlayTypeResult::Probably;
+
// "Maybe" because we support mp3, but "mpeg" can also refer to MP1 and MP2.
if (mime_type->subtype() == "mpeg"sv)
- return Bindings::CanPlayTypeResult::Maybe;
- if (mime_type->subtype() == "ogg"sv)
- return Bindings::CanPlayTypeResult::Probably;
- if (mime_type->subtype() == "wav"sv)
- return Bindings::CanPlayTypeResult::Probably;
- return Bindings::CanPlayTypeResult::Maybe;
+ result = Bindings::CanPlayTypeResult::Maybe;
+
+ return result;
}
return Bindings::CanPlayTypeResult::Empty;
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.h
index 5aee59725b2..3ff78fdf19e 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -58,6 +58,20 @@ public:
[[nodiscard]] GC::Ref buffered() const;
+ static inline constexpr auto supported_video_subtypes = Array {
+ "webm"sv,
+ "mp4"sv,
+ "mpeg"sv,
+ "ogg"sv,
+ };
+ static inline constexpr auto supported_audio_subtypes = Array {
+ "flac"sv,
+ "mp3"sv,
+ "mpeg"sv,
+ "ogg"sv,
+ "wav"sv,
+ "webm"sv,
+ };
Bindings::CanPlayTypeResult can_play_type(StringView type) const;
enum class ReadyState : u16 {