From 31532e36a818b1c2719ee800690cbc416a8756a5 Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Wed, 15 Jan 2025 23:08:23 +0000 Subject: [PATCH] LibWeb: Add `AudioContext.createMediaElementSource()` factory method --- Libraries/LibWeb/WebAudio/AudioContext.cpp | 8 ++++++++ Libraries/LibWeb/WebAudio/AudioContext.h | 3 +++ Libraries/LibWeb/WebAudio/AudioContext.idl | 2 +- .../audioparam-nominal-range.txt | 10 ++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Libraries/LibWeb/WebAudio/AudioContext.cpp b/Libraries/LibWeb/WebAudio/AudioContext.cpp index 35f57d5a579..b91bb771475 100644 --- a/Libraries/LibWeb/WebAudio/AudioContext.cpp +++ b/Libraries/LibWeb/WebAudio/AudioContext.cpp @@ -342,4 +342,12 @@ bool AudioContext::start_rendering_audio_graph() return render_result; } +// https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediaelementsource +WebIDL::ExceptionOr> AudioContext::create_media_element_source(GC::Ptr media_element) +{ + MediaElementAudioSourceOptions options; + options.media_element = media_element; + return MediaElementAudioSourceNode::create(realm(), *this, options); +} + } diff --git a/Libraries/LibWeb/WebAudio/AudioContext.h b/Libraries/LibWeb/WebAudio/AudioContext.h index 7aa02537d1d..8f606b634aa 100644 --- a/Libraries/LibWeb/WebAudio/AudioContext.h +++ b/Libraries/LibWeb/WebAudio/AudioContext.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace Web::WebAudio { @@ -39,6 +40,8 @@ public: WebIDL::ExceptionOr> suspend(); WebIDL::ExceptionOr> close(); + WebIDL::ExceptionOr> create_media_element_source(GC::Ptr); + private: explicit AudioContext(JS::Realm& realm) : BaseAudioContext(realm) diff --git a/Libraries/LibWeb/WebAudio/AudioContext.idl b/Libraries/LibWeb/WebAudio/AudioContext.idl index b8cee9b2e5d..7402b156bdb 100644 --- a/Libraries/LibWeb/WebAudio/AudioContext.idl +++ b/Libraries/LibWeb/WebAudio/AudioContext.idl @@ -13,7 +13,7 @@ interface AudioContext : BaseAudioContext { Promise resume (); Promise suspend (); Promise close (); - [FIXME] MediaElementAudioSourceNode createMediaElementSource (HTMLMediaElement mediaElement); + MediaElementAudioSourceNode createMediaElementSource (HTMLMediaElement mediaElement); [FIXME] MediaStreamAudioSourceNode createMediaStreamSource (MediaStream mediaStream); [FIXME] MediaStreamTrackAudioSourceNode createMediaStreamTrackSource (MediaStreamTrack mediaStreamTrack); [FIXME] MediaStreamAudioDestinationNode createMediaStreamDestination (); diff --git a/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audioparam-interface/audioparam-nominal-range.txt b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audioparam-interface/audioparam-nominal-range.txt index 7b983664e1c..4e04a3c942f 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audioparam-interface/audioparam-nominal-range.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/webaudio/the-audio-api/the-audioparam-interface/audioparam-nominal-range.txt @@ -1,9 +1,9 @@ Harness status: OK -Found 304 tests +Found 306 tests -294 Pass -10 Fail +297 Pass +9 Fail Pass # AUDIT TASK RUNNER STARTED. Pass Executing "initialize" Pass Executing "Offline createGain" @@ -24,7 +24,7 @@ Fail Executing "Offline createScriptProcessor" Pass Executing "Offline createPeriodicWave" Pass Executing "Offline createChannelSplitter" Pass Executing "Offline createChannelMerger" -Fail Executing "Online createMediaElementSource" +Pass Executing "Online createMediaElementSource" Fail Executing "Online createMediaStreamDestination" Pass Executing "AudioListener" Pass Executing "verifyTests" @@ -243,6 +243,8 @@ Pass > [Offline createChannelMerger] Pass AudioNode has no AudioParams as expected Pass < [Offline createChannelMerger] All assertions passed. (total 1 assertions) Pass > [Online createMediaElementSource] +Pass MediaElementAudioSourceNode has no AudioParams as expected +Pass < [Online createMediaElementSource] All assertions passed. (total 1 assertions) Pass > [Online createMediaStreamDestination] Pass > [AudioListener] Pass AudioListener.positionX.minValue is equal to -3.4028234663852886e+38.