The audio module provides functionalities for initializing an audio context and creating audio players for playing MP3 files.
Initializes the audio context with the specified options.
Creates an audio player for playing MP3 audio data.
data
: Byte array containing MP3 audio data.
Suspends the audio context.
Resumes the audio context.
Returns information about the audio decoder.
length()
: Returns the length of the audio in milliseconds.sample_rate()
: Returns the sample rate of the audio.seek(position)
: Seeks to the specified position in the audio.
Plays the audio.
Pauses the audio playback.
Checks if the audio is currently playing.
Closes the audio player.
Returns any error encountered during audio playback.
Resets the audio player.
Returns the size of the audio buffer.
Sets the size of the audio buffer.
size
: Size of the audio buffer in bytes.
Sets the volume level of the audio player.
volume
: Volume level (0.0 to 1.0).
Returns the current volume level of the audio player.
Seeks to the specified position in the audio.
position
: Position to seek to in milliseconds.
import "audio"
// Initialize the audio context
audio.init()
// Embed the audio data
var mp3_data = embed("myaudio.mp3")
// Create an audio player
var player = audio.player(mp3_data)
// Play the audio
player.play()
for player.is_playing() {}
println("Played!")