tags:

views:

121

answers:

1

Hello Friends,

I am creating a alarm application. I am using Audio Session in my main delegate class.

OSStatus result = AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
UInt32 category = kAudioSessionCategory_MediaPlayback;
result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);  

AudioSessionSetActive(YES);

I am using a separate class for audio playing.But i am not able to play audio when iPhone is sleeping.

could any one tell me how to use a audio session so that i can play audio file even when iPhone is sleeping.

Thank You

A: 

If you're actually using an AVAudioPlayer then try adding this where you handle your initialization:

[[AVaudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

The Playback category will allow the sounds to continue if the phone switch is set to vibrate and/or if the phone is locked.

Good luck,

Karl

genvmunix