Crazy Audio Problem

I hate 2 problems…

I’m using Build: 2012.722

  1. I have a sound stream playing a song for my background music in my menus. This plays across multiple screens. This sound is created using an external module. When I use the audio.stop(); method on any other sound clip playing in the exitScene function it stops all sounds, even the background music, even though I expressly declare the reference audio for which I am trying to stop… What’s up with that?

  2. Why does Corona crash EVERY TIME I dispose of an audio item without first stopping it? Why can’t it just show a warning? I never used to have this problem but I guess something has changed. No big deal but it shouldn’t crash Corona.

[import]uid: 63800 topic_id: 20647 reply_id: 320647[/import]

I’ve had the same thing lately, on builds 591 and daily builds.

I have music playing on channel 1, and on pressing a button play a sound effect on channel 2 and stop the music on channel 1.

However audio.stop(music) just stops all audio. [import]uid: 93133 topic_id: 20647 reply_id: 81036[/import]

You must not be using the audio when you dispose it. Yes it will crash. It is an implementation detail for now. The reasons are technical, but the simple explanation is that it was the best trade-off to allow users to manually control the memory management of the audio files (which may be large) and not having to hope that the garbage collector will kick in soon enough. We plan to improve this, but the implementation is tricky to get right. It’s one of those things that must be designed and implemented correctly the first time or you users will get random crashing that is completely out of your control or horrendous memory leaks.
The parameter to audio.stop() is the channel to stop, not the audio handle.

audio.stop(1) means stop channel 1

audio.stop(0) and audio.stop() means stop all channels
audio.stop(nil) is interpreted as the above. Chances are your ‘music’ variable is nil if if it is stopping all audio.
We have discussed changing audio.stop(nil) into a no-op or error, but it is low on our priority list.
[import]uid: 7563 topic_id: 20647 reply_id: 81088[/import]

I appreciate your post and your honesty ewing… I found a way around it for now. Instead of putting the dispose code in the scene’s exit function, I put it in the scenes dispose function. By that time the sounds have stopped… I’m glad that you are giving us more control of the memory. If you ask anyone on the IRC memory management is something I annoy a lot of people about. One issue I have with this implementation is that I have so many random sounds being played and deployed all at random times, it would be a nightmare to keep track of every sound and stop it before it is disposed without a audio.getChannel(referencevar); function. Perhaps I am doing it wrong but this seems to me like a lot of hassle even though it is a blessing at the same time. [import]uid: 63800 topic_id: 20647 reply_id: 81127[/import]