How to block the mic for another app to use?

后端 未结 1 1339
感情败类
感情败类 2021-01-03 06:54

I am working on android voip application. I want to make sure if any other application is using mic. By this I want to prevent access to mic from other applications while I

相关标签:
1条回答
  • 2021-01-03 07:49

    Finally come to know that we can check mic availability as below :

    private void validateMicAvailability() throws MicUnaccessibleException {
        AudioRecord recorder =
            new AudioRecord(AudioSource.MIC, 44100,
                    AudioFormat.CHANNEL_IN_MONO,
                    AudioFormat.ENCODING_DEFAULT, 44100);
        try{
            if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_STOPPED ){
                throw new MicUnaccessibleException("Mic didn't successfully initialized");
            }
    
            recorder.startRecording();
            if(recorder.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING){
                recorder.stop();
                throw new MicUnaccessibleException("Mic is in use and can't be accessed");
            }
            recorder.stop();
        } finally{
            recorder.release();
            recorder = null;
        }
    }
    
    0 讨论(0)
提交回复
热议问题