不录制时隐藏 iOS 应用程序中的红色录制状态栏 [英] Hide Red Recording Status Bar In iOS App When Not Recording

查看:36
本文介绍了不录制时隐藏 iOS 应用程序中的红色录制状态栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用处于后台且未录制时,我无法将红色的正在录制"状态栏隐藏在我的应用中.

I can't get the red "Recording" status bar to hide in my app when the app is in the background and not recording.

我碰巧在使用 The Amazing Audio Engine,但我认为这个问题可以通过该库的知识来解决.它的设置如下:

I happen to be using The Amazing Audio Engine, but I think this question could be tackled knowledge of that library. It gets setup like this:

audioController = [[AEAudioController alloc] initWithAudioDescription:desc inputEnabled:YES];
audioController.audioSessionCategory = kAudioSessionCategory_MediaPlayback;

当用户想录音时,我像这样打开麦克风:

When the user wants to record, I turn on the mic like this:

[audioController addInputReceiver:mic];
audioController.audioSessionCategory = kAudioSessionCategory_PlayAndRecord;

当用户想停止录制时,我将其关闭:

When the user wants to stop recording, I turn it off:

[audioController removeInputReceiver:mic];
audioController.audioSessionCategory = kAudioSessionCategory_MediaPlayback;

问题是,当应用程序没有录制时&用户离开应用程序,红色的正在录制"状态栏仍然显示.我无法停止/处理 audioController,因为该应用可能仍在播放音频.

The problem is, when the app isn't recording & the user leaves the app, the red "Recording" status bar still shows up. I can't stop/dispose the audioController because the app may still be playing audio.

我不希望在我没有录制时显示红色录制状态栏.任何想法如何做到这一点?

我将以下代码块设置为在我的应用中每 2 秒运行一次.

I setup the following block of code to run every 2 seconds in my app.

audioController.audioSessionCategory = kAudioSessionCategory_MediaPlayback;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError* error = nil;
[audioSession setActive:NO error: &error];
NSLog(@"error: %@", error);
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

此日志:

TAAE: Setting audio session category to MediaPlayback
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryEnableBluetoothInput)    result 2003329396 77686174 what
Error Domain=NSOSStatusErrorDomain Code=560030580 "The operation couldn’t be completed. (OSStatus error 560030580.)"

很明显,由于 TAAE 坚持,它无法禁用麦克风.我没有向控制器添加任何输入,所以我不知道它可能是什么.

Obviously it fails to disable the mic because of something TAAE is holding on to. I have not added any inputs to the controller, so I don't know what it could be.

推荐答案

已解决,见编辑 2

只要麦克风在使用中,无论是否录音,条形都不会消失.这是一种安全措施,可以让用户知道应用正在监听麦克风,而不是表明手机正在录音.

The bar will never disappear as long as the mic is in use, recording or not. it's a security measure to allow the user to know that an app is listening to the microphone, not to show that the phone is recording.

让它消失的唯一方法是从输入接收器上取下麦克风

The only way to get it gone is to remove the mic from the input receivers

我发现你的麦克风没有被移除,肯定有一些错误.

I see that your mic isn't being removed, there has to be some bug.

重点是,只要麦克风打开,您就无法隐藏红色栏..

Point is, you cannot hide the Red bar as long as the microphone is opened..

如果你想暂时禁用它,你可以试试这个吗?

if you want to temporarily disable it, you can try this maybe ?

[audioController setInputEnabled:NO]

你到底想完成什么?可能有更好的方法来处理事情

What are you trying to accomplish anyway? there might be a better way to handle things

编辑 1:添加了其他解决方法

我不知道 setInputEnabled 是只读的,抱歉.

I didn't know that setInputEnabled was readonly, sorry.

好吧,另一件事是完全停止控制器,试试这个:

Well, another thing to try is to stop the controller completely, try this:

[audioController stop]

如果没有,如果您不使用ARC,请尝试释放它,或者干脆

if not, try to release it if you're not using ARC, or simply

audioController = Nil;

希望能解决问题.但我更愿意找出为什么它没有从输入接收器中删除 mic .. 也许当您调用 [audioController removeInputReceiver:mic] 时 mic 为零代码> ??

Hope that fixes the issue. but I rather try to find out why it's not removing mic from the input receivers.. perhaps mic is Nil when you call [audioController removeInputReceiver:mic] ??

编辑 2:添加解决方案

当你在inputEnabled设置为YES的情况下初始化时出现问题,因为它是readOnly,你不能禁用输入,唯一的方法是实际释放audioController.如果您使用的是 ARC,只需将其设置为 Nil,否则,只需 [audioController release]

The problem arises when you initialize with inputEnabled set to YES, since it's readOnly, you can't disable the input, the only way is to actually release audioController. if you're using ARC, just set it to Nil, if not, just [audioController release]

这篇关于不录制时隐藏 iOS 应用程序中的红色录制状态栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