iphone - 即使在静音模式下也能在 iPhone 上播放声音

标签 iphone objective-c ipad avaudioplayer

我想制作一个应用程序,它可以在 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/

相关文章:

objective-c - NSString 绘图与 String 作为 NSBezierPath 绘图

iphone - 如何取消使用 [performSelector : withObject: afterDelay:]? 注册的方法

ios - UIPopoverController 中的 UIViewController 始终报告为处于纵向模式

iphone - 字符串日期 2011-11-25T21 :17:49-05:00 的日期格式化程序出现问题

ios - Objective-c 方法队列

iphone - 核心数据: Is it possible to build a desktop app to create the data model for an iPhone app with Core Data?

objective-c - Core MIDI 回调中未注册线程上的 GC

iphone - 如何获取iPhone中安装的应用程序名称列表

iphone - 在 iPhone 上解析 XML 的最佳方法

objective-c - 未安装 Sim 卡弹出在调用功能中显示两次