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

时间:2014-02-01 23:04:03

标签: ios iphone objective-c audio

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

我使用以下代码:

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);

1 个答案:

答案 0 :(得分:7)

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

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

相关问题