Hide Red Recording Status Bar In iOS App When Not Recording

半世苍凉 提交于 2019-11-28 00:45:50

Resolved, see edit 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

Edit 1: Added other workarounds

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

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

[audioController stop]

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

audioController = Nil;

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] ??

Edit 2:Added solution

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]

Try to set audio servicess off when you stop recording:

AudioSessionSetActive(false);

I solved the problem by:

  • Having two audio controllers (as suggested in the comments): one for recording and one for playback. When the app entered background, I called [recordAudioController stop] and when I wanted to start recording again, I re-started this audio controller.
  • Removing a line of code from AEAudioController.m that tried to stop the audio session, making TAAE stop only the AUGraph:

    - (void)stopInternal {
    NSLog(@"TAAE: Stopping Engine");
    
    checkResult(AUGraphStop(_audioGraph), "AUGraphStop");
    
    if ( self.running ) {
        // Ensure top IO unit is stopped (AUGraphStop may fail to stop it)
        checkResult(AudioOutputUnitStop(_ioAudioUnit), "AudioOutputUnitStop");
    }
    
    // --- I removed the following section ---
    if ( !_interrupted ) {
        NSError *error = nil;
    
        if ( ![((AVAudioSession*)[AVAudioSession sharedInstance]) setActive:NO error:&error] ) {
            NSLog(@"TAAE: Couldn't deactivate audio session: %@", error);
        }
    }
    
    processPendingMessagesOnRealtimeThread(self);
    
    if ( _pollThread ) {
        [_pollThread cancel];
        while ( [_pollThread isExecuting] ) {
            [NSThread sleepForTimeInterval:0.01];
        }
        _pollThread = nil;
    }
    }
    

I know the question was a little old, but in case other people met the same problem like me, I gave my final solution. The problem happened in such a recording situation:

  1. start recording

[session setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

  1. stop recording

[session setCategory:AVAudioSessionCategoryPlayback error:&error];

when I comment code that reset the session category to playback, the problem disappeared. I also change the start recording code to:

[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:&error];

so that voice played from receiver to speaker.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!