Audio.play Doesn't Work In Iphone

Hello,

 

I have around ten ogg sounds playing at the same time in my app. They are being played by audio.play.

It is working in android phone but when I try it at iphone, the app is working ok, but the sounds are not playing.

what can be the reason?

Hi there,

 

I’m pretty sure that iOS doesn’t support the .ogg audio format – see here: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html.

 

Instead, you could .wav or any of the other formats they list.

 

  • Andrew

I suggest .CAF files for iOS, they have the best compression rate, so it saves space when providing a binary to the App Store. I uploaded a utility to convert files to CAF format. It’s in Code Exchange.

thanks.

I will try CAF.

Wait, does CAF require decoding? Is there a performance hit for going CAF over WAV if you’re already streaming encoded audio? (ie: AAC background music)

iPhone natively plays CAF files.  It’s what’s used for iOS’ sound effects, such as text message alerts and the like.  So, there’s no noticable performance hit.  I’ve incorporated over 120 sound effects in CAF format in one app, and it’s a total of 8MB, versus over 45MB when they were in their original WAV format.

I understood that there was native playback, but the docs suggested that the hardware decoder would only deal with one file at a time (possibly ruling out hardware decoding while music plays). Good to know there’s is a WAV alternative.

@BeyondtheTech I need to convert the file to CAF in windows. How to do it?

The ogg file is about 130kb for eg., what will be the CAF type size?

I’m completely on the Mac side, not really sure on how to convert files to CAF in Windows.  CAF is an audio file format created by Apple, so I suspect there may not be too many utilities that can convert to it, let alone play it.  QuickTime, however, should be able to play them, perhaps the Pro version could do the conversion?  You can try GoldWave or Sound Forge, I know those were pretty popular back then.

Some of this is just backing up what BeyondtheTech has to say :slight_smile: (And man, your bash script is awesome!)

Alright, so as best as I can tell, the best general use class in the iPhone SDK can play a large number of sounds simultaneously, but for most formats the hardware can only decode one at a time, putting the rest on software. For stuff like MP3, this is quite expensive. uncompressed (AIF/WAV) or IMA4 compressed (CAF) work best for sound effects because they have hardly any CPU utilization.

So in terms of space saving, it depends on your files, but looking at my own project:

MP3 is about 4-5 times smaller than CAF (ie: 30kb sounds become 120-150kb)

CAF is 2-3 times smaller than WAV (30kb becomes 12kb)

The file size loss versus MP3 is pretty severe, but adjusting things like sample rate or channels could help cut that down. It’s also not irresponsible to use AAC or other heavily compressed formats in your game, but expect slowdown when they playback if your game has fast action or an already troubled framerate.

Hi there,

 

I’m pretty sure that iOS doesn’t support the .ogg audio format – see here: http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html.

 

Instead, you could .wav or any of the other formats they list.

 

  • Andrew

I suggest .CAF files for iOS, they have the best compression rate, so it saves space when providing a binary to the App Store. I uploaded a utility to convert files to CAF format. It’s in Code Exchange.

thanks.

I will try CAF.

CAF works. Thanks.

Wait, does CAF require decoding? Is there a performance hit for going CAF over WAV if you’re already streaming encoded audio? (ie: AAC background music)

iPhone natively plays CAF files.  It’s what’s used for iOS’ sound effects, such as text message alerts and the like.  So, there’s no noticable performance hit.  I’ve incorporated over 120 sound effects in CAF format in one app, and it’s a total of 8MB, versus over 45MB when they were in their original WAV format.

I understood that there was native playback, but the docs suggested that the hardware decoder would only deal with one file at a time (possibly ruling out hardware decoding while music plays). Good to know there’s is a WAV alternative.

Hi Everyone

                    I am new to Corona development.I tried simple audio recorder on android but it does not work on it.anyone can plz help me.

@BeyondtheTech I need to convert the file to CAF in windows. How to do it?