audio.dispose()

类型 函数
audio.*
返回值
修订 版本 2024.3703
关键词 audio, dispose
另请参阅 audio.loadSound()
audio.loadStream()

概述

释放与句柄关联的音频内存。

注意事项

内存释放后,不得再使用该句柄。尝试释放音频时,该音频不应处于活动状态(播放或暂停)在任何频道上。

语法

audio.dispose( audioHandle )
audioHandle (必填)

audio.loadSound()audio.loadStream() 返回的要释放的句柄。

示例

-- Load a laser sound and a background music stream into memory
local laserSound = audio.loadSound( "laserSound.wav" )
local backgroundMusic = audio.loadStream( "backgroundMusic.m4a" )

-- Play both the sound and the stream
local playLaserSound = audio.play( laserSound )
local playBackgroundMusic = audio.play( backgroundMusic )

-- Stop both the sound and the stream and 'nil' out each reference
audio.stop( playLaserSound )
playLaserSound = nil
audio.stop( playBackgroundMusic )
playBackgroundMusic = nil

-- Dispose the handles from memory and 'nil' out each reference
audio.dispose( laserSound )
audio.dispose( backgroundMusic )
laserSound = nil  --prevents the handle from being used again
backgroundMusic = nil  --prevents the handle from being used again