1
Fork 0
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:
Timothy Flynn 2023-07-02 21:38:11 -07:00 committed by Andreas Kling
parent 435ced70b8
commit 3793b7c6bd
3 changed files with 20 additions and 17 deletions

View file

@ -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)
{