I began creating an app that will run in the background and globally repurposes the play/pause/forward/backward buttons to change the volume which is intended to apply to any media player.
Example: While streaming media in Pandora or Youtube, pressing pause will
lower the volume then activate pause and pressing play will increase the volume then activate play.
I find that onMediaButtonEvent() will give me a similar effect except that this is localized to only within the app it is written in and applies to only physical hardware play/pause/forward/backward buttons.
Also, I can use onClick() which allows me to decide what happens when a play/pause/forward/backward button is pressed but this is limited to within the app.
Can anyone offer any insight on if there is another function, a work around or if this is even possible? Maybe i am looking in the wrong direction and there is something that needs to be modified in the kernel which is out of bounds.
Related
I wrote some code to play the shuttersound for Android using the camera2 API. The code is:
MediaActionSound mediaActionSound = new MediaActionSound();
mediaActionSound.play(MediaActionSound.SHUTTER_CLICK);
I've tested on more than ten devices. The problems are:
The actually play a different sound that the built-in camera.
Different devices actually play different sound. (It seems that the device manufacturer each has installed a different sound fine.)
There is some information about this file:
/system/media/audio/ui/camera_click.ogg
... but I'm not sure if this is the sound file used. And if so, why do they all sound different and not the same as the built-in camera.
The solution I'm seeking:
Either:
Play exactly the same sound as with the built-in camera. How do I do this?
or
Install a custom sound file into my app and play this same sound across all devices. (However, this method is secondarily preferred because we have to find a custom sound file.)
Please advise.
If the default camera app has its own shutter sound, it's unlikely you can get to it - it's likely either baked into the app APK, or some custom addition to that OEM's set of device sounds that isn't visible to non-system apps.
The main reason to use MediaActionSound to be compliant with the expectation in some countries that camera shutter sounds are not silenceable. MediaActionSound will still play a shutter sound even on a fully-silenced device in such countries, without the developer having to worry about it.
Otherwise, you could just play whatever sound you want on shutter press, if complying with the shutter sound enforcement isn't critical - or you can use your own sound when shutter sound muting isn't enforced (you can check via canDisableShutterSound), and fall back to MediaActionSound in places where shutter sound shouldn't be silenced.
It rely on your decision.
If you want to make your app's brand, just use the one you like or treat the user with their familiar sound. Your don't have to complicate it
I'm aware that this is a commonly asked question, but most questions are quite old, and I was hoping that the situation has changed.
I am looking to activate an application feature from the phone's locked state by pressing the volume up button five times in a row, without having to resort to using a wakelock. This feature should be activatable at any time using the volume while the phone is locked.
I have observed that some phones are able to detect volume button presses (e.g. two volume down presses will load the Camera application), but I have not been able to find out how these apps do it. I figured that if these phones are able to do it, then surely what I'm trying to do is possible?
The KeyListener won't run when the application is paused (which it is if the screen is locked).
But there is a quite clever workaround: play some music (probably silence) and listen to volume changes.
See here for more information on how to do it. AFAIK the above behavior hasn't changed and you mostly likely will have to resort to above workaround.
I'd love to be corrected on that as I've needed this myself.
I'm trying to write a little background program that stops music playing Winamp when another program plays sounds. The part about the accessing Winamp through Java is already solved now I need a way to detect which program plays the currently played sound (probably I want to allow some programs to play their sound without stopping my music). Although I'm doing this in Java (+ the winapi) everything in any language would help.
[edit] as I just got the first downvote on my first question here is some more detail: I already figured out how to use the winapi (but I don't know it) and capture things like volume levels and stuff. What still makes trouble is the mentioned detection of the origin of a sound that is played and aslo which program plays sounds. Is there anything in the winapi that could help me to do this?[/edit]
As Deanna mentioned, you can enumerate audio playback sessions just like Volume Mixer application (started from system tray icon) does and obtain per-session meters indicating session status.
You can find a C++ application that does it in this answer: Peak meters for individual programs on Windows 7. The meters are per-session and an audio-enabled application might have one or more sessions in it, but eventually as long as you enumerate them, you can figure out if there is any active playback there.
I believe the Windows Core Audio API in Vista+ allows you to get the VU levels for each application (After all, the mixer shows it). This should allow you to turn down one application when another is playing, etc.
When unlocking my android 2.3.3 phone at the simple lock screen it vibrates once the slider is touched and a second time a little longer when the slider has been pulled completely to the other side.
I found it a little annoying and so I thought I could somehow switch it off in the settings as I can switch off any other vibration.
There are actually two categories which might make sense in this case:
1) Sound Settings/General/Vibrate with the individual settings: (always, never, only in silent mode, only when not in silent mode)
2) Sound Settings/Feedback/Haptic Feedback (on/off)
I had to find out, that none of these settings have an impact on the unlocking action mentioned above.
So I googled and found some comments about the fact, that the vibration cannot be switched off easily in the settings.
e.g.
http://code.google.com/p/android/issues/detail?id=34040
Now I got curious and I tried to dive in a little deeper into the android sources and found the source for the slider here: https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/widget/SlidingTab.java
see:
vibrate(VIBRATE_SHORT);
and:
vibrate(VIBRATE_LONG);
It seems to me that the vibrate action is called regardless of any settings.
Now I have some questions:
Shouldn't the vibration for unlocking consider the settings from either 1) or 2) above?
How would this be added to the source code and how would this change be applied to the android source repository so that some time later this could be migrated into the next android (if the sliding tab is used there at all)
Would it be possible to update the file SlidingTab.java seperately and test it on my rooted device or would it be necessary to do the complete make for the whole android system and flash my mobile phone with the new system in order to see if it works?
I have found other mobile phones with the same slider and no vibration when unlocking. I am clueless how this can be after I found the prove that it is not able to switch off the vibration in the source code.
thank you for sharing your knowledge with me
Nils
It may be consider or may not.
Not sure here.
If you need to change lock screen at all you can find various implementation. If you need to change default lock screen you need to build entire system.
Every companies customise Android for the phones. Therefore some sliders may have no vibration. Or the phone may have no hardware for it.
i wish to write a plugin that will enable me to access hardware buttons of the phone while using the camera app. how would i go about doing this. or is it even possible.
Sorry, you can't generally do this. There are some keys that applications can respond to while in the background (specifically the media play/pause/etc buttons) but it is not generally possible to process key events while another app has focus.
Your best best is to check the Camera source but you might consider making your own app based on Camera.