Skip to content

Commit

Permalink
LibWeb: List supported media types publicly for HTMLMediaElement
Browse files Browse the repository at this point in the history
  • Loading branch information
ADKaster committed Dec 19, 2024
1 parent 540c840 commit 17af786
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
19 changes: 8 additions & 11 deletions Libraries/LibWeb/HTML/HTMLMediaElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions Libraries/LibWeb/HTML/HTMLMediaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ class HTMLMediaElement : public HTMLElement {

[[nodiscard]] GC::Ref<TimeRanges> 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 {
Expand Down

0 comments on commit 17af786

Please sign in to comment.