mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 15:28:55 +00:00
LibWeb: Implement playbackRate
This commit is contained in:
parent
986fe0f408
commit
14e354bc29
Notes:
github-actions[bot]
2025-02-10 11:39:00 +00:00
Author: https://github.com/Psychpsyo
Commit: 14e354bc29
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3514
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 123 additions and 3 deletions
|
@ -570,7 +570,8 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element()
|
|||
set_duration(NAN);
|
||||
}
|
||||
|
||||
// FIXME: 7. Set the playbackRate attribute to the value of the defaultPlaybackRate attribute.
|
||||
// 7. Set the playbackRate attribute to the value of the defaultPlaybackRate attribute.
|
||||
TRY(set_playback_rate(m_default_playback_rate));
|
||||
|
||||
// 8. Set the error attribute to null and the can autoplay flag to true.
|
||||
m_error = nullptr;
|
||||
|
@ -1650,6 +1651,48 @@ void HTMLMediaElement::set_paused(bool paused)
|
|||
set_needs_style_update(true);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-media-defaultplaybackrate
|
||||
void HTMLMediaElement::set_default_playback_rate(double new_value)
|
||||
{
|
||||
// When the defaultPlaybackRate or playbackRate attributes change value (either by being set by script or by being changed directly by the user agent, e.g. in response to user
|
||||
// control) the user agent must queue a media element task given the media element to fire an event named ratechange at the media element.
|
||||
if (m_default_playback_rate != new_value) {
|
||||
queue_a_media_element_task([this] {
|
||||
dispatch_event(DOM::Event::create(realm(), HTML::EventNames::ratechange));
|
||||
});
|
||||
}
|
||||
|
||||
// on setting the attribute must be set to the new value.
|
||||
m_default_playback_rate = new_value;
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-media-playbackrate
|
||||
WebIDL::ExceptionOr<void> HTMLMediaElement::set_playback_rate(double new_value)
|
||||
{
|
||||
// on setting, the user agent must follow these steps:
|
||||
|
||||
// 1. If the given value is not supported by the user agent, then throw a "NotSupportedError" DOMException.
|
||||
// FIXME: We need to support playback rates other than 1 for this to be even remotely useful.
|
||||
if (new_value != 1.0)
|
||||
return WebIDL::NotSupportedError::create(realm(), "Playback rates other than 1 are not supported."_string);
|
||||
|
||||
// When the defaultPlaybackRate or playbackRate attributes change value (either by being set by script or by being changed directly by the user agent, e.g. in response to user
|
||||
// control) the user agent must queue a media element task given the media element to fire an event named ratechange at the media element.
|
||||
if (m_playback_rate != new_value) {
|
||||
queue_a_media_element_task([this] {
|
||||
dispatch_event(DOM::Event::create(realm(), HTML::EventNames::ratechange));
|
||||
});
|
||||
}
|
||||
|
||||
// 2. Set playbackRate to the new value, and if the element is potentially playing, change the playback speed.
|
||||
m_playback_rate = new_value;
|
||||
if (potentially_playing()) {
|
||||
// FIXME: Do this once playback speeds other than 1 are supported.
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#blocked-media-element
|
||||
bool HTMLMediaElement::blocked() const
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue