Trait web_audio_api::media::MediaStream [−][src]
pub trait MediaStream: Iterator<Item = Result<AudioBuffer, Box<dyn Error + Send>>> + Send + 'static { }
Interface for media streaming.
This is a trait alias for an AudioBuffer
Iterator, for example the OggVorbisDecoder
Below is an example showing how to play the stream directly.
If you want to control the media playback (play/pause, offsets, loops), wrap the MediaStream
in a MediaElement
.
Example
use web_audio_api::SampleRate; use web_audio_api::context::{AudioContext, AsBaseAudioContext}; use web_audio_api::buffer::AudioBuffer; // create a new buffer: 512 samples of silence let silence = AudioBuffer::new(1, 512, SampleRate(44_100)); // create a sequence of this buffer let sequence = std::iter::repeat(silence).take(5); // the sequence should actually yield `Result<AudioBuffer, _>`s let media = sequence.map(|b| Ok(b)); // media is now a proper `MediaStream` and can be used in the audio graph let context = AudioContext::new(); let node = context.create_media_stream_source(media);