Audio cannot play again after repeating touch the object in Corona...

Hi All,

I am not able to hear the sound again after I touched four or five times on the same Object.The following are my code,Please have a look and advise me,Please.

local function paInstance2listener(event)                                                                                                                                                                                                      local pa2Sound = audio.loadStream(PA2AudioPath..soundExt )                                         local pa2SoundChannel = audio.play( pa2Sound, { channel= 2, loops=0}  )                                                                                                                                                                         return true                              end                                   paInstance2:addEventListener( "touch", paInstance2listener )                                                          pa3Sheet = sprite.newSpriteSheet(PA3ImagePath,PAImageWidth , PAImageHeight)                             pa3SpriteSet = sprite.newSpriteSet(pa3Sheet, 1, 1)                             sprite.add(  pa3SpriteSet, refid, 1, 1, 1, 0 )                             paInstance3 = sprite.newSprite( pa3SpriteSet )                             paInstance3.x = displayOffsetX(828,offsetx)                             paInstance3.y = displayOffsetY(155,offsety1,offsety2)                             screenGroup:insert(paInstance3)

Hi All,

I am not able to hear the sound again after I touched four or five times on the same Object.The following are my code,Please have a look and advise me,Please.

local function paInstance2listener(event)                                                                                                                                                                                                      local pa2Sound = audio.loadStream(PA2AudioPath…soundExt )                                         local pa2SoundChannel = audio.play( pa2Sound, { channel= 2, loops=0}  )                                                                                                                                                                         return true                              end                                   paInstance2:addEventListener( “touch”, paInstance2listener )                                                          pa3Sheet = sprite.newSpriteSheet(PA3ImagePath,PAImageWidth , PAImageHeight)                             pa3SpriteSet = sprite.newSpriteSet(pa3Sheet, 1, 1)                             sprite.add(  pa3SpriteSet, refid, 1, 1, 1, 0 )                             paInstance3 = sprite.newSprite( pa3SpriteSet )                             paInstance3.x = displayOffsetX(828,offsetx)                             paInstance3.y = displayOffsetY(155,offsety1,offsety2)                             screenGroup:insert(paInstance3)

Hi Corona Team and Corona Communities,

Please help me.Thanks for your assistance.

Best Regards,

John

Hi John,

I see two issues here:

  1. you have put no “phase” control into your touch listener for the object. So, it’s going to try and play the sound stream many times consecutively, including on the “moved” phase… this means it might be trying to play that stream 10-20 times in a “swipe”, overloading the system or causing other internal issues. You need to limit this to only the “began” or “ended” phase, and build in conditional logic so that if the sound is already playing, the code doesn’t attempt to play it again.

  2. you are using the deprecated “sprite” library. The newer system has been in place for over a year, and you should change to it immediately… no support (here or otherwise) will be given to the old sprite library. Here are some references on the new system:

http://www.coronalabs.com/blog/2013/05/14/sprites-and-image-sheets-for-beginners/

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Best regards,

Brent

Hi Brent,

Your answer is useful to me.Thanks for your assistance…

Best Regards,

John

Hi All,

I am not able to hear the sound again after I touched four or five times on the same Object.The following are my code,Please have a look and advise me,Please.

local function paInstance2listener(event)                                                                                                                                                                                                      local pa2Sound = audio.loadStream(PA2AudioPath…soundExt )                                         local pa2SoundChannel = audio.play( pa2Sound, { channel= 2, loops=0}  )                                                                                                                                                                         return true                              end                                   paInstance2:addEventListener( “touch”, paInstance2listener )                                                          pa3Sheet = sprite.newSpriteSheet(PA3ImagePath,PAImageWidth , PAImageHeight)                             pa3SpriteSet = sprite.newSpriteSet(pa3Sheet, 1, 1)                             sprite.add(  pa3SpriteSet, refid, 1, 1, 1, 0 )                             paInstance3 = sprite.newSprite( pa3SpriteSet )                             paInstance3.x = displayOffsetX(828,offsetx)                             paInstance3.y = displayOffsetY(155,offsety1,offsety2)                             screenGroup:insert(paInstance3)

Hi Corona Team and Corona Communities,

Please help me.Thanks for your assistance.

Best Regards,

John

Hi John,

I see two issues here:

  1. you have put no “phase” control into your touch listener for the object. So, it’s going to try and play the sound stream many times consecutively, including on the “moved” phase… this means it might be trying to play that stream 10-20 times in a “swipe”, overloading the system or causing other internal issues. You need to limit this to only the “began” or “ended” phase, and build in conditional logic so that if the sound is already playing, the code doesn’t attempt to play it again.

  2. you are using the deprecated “sprite” library. The newer system has been in place for over a year, and you should change to it immediately… no support (here or otherwise) will be given to the old sprite library. Here are some references on the new system:

http://www.coronalabs.com/blog/2013/05/14/sprites-and-image-sheets-for-beginners/

http://www.coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

http://docs.coronalabs.com/guide/media/imageSheets/index.html

Best regards,

Brent

Hi Brent,

Your answer is useful to me.Thanks for your assistance…

Best Regards,

John