Current section
Files
Jump to
Current section
Files
src/glor.gleam
pub type 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
///
/// ```gleam
/// let player = glor.new("https://my-website.com/my-sound-effect.mp3")
/// glor.play(player)
/// ```
///
@external(javascript, "./glor_ffi.mjs", "make")
pub fn new(url: String) -> AudioPlayer
/// Start playing the audio.
///
/// If the audio is already playing then nothing will happen.
///
@external(javascript, "./glor_ffi.mjs", "play")
pub fn play(audio: AudioPlayer) -> Nil
/// Pause the audio.
///
/// If the audio is already paused then nothing will happen.
///
@external(javascript, "./glor_ffi.mjs", "pause")
pub fn pause(audio: AudioPlayer) -> Nil
/// Get the current volume as a float between 0 (silent) and 1 (full volume).
///
@external(javascript, "./glor_ffi.mjs", "volume")
pub fn volume(audio: AudioPlayer) -> Float
/// Set the current volume level with a float between 0 (silent) and 1 (full
/// volume).
///
/// The default value is 1.
///
@external(javascript, "./glor_ffi.mjs", "set_volume")
pub fn set_volume(audio: AudioPlayer, amount: Float) -> Nil
/// Get whether the audio will restart from the beginning when the end of the
/// track is reached.
///
@external(javascript, "./glor_ffi.mjs", "loop")
pub fn loop(audio: AudioPlayer) -> Bool
/// Set whether the audio will restart from the beginning when the end of the
/// track is reached.
///
/// The default value is false.
///
@external(javascript, "./glor_ffi.mjs", "set_loop")
pub fn set_loop(audio: AudioPlayer, status: Bool) -> Nil
/// Get the current speed at which the audio will play, with 1 being normal rate.
///
@external(javascript, "./glor_ffi.mjs", "playback_rate")
pub fn playback_rate(audio: AudioPlayer) -> Float
/// 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.
///
@external(javascript, "./glor_ffi.mjs", "set_playback_rate")
pub fn set_playback_rate(audio: AudioPlayer, amount: Float) -> Nil
/// 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.
///
@external(javascript, "./glor_ffi.mjs", "preserves_pitch")
pub fn preserves_pitch(audio: AudioPlayer) -> Bool
/// 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.
///
@external(javascript, "./glor_ffi.mjs", "set_preserves_pitch")
pub fn set_preserves_pitch(audio: AudioPlayer, status: Bool) -> Nil