iOS: Some millisecond break, when playing audio

93 views
Skip to first unread message

Horst

unread,
Dec 1, 2011, 7:54:29 AM12/1/11
to phonegap
Hi,

i make a game with phonegap. But i have a little problem with sound.
Every time, when i play a sample, i get a little interrupt. Only some
milliseconds, but while playing the game this is very annoying. In the
game coins can be collected, every time the player gets one, i play a
"pling". And the game freezes for some ms.

I have tried to use wav instead of mp3. No change.
I have tried to remove callback functions and use only
coin = new Media('sfx/coin.wav');
and
coin.play();
But nothing helps. I havent tested lately, but i think on android i
hadn't this problem. I use PhoneGap 1.1.0 at moment. Tested on iPad2
and iPod Touch with iOS 4 and 5.

Has anyone an idea, how i can play ingame audio?

best regards
Horst

Anil Kumar

unread,
Dec 1, 2011, 8:15:13 AM12/1/11
to phon...@googlegroups.com
It is due to loading your sound in memory and cpu becomes/halt for ms.
You can do preloading all sounds and then play any of them would not come this issue
you may try

 introSoundPlayer = new Media("raw/intro.mp3",function (){ Alert("Sound Loaded"); 
    // here can initialize your app and other components
},
    function (){ Alert("Sound Loading Error"); }
);
introSoundPlayer.play();

--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Horst

unread,
Dec 1, 2011, 9:27:59 AM12/1/11
to phonegap
Hello Anil,

thanks, but i get the halt every time, i play the sound. Not only the
first time. In my example above the coin=new Media... is called in
init routine and the coin.play() every time i play the sound. So i
think it should already be loaded after first play.

best regards
Horst

Giacomo Balli

unread,
Dec 1, 2011, 12:33:57 PM12/1/11
to phonegap
are you sure the first ms of the sound file is not silent?

Horst

unread,
Dec 2, 2011, 9:06:19 AM12/2/11
to phonegap
@Giacomo: The problem is not a delay in playing. It is a short halt of
the complete app. In a normal app this should be an issue. But in a
game its really annoying, when every sound makes a break.

Horst

unread,
Dec 5, 2011, 5:44:17 AM12/5/11
to phonegap
My error. 3 days before my post an issue was already opened:
https://issues.apache.org/jira/browse/CB-59

KyrePh

unread,
Dec 5, 2011, 9:43:01 AM12/5/11
to phonegap
If you're trying to play back sound effects, use the SoundPlug plugin.
Media is more useful for BGM audio than effects if you're trying to
make a game in PhoneGap.

Matteo

unread,
Dec 6, 2011, 3:58:58 AM12/6/11
to phon...@googlegroups.com
try to defer the call to the sound function.
Eg:
setTimeout(function() { playSound(); }, 0);

Or you may also try to force browser repaint querying offsetHeight for the elements being updated.

Horst

unread,
Dec 6, 2011, 4:35:15 AM12/6/11
to phonegap
Hello Matteo,

i have already read your article: http://cubiq.org/build-and-publish-an-html5-game-for-ipad-part-3

But i have submitted my game yesterday to apple. My testers are
satisfied with the performance.

best regards
Horst

Matteo

unread,
Dec 6, 2011, 9:28:49 AM12/6/11
to phon...@googlegroups.com
any sneak preview?

Horst

unread,
Dec 6, 2011, 10:45:52 AM12/6/11
to phonegap
;-)
You can use the Android Version as preview: https://market.android.com/details?id=net.klier.dduck
But i have done much improvements to iOS, because the css animations
are so smooth. Now i port the new features back to the android
version.
Reply all
Reply to author
Forward
0 new messages