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
impl MediaRecorder
Sourcepub fn is_type_supported(mime_type: &str) -> bool
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.
Sourcepub fn new(stream: &MediaStream, options: MediaRecorderOptions) -> Self
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.
pub fn set_ondataavailable<F: FnMut(BlobEvent) + Send + 'static>( &self, callback: F, )
pub fn clear_ondataavailable(&self)
pub fn set_onstop<F: FnOnce(Event) + Send + 'static>(&self, callback: F)
pub fn clear_onstop(&self)
pub fn set_onerror<F: FnOnce(ErrorEvent) + Send + 'static>(&self, callback: F)
pub fn clear_onerror(&self)
pub fn stop(&self)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MediaRecorder
impl !RefUnwindSafe for MediaRecorder
impl Send for MediaRecorder
impl Sync for MediaRecorder
impl Unpin for MediaRecorder
impl !UnwindSafe for MediaRecorder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more