Struct MediaRecorder

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

Record and encode media

use web_audio_api::context::AudioContext;
use web_audio_api::media_recorder::{MediaRecorder, MediaRecorderOptions};

let context = AudioContext::default();
let output = context.create_media_stream_destination();

let options = MediaRecorderOptions::default(); // default to audio/wav
let recorder = MediaRecorder::new(output.stream(), options);
recorder.set_ondataavailable(|event| {
    println!("Received {} bytes of data", event.blob.size());
});
recorder.start();

§Examples

  • cargo run --release --example recorder

Implementations§

Source§

impl MediaRecorder

Source

pub fn is_type_supported(mime_type: &str) -> bool

A static method which returns a true or false value indicating if the given MIME media type is supported.

Source

pub fn new(stream: &MediaStream, options: MediaRecorderOptions) -> Self

Creates a new MediaRecorder object, given a MediaStream to record.

Only supports WAV file format currently, so options.mime_type should be set to audio/wav or left empty.

§Panics

This function will panic with a NotSupportedError when the provided mime type is not supported. Be sure to check Self::is_type_supported before calling this constructor.

Source

pub fn set_ondataavailable<F: FnMut(BlobEvent) + Send + 'static>( &self, callback: F, )

Source

pub fn clear_ondataavailable(&self)

Source

pub fn set_onstop<F: FnOnce(Event) + Send + 'static>(&self, callback: F)

Source

pub fn clear_onstop(&self)

Source

pub fn set_onerror<F: FnOnce(ErrorEvent) + Send + 'static>(&self, callback: F)

Source

pub fn clear_onerror(&self)

Source

pub fn start(&self)

Begin recording media

§Panics

Will panic when the recorder has already started

Source

pub fn stop(&self)

Trait Implementations§

Source§

impl Debug for MediaRecorder

Source§

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

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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.
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,