mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 08:15:07 +00:00
LibWeb: Indicate that we may be able to play video MIME types
This commit is contained in:
parent
e2f32e6ab3
commit
5f9fc5aedc
2 changed files with 14 additions and 6 deletions
|
@ -22,6 +22,7 @@
|
|||
#include <LibWeb/HTML/TrackEvent.h>
|
||||
#include <LibWeb/HTML/VideoTrack.h>
|
||||
#include <LibWeb/HTML/VideoTrackList.h>
|
||||
#include <LibWeb/MimeSniff/MimeType.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
@ -66,8 +67,10 @@ void HTMLMediaElement::parse_attribute(DeprecatedFlyString const& name, Deprecat
|
|||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-navigator-canplaytype
|
||||
Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(DeprecatedString const& type) const
|
||||
WebIDL::ExceptionOr<Bindings::CanPlayTypeResult> HTMLMediaElement::can_play_type(DeprecatedString const& type) const
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
|
||||
// The canPlayType(type) method must:
|
||||
// - return the empty string if type is a type that the user agent knows it cannot render or is the type "application/octet-stream"
|
||||
// - return "probably" if the user agent is confident that the type represents a media resource that it can render if used in with this audio or video element
|
||||
|
@ -75,10 +78,15 @@ Bindings::CanPlayTypeResult HTMLMediaElement::can_play_type(DeprecatedString con
|
|||
// Generally, a user agent should never return "probably" for a type that allows the codecs parameter if that parameter is not present.
|
||||
if (type == "application/octet-stream"sv)
|
||||
return Bindings::CanPlayTypeResult::Empty;
|
||||
// FIXME: Eventually we should return `Maybe` here, but for now `Empty` is our best bet :^)
|
||||
// Being honest here leads to some apps and frameworks skipping things like audio loading,
|
||||
// which for the time being would create more issues than it solves - e.g. endless waiting
|
||||
// for audio that will never load.
|
||||
|
||||
auto mime_type = TRY_OR_THROW_OOM(vm, MimeSniff::MimeType::parse(type));
|
||||
|
||||
if (mime_type.has_value() && mime_type->type() == "video"sv) {
|
||||
if (mime_type->subtype() == "webm"sv)
|
||||
return Bindings::CanPlayTypeResult::Probably;
|
||||
return Bindings::CanPlayTypeResult::Maybe;
|
||||
}
|
||||
|
||||
return Bindings::CanPlayTypeResult::Empty;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue