Kamran
Kamran

Reputation: 53

Sound delay on emulator in corona sdk

I'm currently creating a game with corona sdk. While creating game i faced issues in playing audio files. Issue was that, a tennis ball is dropped on ground and audio should be played. But what happen was the audio was delayed a second. On emulator the audio was synchronized but while i ported apk on my galaxy s2, android version 4.2.2 i faced a delay. Below is the code which i used to play audio.

I loaded audio file first as program executed:

local audio = audio.loadSound("hit ball.mp3")

Then somewhere in middle I used collision and on collision I played that audio file:

local function onCollisionSound()
      audio.play(audio)
end

ball:addEventListener("collision", onCollisionSound)

I also tried with media api but it also didnt worked.

Upvotes: 0

Views: 664

Answers (2)

Rob Miracle
Rob Miracle

Reputation: 3063

Generally with Android 4.1 and later, the audio.* API calls shouldn't be lagging. Google fixed the bug in the 4.1 release, but on older versions, it could still be a problem. However, that doesn't mean the device maker hasn't done some things that hurt sound performance. When exact timing is required, we do recommend using media.* API calls.

Also, please make sure your sound clip doesn't have any delays at the beginning.

Upvotes: 0

zakinster
zakinster

Reputation: 10698

This may be an issue with OpenAL. All audio.* methods are based on OpenAL which is not natively supported by the Android NDK (which supports OpenSL ES instead). The solution to make it work is still a bit buggy and may introduced a delay with some Android versions/devices :

(Directly from the Corona SDK documentation of audio.play())

NOTE: A known issue with Android causes sound to be delayed by 1 to 2 seconds when started.

You may try to use the deprecated media.* API instead which doesn't use OpenAL, this may resolve your problem.

Upvotes: 1

Related Questions