glor

Types

pub type AudioPlayer

Values

pub fn loop(audio: AudioPlayer) -> Bool

Get whether the audio will restart from the beginning when the end of the track is reached.

pub fn new(url: String) -> AudioPlayer

Create a new audio player. The argument is a URL to an audio file that will be played by a web browser audio element.

Examples

let player = glor.new("https://my-website.com/my-sound-effect.mp3")
glor.play(player)
pub fn pause(audio: AudioPlayer) -> Nil

Pause the audio.

If the audio is already paused then nothing will happen.

pub fn play(audio: AudioPlayer) -> Nil

Start playing the audio.

If the audio is already playing then nothing will happen.

pub fn playback_rate(audio: AudioPlayer) -> Float

Get the current speed at which the audio will play, with 1 being normal rate.

pub fn preserves_pitch(audio: AudioPlayer) -> Bool

Get whether a time stretching algorithm is applied to the audio so that the pitch does not change when the playback rate changes.

Permitting the pitch to change may result in better sounding audio if the playback rate is not close to 1, but this is subjective and a matter of personal taste.

pub fn set_loop(audio: AudioPlayer, status: Bool) -> Nil

Set whether the audio will restart from the beginning when the end of the track is reached.

The default value is false.

pub fn set_playback_rate(
  audio: AudioPlayer,
  amount: Float,
) -> Nil

Set the current speed at which the audio will play, with 1 being normal rate.

Browsers will stop playing the audio if this value is too large or too small. Between 0.25 and 4 is widely supported.

The default value is 1.

pub fn set_preserves_pitch(
  audio: AudioPlayer,
  status: Bool,
) -> Nil

Set whether a time stretching algorithm is applied to the audio so that the pitch does not change when the playback rate changes.

Permitting the pitch to change may result in better sounding audio if the playback rate is not close to 1, but this is subjective and a matter of personal taste.

The default value is true.

pub fn set_volume(audio: AudioPlayer, amount: Float) -> Nil

Set the current volume level with a float between 0 (silent) and 1 (full volume).

The default value is 1.

pub fn volume(audio: AudioPlayer) -> Float

Get the current volume as a float between 0 (silent) and 1 (full volume).

Search Document