我正在制作一个即使 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);
最佳答案
您使用 AudioServicesPlaySystemSound 触发声音的方式将始终遵循铃声/静音开关。
要在设备设置为静音时播放声音,您需要使用另一种方式,例如 AVAudioPlayer 类。
关于ios - iPhone 处于静音模式时不播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21504817/