summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp43
-rw-r--r--Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h3
2 files changed, 43 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 036376ebb8..d71996360a 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -128,9 +128,17 @@ void HTMLMediaElement::set_duration(double duration)
}
// https://html.spec.whatwg.org/multipage/media.html#dom-media-pause
-void HTMLMediaElement::pause() const
+WebIDL::ExceptionOr<void> HTMLMediaElement::pause()
{
- dbgln("(STUBBED) HTMLMediaElement::pause()");
+ // 1. If the media element's networkState attribute has the value NETWORK_EMPTY, invoke the media element's resource
+ // selection algorithm.
+ if (m_network_state == NetworkState::Empty)
+ TRY(select_resource());
+
+ // 2. Run the internal pause steps for the media element.
+ TRY(pause_element());
+
+ return {};
}
// https://html.spec.whatwg.org/multipage/media.html#media-element-load-algorithm
@@ -784,6 +792,37 @@ void HTMLMediaElement::set_ready_state(ReadyState ready_state)
}
}
+// https://html.spec.whatwg.org/multipage/media.html#internal-pause-steps
+WebIDL::ExceptionOr<void> HTMLMediaElement::pause_element()
+{
+ // FIXME: 1. Set the media element's can autoplay flag to false.
+
+ // 2. If the media element's paused attribute is false, run the following steps:
+ if (!paused()) {
+ // 1. Change the value of paused to true.
+ set_paused(true);
+
+ // FIXME: 2. Take pending play promises and let promises be the result.
+
+ // 3. Queue a media element task given the media element and the following steps:
+ queue_a_media_element_task([this]() {
+ auto& realm = this->realm();
+
+ // 1. Fire an event named timeupdate at the element.
+ dispatch_event(DOM::Event::create(realm, HTML::EventNames::timeupdate).release_value_but_fixme_should_propagate_errors());
+
+ // 2. Fire an event named pause at the element.
+ dispatch_event(DOM::Event::create(realm, HTML::EventNames::pause).release_value_but_fixme_should_propagate_errors());
+
+ // FIXME: 3. Reject pending play promises with promises and an "AbortError" DOMException.
+ });
+
+ // FIXME: 4. Set the official playback position to the current playback position.
+ }
+
+ return {};
+}
+
// https://html.spec.whatwg.org/multipage/media.html#notify-about-playing
void HTMLMediaElement::notify_about_playing()
{
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
index f98bf13525..b16127f5e4 100644
--- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -46,7 +46,7 @@ public:
WebIDL::ExceptionOr<void> load();
double duration() const;
bool paused() const { return m_paused; }
- void pause() const;
+ WebIDL::ExceptionOr<void> pause();
JS::NonnullGCPtr<VideoTrackList> video_tracks() const { return *m_video_tracks; }
@@ -78,6 +78,7 @@ private:
void forget_media_resource_specific_tracks();
void set_ready_state(ReadyState);
+ WebIDL::ExceptionOr<void> pause_element();
void notify_about_playing();
void set_paused(bool);
void set_duration(double);