MartinSStewart/elm-audio/1.0.0

NOTE: the latest version is 4.0.4

Audio

Applications

Create an Elm app that supports playing audio.

{ init : flags -> ( model, Cmd msg, AudioCmd msg )
, view : model -> Html msg
, update : msg -> model -> ( model, Cmd msg, AudioCmd msg )
, subscriptions : model -> Sub msg
, audio : model -> Audio
, audioPort : Ports msg
}
-> Program flags (Model msg model) (Msg msg)

Browser.element but with the ability to play sounds.

{ init : flags -> ( model, Cmd msg, AudioCmd msg )
, view : model -> Document msg
, update : msg -> model -> ( model, Cmd msg, AudioCmd msg )
, subscriptions : model -> Sub msg
, audio : model -> Audio
, audioPort : Ports msg
}
-> Program flags (Model msg model) (Msg msg)

Browser.document but with the ability to play sounds.

{ init : flags -> Url -> Key -> ( model, Cmd msg, AudioCmd msg )
, view : model -> Document msg
, update : msg -> model -> ( model, Cmd msg, AudioCmd msg )
, subscriptions : model -> Sub msg
, onUrlRequest : UrlRequest -> msg
, onUrlChange : Url -> msg
, audio : model -> Audio
, audioPort : Ports msg
}
-> Program flags (Model msg model) (Msg msg)

Browser.application but with the ability to play sounds.

Load audio

Load audio so you can later play it.

type AudioCmd userMsg

An audio command.

loadAudio : (Result LoadError Source -> msg) -> String -> AudioCmd msg

Load audio from a url.

= MediaDecodeAudioDataUnknownContentType
| NetworkError

Possible errors we can get when loading audio files.

type Source
cmdBatch : List (AudioCmd userMsg) -> AudioCmd userMsg

Combine multiple commands into a single command. Conceptually the same as Cmd.batch.

A command that does nothing. Conceptually the same as Cmd.none.

sourceDuration : Source -> Duration

Get how long an audio source plays for.

Play audio

Define what audio should be playing.

type Audio

Some kind of sound we want to play. To create Audio start with audio.

audio : Source -> Posix -> Audio

Play audio from an audio source at a given time. This is the same as using audioWithConfig audioDefaultConfig.

group : List Audio -> Audio

Combine multiple Audios into a single Audio.

The sound of no sound at all.

audioWithConfig : PlayAudioConfig -> Source -> Posix -> Audio

Play audio from an audio source at a given time with config.

audioDefaultConfig : PlayAudioConfig

Default config used for audioWithConfig.

type alias PlayAudioConfig =
{ loop : Maybe LoopConfig
, playbackRate : Float
, startAt : Duration
}

Extra settings when playing audio from a file.

type alias LoopConfig =
{ loopStart : Duration
, loopEnd : Duration
}

Control how audio loops. loopEnd defines where (relative to the start of the audio) the audio should loop and loopStart where it should loop to.

-- Here we have a song that plays an intro once and then loops between the 10 second point and the end of the song.
let
    default =
        Audio.audioDefaultConfig


    songLength =
        Audio.sourceDuration coolBackgroundMusic
in
audioWithConfig
    { default | loop = Just { loopStart = Duration.seconds 10, loopEnd = songLength } }
    coolBackgroundMusic
    startTime

Audio effects

Effects you can apply to Audio.

scaleVolume : Float -> Audio -> Audio

Scale how loud a given Audio is. If the the volume is less than 0, 0 will be used instead.

scaleVolumeAt : VolumeTimeline -> Audio -> Audio

Scale how loud a given Audio is given points in time. The volume will transition linearly between those points.

Internal stuff

type Model userMsg userModel
type Msg userMsg

Lamdera stuff

WIP support for Lamdera. Ignore this for now.

{ init :
Url -> Key -> ( model, Cmd frontendMsg, AudioCmd frontendMsg )
, view : model -> Document frontendMsg
, update :
frontendMsg
-> model
-> ( model, Cmd frontendMsg, AudioCmd frontendMsg )
, updateFromBackend :
toFrontend
-> model
-> ( model, Cmd frontendMsg, AudioCmd frontendMsg )
, subscriptions : model -> Sub frontendMsg
, onUrlRequest : UrlRequest -> frontendMsg
, onUrlChange : Url -> frontendMsg
, audio : model -> Audio
, audioPort : Ports frontendMsg
}
-> { init :
Url -> Key -> ( Model frontendMsg model, Cmd (Msg frontendMsg) )
, view : Model frontendMsg model -> Document (Msg frontendMsg)
, update :
Msg frontendMsg
-> Model frontendMsg model
-> ( Model frontendMsg model, Cmd (Msg frontendMsg) )
, updateFromBackend :
toFrontend
-> Model frontendMsg model
-> ( Model frontendMsg model, Cmd (Msg frontendMsg) )
, subscriptions : Model frontendMsg model -> Sub (Msg frontendMsg)
, onUrlRequest : UrlRequest -> Msg frontendMsg
, onUrlChange : Url -> Msg frontendMsg
}

Lamdera.frontend but with the ability to play sounds (highly experimental, just ignore this for now).