mirror of
https://github.com/RGBCube/serenity
synced 2025-05-22 17:15:08 +00:00
LibWeb: Move helper to toggle a media element's playback to the element
This will be needed elsewhere.
This commit is contained in:
parent
435ced70b8
commit
3793b7c6bd
3 changed files with 20 additions and 17 deletions
|
@ -366,6 +366,23 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::pause()
|
|||
return {};
|
||||
}
|
||||
|
||||
WebIDL::ExceptionOr<void> HTMLMediaElement::toggle_playback()
|
||||
{
|
||||
// FIXME: This runs from outside the context of any user script, so we do not have a running execution
|
||||
// context. This pushes one to allow the promise creation hook to run.
|
||||
auto& environment_settings = document().relevant_settings_object();
|
||||
environment_settings.prepare_to_run_script();
|
||||
|
||||
ScopeGuard guard { [&] { environment_settings.clean_up_after_running_script(); } };
|
||||
|
||||
if (potentially_playing())
|
||||
TRY(pause());
|
||||
else
|
||||
TRY(play());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/media.html#dom-media-volume
|
||||
WebIDL::ExceptionOr<void> HTMLMediaElement::set_volume(double volume)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue