Skip to content

Audio

Overview

The audio module provides methods for playing back project's audio files.

API

audio::play

Plays an audio file from your project's audio directory,

audio::play(name: &str);
ParamTypeDefaultDescription
name&strThe name of the audio asset to play.

audio::is_playing

Returns true if the given audio track is currently being played.

audio::is_playing(name: &str) -> bool
ParamTypeDefaultDescription
name&strThe name of the audio asset check.

audio::pause

Pauses the given audio track.

audio::pause(name: &str)
ParamTypeDefaultDescription
name&strThe name of the audio asset to pause.

audio::stop

Stops the given audio track and resets its progress to the beginning.

audio::stop(name: &str)
ParamTypeDefaultDescription
name&strThe name of the audio asset to stop.

audio::get_volume

Gets the current volume of the sound identified by name, expressed as a percentage (0.0 to 1.0).

audio::get_volume(name: &str) -> f32
ParamTypeDefaultDescription
name&strThe name of the audio asset to get the volume of.

audio::set_volume

Sets the volume of the sound identified by name, using a 0.0 to 1.0 linear scale.

audio::set_volume(name: &str, volume: f32)
ParamTypeDefaultDescription
name&strThe name of the audio asset to set the volume of.
volumef32Percentage of max volume (between 0.0-1.0)

audio::mute

Mutes the sound identified by name.

audio::mute(name: &str)
ParamTypeDefaultDescription
name&strThe name of the audio asset to mute.

audio::is_muted

Returns true if the sound identified by name is currently muted.

audio::is_muted(name: &str) -> bool
ParamTypeDefaultDescription
name&strThe name of the audio asset to check if muted.

audio::unmute

Resets the sound's volume to the last volume before it was muted.

audio::unmute(name: &str)
ParamTypeDefaultDescription
name&strThe name of the audio asset to unmute.