1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 09:37:34 +00:00

LibWeb: Implement HTMLMediaElement.play

This also includes the HTMLMediaElement's list of pending play promises,
which is coupled pretty tightly with HTMLMediaElement.play.
This commit is contained in:
Timothy Flynn 2023-04-07 12:52:41 -04:00 committed by Linus Groh
parent b8a37ef809
commit d99a075ff9
3 changed files with 170 additions and 12 deletions

View file

@ -9,9 +9,11 @@
#include <AK/ByteBuffer.h>
#include <AK/Variant.h>
#include <LibJS/Heap/MarkedVector.h>
#include <LibJS/SafeFunction.h>
#include <LibWeb/HTML/EventLoop/Task.h>
#include <LibWeb/HTML/HTMLElement.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <math.h>
namespace Web::HTML {
@ -46,6 +48,7 @@ public:
WebIDL::ExceptionOr<void> load();
double duration() const;
bool paused() const { return m_paused; }
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> play();
WebIDL::ExceptionOr<void> pause();
JS::NonnullGCPtr<VideoTrackList> video_tracks() const { return *m_video_tracks; }
@ -74,15 +77,30 @@ private:
WebIDL::ExceptionOr<void> fetch_resource(AK::URL const&, Function<void()> failure_callback);
static bool verify_response(JS::NonnullGCPtr<Fetch::Infrastructure::Response>, ByteRange const&);
WebIDL::ExceptionOr<void> process_media_data(Function<void()> failure_callback);
WebIDL::ExceptionOr<void> handle_media_source_failure();
WebIDL::ExceptionOr<void> handle_media_source_failure(Span<JS::NonnullGCPtr<WebIDL::Promise>> promises);
void forget_media_resource_specific_tracks();
void set_ready_state(ReadyState);
WebIDL::ExceptionOr<void> play_element();
WebIDL::ExceptionOr<void> pause_element();
void notify_about_playing();
void set_paused(bool);
void set_duration(double);
JS::MarkedVector<JS::NonnullGCPtr<WebIDL::Promise>> take_pending_play_promises();
void resolve_pending_play_promises(ReadonlySpan<JS::NonnullGCPtr<WebIDL::Promise>> promises);
void reject_pending_play_promises(ReadonlySpan<JS::NonnullGCPtr<WebIDL::Promise>> promises, JS::NonnullGCPtr<WebIDL::DOMException> error);
// https://html.spec.whatwg.org/multipage/media.html#reject-pending-play-promises
template<typename ErrorType>
void reject_pending_play_promises(ReadonlySpan<JS::NonnullGCPtr<WebIDL::Promise>> promises, FlyString const& message)
{
auto& realm = this->realm();
auto error = ErrorType::create(realm, message.to_deprecated_fly_string());
reject_pending_play_promises(promises, error);
}
// https://html.spec.whatwg.org/multipage/media.html#media-element-event-task-source
UniqueTaskSource m_media_element_event_task_source {};
@ -96,6 +114,9 @@ private:
// https://html.spec.whatwg.org/multipage/media.html#dom-media-duration
double m_duration { NAN };
// https://html.spec.whatwg.org/multipage/media.html#list-of-pending-play-promises
JS::MarkedVector<JS::NonnullGCPtr<WebIDL::Promise>> m_pending_play_promises;
// https://html.spec.whatwg.org/multipage/media.html#dom-media-paused
bool m_paused { true };