我想制作一个应用程序,它可以在 iPhone 处于静音模式时创建声音、音乐或系统声音。在静音模式下是否可以播放任何类型的声音,无论是音乐还是系统音?
最佳答案
这是不可取的,但我能说你做不到。您可能有充分的理由播放声音。
如果您使用的是 Audio Session ,则包括 <AVFoundation/AVFoundation.h>
在文件的开头和
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: nil];
应该可以解决问题。请注意,如果您播放音乐或声音,则 iPod 播放将暂停。
完成此操作后,可能在您播放声音的某个类的初始化中某处,您可以像这样实例化声音:
// probably an instance variable: AVAudioPlayer *player;
NSString *path = [[NSBundle mainBundle] pathForResource...];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url];
完成后,您可以随时使用它:
[player play]; // Play the sound
[player pause]; // Pause the sound halfway through playing
player.currentTime += 10 // skip forward 10 seconds
player.duration // Get the duration
还有其他好东西。查找 AVAudioPlayer类引用。
关于iphone - 即使在静音模式下也能在 iPhone 上播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3740528/