我在使用 AudioServicesPlaySystemSound 时遇到问题。当输出通过扬声器时,效果很好。但是,当用户插入耳机时,没有输出。有没有一种简单的方法来设置某种监听器,以便音频在插入耳机时自动通过耳机路由,否则通过扬声器?
我正在使用以下方法播放简短的 AIF 声音样本:
-(void)playAif:(NSString *)filename {
SystemSoundID soundID;
NSString *path = [[NSBundle mainBundle]
pathForResource:filename ofType:@"aif"];
if (path) { // test for path, to guard against crashes
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path],&soundID);
AudioServicesPlaySystemSound (soundID);
}
}
我知道我一定遗漏了一些东西,一些可以做到这一点的设置。有任何想法吗?