In my app I have an additional library for SIP calling, which on some phones (Huawei 5.1) locks volume to around 50% (or even less) for some reason and it keeps it like that for the whole phone volume meanwhile service is running.
I tried setting:
am.SetStreamVolume(Android.Media.Stream.Music,am.GetStreamMaxVolume(Android.Media.Stream.Music), 0);
And playing beeping noise with MediaPlayer/Soundpool.
I also tried setting Microfone to
Mode.Ringtone / Mode.Normal,...
but the volume is still low when this library/service is running.
Is there any other setting option possible that could override some setting in the library, because if I look current volumes, it's all on MAX (Media/Notification/Ringtone/...)?
In this library, you have to initialize sampleRate / buff size, which I do with getting default values from Android
String rate = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
String size = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
Some companies add a volume limit to protect user. I met similar issue before on samsung note 4. I am not sure whether APP has the permission to break this limit(mostly not allow).
In order to find the relative setting, please try this: Play music by the default music player, and press volume+. Keep volume up and then your phone may toast a dialog to tip you. And you can change this setting.
Hope it works :)
Related
My application is measuring volume of captured audio as a function of samples absolute amplitude.
I've noticed and unexpected behavior in android.media.AudioRecord of Android SDK. Let's assume following flow:
Application is launched
Audio volume is being measured
Phone call is answered/dialed
Audio volume is being measured
The noise around the microphone is produced by TV with constant volume setting. Values measured for point 2 are in range [55-65] and values measured for point 4 are in range [15-25] (please see the audio visualization for 2. and 4. below).
I understand that there must be some volume adjustment going on when phone call occurs. Is it possible to monitor those adjustments or to get rid of them?
I've tried AutomaticGainControl but it is not supported on my Nexus 5 and I do not want to use it since the target devices might not support it as well.
Update
This volume adjustment is happening not only after phone call. I've just noticed the same behavior when phone was just lying on the table measuring volume.
In regard to resources that your app is sharing with other apps (the microphone in this matter) - you should always treat them carefully and assume there configuration may change during a phone call or other usage like switching to another app that's using the microphone.
Instead of trying to monitor for changes in gain , which may require root or other elevated privileges - I would take another approach and do the following:
Save the mic sensitivity level to a configuration file (shared_prefs) in your recording activity when the user is recording . do the same if the user changes it of course during usage of your app.
In the onResume proc of your recording activity - load the mic sensitivity level value and set it before continuing to record (How to adjust microphone sensitivity while recording audio in android - Solved)
If there is a phone call that throws your app to the background and takes control of the mic, once it's finished - your app will return to the foreground and retain the mic sensitivity level for further recording.
Hope this helps.
I have an audio app that plays multiple tracks at the same time, each with their own mediaPlayer. Each track is reasonably long, upwards of two minutes.
So long as the tracks are encoded as ogg files, everything works great on Android 4.x. I've yet to encounter a device running stock 4.x that has any audio problems with this setup.
But on Lollipop 5.x there are a wide variety of audio problems - stuttering, tracks cutting out, and bluetooth audio almost never seems to work.
I've discovered that going into Developer options in 5.x and unchecking "use Nuplayer (experimental)" instantly solves these problems and returns to 4.x levels of performance.
Is there a way I can programmatically force my app to use the 4.x media stack (I believe it's called Awesomeplayer?) and not to use the new Nuplayer system? At least until I can discover the source of the Nuplayer problems?
Update:
Setting a partial wake lock on the MediaPlayer resolves this problem:
playerToPrepare.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
A partial wake lock shouldn't have too big of an impact, and it seems like MediaPlayer itself cleans this up when playback completes.
-- Original Answer ---
So, I finally found a way to safely detect wether or not NuPlayer will be used or not on Lollipop. Seems like the best strategy for now is to inform the user to open Developer Settings and enable AwesomePlayer until Google fixes NuPlayer.
Sadly, there's no good way to change this setting for the user, we can just read its value unless you're signed as a system application.
This approach checks Android's system properties values to see if the user have enabled the use of AwesomePlayer or not under Developer Settings. Since Lollipop have NuPlayer on by default, if this value is disabled, we know NuPlayer will be used.
Drop SystemProperties.java into your project for access to read the system properties, do not change its package name from android.os (it calls through to its corresponding JNI methods, so needs to stay the same).
You can now check if the phone is Lollipop/5.0, if AwesomePlayer is enabled, and act accordingly if it's not (e.g. by opening the Developer Settings):
public void openDeveloperSettingsIfAwesomePlayerNotActivated(final Context context) {
final boolean useAwesome = SystemProperties.getBoolean("persist.sys.media.use-awesome", false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !useAwesome) {
final Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
context.startActivity(intent);
}
}
Enabling/Disabling NuPlayer didn't help. But I managed the wakelock part with a friendly UI. I'll look tonight as SysCtl from KitKat and compare it with the one on Lollipop, maybe I'll find something interesting.
So bluetooth stuttering is related to the dumb kernel on 5.02 that stutters the playback as soon as screen is off. I used a partial wakelock so the cpu stays active after screen off with this app. It works. No more stuttering. As for speakers that require high sample rate I just switched the cpu governor to performance. It's a workaround but the partial wakelock should work especially on bluetooth headphones. Here's the app's link https://play.google.com/store/apps/details?id=eu.thedarken.wl&hl=en
How do you fire the iblazr programmatically?
No API I can find, they're not responding to inquiry.
I'm looking for a solution for iPhone and Android.
Since you have to enable the flash device with the media volume at max, I suspected it must have something to do with the volume output that triggers it.
So, I plugged it in, started my music player, and it started flashing to the music for the most part.
Turning down the volume stopped the flashing and turning it back up caused the LED to again start flashing.
Based on that I would assume you simply have to output a loud audio clip to turn it on while the media volume is set to max.
Update:
After experimenting on my theory, the device I have (iblazr compatible 16 LED Chinese version), the frequency of the tone is the key and determines the brightness. Using the Windows API Beep(frequency, duration) function, the light first turns on at a frequency of 6500 and gets brighter as the frequency increases. Seems like it is pretty bright at 7000!
They finally published it here:
https://github.com/ConcepterDev/iblazr-original-protocol
You can control the original iblazr by sending the specified tone for the specified duration to the headphone jack:
function frequency (Hz) duration
----------------------------------------------
wake iblazr 800 200±150ms
flash 15750 300ms (auto)
pre-flash 10000 until focused
constant light 2500-9500 infinite
As of now, the volume can be set per Stream type. I am just wondering if there is a way to control the volume per application. For example, for this specific game application I can set to to volume level 10 without changing the volume for other application which has the same stream type.
Any feedback will be greatly appreciated.
Thanks,
artsylar
This is not supported by the OS.
You are welcome to try to fake it by remembering the current volume level, changing it, then restoring the original volume level. However, it will be impossible to cover all the cases where the volume level needs to be reset (e.g., your app crashes).
I want to fine tune the volume of the current media file playing.
So there are two applications here, the mediaplayer application, that could be the default Music application, and my application, where I want to tune the volume.
What I do now is to use setStreamVolume, but the index only goes from the max volume to 0, and that's 15 levels only (at least in the emulator).
What I want is to fine tune it in for example, 100 or 200 levels.
Is that possible?
Thanks!
I just searched around for a bit and it seems like this isn't possible using the android API.
I think Fine Volume Control is what you want. It provides 100 levels of adjustment. You can get it in market