Built-ins
Audio
Sound playback. The other half of this pair is the GUI, which has a page of its own.
Media (Audio)
Play and control audio files (WAV, MP3, FLAC, Vorbis) asynchronously.Requires use permissions { Media }.
use permissions { Media, Time }
// Play audio asynchronously (returns an audio instance id)
let audioId = Media.playSound("sound.mp3")
// Control volume (scale: 0 to 200, representing 0% to 200%)
Media.setVolume(audioId, 150)
// Check if playing
if (Media.isPlaying(audioId)) {
out "Audio is playing!"
}
// Pause, resume or stop
Media.pause(audioId)
Time.sleep(1000)
Media.resume(audioId)
// Stop a specific instance or stop all audio
Media.stop(audioId)
Media.stopAll()Audio operations can throw catchable errors: IOError if the file is missing, or MediaError if the format is invalid or no audio device is found. Permission denial is fatal (sec_media_no_permission).
| Method | Returns | Description |
|---|---|---|
Media.playSound(path) | int | Starts playing a sound file asynchronously → audio id |
Media.stop(id) | null | Stops the specified audio instance |
Media.stopAll() | null | Stops all playing audio instances |
Media.pause(id) | null | Pauses the specified audio instance |
Media.resume(id) | null | Resumes the specified paused audio instance |
Media.setVolume(id, volume) | null | Sets the volume of the audio instance (0 to 200) |
Media.isPlaying(id) | bool | Checks if the specified audio instance is currently playing |
Media.playingCount() | int | Returns the total number of playing audio instances |