Audio represents an object that allows to play audio, e.g. mp3 files.
Audio.load(url): Promise(audio)
- load audio file and return promise that will be resolved to Audio object. throws "404" exception if file not found.
audio.progress
, float in range 0.0 ... 1.0 - progress of playingaudio.volume
, float in range 0.0 ... 1.0 - sound volume
audio.play() : Promise
- plays the sound, returns promise that will be resolved at the end of playback;audio.pause()
- pauses playback;audio.resume()
- resumes paused playback;audio.stop()
- stops playback;
This code loads and plays hello phrase:
async function sayHello() {
let audio = await Audio.load(__DIR__ + "/sounds/hello.mp3");
console.log("playing started");
await audio.play();
console.log("playing done");
}