mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 04:25:13 +00:00
LibWeb: List supported media types publicly for HTMLMediaElement
This commit is contained in:
parent
8ebf2c3007
commit
202bf901d7
Notes:
github-actions[bot]
2024-12-25 11:32:53 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/202bf901d76 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2980
2 changed files with 22 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -58,6 +58,20 @@ public:
|
|||
|
||||
[[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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue