Android AudioRecord is there a way to release when I no longer have a reference?

I'm implementing an Android app that uses microphone input via the AudioRecord class. I haven't called release() method on AudioRecord instance and closed the app. Now I'm not able to initialize another AudioRecord and recording audio is basically blocked for all other apps as well.

AudioHardwareALSA: error:Input stream already opened for voice recording

Is there any way to release AudioRecord instance when I no longer have a reference to it? The only way I've found so far is to restart a phone which is not a viable solution.

Upvotes: 0

Views: 537

Answers (1)

Usman Ghauri
Usman Ghauri

Reputation: 941

Release all your resounrces in onDestroy Method

@Override
protected void onDestroy() {
    super.onDestroy();
    // release resources
    releaseResources();
    visualizerView = null;
}

in release resources method what i do is see if recording is running then stop/ cancel it and thats all within try catch block

Upvotes: 1

Related Questions