Sound problems on iPhone

112 views
Skip to first unread message

Jerryatrix

unread,
Dec 18, 2010, 10:18:18 AM12/18/10
to phonegap
I have a problem when playing sounds using the media class.
I preload my sounds at appropriate points during the lifetime of the
app, but regardless of this, after calling play(), there is a delay of
300 - 500 milliseconds.

That means that after a user pushes a button the sound plays noticably
later. In addition to this, during the delay period other aspects of
the application are affected. Animations freeze and objects that I
create with script don't get created properly.

I have been able to work around most of these problems, but the delay
itself is not so easy to deal with. Looking on this forum other people
seem to be talking about this problem.
A proposed solution was to use non compressed audio files (wav or aiff
files). Unfortunately using a wav file doesn't make it any better.

In this post someone mentions that a previous version of phonegap did
not do this.
( http://groups.google.com/group/phonegap/browse_thread/thread/d0e20cff2e024935/f1a39d710b68ef3e?lnk=gst&q=aiff#f1a39d710b68ef3e
)

Does anyone else have these problems? If the older phonegap version
didn't have these problems, is it possible to lift the old audio
processing code and put in the new version? Or is that science
fiction?

help..?

Nick McCloud

unread,
Dec 19, 2010, 5:24:18 PM12/19/10
to phonegap
What platform???

Have you tried using the onTouch event rather than leaving it to the
delay that comes with the standard click event?

