0

I am using the SystemSound's framework to play sounds in my application. For devices with IOS3 it is working correctly. But recently I've updated the operating system to IOS4 and I am having a strange problem with the volume. Now I can't change the volume of my sounds during the game, it seems that this framework is using the ring volume and I can't change this volume within an application. I have a couple of questions about that.

  1. Is it the expected behavior or i may have something wrong with my code?
  2. First, why this is happening with IOS4 devices and not with earlier versions.
  3. Is there any workaround to fix it without having to use another framework?

The code that i am using is something like this:

SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);

if (error == kAudioServicesNoError)
     self.soundID = aSoundID;
.

.

.

AudioServicesPlaySystemSound(self.soundID);

I would really appreciate your help!

Thanks,

Juan Pablo

2 Answers2

2

I haven't used audio myself, but I did find a few interesting things that seem relevant (seeing how no one has actually answered your question yet).

I may be misunderstanding the issue, but according to an answer in this question if you're playing a system sound you don't have much control over it.

However, the AVAudioPlayer Class should have everything you need to control sounds and volume, etc. Try using the -initWithContentsOfURL:error:, –prepareToPlay, and -play methods, as well as the volume property - I think it will get you where you want to be.

Community
  • 1
  • 1
JoBu1324
  • 7,751
  • 6
  • 44
  • 61
  • As an additional comment to this answer, you can also use the `OpenAL` framework which gives a lot more control over sounds for games. It's probably not to wise to use system sounds for a game where volume control is more closely controlled. More info in this google book: http://books.google.com/books?id=QoxeAqTvevIC&pg=PA327&lpg=PA327&dq=iphone+system+sound+services&source=bl&ots=fKRgS_JEj4&sig=K4lbJBT3ieXv_K8WXo6Ga2UhL4s&hl=en&ei=7Dc2TIXjC4G8lQeYooHTBw&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCgQ6AEwAw#v=onepage&q=iphone%20system%20sound%20services&f=false – iwasrobbed Jul 08 '10 at 20:42
0

1 & 2) I had the same problem with iOS 4, I think this is expected behaviour in 4.0+ I found out it was because I hadn't set the Session category:

3) I did the following and now it's working.

NSError *setCategoryError = nil;  
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];  

if (setCategoryError) { 
 //handle error
}

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6-SW6

Leg10n
  • 552
  • 7
  • 24