Event

audio:finish

Client

Fired 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_playing returns false.
  • Stopping — calling self:stop does 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:destroy it.
  • Audio types — fires for both core.audio_2d and core.audio_3d.

Arguments

TypeNameDescription
core.audio_2d | core.audio_3daudioAudio instance whose playback has finished

Examples

Clean up a fire and forget sound
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")
Play a playlist one track after another
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()

On this page