Documentation
¶
Overview ¶
Package audio provides constructors and methods for the HTML <audio> element.
The <audio> HTML element embeds sound content in documents. It supports multiple audio sources through the src attribute or nested <source> elements, allowing the browser to select the most suitable format based on codec support. Common uses include background music, sound effects, podcasts, and audio players. The element provides built-in playback controls and supports streaming via MediaStream for real-time audio applications.
Index ¶
- Variables
- func Fallback(fallback string) *element
- func New(nodes ...node.Node) *element
- func PreloadAuto(nodes ...node.Node) *element
- func PreloadMetadata(nodes ...node.Node) *element
- func PreloadNone(nodes ...node.Node) *element
- func Sources(sources ...node.Node) *element
- func Src(src string) *element
- type Element
Constants ¶
This section is empty.
Variables ¶
var ( TagOpen = []byte("<audio") TagClose = []byte("</audio>") AttrAutoplay = []byte(" autoplay") AttrControls = []byte(" controls") AttrLoop = []byte(" loop") AttrMuted = []byte(" muted") AttrSrc = []byte(" src=\"") AttrControlsList = []byte(" controlslist=\"") AttrCrossOrigin = []byte(" crossorigin=\"") AttrDisableRemotePlayback = []byte(" disableremoteplayback") AttrLoading = []byte(" loading=\"") AttrPreload = []byte(" preload=\"") )
Byte constants for HTML rendering.
Functions ¶
func Fallback ¶
func Fallback(fallback string) *element
Fallback creates a new audio element with fallback text content for unsupported browsers. Example: audio.Fallback("Your browser does not support audio.") Renders: <audio>Your browser does not support audio.</audio>
func New ¶
New creates a new audio element without any initial attributes. Example: audio.New() Renders: <audio></audio>
func PreloadAuto ¶
PreloadAuto creates an audio element with preload="auto" (loads entire audio). Example: audio.PreloadAuto() Renders: <audio preload="auto"></audio>
func PreloadMetadata ¶
PreloadMetadata creates an audio element with preload="metadata" (loads only metadata). Example: audio.PreloadMetadata() Renders: <audio preload="metadata"></audio>
func PreloadNone ¶
PreloadNone creates an audio element with preload="none" (no preloading). Example: audio.PreloadNone() Renders: <audio preload="none"></audio>
func Sources ¶
Sources creates a new audio element with multiple <source> child elements. Example: audio.Sources(source.AudioMP3("/music/song.mp3"), source.AudioOgg("/music/song.ogg")) Renders: <audio><source src="/music/song.mp3" type="audio/mpeg" /><source src="/music/song.ogg" type="audio/ogg" /></audio>