Implement AudioContext.createMediaElementAudioSourceNode()

This commit is contained in:
Fernando Jiménez Moreno 2019-11-07 18:31:56 +01:00
parent a72e46f9c8
commit 04f4da3e13
3 changed files with 20 additions and 7 deletions

View file

@ -20,6 +20,8 @@ use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::DomRoot;
use crate::dom::htmlmediaelement::HTMLMediaElement;
use crate::dom::mediaelementaudiosourcenode::MediaElementAudioSourceNode;
use crate::dom::promise::Promise;
use crate::dom::window::Window;
use crate::task_source::TaskSource;
@ -244,6 +246,16 @@ impl AudioContextMethods for AudioContext {
// Step 6.
promise
}
/// https://webaudio.github.io/web-audio-api/#dom-audiocontext-createmediaelementsource
fn CreateMediaElementSource(
&self,
media_element: &HTMLMediaElement,
) -> Fallible<DomRoot<MediaElementAudioSourceNode>> {
let global = self.global();
let window = global.as_window();
MediaElementAudioSourceNode::new(window, self, media_element)
}
}
impl From<AudioContextLatencyCategory> for LatencyCategory {

View file

@ -27,7 +27,7 @@ impl MediaElementAudioSourceNode {
#[allow(unrooted_must_root)]
fn new_inherited(
context: &AudioContext,
options: &MediaElementAudioSourceOptions,
media_element: &HTMLMediaElement,
) -> Fallible<MediaElementAudioSourceNode> {
let node = AudioNode::new_inherited(
AudioNodeInit::MediaElementSourceNode,
@ -41,8 +41,8 @@ impl MediaElementAudioSourceNode {
MediaElementSourceNodeMessage::GetAudioRenderer(sender),
));
let audio_renderer = receiver.recv().unwrap();
options.mediaElement.set_audio_renderer(audio_renderer);
let media_element = Dom::from_ref(&*options.mediaElement);
media_element.set_audio_renderer(audio_renderer);
let media_element = Dom::from_ref(media_element);
Ok(MediaElementAudioSourceNode {
node,
media_element,
@ -53,9 +53,9 @@ impl MediaElementAudioSourceNode {
pub fn new(
window: &Window,
context: &AudioContext,
options: &MediaElementAudioSourceOptions,
media_element: &HTMLMediaElement,
) -> Fallible<DomRoot<MediaElementAudioSourceNode>> {
let node = MediaElementAudioSourceNode::new_inherited(context, options)?;
let node = MediaElementAudioSourceNode::new_inherited(context, media_element)?;
Ok(reflect_dom_object(
Box::new(node),
window,
@ -68,11 +68,12 @@ impl MediaElementAudioSourceNode {
context: &AudioContext,
options: &MediaElementAudioSourceOptions,
) -> Fallible<DomRoot<MediaElementAudioSourceNode>> {
MediaElementAudioSourceNode::new(window, context, options)
MediaElementAudioSourceNode::new(window, context, &*options.mediaElement)
}
}
impl MediaElementAudioSourceNodeMethods for MediaElementAudioSourceNode {
/// https://webaudio.github.io/web-audio-api/#dom-mediaelementaudiosourcenode-mediaelement
fn MediaElement(&self) -> DomRoot<HTMLMediaElement> {
DomRoot::from_ref(&*self.media_element)
}

View file

@ -33,7 +33,7 @@ interface AudioContext : BaseAudioContext {
Promise<void> suspend();
Promise<void> close();
// MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement);
[Throws] MediaElementAudioSourceNode createMediaElementSource(HTMLMediaElement mediaElement);
// MediaStreamAudioSourceNode createMediaStreamSource(MediaStream mediaStream);
// MediaStreamTrackAudioSourceNode createMediaStreamTrackSource(MediaStreamTrack mediaStreamTrack);
// MediaStreamAudioDestinationNode createMediaStreamDestination();