Audio error and sound is gone when tap on the same character

Hi all,

I have an iOS book app already approved on the App Store,but there is a problem. The book runs smoothly without any problem whatsoever. Toward to end of the book, however, users tap on one of the characters and the sound fx plays as expected. But when users tap the same character while to audio sound is still playing again, all the sound stop. Now there is no more sound on the book app. It’s just gone. We tried it on our devices, and faced the same issue. One way to bring the audio back is the kill the book app process and restart it (iOS 6 - reboot the device, iOS 7 kill the process.)

I tried the book on the simulator to see what the issue is. The simulator showed this message “audio error can’t play shared streamed sample because it is already in use.” I know that it’s an audio issue, but don’t know how to fix it. Can anyone help?

FYI: I used the latest Corona SDK public build and Kwik.

Thank you,

Golf

Hm, I haven´t seen this error message before. 

Since you seem to be an experienced user I guess you have already checked all common things.

Are you using your own method/function to handle the audio? Based on the error message I would suggest to check if you are playing one sound file multiple times in the same moment.

Hi CineTek,

Thank you for your reply. I’m not a coder, but I’ve been playing around Corona SDK and Kwik for a while. I have not used my own function at all. The codes were generated by Kwik, but I know a little bit of lua programming. As you pointed out, I’m in deed playing one sound file for more than one characters in the book app. The problem is that even I use the audio.loadSound for the audio file that I wanted to play multiple times, it still gives this error.

My situation is this: on one of the pages, I have three characters. two characters shared one audio file. When I tap on one of them, the audio plays without problem. Once the audio finished, I tap another character that shares the same audio file. No problem. But when I tap another one while the audio file hasn’t finished playing for the other character, the error occurs. Once it occurred, the audio of the whole app stops! This really give me a head ache as I don’t know what is going on.

Ah okay :slight_smile:

Are you specifically saying which channel should play the audio? Is it the same channel for the two characters? 

May you post some code samples of how you are playing the audio? Just post the important part(s) or send the file with the error to me, I can take a look at it. 

Max / CineTek

Thank you, Max!

Here are the codes:

-- Audio callings local page33 = audio.loadStream( audioDir.."page33.mp3") local kidscheering = audio.loadSound( audioDir.."kidscheering.mp3") local okwillcallyousp = audio.loadSound( audioDir.."okwillcallyouspot.mp3")

and the button functions:

-- Button functions function but\_boy(self) wBounce\_boy() audio.setVolume(1, {channel=3} ) audio.play( kidscheering, {channel=3, loops = 0, fadein=0 } ) end function but\_girl(self) wBounce\_g() audio.setVolume(1, {channel=3} ) audio.play( kidscheering, {channel=3, loops = 0, fadein=0 } ) end function but\_mom(self) audio.setVolume(1, {channel=2} ) audio.play( okwillcallyousp, {channel=2, loops = 0, fadein=0 } ) end 

Lastly, the dispose:

dispose = function(event) cancelAllTweens() cancelAllTimers(); cancelAllTransitions() audio.stop(1); audio.dispose(page33); page33 = nil audio.stop(3); audio.dispose(kidscheering); kidscheering = nil audio.stop(2); audio.dispose(okwillcallyousp); okwillcallyousp = nil page33bg:removeEventListener( Gesture.SWIPE\_EVENT, pageSwap ); Gesture.deactivate(page33bg) end 

I have noticed that the shared audio file for the two characters use the same channel (channel 3). Is this the issue?

Thanks again for taking your time to help me out!

Okay, I am not familiar with Kwik but it seems to use a lot of custom code - which is fine because it helps game designers like you to keep their coding as simple as possible :) 

If your game does not use the other channels then I would just change the channel to 4 or something else. 

So your code will look like this:

function but\_girl(self) wBounce\_g() audio.setVolume(1, {channel=4} ) audio.play( kidscheering, {channel=4, loops = 0, fadein=0 } ) end

Thanks, Max. That’s what I thought so too. So I should have this line in the dispose function as well?

audio.stop(4); audio.dispose(kidscheering); kidscheering = nil

Just want to be sure that I close all the channels.

