android-audiomanager

What is the difference between AudioManager's stream types at low level?

梦想与她 提交于 2019-11-30 02:44:53
问题 There are several stream types in AudioManager. How did they differ at low level? Could it be that usage of e.g. AudioManager.STREAM_MUSIC blocks input microphone stream? Or something else? 回答1: One most significant difference is a volume control. As the document says, we can set a volume level or adjust a volume for each streams respectively. And we can control "Audio Focus" that let other apps stop playback or lower the volumes so we can play a sound clearly on a specific stream, or the

MediaPlayer cutting off playback too early on Lollipop when Screen is off

孤街醉人 提交于 2019-11-29 22:09:49
问题 I've been running into an issue with the MediaPlayer on Lollipop devices. Basically when the device screen is off (i.e. user locked the device) the playback continues, but ends about 1 - 2 seconds too early. This doesn't happen when the screen is on though. I have an onCompletionListener on the MediaPlayer: @Override public void onCompletion(final MediaPlayer mediaPlayer) { int progress = mediaPlayer.getCurrentPosition(); int duration = mediaPlayer.getDuration(); Log.d("PlaybackController",

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

倾然丶 夕夏残阳落幕 提交于 2019-11-29 16:53:00
问题 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.

Volume change Listener: Is registerMediaButtonEventReceiver preferable to onKeyDown?

和自甴很熟 提交于 2019-11-29 14:28:59
问题 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

stream volume in SoundPool vs volume in AudioManager

会有一股神秘感。 提交于 2019-11-29 06:15:03
问题 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

Android MediaPlayer - how to play in the STREAM_ALARM?

倾然丶 夕夏残阳落幕 提交于 2019-11-29 03:46:01
I've tried settings the audio stream of the media player in my application using the following code but when I do this I hear no sound in the emulator. If I don't set the stream for the player then the audio plays fine. I'm sure I'm using this wrong but cannot workout how, any help? MediaPlayer player = MediaPlayer.create(getApplicationContext(), R.raw.test_audio); AudioManager audioManager = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE); audioManager.getStreamVolume(AudioManager.STREAM_ALARM); audioManager.setStreamVolume(AudioManager.STREAM_ALARM,

Detect whether headset has microphone

◇◆丶佛笑我妖孽 提交于 2019-11-29 02:22:28
I need to detect whether the plugged in wired headset has microphone or not. I can check if a headset is plugged in using isWiredHeadSetOn() , but for microphone does not seem to be such a method in AudioManager class. I have found some suggestions using ACTION_HEADSET_PLUG , but I am interested to find out this information even if the headset has been plugged in before opening my application, this event won't be fired during the lifetime of my app. Any ideas regarding this issue? Thank you in advance. UPDATE: Go ahead and register ACTION_HEADSET_PLUG in your activity's onResume() . If user

Android Context Memory Leak ListView due to AudioManager

半腔热情 提交于 2019-11-28 23:07:56
I have a ListView and I would expect it to be cleared from memory when the activity finishes. However, it appears that it is leaking. When I check the Memory Dump, and get the pathToGC for the ListView I get the following, Class Name | Shallow Heap | Retained Heap android.widget.ExpandableListView @ 0x4063e560 | 768 | 39,904 |- list, mList com.hitpost.TeamChooser @ 0x405f92e8 | 176 | 1,648 | '- mOuterContext android.app.ContextImpl @ 0x40657368 | 160 | 304 | '- mContext android.media.AudioManager @ 0x40662600 | 40 | 168 | '- this$0 android.media.AudioManager$1 @ 0x406626b0 Unknown| 24 | 24 I

How do I register in manifest an *inner* MEDIA_BUTTON BroadcastReceiver?

ε祈祈猫儿з 提交于 2019-11-28 14:04:20
I managed to get my headset buttons get recognized by my app when pressed, but one of the buttons needs to call a method that's in MyCustomActivity. The problem is onReceive's 1st parameter is a Context that cannot be cast to Activity and so I am forced to implement my BroadcastReceiver as an inner class inside MyCustomActivity. So far so good but how do I register this inner MediaButtonEventReceiver in the manifest? For the independent class, this was simple: <receiver android:name=".RemoteControlReceiver"> <intent-filter> <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent

How to Play audio through speaker even when headset is plugged in?

老子叫甜甜 提交于 2019-11-28 07:30:00
The title of the question might look repeated, but my problem is a sometimes problem and causes glitches. I have used the below code to play through speaker when headset is plugged in. AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); audioManager.setMode(AudioManager.STREAM_MUSIC); audioManager.setSpeakerphoneOn(true); if(! Globals.mediaPlayer.isPlaying()){ Globals.mediaPlayer.start(); } The above code plays audio in the following ways: 1. Very few times, it plays perfectly. 2. Most of the times, it plays with a looping sound in the background. 3. Few