Audia
An HTML5 library that implements (and extends) the Audio object using the Web Audio API.
Install / Use
/learn @richtaur/AudiaREADME
Audia
Audia reimplements and extends the HTML5 Audio object using the Web Audio API.
Benefits
-
Future-proof
-
Fails gracefully
-
Consistent API with HTML5 Audio which you probably already know
-
Fixes bugs in some Audio implementations
-
Implementation of
Audiois weak across the board. Even in the best browers -
this is future-proof. you get Audio which is the best you can get for now, then later down the road you get web audio api
-
and seriously, you'll need a wrapper for WAI anyway
A complete write-up on this project can be found on the Lost Decade Games blog.
API Documentation
Everything is identical to the HTML5 Audio spec. Anything not working as it should? File an issue! :)
In fact in many cases Audia is BETTER than the browser's native Audio implementation, even if it doesn't also support Web Audio API.
Global Audia object
TODO: Provide thin wrappers around the base code.
-
Audia (global object)
-
version:
StringThe version of Audia being run. (Example:"0.1.0") -
canPlayType: you can pass in mp3, ogg (helpers since normally it wants audio/ogg audio/mp3)
Gimme some sugar baby
Audia also has the below API. If any of the below functionality is not supported by the client, Audia will fail silently.
Audia instances
Example: var sound = new Audia();
Properties
Each Audia instance has the following properties:
- currentTime:
NumberThe playback point of the sound (in seconds). - duration:
NumberThe length of the current sound buffer in seconds. (Read-only) - loop:
BooleanIf set to true, the audio will play again when it reaches the end of playback. (default:false) - muted:
BooleanTrue if the sound has been muted, otherwise false. - paused:
BooleanTrue if the sound is paused, false if it's playing. (Read-only) - src:
StringThe URL of a sound file to load. - volume:
NumberThe volume of the playback where0is muted and1is normal volume. (arbitrary maximum =10), (default:1) - onended:
FunctionGets called when playback reaches the end of the buffer. - onload:
FunctionGets called when a sound file (requested by settingsrc) is done loading.
* The italicized properties are only available if the client supports Web Audio API (otherwise they fail silently).
Methods
- play: Begins playback of the sound buffer. Arguments:
currentTime(optional) Sets thecurrentTimeproperty before playing. - pause: Pauses sound playback (retaining
currentTime). - stop: Stops sound playback (resetting
currentTimeto0). // TODO: it's actually .muted (Boolean) - mute: Silences playback of the sound buffer.
- unmute: Restores audible playback of the sound buffer.
Examples
Create a sound object and play an mp3
var sound = new Audia();
sound.src = "onslaught.mp3";
sound.play();
Create sounds with some sugar
var backgroundMusic = new Audia("joshua_morse.mp3");
var battleMusic = new Audia({
src: "a_recurring_conflict.mp3",
loop: true
});
Move the playback pointer to 30 seconds into the sound buffer
sound.currentTime = 30;
Calculate the percentage of song that's played
var percentage = (sound.currentTime / sound.duration) * 100;
Stop it if it's playing
if (sound.playing) {
sound.stop();
}
Play it when it loads
sound.onload = function () {
doSomething();
};
sound.src = "new_song.mp3";
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
