Iphone, how to play sound even in silent mode or without sound?

as a theme ... is it possible?

thank

Again, I added the code as follows, please check which step is wrong .thanks.

//@step AudioSessionInitialize (NULL, NULL, NULL, NULL); AudioSessionSetActive(true); UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; OSStatus error = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory); if (error) printf("ERROR AudioSessionSetProperty ! %d\n", error); //@step NSString* filePath = @"AlarmClockBell.caf"; [Util restoreResourceFile:filePath]; filePath =[Util getFileFullPathFromSysDoc:filePath]; NSURL *soundFileURL = [NSURL fileURLWithPath:filePath]; NSError* error ; AVAudioPlayer * audioPalyer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: &error]; if (nil == audioPalyer) { AppTrace3(self, @"Faild to play", soundFileURL, error); return FALSE; } [audioPalyer prepareToPlay]; [audioPalyer setVolume: 5 ]; [audioPalyer setDelegate: self]; audioPalyer.numberOfLoops = 10; [audioPalyer play]; 

thank...

+2
iphone
May 01 '10 at 6:03 a.m.
source share
3 answers

If you look in the documents in the Audio Connections section, you will find several modes that you can configure to tell the system how your application plans to use audio. By default, AVAudioSessionCategorySoloAmbient used, which monitors the call / silent switch and screen lock.

In order for your application to ignore the ring / tick settings, you can try changing the category:

 #import <AudioToolbox/AudioToolbox.h> AudioSessionInitialize (NULL, NULL, NULL, NULL); AudioSessionSetActive(true); UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback; AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory); 

If you want iPod audio to continue playing in the background, you'll also want to check out kAudioSessionProperty_OverrideCategoryMixWithOthers .

+6
May 01 '10 at 9:41 a.m.
source share

Like iOS 6, there is an alternative method, more compact than Ramin answer .

 #import <AVFoundation/AVFoundation.h> [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 

To continue background sound from other applications, add the AVAudioSessionCategoryOptionMixWithOthers parameter:

 [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; 

Details at Apple Link to the AVAudioSession class .

+1
Oct 18 '13 at 13:45
source share

There must have been several games that I had, which (even when it is in mute mode) will play sound. Unfortunately, this was discovered while trying to play games secretly in the classroom.

As for how to actually do this, I really don't know.

0
May 01 '10 at 6:50
source share



All Articles