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
Related
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);
}
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 use this code to try:
AudioManager audioManager = (AudioManager)getApplication().getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
And then:
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), Uri.parse("url.mp3"));
r.play();
But my app doesn' reproduce any sound.
How can i solve my problem?
According to the OP, the best answer can be found using the MediaPlayer (a link with an example is given in the comments section of this answer).
-- Previous Edits --
Haven't tested this so forgive me if it is buggy, but I think it may work better by setting the default value for the ringtone and then calling that default value. I haven't had a chance to test the code, but it should look something like...
To route the audio to your earpiece:
private AudioManager audioManager;
audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(false);
Then check out AudioTracks, it might be the way to go with what you want to do as Ringtone's have default actions based on Android's native processing; it should be something like
InputStream in =getResources().openRawResource("user_mp3");
AudioTrack audio = new AudioTrack(AudioManager.STREAM_MUSIC, 11025, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, buffersize, AudioTrack.MODE_STREAM);
byte[] sound = null;
sound = new byte[in.available()];
sound =convertStreamToByteArray(in);
in.close();
audio.write(sound, 0, sound.length());
audio.play();
But be sure to set your mode back to normal with your AudioManager when you are done. I think this should work. There is also the deprecated AudioManager.ROUTE_EARPIECE call, you might want to check and see how they have replaced it.
Again, didn't have time to test this, just typed it up on the fly. Let me know if you find an error.
My original "ringtone" style output:
Uri soundPath = Uri.parse("uri_link_for_mp3");
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE, soundPath);
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), ringtone);
r.play();
Had to type this up kind of quick, might have missed something just not thinking of it. There is a good link for this though: Setting Ringtone in Android