I will try this today and will get back with the result. Thanks again for helping me on this :slight_smile:

Aughh… Still the same error. Don’t know what went wrong :frowning:

This only happens if you touch both characters and they try to play the same sound? Is there any other scene/page where you could replicate this situation?

What else happens if you tap on the characters? Is the dispose function called at the same time?

It happens even I tap the same character twice while the audio isn’t finished playing. On other pages I have the same settings like this, it gave the same error, but it didn’t stop the audio of a whole app. This error only occurs toward the end of the app.

On the other hand, if I tap a character, wait until the audio finished playing, then tap the same character again. No problem. It seems like there is a problem playing the audio simultaneously.

ok, this is a little bit strange that even after you have changed the channel the error still occurs.

I would suggest to change the code to the following and add a little check at the beginning of your functions:

function but\_girl(self) wBounce\_g() -- check if channel is active/used at the moment if audio.isChannelActive ( 4 ) then audio.stop(4) end audio.setVolume(1, {channel=4} ) audio.play( kidscheering, {channel=4, loops = 0, fadein=0 } ) end 

If this only happens at the very end of your game then there might be a problem with the audio files not being disposed/deleted correctly at the end of each page… 

Btw, what is happening when you call “wBounce_g()” or “wBounce_boy()”?

May you post at least one of these function, too?

Max

The wBounce_g and wBounce_boy are the animations that when I tap either one of them, it will bounce and audio file plays. the codes are:

--Animations -- Wait request for wBounce\_boy local wBounce\_boy = function(event) if gtStash.gt\_wBounce\_boy then gtStash.gt\_wBounce\_boy:toBeginning() end local onEnd\_wBounce\_boy\_781 = function() boy33.x = boy33.oriX; boy33.y = boy33.oriY; boy33.xScale = 1;boy33.yScale = 1; boy33.alpha = boy33.oldAlpha; boy33.rotation = 0; boy33.isVisible = true; end --ends reStart for wBounce\_boy gtStash.gt\_wBounce\_boy = gtween.new( boy33, 0.1, { y=492}, {ease = gtween.easing.linear, repeatCount = 10, reflect = true, delay=0.1, onComplete=onEnd\_wBounce\_boy\_781}) end --closes function wBounce\_boy -- Wait request for wBounce\_g local wBounce\_g = function(event) if gtStash.gt\_wBounce\_g then gtStash.gt\_wBounce\_g:toBeginning() end local onEnd\_wBounce\_g\_891 = function() girl33.x = girl33.oriX; girl33.y = girl33.oriY; girl33.xScale = 1;girl33.yScale = 1; girl33.alpha = girl33.oldAlpha; girl33.rotation = 0; girl33.isVisible = true; end --ends reStart for wBounce\_g gtStash.gt\_wBounce\_g = gtween.new( girl33, 0.1, { y=480}, {ease = gtween.easing.linear, repeatCount = 10, reflect = true, delay=0.1, onComplete=onEnd\_wBounce\_g\_891}) end --closes function wBounce\_g

I will try the codes you suggested now.

Okay, it seems like there does not happen anything important regarding the issue. 

Hey Max,

Your little codes helps! The error did not occur when I tap on the girl twice in a row. I think checking if that channel is active, then put the audio to a stop is exactly what I need to do! Guess I have to insert your codes on every page that has the same situation like this.

Yeah, you need to put this in each of your audio sections in order to avoid this error, I am glad it helped :slight_smile:

Definitely! Thank you so much, Max! You’re my life saver :slight_smile: I will try inserting these codes on every page that has this kind of audio section, and will keep you posted.

Thanks again Max.

  • Will and Golf

Sometimes it is easier to write a little module which keeps track of your audio files and stuff so you do not have to worry about this at all in your main code :wink:

I am going to write a tutorial about modules very soon, you can take a look at it if you are interested in making your life a little bit easier :slight_smile:

Best,

Max

Also please mark my answer above as solved so anyone else having the same issue finds the solution :slight_smile:

Yep, I will. Thanks!

Well, you should mark the correct post as “best answer” and set the thread to “solved”  :lol: