AudioContext

Struct AudioContext 

Source
pub struct AudioContext { /* private fields */ }
Expand description

The AudioContext class. AudioContext

Implementations§

Source§

impl AudioContext

Source

pub fn base_latency(&self) -> f64

Getter of the baseLatency attribute. AudioContext.baseLatency

Source§

impl AudioContext

Source

pub fn output_latency(&self) -> f64

Getter of the outputLatency attribute. AudioContext.outputLatency

Source§

impl AudioContext

Source

pub fn sink_id(&self) -> Any

Getter of the sinkId attribute. AudioContext.sinkId

Source§

impl AudioContext

Source

pub fn onsinkchange(&self) -> Any

Getter of the onsinkchange attribute. AudioContext.onsinkchange

Source

pub fn set_onsinkchange(&mut self, value: &Any)

Setter of the onsinkchange attribute. AudioContext.onsinkchange

Source§

impl AudioContext

Source

pub fn onerror(&self) -> Any

Getter of the onerror attribute. AudioContext.onerror

Source

pub fn set_onerror(&mut self, value: &Any)

Setter of the onerror attribute. AudioContext.onerror

Source§

impl AudioContext

Source

pub fn new() -> AudioContext

The new AudioContext(..) constructor, creating a new AudioContext instance

Examples found in repository?
examples/audio.rs (line 5)
4fn main() {
5    let context = AudioContext::new();
6    println!("Got an AudioContext");
7
8    // Create oscillator
9    let mut oscillator = context.create_oscillator();
10    println!("Configuring oscillator");
11    oscillator.set_type_(&OscillatorType::TRIANGLE);
12    oscillator.frequency().set_value(261.63); // Middle C
13
14    let document = window().document();
15    let body = document.get_elements_by_tag_name(&"body".into()).item(0);
16    let mut button = document
17        .create_element(&"BUTTON".into())
18        .dyn_into::<HTMLButtonElement>()
19        .unwrap();
20
21    button.set_text_content(&"Click me".into());
22    button.add_event_listener(
23        &JsString::from("click"),
24        &EventListener::from_closure(move |_e: Event| {
25            println!("Playing");
26            oscillator.connect_with_destination_param(
27                context.destination().unchecked_ref::<AudioParam>(),
28            );
29            oscillator.start_with_when(0.0);
30            println!("All done!");
31            Undefined::VALUE
32        }),
33    );
34    body.append_child(button.dyn_ref::<Node>().unwrap());
35}
Source§

impl AudioContext

Source

pub fn new_with_context_options( context_options: &AudioContextOptions, ) -> AudioContext

The new AudioContext(..) constructor, creating a new AudioContext instance

Source§

impl AudioContext

Source

pub fn get_output_timestamp(&self) -> AudioTimestamp

The getOutputTimestamp method. AudioContext.getOutputTimestamp

Source§

impl AudioContext

Source

pub fn resume(&self) -> Promise<Undefined>

The resume method. AudioContext.resume

Source§

impl AudioContext

Source

pub fn suspend(&self) -> Promise<Undefined>

The suspend method. AudioContext.suspend

Source§

impl AudioContext

Source

pub fn close(&self) -> Promise<Undefined>

The close method. AudioContext.close

Source§

impl AudioContext

Source

pub fn set_sink_id(&self, sink_id: &Any) -> Promise<Undefined>

The setSinkId method. AudioContext.setSinkId

Source§

impl AudioContext

Source

pub fn create_media_element_source( &self, media_element: &HTMLMediaElement, ) -> MediaElementAudioSourceNode

The createMediaElementSource method. AudioContext.createMediaElementSource

Source§

impl AudioContext

Source

pub fn create_media_stream_source( &self, media_stream: &MediaStream, ) -> MediaStreamAudioSourceNode

The createMediaStreamSource method. AudioContext.createMediaStreamSource

Source§

impl AudioContext

Source

pub fn create_media_stream_track_source( &self, media_stream_track: &MediaStreamTrack, ) -> MediaStreamTrackAudioSourceNode

The createMediaStreamTrackSource method. AudioContext.createMediaStreamTrackSource

Source§

impl AudioContext

Methods from Deref<Target = BaseAudioContext>§

Source

pub fn destination(&self) -> AudioDestinationNode

Getter of the destination attribute. BaseAudioContext.destination

Examples found in repository?
examples/audio.rs (line 27)
4fn main() {
5    let context = AudioContext::new();
6    println!("Got an AudioContext");
7
8    // Create oscillator
9    let mut oscillator = context.create_oscillator();
10    println!("Configuring oscillator");
11    oscillator.set_type_(&OscillatorType::TRIANGLE);
12    oscillator.frequency().set_value(261.63); // Middle C
13
14    let document = window().document();
15    let body = document.get_elements_by_tag_name(&"body".into()).item(0);
16    let mut button = document
17        .create_element(&"BUTTON".into())
18        .dyn_into::<HTMLButtonElement>()
19        .unwrap();
20
21    button.set_text_content(&"Click me".into());
22    button.add_event_listener(
23        &JsString::from("click"),
24        &EventListener::from_closure(move |_e: Event| {
25            println!("Playing");
26            oscillator.connect_with_destination_param(
27                context.destination().unchecked_ref::<AudioParam>(),
28            );
29            oscillator.start_with_when(0.0);
30            println!("All done!");
31            Undefined::VALUE
32        }),
33    );
34    body.append_child(button.dyn_ref::<Node>().unwrap());
35}
Source

pub fn sample_rate(&self) -> f32

Getter of the sampleRate attribute. BaseAudioContext.sampleRate

Source

pub fn current_time(&self) -> f64

Getter of the currentTime attribute. BaseAudioContext.currentTime

Source

pub fn listener(&self) -> AudioListener

Getter of the listener attribute. BaseAudioContext.listener

Source

pub fn state(&self) -> AudioContextState

Getter of the state attribute. BaseAudioContext.state

Source

pub fn render_quantum_size(&self) -> u32

Getter of the renderQuantumSize attribute. BaseAudioContext.renderQuantumSize

Source

pub fn audio_worklet(&self) -> AudioWorklet

Getter of the audioWorklet attribute. BaseAudioContext.audioWorklet

Source

pub fn onstatechange(&self) -> Any

Getter of the onstatechange attribute. BaseAudioContext.onstatechange

Source

pub fn set_onstatechange(&mut self, value: &Any)

Setter of the onstatechange attribute. BaseAudioContext.onstatechange

Source

pub fn create_analyser(&self) -> AnalyserNode

The createAnalyser method. BaseAudioContext.createAnalyser

Source

pub fn create_biquad_filter(&self) -> BiquadFilterNode

The createBiquadFilter method. BaseAudioContext.createBiquadFilter

Source

pub fn create_buffer( &self, number_of_channels: u32, length: u32, sample_rate: f32, ) -> AudioBuffer

The createBuffer method. BaseAudioContext.createBuffer

Source

pub fn create_buffer_source(&self) -> AudioBufferSourceNode

The createBufferSource method. BaseAudioContext.createBufferSource

Source

pub fn create_channel_merger(&self) -> ChannelMergerNode

The createChannelMerger method. BaseAudioContext.createChannelMerger

Source

pub fn create_channel_merger_with_number_of_inputs( &self, number_of_inputs: u32, ) -> ChannelMergerNode

The createChannelMerger method. BaseAudioContext.createChannelMerger

Source

pub fn create_channel_splitter(&self) -> ChannelSplitterNode

The createChannelSplitter method. BaseAudioContext.createChannelSplitter

Source

pub fn create_channel_splitter_with_number_of_outputs( &self, number_of_outputs: u32, ) -> ChannelSplitterNode

The createChannelSplitter method. BaseAudioContext.createChannelSplitter

Source

pub fn create_constant_source(&self) -> ConstantSourceNode

The createConstantSource method. BaseAudioContext.createConstantSource

Source

pub fn create_convolver(&self) -> ConvolverNode

The createConvolver method. BaseAudioContext.createConvolver

Source

pub fn create_delay(&self) -> DelayNode

The createDelay method. BaseAudioContext.createDelay

Source

pub fn create_delay_with_max_delay_time(&self, max_delay_time: f64) -> DelayNode

The createDelay method. BaseAudioContext.createDelay

Source

pub fn create_dynamics_compressor(&self) -> DynamicsCompressorNode

The createDynamicsCompressor method. BaseAudioContext.createDynamicsCompressor

Source

pub fn create_gain(&self) -> GainNode

The createGain method. BaseAudioContext.createGain

Source

pub fn create_iir_filter( &self, feedforward: TypedArray<f64>, feedback: TypedArray<f64>, ) -> IIRFilterNode

The createIIRFilter method. BaseAudioContext.createIIRFilter

Source

pub fn create_oscillator(&self) -> OscillatorNode

The createOscillator method. BaseAudioContext.createOscillator

Examples found in repository?
examples/audio.rs (line 9)
4fn main() {
5    let context = AudioContext::new();
6    println!("Got an AudioContext");
7
8    // Create oscillator
9    let mut oscillator = context.create_oscillator();
10    println!("Configuring oscillator");
11    oscillator.set_type_(&OscillatorType::TRIANGLE);
12    oscillator.frequency().set_value(261.63); // Middle C
13
14    let document = window().document();
15    let body = document.get_elements_by_tag_name(&"body".into()).item(0);
16    let mut button = document
17        .create_element(&"BUTTON".into())
18        .dyn_into::<HTMLButtonElement>()
19        .unwrap();
20
21    button.set_text_content(&"Click me".into());
22    button.add_event_listener(
23        &JsString::from("click"),
24        &EventListener::from_closure(move |_e: Event| {
25            println!("Playing");
26            oscillator.connect_with_destination_param(
27                context.destination().unchecked_ref::<AudioParam>(),
28            );
29            oscillator.start_with_when(0.0);
30            println!("All done!");
31            Undefined::VALUE
32        }),
33    );
34    body.append_child(button.dyn_ref::<Node>().unwrap());
35}
Source

pub fn create_panner(&self) -> PannerNode

The createPanner method. BaseAudioContext.createPanner

Source

pub fn create_periodic_wave( &self, real: TypedArray<f32>, imag: TypedArray<f32>, ) -> PeriodicWave

The createPeriodicWave method. BaseAudioContext.createPeriodicWave

Source

pub fn create_periodic_wave_with_constraints( &self, real: TypedArray<f32>, imag: TypedArray<f32>, constraints: &PeriodicWaveConstraints, ) -> PeriodicWave

The createPeriodicWave method. BaseAudioContext.createPeriodicWave

Source

pub fn create_script_processor(&self) -> ScriptProcessorNode

The createScriptProcessor method. BaseAudioContext.createScriptProcessor

Source

pub fn create_script_processor_with_buffer_size( &self, buffer_size: u32, ) -> ScriptProcessorNode

The createScriptProcessor method. BaseAudioContext.createScriptProcessor

Source

pub fn create_script_processor_with_buffer_size_and_number_of_input_channels( &self, buffer_size: u32, number_of_input_channels: u32, ) -> ScriptProcessorNode

The createScriptProcessor method. BaseAudioContext.createScriptProcessor

Source

pub fn create_script_processor_with_buffer_size_and_number_of_input_channels_and_number_of_output_channels( &self, buffer_size: u32, number_of_input_channels: u32, number_of_output_channels: u32, ) -> ScriptProcessorNode

The createScriptProcessor method. BaseAudioContext.createScriptProcessor

Source

pub fn create_stereo_panner(&self) -> StereoPannerNode

The createStereoPanner method. BaseAudioContext.createStereoPanner

Source

pub fn create_wave_shaper(&self) -> WaveShaperNode

The createWaveShaper method. BaseAudioContext.createWaveShaper

Source

pub fn decode_audio_data( &self, audio_data: &ArrayBuffer, ) -> Promise<AudioBuffer>

The decodeAudioData method. BaseAudioContext.decodeAudioData

Source

pub fn decode_audio_data_with_success_callback( &self, audio_data: &ArrayBuffer, success_callback: &Function, ) -> Promise<AudioBuffer>

The decodeAudioData method. BaseAudioContext.decodeAudioData

Source

