Event
audio:finish
ClientFired when an audio instance reaches the end of its playback
Signal
"audio:finish"Only playbacks that reach their natural end finish.
- Natural end — fires once the sound has played all the way through, after which
self:is_playingreturnsfalse. - Stopping — calling
self:stopdoes not fire this signal, the playback was interrupted rather than finished. - Looped audio — looped audio never finishes. See
self:set_looped. - Still alive — the audio is still alive when it fires, so you can replay it, chain the next sound or
self:destroyit. - Audio types — fires for both
core.audio_2dandcore.audio_3d.
Arguments
| Type | Name | Description |
|---|---|---|
core.audio_2d | core.audio_3d | audio | Audio instance whose playback has finished |
Examples
local function play_once(path)
local entity = core.audio_2d.create(path)
entity:play()
end
util.event.on("audio:finish", function(audio)
audio:destroy()
end)
play_once("sounds/click.ogg")local playlist = { "music/intro.ogg", "music/main.ogg", "music/outro.ogg" }
local index = 0
local function next_track()
index = index + 1
if not playlist[index] then return end
local entity = core.audio_2d.create(playlist[index])
entity:play()
end
util.event.on("audio:finish", function(audio)
audio:destroy()
next_track()
end)
next_track()