Problem loading audio

Hi,
I have a problem with Corona sometimes not loading my audio.

local audioSpeelt=0  
local function Boom(event)  
 if event.phase == "began" then  
 if audioSpeelt==1 then  
 --print ("audio is playing")  
 else  
 if audioCounterTable.boomCounter==7 then  
 audioCounterTable.boomCounter=1  
 end  
 local function disposeBoom()  
 --print("dispose boomAudio")  
 audio.stop(1)  
 audio.dispose(boomAudio)  
 boomAudio=nil  
 audioSpeelt=0  
  
 end  
 local boomAudio=music(boomAudioTable[audioCounterTable.boomCounter])  
 if boomAudio ~= nil then  
 audio.play(boomAudio,{channel=1,onComplete=disposeBoom})  
 audioSpeelt=1  
 end  
 audioCounterTable.boomCounter=audioCounterTable.boomCounter+1  
 end  
 end  
 return true  
end  

This all works, and when I run and check the memory the memory does not grow.
But when I run this function like 80 times, during a stress test. it gives me the error:
WARNING: Failed to create audio sound(audio/lente/1/boom2.aac)
This happens after around 80 times of tapping the button.

I have several of these functions in my code all. If you tap one 80 times it happens it you tap a combination of them around 80 times it happens.
It cannot load the audiofile for a certain reason. No idea why. In the console when I run it from the ipad itself I get no error message at all. With Corona I at least get that warning. I am all out of ideas at the moment.
[import]uid: 100901 topic_id: 35346 reply_id: 335346[/import]

Ok,
I Changed local music=audio.loadStream to local music=audio.loadSound and the problem seems to be gone.
All the audio I use is less than the 30 second limit. [import]uid: 100901 topic_id: 35346 reply_id: 140469[/import]

Why dispose it ? And then reload it ?

Seems like it’s a short sound effects (sfx) file, yes ?

Did you try just leaving it ?
I’ve used 6 short sfx audio files, 2-10 secs, and the memory does not grow.
Memory is a little bigger to start because it loads all the files.
But memory doesn’t grow and sounds play with no lag or errors.

If the files are longer, ex. narration, or if you use storyboard and use different sfx files for different scenes then it makes more sense to dispose. [import]uid: 186251 topic_id: 35346 reply_id: 140471[/import]

It’s very likely you were disposing the sound and trying to load the stream again before it could clean up after itself. audio.loadStream() is for longer tracks that you don’t want to have your game pause while they are loading. audio.loadSound() completely loads the sound and closes the file before it starts playing and is designed for short clips.

And I have to agree with @sam3dus, if you are going to be using the same sound over and over, load it once and then just play it over and over, no need to dispose it if your going to be using it a lot. It’s not going to alter your memory footprint and will be much more efficient than the constant churning of file IO and memory to load, play, dispose, garbage collect etc.
[import]uid: 199310 topic_id: 35346 reply_id: 140473[/import]

I did try leaving it, but that was in another app and the app just crashed after a while. When I used the dispose method it stopped crashing. Also In apps even before that one I made my apps in Obj-C and I had to remove all my audio from memory there myself, so It is kind of a habit from that period.

Well, I am using storyboard and there are around 15-20 touchable animations on screen that all have around 3-7 sentences attached. The sentences all are different lengths, but all less than 30 sec.

There are around 12 different storyboards. With a lof animations/images and over 500 sentences in total in the app.

But the loadSound seems to have fixed it.
[import]uid: 100901 topic_id: 35346 reply_id: 140475[/import]

When I’ve had a similar app, I loaded the voice overs for a given scene in the scene’s createScene() function and disposed them in the destroyScene() phase. You have to be careful to make sure if your using onComplete() that those sounds are stopped before exiting the scene or it will try to execute the call back after the scene is gone and that will cause a crash.

But for interface sounds, like beeps, clicks, Hurray!'s and such, I load them in main.lua and keep them around the whole time. [import]uid: 199310 topic_id: 35346 reply_id: 140476[/import]

Yeah I have a if audioPlayingTrue function that skips the onComplete part if audio is playing. Learned in my other app I build in Corona.
[import]uid: 100901 topic_id: 35346 reply_id: 140489[/import]

Ok,
I Changed local music=audio.loadStream to local music=audio.loadSound and the problem seems to be gone.
All the audio I use is less than the 30 second limit. [import]uid: 100901 topic_id: 35346 reply_id: 140469[/import]

Why dispose it ? And then reload it ?

Seems like it’s a short sound effects (sfx) file, yes ?

Did you try just leaving it ?
I’ve used 6 short sfx audio files, 2-10 secs, and the memory does not grow.
Memory is a little bigger to start because it loads all the files.
But memory doesn’t grow and sounds play with no lag or errors.

If the files are longer, ex. narration, or if you use storyboard and use different sfx files for different scenes then it makes more sense to dispose. [import]uid: 186251 topic_id: 35346 reply_id: 140471[/import]

It’s very likely you were disposing the sound and trying to load the stream again before it could clean up after itself. audio.loadStream() is for longer tracks that you don’t want to have your game pause while they are loading. audio.loadSound() completely loads the sound and closes the file before it starts playing and is designed for short clips.

And I have to agree with @sam3dus, if you are going to be using the same sound over and over, load it once and then just play it over and over, no need to dispose it if your going to be using it a lot. It’s not going to alter your memory footprint and will be much more efficient than the constant churning of file IO and memory to load, play, dispose, garbage collect etc.
[import]uid: 199310 topic_id: 35346 reply_id: 140473[/import]

I did try leaving it, but that was in another app and the app just crashed after a while. When I used the dispose method it stopped crashing. Also In apps even before that one I made my apps in Obj-C and I had to remove all my audio from memory there myself, so It is kind of a habit from that period.

Well, I am using storyboard and there are around 15-20 touchable animations on screen that all have around 3-7 sentences attached. The sentences all are different lengths, but all less than 30 sec.

There are around 12 different storyboards. With a lof animations/images and over 500 sentences in total in the app.

But the loadSound seems to have fixed it.
[import]uid: 100901 topic_id: 35346 reply_id: 140475[/import]

When I’ve had a similar app, I loaded the voice overs for a given scene in the scene’s createScene() function and disposed them in the destroyScene() phase. You have to be careful to make sure if your using onComplete() that those sounds are stopped before exiting the scene or it will try to execute the call back after the scene is gone and that will cause a crash.

But for interface sounds, like beeps, clicks, Hurray!'s and such, I load them in main.lua and keep them around the whole time. [import]uid: 199310 topic_id: 35346 reply_id: 140476[/import]

Yeah I have a if audioPlayingTrue function that skips the onComplete part if audio is playing. Learned in my other app I build in Corona.
[import]uid: 100901 topic_id: 35346 reply_id: 140489[/import]

I have the same problem with audio.loadStream(). I just dispose audios when move from one page to another page using director, but most of the time the next page audios which are different files will failed to load.

Is there a safe way to dispose the audio or any tricks to handle this properly?

Thank you

I have the same problem with audio.loadStream(). I just dispose audios when move from one page to another page using director, but most of the time the next page audios which are different files will failed to load.

Is there a safe way to dispose the audio or any tricks to handle this properly?

Thank you