android-audiomanager

Headphone Jack Listener Android

*爱你&永不变心* 提交于 2019-11-30 21:07:25
Does anyone know how I can detect if the headphone jack on a device is unplugged on Android? I have a music player and I need to pause the music when the headphones are unplugged. The closest thing I have found is using the AudioManager . Is that the right direction to go? This is what I ended up doing: private class NoisyAudioStreamReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) { pause(); } } } private IntentFilter intentFilter = new IntentFilter(AudioManager.ACTION

What do the the flag parameter means and range of possible min and max of droid device

戏子无情 提交于 2019-11-30 20:24:25
I want to know what is flag(or what are the possible values for flag) in audiomanager.setStreamVolume (int streamType, int index, int flags); I know we can get the maximum stream using audiomanger.getMaxStream(audioManager.getStreamMax(AudioManager.STREAM_MUSIC)); But in some device it gives 13,15, it depends on Android version or device hardware and what is it range(minimum possible value, maximum possible value) Sets the volume index for a particular stream. This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().// what does it mean.

Playing two sounds Simutaneosly

China☆狼群 提交于 2019-11-30 19:53:13
I am trying to play two sounds simutaneosly in android.I have created two MediaPlayers and am using the code below.They are currently playing one after another.Or not exactly one after another but kinda delayed into eachother. private void playSound(){ if (mp1 != null) { mp1.release(); } if (mp2 != null) { mp2.release(); } mp1 = MediaPlayer.create(this, soundArray[0]); mp2 = MediaPlayer.create(this, soundArray[3]); mp1.start(); mp2.start(); } Thanks Emile Vrijdags Playing two digital sounds simultaneously is as simple as summing them together (as in the real world), so you could do that

Pause Phone Ringtone while Speaking through Text To Speech and then Resume

末鹿安然 提交于 2019-11-30 15:45:20
问题 I am making a caller speaking application which speak caller name using TTS. I want to pause the ringtone while TTS is speaking then resuming the ringtone. From what i have researched we can use AudioFocus (hope so). Anyway i am using the following code Update I am using this code now. public void speak(final String talk) throws InterruptedException { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int musicVolume= audioManager.getStreamVolume

Pause Phone Ringtone while Speaking through Text To Speech and then Resume

落爺英雄遲暮 提交于 2019-11-30 15:43:41
I am making a caller speaking application which speak caller name using TTS. I want to pause the ringtone while TTS is speaking then resuming the ringtone. From what i have researched we can use AudioFocus (hope so). Anyway i am using the following code Update I am using this code now. public void speak(final String talk) throws InterruptedException { final AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int musicVolume= audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicVolume, 0);

How to increase the ringer & notification volume programmatically in android

和自甴很熟 提交于 2019-11-30 14:44:17
I am trying to enable the ringer normal mode and increase the volume programmatically. AudioManager mobilemode = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); // int streamMaxVolume = mobilemode.getStreamMaxVolume(AudioManager.STREAM_RING); switch (mobilemode.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: Log.i("MyApp","Silent mode"); mobilemode.setRingerMode(AudioManager.RINGER_MODE_NORMAL); mobilemode.setStreamVolume (AudioManager.STREAM_MUSIC,mobilemode.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0); break; case AudioManager.RINGER_MODE_VIBRATE: Log.i("MyApp",

What is the android api for getting the list of connected audio devices?

梦想与她 提交于 2019-11-30 11:13:50
I used the below added code to get the connected audio devices for android device. Used AudioManager api method getDevices() and got the result with connected devices like earphones, speaker, headphones. But this getDevices() method is available since android api level 23 (Marshmallow) only. But my application should support from api level 21 (Lollipop). Please can anybody let me know the alternative api to get the available audio device for the android device. Code used with api level 23. AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (android.os.Build

Volume change Listener: Is registerMediaButtonEventReceiver preferable to onKeyDown?

蹲街弑〆低调 提交于 2019-11-30 09:30:24
Looking for a "most comprehensive & compatible (i.e. all Android versions...)" way to listen to volume changes, I found 2 different approaches to handle this: registerMediaButtonEventReceiver onKeyDown + SettingsContentObserver Which method is preferable? And why? UPDATE 1: Thanks to the comment below, I discovered that onKeyDown() actually takes over the volume key, which may not be a complete solution as one of the posts mentioned that volume could be changed via interfaces other than the hardware buttons (not to mention that Google seems to be gradually taking away those "take over"

stream volume in SoundPool vs volume in AudioManager

丶灬走出姿态 提交于 2019-11-30 06:29:41
I am so confused... SoundPool.play(int soundID, float leftVolume, float rightVolume , int priority, int loop, float rate) volume here is from 0.0 to 1.0 Tutorials I've seen recommend to calculate stream volume as: AudioManager mgr = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE); int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); streamVolume = streamVolume / AudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); which makes sense. I would assume that this volume would

How to set volume for text-to-speech “speak” method?

跟風遠走 提交于 2019-11-30 04:04:57
I'm at a lost. I want to be able to adjust the speak volume. Whatever I do, I can't increase its volume. How do I make it as loud as that found in the Android settings (as below)? System Settings -> Voice input and output -> Text-to-Speech settings -> Listen to an example My code at this moment is: AudioManager mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); mAudioManager.setSpeakerphoneOn(true); int loudmax = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); mAudioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION,loudmax, AudioManager.FLAG_PLAY