natiny.clip.reload

Lua
natiny.clip.reload(clip, ogg)

Replaces the samples inside an existing clip. The handle does not change.

Parameters

Name Type Description
clip number Live clip handle from natiny.clip.load
ogg number Resource handle containing Ogg Vorbis data

Example

Lua
local clip   = natiny.clip.load(resource)
local source = natiny.audio.create_source(clip)
local replacement = natiny.resource.load("sounds/rain.ogg")

-- every source on this clip picks up the new sound
natiny.clip.reload(clip, replacement)
natiny.resource.destroy(replacement)

Notes

  • Active sources restart from the beginning of the new sound. Paused and stopped sources remain paused and stopped.
  • Raises an error if clip is not live or ogg cannot be decoded as Ogg Vorbis. A failure leaves the old samples unchanged.
  • The resource bytes are consumed during the call and may be destroyed after a successful reload.
  • The old samples are released only once the mixer is known to have stopped reading them, so a reload is safe while sound is playing.