pub fn decode_audio_data_with_success_callback_and_error_callback( &self, audio_data: &ArrayBuffer, success_callback: &Function, error_callback: &Function, ) -> Promise<AudioBuffer>

The decodeAudioData method. BaseAudioContext.decodeAudioData

Methods from Deref<Target = EventTarget>§

Source

pub fn add_event_listener( &self, type_: &JsString, callback: &EventListener, ) -> Undefined

The addEventListener method. EventTarget.addEventListener

Examples found in repository?
examples/button.rs (lines 24-31)
4fn main() {
5    let con = Console::get();
6    let document = window().document();
7    let bodies = document.get_elements_by_tag_name(&"body".into());
8    if bodies.length() == 0 {
9        con.log(&["I Ain't got Nobody!".into()]);
10        return;
11    }
12    let body = bodies.item(0);
13    let mut button = document
14        .create_element(&"BUTTON".into())
15        .dyn_into::<HTMLButtonElement>()
16        .unwrap();
17
18    let style = button.style();
19    style.set_property(&"color".into(), &"red".into());
20    style.set_property(&"background-color".into(), &"#aaf".into());
21    style.set_property(&"border".into(), &"solid".into());
22
23    button.set_text_content(&"Click me".into());
24    button.add_event_listener(
25        &"click".into(),
26        &EventListener::from_closure(move |e: Event| {
27            let p = e.dyn_into::<PointerEvent>().unwrap();
28            con.log(&[p.client_x().into()]);
29            Undefined::VALUE
30        }),
31    );
32    body.append_child(button.dyn_ref::<Node>().unwrap());
33}
More examples
Hide additional examples
examples/audio.rs (lines 22-33)
4fn main() {
5    let context = AudioContext::new();
6    println!("Got an AudioContext");
7
8    // Create oscillator
9    let mut oscillator = context.create_oscillator();
10    println!("Configuring oscillator");
11    oscillator.set_type_(&OscillatorType::TRIANGLE);
12    oscillator.frequency().set_value(261.63); // Middle C
13
14    let document = window().document();
15    let body = document.get_elements_by_tag_name(&"body".into()).item(0);
16    let mut button = document
17        .create_element(&"BUTTON".into())
18        .dyn_into::<HTMLButtonElement>()
19        .unwrap();
20
21    button.set_text_content(&"Click me".into());
22    button.add_event_listener(
23        &JsString::from("click"),
24        &EventListener::from_closure(move |_e: Event| {
25            println!("Playing");
26            oscillator.connect_with_destination_param(
27                context.destination().unchecked_ref::<AudioParam>(),
28            );
29            oscillator.start_with_when(0.0);
30            println!("All done!");
31            Undefined::VALUE
32        }),
33    );
34    body.append_child(button.dyn_ref::<Node>().unwrap());
35}
Source

pub fn add_event_listener_with_options( &self, type_: &JsString, callback: &EventListener, options: &Any, ) -> Undefined

The addEventListener method. EventTarget.addEventListener

Source

pub fn remove_event_listener( &self, type_: &JsString, callback: &EventListener, ) -> Undefined

The removeEventListener method. EventTarget.removeEventListener

Source

pub fn remove_event_listener_with_options( &self, type_: &JsString, callback: &EventListener, options: &Any, ) -> Undefined

The removeEventListener method. EventTarget.removeEventListener

Source

pub fn dispatch_event(&self, event: &Event) -> bool

The dispatchEvent method. EventTarget.dispatchEvent

Source

pub fn when(&self, type_: &JsString) -> Observable

The when method. EventTarget.when

Source

pub fn when_with_options( &self, type_: &JsString, options: &ObservableEventListenerOptions, ) -> Observable

The when method. EventTarget.when

Methods from Deref<Target = Any>§

Source

pub fn get<T>(&self, prop: T) -> Val
where T: Into<Val>,

Gets the property prop

Source

pub fn set<K, V>(&self, prop: K, val: V)
where K: Into<Val>, V: Into<Val>,

Set the underlying js object property prop to val

Source

pub fn has<T>(&self, prop: T) -> bool
where T: Into<Val>,

Checks whether a property prop exists

Source

pub fn has_own_property(&self, prop: &str) -> bool

