Tag: avaudiosession

iOS8 AVAudioSession setActive错误

我在XCode 6中testing我的应用程序,并在iOS8中查找AVAudioSession的问题。 当我打电话 [[AVAudioSession sharedInstance] setActive:NO er​​ror:nil]; 我收到以下错误信息: AVAudioSession.mm:623: – [AVAudioSession setActive:withOptions:error:]:取消激活正在运行I / O的audio会话。 在停用audio会话之前,应该停止或暂停所有I / O。 在AVAudioSession.h,它说 请注意,如果会话在运行或暂停I / O(如audio队列,播放器,录像机,转换器,远程I / O等)时设置为非活动状态,则此方法将在iOS 8或之后的应用程序中引发exception。 。 但是我不确定如何检查是否正在运行I / O,以及如何在需要重置audio会话时处理所有的I / O。

耳机是否插入? IOS 7

开发一个iPhone应用程序,audio文件也需要通过耳机收听。 如何检查耳机是否插入,以便我可以告诉用户插入耳机。 我从另一个线程有以下代码,但audioSessionGetProperty方法已被弃用。 任何人都知道如何改变下面的代码来使这个工作或有自己的代码/解决scheme。 谢谢。 – (BOOL)isHeadsetPluggedIn { UInt32 routeSize = sizeof (CFStringRef); CFStringRef route; //Maybe changing it to something like the following would work for iOS7? //AVAudioSession* session = [AVAudioSession sharedInstance]; //OSStatus error = [session setCategory:kAudioSessionProperty_AudioRoute…? //the line below is whats giving me the warning OSStatus error = AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &routeSize, &route); /* Known […]

使用AVAudioPlayer不工作检测iPhone的环/静音/静音开关?

我尝试过使用这些方法来试图检测Ring / Silent开关是否激活: 如何以编程方式感应iPhone静音开关? AVAudioSession类别不起作用文档指示 但在我的iPhone 4上,“状态”值始终是“扬声器”(并且由CFStringGetLength(状态)返回的长度值始终为7)。 有没有人使用这种方法成功? 如果是这样,在什么样的设备和SDK版本? 我这样称呼它: – (BOOL)deviceIsSilenced { CFStringRef state; UInt32 propertySize = sizeof(CFStringRef); OSStatus audioStatus = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state); if (audioStatus == kAudioSessionNoError) { NSLog(@"audio route: %@", state) // "Speaker" regardless of silent switch setting, but "Headphone" when my headphones are plugged in return (CFStringGetLength(state) <= 0); } return […]