我想制作一个应用程序,当 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/57952348/