views:

29

answers:

1

Hello everyone

i used code below in my application and if i increase or decrease the volume from the iphone's button it still the same but if the phone in silent mode the voice will be muted

the code:

-(void) playNote: (NSString *)Note type: (NSString *)type
{
    CFURLRef        soundFileURLRef;
    SystemSoundID   soundFileObject;
    CFBundleRef mainBundle;
    mainBundle = CFBundleGetMainBundle ();

// Get the URL to the sound file to play
soundFileURLRef  =  CFBundleCopyResourceURL (mainBundle,
         (CFStringRef)Note,
         (CFStringRef)type,
         NULL);

NSLog(@"%@\n", soundFileURLRef); // Create a system sound object representing the sound file AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

   AudioServicesPlaySystemSound (soundFileObject);
}

Best Regards

A: 

You need to set your Audio Category properly before playing back sounds.

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
Wim Haanstra
where to put this code in the ViewDidload ??
Bobj-C
Well, at least before playing your sound. Not sure if it will compile directly like this. But you can also take a look at the AudioSession reference.
Wim Haanstra