Checks whether a non-inherited property prop exists

Source

pub fn type_of(&self) -> String

Gets the typeof the underlying js object

Source

pub fn at<T>(&self, idx: T) -> Val
where T: Into<Val>,

Gets the element at index idx. Assumes the underlying js type is indexable

Source

pub fn to_vec<V>(&self) -> Vec<V>
where V: FromVal,

Converts the underlying js array to a Vec of V

Source

pub fn call(&self, f: &str, args: &[Val]) -> Val

Calls the method f with args, can return an undefined js value

Source

pub fn new(&self, args: &[Val]) -> Val

Calls the object’s constructor with args constructing a new object

Source

pub fn invoke(&self, args: &[Val]) -> Val

Invokes the function object with args, can return an undefined js value

Source

pub fn await_(&self) -> Val

Awaits the invoked function object

Source

pub fn instanceof(&self, v: Val) -> bool

Checks whether this Val is an instanceof v

Source

pub fn is_number(&self) -> bool

Source

pub fn is_bool(&self) -> bool

Source

pub fn is_string(&self) -> bool

Source

pub fn is_null(&self) -> bool

Source

pub fn is_undefined(&self) -> bool

Source

pub fn is_error(&self) -> bool

Source

pub fn is_function(&self) -> bool

Source

pub fn as_<T>(&self) -> T
where T: FromVal,

Source

pub fn to_utf16(&self) -> Option<Vec<u16>>

Extracts UTF-16 data as Option<Vec>

Source

pub fn to_utf16_result(&self) -> Result<Vec<u16>, Val>

Extracts UTF-16 data, returning error if null or if self is error

Trait Implementations§

Source§

impl AsMut<Val> for AudioContext

Source§

fn as_mut(&mut self) -> &mut Any

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Val> for AudioContext

Source§

fn as_ref(&self) -> &Any

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for AudioContext

Source§

fn clone(&self) -> AudioContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AudioContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for AudioContext

Source§

type Target = BaseAudioContext

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for AudioContext

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl DynCast for AudioContext

Source§

fn instanceof(val: &Any) -> bool

Implementation of val instanceof ThisType.
Source§

fn unchecked_from_val(v: Any) -> Self

Zero-cost unchecked conversion from Val into Self.
Source§

fn unchecked_from_val_ref(v: &Any) -> &Self

Zero-cost unchecked conversion from &Val into &Self.
Source§

fn unchecked_from_val_mut(v: &mut Any) -> &mut Self

Zero-cost unchecked conversion from &mut Val into &mut Self.
Source§

fn has_type<T>(&self) -> bool
where T: DynCast,

Source§

fn dyn_into<T>(self) -> Result<T, Self>
where T: DynCast,

Source§

fn dyn_ref<T>(&self) -> Option<&T>
where T: DynCast,

Source§

fn dyn_mut<T>(&mut self) -> Option<&mut T>
where T: DynCast,

Source§

fn unchecked_into<T>(self) -> T
where T: DynCast,

Source§

fn unchecked_ref<T>(&self) -> &T
where T: DynCast,

Source§

fn unchecked_mut<T>(&mut self) -> &mut T
where T: DynCast,

Source§

fn is_instance_of<T>(&self) -> bool
where T: DynCast,

Source§

fn is_type_of(val: &Val) -> bool

Customisable brand check – defaults to instanceof.
Source§

impl From<&AudioContext> for Any

Source§

fn from(s: &AudioContext) -> Any

Converts to this type from the input type.
Source§

impl From<AudioContext> for Any

Source§

fn from(s: AudioContext) -> Any

Converts to this type from the input type.
Source§

impl FromVal for AudioContext

Source§

fn from_val(v: &Any) -> Self

Creates a Val object from another
Source§

fn take_ownership(v: AnyHandle) -> Self

Takes the ownership of a handle
Source§

fn as_handle(&self) -> AnyHandle

Returns the raw js handle
Source§

impl PartialEq for AudioContext

Source§

fn eq(&self, other: &AudioContext) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for AudioContext

Source§

fn partial_cmp(&self, other: &AudioContext) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for AudioContext

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.