Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

audio loadSound and loadStream failing occasionally
Started by stefano.mazzotta Sep 20 2019 07:17 AM

4 replies to this topic
audio loadstream loadsound fail
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

stefano.mazzotta

[GLOBAL: userInfoPane.html]
stefano.mazzotta
  • Observer

  • 6 posts
  • Corona SDK

Hi,

My app has some .wav files (22050 Hz, 1 to 2 MB size)

 

I load these files in the main.lua and I use them in different scenes.

 

Everything looks fine but sometimes I get this warning:

 
WARNING: audio.loadStream() failed to create stream 'sound/effects/button.wav'
 
That's the same with loadSound and loadStream,
tested with Corona simulator and with my android phone.
 
I can say that it occours once in 30 or something like this.
 
Is this a "known" thing?
I've tried this silly workaround, but it goes overflow... and I'm sure I'm going to the programmer hell for this.
 
while handler == nil do
    handler = audio.loadStream( filePath ) --"sound/effects/button.wav"
end
 
Any hint?
Maybe the main.lua is not a good place to load resources?
 
Version: 2019.3508
 
Thanks in advance
 


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,207 posts
  • Enterprise

main.lua is a very common place to load sounds. Depending on the complexity of the apps, some developers will load sound in their own module, but it's usually loaded out of main,lua. 

 

Usually loading problems are file based and would happen all the time. 

 

As far as your resource loading loop, I would add a counter so you don't accidentally create an infinite loop.

local counter = 10
while handler == nil and counter > 0 do
    handler = audio.loadStream( filePath) 
    counter = counter - 1
end

Rob



[TOPIC: post.html]
#3

stefano.mazzotta

[GLOBAL: userInfoPane.html]
stefano.mazzotta
  • Observer

  • 6 posts
  • Corona SDK

main.lua is a very common place to load sounds. Depending on the complexity of the apps, some developers will load sound in their own module, but it's usually loaded out of main,lua. 

 

Usually loading problems are file based and would happen all the time. 

 

As far as your resource loading loop, I would add a counter so you don't accidentally create an infinite loop.

local counter = 10
while handler == nil and counter > 0 do
    handler = audio.loadStream( filePath) 
    counter = counter - 1
end

Rob

 

Hi Rob, thanks a lot for your kind reply.

 

I actually have a separated module, but it gets loaded and used inside the main, so I've simplified the structure to explain the problem.

 

By the way, do you think that a loading loop would be fine?

I think that my overflow is a clear sign that 10, 100 or 1000 tries might fail...

IDK, the loop-thing sounds like a bad practice to me.

 

I'm also disoriented because I've studied the doc, I've seen the tutorials, I've searched the forum, I've searched the web, and nobody mention this issue.

 

"Usually loading problems are file based and would happen all the time. ",

I wish I don't have to surrender to app crashes for this reason. (nor check if loaded after x attempt, then force to exit the app for each resource file...)

 

 

Ste



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,207 posts
  • Enterprise

This is an issue that we've not seen before unless the file was corrupt, which it would fail all the time.

 

The loop seems icky because it is, but if you're going to, rate limit it.

 

Rob



[TOPIC: post.html]
#5

stefano.mazzotta

[GLOBAL: userInfoPane.html]
stefano.mazzotta
  • Observer

  • 6 posts
  • Corona SDK

This is an issue that we've not seen before unless the file was corrupt, which it would fail all the time.

 

The loop seems icky because it is, but if you're going to, rate limit it.

 

Rob

 

 

Summing up, 

the problem deserves no consideration at all,

let's point out an insignificant error in a loop... (a loop I made just for a debug check)

 

If this is all you can close the discussion I guess.

 

thank you very much.




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: audio, loadstream, loadsound, fail