当iPhone处于静音模式时,声音无法播放

Tho*_*lli 3 iphone audio objective-c ios

即使iPhone处于静音模式,我正在制作一个需要播放声音的应用程序,但是我现在拥有的代码(看看这篇文章的底部)如果iPhone处于静音模式,它就不会播放声音.

我使用以下代码:

Viewcontroller.h:

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

}
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

Bam*_*rld 7

使用AudioServicesPlaySystemSound触发声音的方式将始终遵循振铃/静音开关.

要在设备设置为静音时播放声音,您需要使用其他方式,如AVAudioPlayer类.