I want to create an app that only letting through microphone sound by pressing and holding the headphone pause button.
I am trying the following code to mute the microphone:
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setMicrophoneMute(true);
But when this code is executed the microphone still works, can any one help me to disable the microphone? And also when the app is running in the background, it still needs to disable the microphone.
private void setMicMuted(boolean state){
AudioManager myAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
// get the working mode and keep it
int workingAudioMode = myAudioManager.getMode();
myAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
// change mic state only if needed
if (myAudioManager.isMicrophoneMute() != state) {
myAudioManager.setMicrophoneMute(state);
}
// set back the original working mode
myAudioManager.setMode(workingAudioMode);
}
Related
Any ideas why output audio volume should not be adjusted by this code? I am developing for Vuzix M400 and I am using Vonage Video API (Tokbox).
It works just fine on ordinary android smartphones so I searched Vuzix documentation and found that AudioManager is right way to adjust volume on this device.
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
I have tried:
Set volume control stream on start of activity setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
Use Tokboxes CustomAudioDevice
CustomAudioDevice customAudioDevice = new CustomAudioDevice(MainActivity.this);
AudioDeviceManager.setAudioDevice(customAudioDevice);
Use adjustVolume instead of adjustStreamVolume
I have some videos of which audios sound should be available only through earphone, not from inbuilt speaker or external speakers.
NOTE: It should not allow External Speakers with 3.5mm jack.
What is the possibility to solve it?
It will be great if anybody help me out with this.
Check if the headset is plugged in:
private boolean isHeadphonesPlugged(){
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
AudioDeviceInfo[] audioDevices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL);
for(AudioDeviceInfo deviceInfo : audioDevices){
if(deviceInfo.getType()==AudioDeviceInfo.TYPE_WIRED_HEADPHONES
|| deviceInfo.getType()==AudioDeviceInfo.TYPE_WIRED_HEADSET){
return true;
}
}
return false;
}
In a separated thread checks if the headPhones are going to be plugged out using the method above(in that case you have to stop your mediaPlayer and apply your logic)!
For reference
I want to build a app where I want to modulate the sound in a call.I have written a code that record the sound nd play it in different pitch.Now I want this feature while calling.I want to mute the call record the sound then play it with diff pitch.How to mute the call but still record the audio.
This answer works to mute your microphone during a call:
Boolean isMuted = false;
Then in your event, say an onClick
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if(!isMuted){
if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
audioManager.setMicrophoneMute(true);
}
isMuted = true;
}else{
if((audioManager.getMode()== AudioManager.MODE_IN_CALL)||(audioManager.getMode()== AudioManager.MODE_IN_COMMUNICATION)){
audioManager.setMicrophoneMute(false);
}
isMuted = false;
}
Remember to enable permissions in your manifest:
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Step 1.
set permission in manifest
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Step 2.
reverse microphone status
AudioManager audioManager =
(AudioManager) getBaseContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager!=null) {
audioManager.setMicrophoneMute(!audioManager.isMicrophoneMute());
}
I couldn't make AudioManager.setMicrophoneMute(boolean) work on my Honor device, but I found another way to do this. I needed this funcionality in my custom dial app, so I already had custom InCallService, intercepting all calls. This class has method setMuted(boolean state) which works perfectly.
I need to know how to boost call recording volume level
I am seeing this option on this app
https://play.google.com/store/apps/details?id=com.bazmo.TCR
Is anybody know some things about ?
i dont want it already tried!
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
Or how to open(extract) media file and Amplitude(increase sound volume level) voice then save out put to new media file.I saw some things on https://code.google.com/p/musicg
but dont know how to use...
And other question is there any method to reduce or adjust the microphone sound?
The last question how to add all android media recorder source(all sources the android device need to record sound) to my project?
To increase the call recording volume use AudioManager as follows:
int deviceCallVol;
AudioManager audioManager;
Start Recording:
audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
//get the current volume set
deviceCallVol = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
//set volume to maximum
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL), 0);
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
Stop Recording:
//revert volume to initial state
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, deviceCallVol, 0);
I'm new to Slick2D, LWJGL, etc. Anyway I've been trying to make a simple in-game menu when pressing the escape button. Everything works fine, however when I hit the escape button I would like the current music to pause and play a sound when the menu opens. Then for the music to continue when the menu closes. However when I do hit escape it works the sound plays and the music stops, but when I hit escape again the music doesn't resume. Any suggestions?
if(input.isKeyPressed(Input.KEY_ESCAPE)) {
//Toggles Menu Open/Close
inGameMenu = !inGameMenu;
//Toggle Music to shut off
pauseMusic = !pauseMusic;
//Opacity trick
InGameMenu.resetOpacity = !InGameMenu.resetOpacity;
//toggle menu open/close
InGameMenu.closeMenu = !InGameMenu.closeMenu;
if(pauseMusic){
if(Sound.bgMusic.playing()){
Sound.bgMusic.pause();
}
ObjectSounds.menuOpen.play();
} else {
if(ObjectSounds.menuOpen.playing()) {
ObjectSounds.menuOpen.stop();
}
if(!Sound.bgMusic.playing())
Sound.bgMusic.play();
}
System.out.println(pauseMusic);
}
Turns out Music is its own dedicated audio channel, but there is Sound which is another.