ThomasGulli
ThomasGulli

Reputation: 604

Sound not playing when iPhone is in silent mode

I am making an app that needs to play sounds even if the iPhone is in silent mode, but with the code I have now (look at bottom of this post) it wont't play sounds if the iPhone is in silent mode.

I am using the following code:

Viewcontroller.h:

@interface SoundViewController : UIViewController <UICollectionViewDataSource, UIApplicationDelegate, AVAudioPlayerDelegate, ADBannerViewDelegate, UIActionSheetDelegate> {
    SystemSoundID SoundID;
    NSString *listPath;

}

ViewController.m:

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (__bridge CFStringRef) [mainArray objectAtIndex:indexPath.row], CFSTR("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);

Upvotes: 3

Views: 1090

Answers (1)

Bamsworld
Bamsworld

Reputation: 5680

The way you are triggering sounds using AudioServicesPlaySystemSound will ALWAYS obey the ringer/silent switch.

To play sound when the device is set to silent you need to use another way such as AVAudioPlayer class.

Upvotes: 8

Related Questions