How to assign audio channels to a table?

How can i assign audio channels to this tables?

what i did is sounds[“hello”] = audio.loadSound(“sounds/hello.mp3,” {channel =1}) 

is there another way? didnt work when i did audio.stop(1)

local sounds = {} sounds["hello"] = audio.loadSound("sounds/hello.mp3") sounds["hi"] = audio.loadSound("sounds/hi.mp3") sounds["wrong"] = audio.loadSound("sounds/wrong.mp3") sounds["congrats"] = audio.loadSound("sounds/congrats.mp3")

I see the problem, audio.stop() does not take any handles from audio.loadSound(). You would have to play the music as soon as it is declared. Or you would not be able to use audio.stop(). 

https://docs.coronalabs.com/api/library/audio/stop.html

Try looking at this project, it was a Udemy course, the game would be broken, but the code left is pretty helpful. The project uses .loadStream(), but he finds away to start and stop the music. Look in main.lua, scene_game, scene_menu, and scene_upgrades. 

P.S. I won’t be able to upload the whole .zip file so I am only uploading the four files. 

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

I see the problem, audio.stop() does not take any handles from audio.loadSound(). You would have to play the music as soon as it is declared. Or you would not be able to use audio.stop(). 

https://docs.coronalabs.com/api/library/audio/stop.html

Try looking at this project, it was a Udemy course, the game would be broken, but the code left is pretty helpful. The project uses .loadStream(), but he finds away to start and stop the music. Look in main.lua, scene_game, scene_menu, and scene_upgrades. 

P.S. I won’t be able to upload the whole .zip file so I am only uploading the four files. 

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