Closed RishiKar closed 2 years ago
Are you sure it's not flutter_sound that's not releasing the microphone?
Hi Ryan, I verified my code again and aggressively called all stop and cancel methods.
void stopAndRelease() async {
await _createRecordingFile.stopRecorder();
await _recorder.stopRecorder();
await _createRecordingFile.closeRecorder();
await _recorder.closeRecorder();
await _audioStream.close();
await _recordingDataController.close();
await _recordingDataSubscription.cancel();
}
I got this from the logs so but was not able to understand them
[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: PlatformException(2003329396, The operation couldn’t be completed. (OSStatus error 2003329396.), null, null)
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
<asynchronous suspension>
#2 AudioSession.configure (package:audio_session/src/core.dart:195:5)
<asynchronous suspension>
#3 AudioPlayerService.initAudioSession (package:sixthousandthoughts/services/audioplayer_service.dart:15:5)
<asynchronous suspension>
(Edited by @ryanheise to format multiline code blocks)
I found this S/O answer: https://stackoverflow.com/questions/21893007/how-to-consistently-stop-avaudiosession-after-avspeechutterance
It basically says you may get this error if you try to deactivate your audio session too soon before the audio sources have been completely closed.
Thanks Ryan, I am not sure how I can check whether it is too soon but I will review the code to reorder the close/cancel methods and check again to make sure I am waiting for them to finish.
Is it ok if I keep the issue open until then? If you have any suggestions or have faced this in any of your work, I would be very grateful for any directions on this.
I would also check that flutter_sound also actually releases the resources before the session is deactivated. This may involve looking at flutter_sound's code. A quick test you can do is to insert a delay before deactivating the session and see if it has any effect.
Hi @ryanheise , It was not related to audio session plug-in . I believe it had something to do with not canceling the recording stream correctly. For now, I can see that the mic resources are being released correctly. 🤞 I will close the issue. Thank you for your help and suggestions.
Hi @ryanheise , I have been stuck at trying to identify why I can't get the microphone to be release after stopping recording. A user can see this in the form of an orange dot on iOS devices (indicating mic is in use). I am initialising an audio session using
audio_session
. Then I record usingflutter_sound
. On stop, I make sure I callstopRecorder
,closeRecorder
and close and cancel all streams. Is there a way to use AudioSession.instance.setActive(false) in the dispose call or some other way? This is audio_session initialisation:(Edited by @ryanheise to correctly format multiline code blocks)