AUDIOS

Struct AUDIOS 

Source
pub struct AUDIOS;
Expand description

Audio loading, cache and render service.

If the app is running without a VIEW_PROCESS all audios are dummy, see load_in_headless for details.

Implementations§

Source§

impl AUDIOS

Source

pub fn load_in_headless(&self) -> Var<bool>

If should still download/read audio bytes in headless/renderless mode.

When an app is in headless mode without renderer no VIEW_PROCESS is available, so audios cannot be decoded, in this case all audios are dummy loading and no attempt to download/read the audio files is made. You can enable loading in headless tests to detect IO errors, in this case if there is an error acquiring the audio file the audio will be a dummy with error.

Source

pub fn limits(&self) -> Var<AudioLimits>

Default loading and decoding limits for each audio.

Source

pub fn read(&self, path: impl Into<PathBuf>) -> AudioVar

Request an audio, reads from a path and caches it.

This is shorthand for calling AUDIOS.audio with AudioSource::Read and AudioOptions::cache.

Source

pub fn download<U>(&self, uri: U, accept: Option<Txt>) -> AudioVar
where U: TryInto<Uri>, <U as TryInto<Uri>>::Error: ToTxt,

Request an audio, downloads from an uri and caches it.

Optionally define the HTTP ACCEPT header, if not set all audio formats supported by the view-process backend are accepted.

This is shorthand for calling AUDIOS.audio with AudioSource::Download and AudioOptions::cache.

Source

pub fn from_static( &self, data: &'static [u8], format: impl Into<AudioDataFormat>, ) -> AudioVar

Request an audio from &'static [u8] data.

The data can be any of the formats described in AudioDataFormat.

This is shorthand for calling AUDIOS.audio with AudioSource::Data and AudioOptions::cache.

§Examples

Get an audio from a PNG file embedded in the app executable using include_bytes!.

let audio_var = AUDIOS.from_static(include_bytes!("ico.png"), "png");
Source

pub fn from_data( &self, data: IpcBytes, format: impl Into<AudioDataFormat>, ) -> AudioVar

Get a cached audio from shared data.

The data can be any of the formats described in AudioDataFormat.

This is shorthand for calling AUDIOS.audio with AudioSource::Data and AudioOptions::cache.

Source

pub fn audio( &self, source: impl Into<AudioSource>, options: AudioOptions, limits: Option<AudioLimits>, ) -> AudioVar

Request an audio, with full load and cache configuration.

If limits is None the AUDIOS.limits is used.

Always returns a loading audio due to the deferred nature of services. If the audio is already in cache it will be set and bound to it once the current update finishes.

Source

pub fn audio_task<F>( &self, source: impl IntoFuture<IntoFuture = F>, options: AudioOptions, limits: Option<AudioLimits>, ) -> AudioVar
where F: Future<Output = AudioSource> + Send + 'static,

Await for an audio source, then get or load the audio.

If limits is None the AUDIOS.limits is used.

This method returns immediately with a loading AudioVar, when source is ready it is used to get the actual AudioVar and binds it to the returned audio.

Note that the cache_mode always applies to the inner audio, and only to the return audio if cache_key is set.

Source

pub fn register( &self, key: Option<AudioHash>, audio: (ViewAudioHandle, AudioMetadata, AudioDecoded), ) -> AudioVar

Associate the audio produced by direct interaction with the view-process with the key in the cache.

Returns an audio var that tracks the audio, note that if the key is already known does not use the audio data.

Note that you can register tracks in AudioTrack::insert_track, this method is only for tracking a new track.

Note that the audio will not automatically restore on respawn if the view-process fails while decoding.

Source

pub fn clean(&self, key: AudioHash)

Remove the audio from the cache, if it is only held by the cache.

You can use AudioSource::hash128_read and AudioSource::hash128_download to get the key for files or downloads.

Source

pub fn purge(&self, key: AudioHash)

Remove the audio from the cache, even if it is still referenced outside of the cache.

You can use AudioSource::hash128_read and AudioSource::hash128_download to get the key for files or downloads.

Source

pub fn cache_key(&self, audio: &AudioTrack) -> Option<AudioHash>

Gets the cache key of an audio.

Source

pub fn is_cached(&self, audio: &AudioTrack) -> bool

If the audio is cached.

Source

pub fn clean_all(&self)

Clear cached audios that are not referenced outside of the cache.

Source

pub fn purge_all(&self)

Clear all cached audios, including audios that are still referenced outside of the cache.

Audio memory only drops when all strong references are removed, so if an audio is referenced outside of the cache it will merely be disconnected from the cache by this method.

Source

pub fn extend(&self, extension: Box<dyn AudiosExtension>)

Add an audios service extension.

See AudiosExtension for extension capabilities.

Source

pub fn available_formats(&self) -> Vec<AudioFormat>

Audio formats implemented by the current view-process and extensions.

Source§

impl AUDIOS

Source

pub fn open_output( &self, id: impl Into<AudioOutputId>, init: impl FnOnce(&mut AudioOutputOptions) + Send + 'static, ) -> ResponseVar<AudioOutput>

Open an audio output stream, or get a reference clone to the already open stream.

If the id is not already open the init closure is called to configure the output request. By default the configuration creates an output for the default audio output device, in the playing state, with 100% volume and speed.

Output remains open until all clones of it are dropped, or until the app exit if AudioOutput::perm is called.

Note that output streams are not direct connections to the audio output device, the view-process will mix all audio streams playing in parallel to the single audio output stream. Also note that usually the view-process will retain the device connection for the duration of the process, created with first output, this is the recommended behavior in most operating systems.

Auto Trait Implementations§

§

impl Freeze for AUDIOS

§

impl RefUnwindSafe for AUDIOS

§

impl Send for AUDIOS

§

impl Sync for AUDIOS

§

impl Unpin for AUDIOS

§

impl UnwindSafe for AUDIOS

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> StateValue for T
where T: Any + Send + Sync,