views:

32

answers:

2

Hi,

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

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.

JoBu1324
iWasRobbed
A: 

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
you should do that prior to playing sound, like in application delegate.
Leg10n