Documentation
¶
Overview ¶
Package audio plays sound: a Sound, a short sound decoded once and played any number of times, overlapping, and a Player of long audio, streamed and decoded as it plays, as NSH's Sound and AudioPlayer. Core does the engine's part, so both belong to the engine and the owner of the scope that made them, and the platform plays them where core.Env.CanPlayAudio says it does; elsewhere they fail with Unavailable.
Both are called on the engine's goroutine, as every scope service is; other goroutines reach them through core.Scope.Post. Their callbacks run on the engine's goroutine too, in a later turn, so they may set signals. A closed sound's or player's callbacks never run.
Index ¶
Constants ¶
const ( // NotAllowed: refused by a capability, core.AccessAudio or, for an http(s) source, core.AccessNetwork; or by the web's autoplay policy before a user gesture. NotAllowed = core.AudioNotAllowed // Network: the source could not be fetched. Network = core.AudioNetwork // Decode: a format the platform cannot read, which is an error, never silence. Decode = core.AudioDecode // NotSupported: a source the platform does not play. NotSupported = core.AudioNotSupported // QuotaExceeded: past one of NSH's limits, which hold per engine: a sound of more than 8 MiB encoded or 5 seconds decoded (longer audio is a player's), a 65th sound, or sounds of more than 16 MiB decoded. QuotaExceeded = core.AudioQuotaExceeded Unavailable = core.AudioUnavailable // Failed: the platform failed otherwise, such as a player whose output went away. An output that fails is silence, not an error, for sounds. Failed = core.AudioFailed )
The errors a sound or a player fails with.
const ( // PlayerIdle: nothing asked of it yet. PlayerIdle = core.AudioPlayerIdle // PlayerLoading: loading its source, or waiting for data as it plays. PlayerLoading = core.AudioPlayerLoading // PlayerPlaying: playing. PlayerPlaying = core.AudioPlayerPlaying // PlayerPaused: loaded and not playing, paused by the app or by the system, as for a call. PlayerPaused = core.AudioPlayerPaused // PlayerEnded: played to its end; Play starts it over. PlayerEnded = core.AudioPlayerEnded // PlayerFailed: it failed, and plays nothing until Play or Preload loads it again. PlayerFailed = core.AudioPlayerFailed )
The states of a player.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error = core.AudioError
Error is why a sound or a player failed, named as NSH's codes, which follow the web's MediaError: NotAllowed to Failed. A failure that says more wraps one with the platform's words, which errors.Is and errors.As find. A player's arrives through OnError and Play's callback.
type Player ¶
type Player = core.AudioPlayer
Player plays long audio, as a Video without a picture. It loads nothing until Play or Preload; Pause, Seek (clamped to the duration), SetVolume, SetRate and SetLoop are commands in the batch, and a seek while paused or before the duration is known applies once the platform can seek, Play starting from there. Position, Duration (0 until loaded) and State are what core kept from the platform's events, so reading them asks no platform. Close stops it and releases the platform's player, as the owner that made it does as it goes, so a window or an embedded view that closes stops its audio.
type PlayerOptions ¶
type PlayerOptions = core.AudioPlayerOptions
PlayerOptions are a Player's callbacks, the interval of its progress and its audio session.
type PlayerState ¶
type PlayerState = core.AudioPlayerState
PlayerState is where a player is: PlayerIdle to PlayerFailed.
type Sound ¶
Sound is a short sound decoded into memory once. Play starts a playback within a frame, as a command in the batch of the turn that calls it, so nothing is opened, fetched or decoded then; playbacks overlap, at most 32 at once, past which the platform stops the oldest. Stop stops every playback of its source, Duration is its decoded length and Close frees it, as the owner that loaded it does as it goes.
type Source ¶
type Source = core.AudioSource
Source is what a sound or a player plays, as an image's source: URI, an "asset:" path in the app's resources, a file path or file: URL, a data: URL or an http(s) URL; or Data, the bytes of a file, such as one embedded with go:embed, named by the format their first bytes say. The platform resolves it as it resolves an image's source and decodes it with its own decoders: ship WAV, AAC (.m4a) or MP3.
type Voice ¶
type Voice = core.SoundVoice
Voice is how a playback of a Sound plays: Volume from 0 to 1 and Rate from 0.5 to 2, with 0 as 1 for both and other values clamped.