Transition and sound to play together? help

Hello again,

I have a problem where a transition and a sound should play together, but the function should proceed after the sound has finished playing.

The fact is on the Corona SDK everything works, on the iPhone I get the sound to play but not the animation, or have everything completely froze.

I tried to tweak it in dozen of ways with coroutines and delays and stuff, still working on Corona and not on the iPhone. Any help?

 -- correct answer + transition function screen:correctAnswer() function transitionFinished() flashcard:setTextColor( 255, 255, 255 ) -- white screen:setCard() screen:resume() end function popFinished() flashcard.tween = transition.to(flashcard, {xScale = 1, yScale = 1, time = 200}) --, onComplete=transitionFinished end screen:wait() -- play sound if sound then if voice then local voiceSound = audio.loadSound( card.name .. ".aiff") local time = audio.getDuration( voiceSound ) co = coroutine.create(function () timer.performWithDelay( time, transitionFinished ) end) coroutine.resume(co) local audioChannel = audio.play( audio.loadSound( voiceSound) ) --, { onComplete=transitionFinished } else local audioChannel = audio.play( coinSound, { onComplete=transitionFinished } ) end end if card.guesses \> 0 then card.guesses = card.guesses - 1 end screen:update() screen:saveIt() flashcard:setTextColor( 0, 255, 0 ) -- green flashcard.tween = transition.to(flashcard, {xScale = 1.2, yScale = 1.2, time = 100, onComplete=popFinished}) end

I’m not sure if you’re hitting this line…

[lua]

local voiceSound = audio.loadSound( card.name … “.aiff”)

[/lua]

or this one…

[lua]

local audioChannel = audio.play( audio.loadSound( voiceSound) )

[/lua]

…but both of those will probably cause a resource load in the middle of your transition.

I actually changed it so many times that I probably made a mess now…

this is how was originally

if sound then if voice then local audioChannel = audio.play( audio.loadSound( card.name .. ".aiff"), { onComplete=transitionFinished }) else local audioChannel = audio.play( coinSound, { onComplete=transitionFinished } ) end end

but I feel that is it goes onComplete and skip the rest (at least on the iphone).

By the way, even like that the sound was fine, but no animation.

Yeah, I think the loading sound will take priority of the processor at that time, I generally put my sound needs in a separate module and pre-load where possible.  First off, .mp3 might be a smaller footprint memory wise, and are you able to determine which cards are available in advance?  You could possibly pre-load just specific audio clips.

I made yet another build and revert it as it was before, now works  <_< I spent the last 4 hours on that…

Ouch.  Well at least it works, right?  :slight_smile:

I’m not sure if you’re hitting this line…

[lua]

local voiceSound = audio.loadSound( card.name … “.aiff”)

[/lua]

or this one…

[lua]

local audioChannel = audio.play( audio.loadSound( voiceSound) )

[/lua]

…but both of those will probably cause a resource load in the middle of your transition.

I actually changed it so many times that I probably made a mess now…

this is how was originally

if sound then if voice then local audioChannel = audio.play( audio.loadSound( card.name .. ".aiff"), { onComplete=transitionFinished }) else local audioChannel = audio.play( coinSound, { onComplete=transitionFinished } ) end end

but I feel that is it goes onComplete and skip the rest (at least on the iphone).

By the way, even like that the sound was fine, but no animation.

Yeah, I think the loading sound will take priority of the processor at that time, I generally put my sound needs in a separate module and pre-load where possible.  First off, .mp3 might be a smaller footprint memory wise, and are you able to determine which cards are available in advance?  You could possibly pre-load just specific audio clips.

I made yet another build and revert it as it was before, now works  <_< I spent the last 4 hours on that…

Ouch.  Well at least it works, right?  :slight_smile: