Ejemplo n.º 1
0
    public void stop()
    {
        if (!running)
        {
            return;
        }
        running = false;

        if (echoCanceller != null)
        {
            try
            {
                echoCanceller.Release();
                echoCanceller.Dispose();
            }
            catch (Exception)
            {
            }
            echoCanceller = null;
        }

        if (noiseSuppressor != null)
        {
            try
            {
                noiseSuppressor.Release();
                noiseSuppressor.Dispose();
            }
            catch (Exception)
            {
            }
            noiseSuppressor = null;
        }

        if (audioRecorder != null)
        {
            try
            {
                audioRecorder.Stop();
                audioRecorder.Release();
            }
            catch (Exception)
            {
            }
            audioRecorder.Dispose();
            audioRecorder = null;
        }

        if (audioEncoder != null)
        {
            audioEncoder.stop();
            audioEncoder.Dispose();
            audioEncoder = null;
        }

        buffer       = null;
        shortsBuffer = null;
        bufferSize   = 0;
        lock (outputBuffers)
        {
            outputBuffers.Clear();
        }


        AudioManager am = (AudioManager)MainActivity.Instance.GetSystemService(Context.AudioService);

        if (Build.VERSION.SdkInt < BuildVersionCodes.O)
        {
            if (focusListener != null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                am.AbandonAudioFocus(focusListener);
#pragma warning restore CS0618 // Type or member is obsolete
                focusListener.Dispose();
                focusListener = null;
            }
        }
        else
        {
            if (focusListener != null)
            {
                if (focusRequest != null)
                {
                    am.AbandonAudioFocusRequest(focusRequest);
                    focusRequest.Dispose();
                    focusRequest = null;
                }
                focusListener.Dispose();
                focusListener = null;
            }
        }
    }