When you call audio.loadSound() (or .loadStream() ), you get a handle to the sound object. Think of it as the in-memory version of the sounds.
When you’re ready to play it, you call audio.play( handle ), i.e.
audio.play(sounds["hello"])
Doing so will auto-select a channel, the sound plays and quits when done. However you don’t know what channel it’s playing on. To do that you can:
local helloChannel = audio.play( sounds["hello"] )
That will auto-select a channel and then return you the channel number that you can then do:
audio.stop( helloChannel )
Frequently though, you may want to assign a channel specifically for background music, voice overs etc. You do this by reserving channels so they are not available to the auto-select pool and then tell audio.play to use a specific channel.
-- somewhere in main.lua: -- play background audio on 1, voice overs on 2 audio.reserveChannels( 2 )
then when you’re ready to play a voice over:
audio.play( sounds["hello"], { channel = 2 } )
The last version you specifically say what channel to play on. You could store the return value in a variable, but it’s kinda pointless since you know what channel you decided to play on.
Rob