On Dec 18, 3:18 pm, Jerryatrix <bitwalkerja...@gmail.com> wrote:
> I have a problem when playing sounds using the media class.
> I preload my sounds at appropriate points during the lifetime of the
> app, but regardless of this, after calling play(), there is a delay of
> 300 - 500 milliseconds.
>
> That means that after a user pushes a button the sound plays noticably
> later. In addition to this, during the delay period other aspects of
> the application are affected. Animations freeze and objects that I
> create with script don't get created properly.
>
> I have been able to work around most of these problems, but the delay
> itself is not so easy to deal with. Looking on this forum other people
> seem to be talking about this problem.
> A proposed solution was to use non compressed audio files (wav or aiff
> files). Unfortunately using a wav file doesn't make it any better.
>
> In this post someone mentions that a previous version of phonegap did
> not do this.
> (http://groups.google.com/group/phonegap/browse_thread/thread/d0e20cff...

Jaredx2

unread,
Dec 19, 2010, 10:56:35 PM12/19/10
to phonegap

Jerryatrix

unread,
Dec 20, 2010, 2:31:37 AM12/20/10
to phonegap
Thanks Jared, that looks really promising. I will check it out and
report back.
It looks like there is not much documentation for the plugin, so do
you think you could explain what I should be looking for when I
"pay attention to how it works." Are there some gotchas?

Justin

On Dec 20, 12:56 pm, Jaredx2 <jare...@gmail.com> wrote:
> On iPhone you can use the plugin:https://github.com/bni/phonegap-plugins/tree/master/SoundPlug/
>
> Makes the gap go away but you need to pay attention to how it works.
>
> Jared
>
> http://groups.google.com/group/phonegap/browse_thread/thread/d0e20cff...
>
> Lemming Labshttp://www.lemminglabs.com

Jerryatrix

unread,
Dec 20, 2010, 2:36:13 AM12/20/10
to phonegap
Thanks Nick

Sorry I mentioned the platform in the title but not the body of the
post.

I am programming for the iPhone. Actually I am using OpenLaszlo to
generate the javascript, and that unfortunately adds another layer of
uncertainty to the problem.
The objects I create in script are OpenLaszlo objects and the
animations OpenLaszlo animations.

I have tried the onmousedown event but will try using the ontouch
event and see if it makes a difference.

Thanks

Björn Nilsson

unread,
Dec 20, 2010, 4:02:53 AM12/20/10
to phonegap
That plugin I did is just a hack I made to get around exactly the
problem described in the start of this thread. It is some code from an
ancient version of PhoneGap that I hacked up into a plugin.

Also I think this is not the proper way to play sounds on iOS. I think
there was good reasons the code was completly changed after 0.8.0
version.

That being said I use this code in my game Orbium and it works alright
for that use case (arcade game). No complaints from Apple or users of
the app.

There is also this bug report that has a minimal test case that showns
the bug in the PhoneGap Media function:
http://phonegap.lighthouseapp.com/projects/20116/tickets/60-regression-in-mediasoundm-since-080

On Dec 20, 4:56 am, Jaredx2 <jare...@gmail.com> wrote:
> On iPhone you can use the plugin:https://github.com/bni/phonegap-plugins/tree/master/SoundPlug/
>
> Makes the gap go away but you need to pay attention to how it works.
>
> Jared
>
> http://groups.google.com/group/phonegap/browse_thread/thread/d0e20cff...
>
> Lemming Labshttp://www.lemminglabs.com

Jerryatrix

unread,
Dec 20, 2010, 7:25:01 PM12/20/10
to phonegap
I added the SoundPlug plugin and it is much faster. Problem largely
solved, I still have some animation jerkiness.
I will play around a bit, but probably will use the Media object where
possible (background audio ) and SoundPlug for sounds generated as a
result of user actions.

I also checked out Orbium. I liked that. Good work Björn.



On Dec 20, 6:02 pm, Björn Nilsson <bni....@gmail.com> wrote:
> That plugin I did is just a hack I made to get around exactly the
> problem described in the start of this thread. It is some code from an
> ancient version of PhoneGap that I hacked up into a plugin.
>
> Also I think this is not the proper way to play sounds on iOS. I think
> there was good reasons the code was completly changed after 0.8.0
> version.
>
> That being said I use this code in my game Orbium and it works alright
> for that use case (arcade game). No complaints from Apple or users of
> the app.
>
> There is also this bug report that has a minimal test case that showns
> the bug in the PhoneGap Media function:http://phonegap.lighthouseapp.com/projects/20116/tickets/60-regressio...

Ade Goddard

unread,
Dec 20, 2010, 10:23:42 PM12/20/10
to Jerryatrix, phonegap
Just checking u are not using mp3 etc as they r slower due to
compression. Wav / caff better for s effects

Sent from my iPhone

> --
> 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

Jerryatrix

unread,
Dec 21, 2010, 9:04:22 AM12/21/10
to phonegap
Yes I am using wav files, unfortunately that has not solved the
problem.
But SoundPlug is looking very useful.



On Dec 21, 12:23 pm, Ade Goddard <ade.godd...@gmail.com> wrote:
> Just checking u are not using mp3 etc as they r slower due to
> compression. Wav / caff better for s effects
>
> Sent from my iPhone
>

dman

unread,
Dec 22, 2010, 9:09:58 AM12/22/10
to phonegap
I had the same problem when I did my iPhone game, Vowel It Up! I used
the same API as well. AudioSystemServicesPlay sound or something like
that.

I found that the overall mechanism going from phonegap -> ObjC can be
slow too, especially if trying to play a lot of things. I don't think
it's the fault of the phonegap code, as the Webkit API doesn't provide
a clean mechanism to call from Javascript -> ObjC.

I did find a workaround for this with my latest game, which is to run
a timer from ObjC and call into a javascript function for game
updates. This can make your game much more responsive -- especially
if you need to call back out to ObjC for sound, etc. I also am using
Cocos2d for the sprite animation as well. This is probably the basic
limits of web based games on a small device, before moving straight to
a native implementation.... Once I started playing around with some
plugins, it seems ObjC isn't all that bad.

Once you get your game out the door, I would recommend looking at
cocos2d.

Oh, and I converted my wavs to caf, I'm not sure it helped with
performance or not though....

nige...@googlemail.com

unread,
Dec 22, 2010, 11:33:07 AM12/22/10
to phonegap
Is there a useful plugin for sprite rendering? In particular moving an
object between 2 points

Jerryatrix

unread,
Dec 23, 2010, 11:50:11 PM12/23/10
to phonegap
Thanks for all the help and useful information from everyone. I had
been ready to throw in the towel at one point.
In the end I use soundplug for the sounds generated from user actions,
button touches basically. I use the Media class for the other sounds.
It is an education game which requires the playing of foreign language
audio snippets. So I do have to use MP3 realistically, otherwise the
size of the application will balloon. But the timing of those files is
not as critical as for sound effects.

I found that while using AudioSystemServicesPlay(via SoundPlug) did
improve things greatly, I still got delays, animation jerkiness and
other nasties when there was a lot going on in the application.
Eliminating these basically meant optimizing my code in areas, caching
selectively and caching at the right time. I think the sound problems
are symptomatic of the limitations in threading support using
javascript on the iphone. Perhaps the Media class can be optimized
further, I am not sure, but I don't think that it is the real culprit.

In java you would use threads to regulate the sound/animation and
caching activities, and stop them from interfering with each other.
But in javascript I suspect it becomes a race for CPU time. Well I can
only program javascript because it looks like java. I am sure there
are experts here who can shed more light on it than me.

Dman: I have been reading up on Objective C for subsequent projects
and I looked at Cocos2d. But I also want to make android versions in
the future, so I think phonegap is the best way forward. Open to
suggestions however.
Reply all
Reply to author
Forward
0 new messages