use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class MediaPresetReverbTest method test2_1InsertSoundModification.
//Test case 2.1: test actual insert reverb influence on sound
@LargeTest
public void test2_1InsertSoundModification() throws Exception {
boolean result = false;
String msg = "test2_1InsertSoundModification()";
EnergyProbe probe = null;
AudioEffect vc = null;
MediaPlayer mp = null;
AudioEffect rvb = null;
AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
int ringerMode = am.getRingerMode();
am.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
int volume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
try {
// creating a volume controller on output mix ensures that ro.audio.silent mutes
// audio after the effects and not before
vc = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, VOLUME_EFFECT_UUID, 0, 0);
vc.setEnabled(true);
mp = new MediaPlayer();
mp.setDataSource(MediaNames.SINE_200_1000);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
// create reverb with UUID instead of PresetReverb constructor otherwise an auxiliary
// reverb will be chosen by the effect framework as we are on session 0
rvb = new AudioEffect(AudioEffect.EFFECT_TYPE_NULL, PRESET_REVERB_EFFECT_UUID, 0, 0);
rvb.setParameter(PresetReverb.PARAM_PRESET, PresetReverb.PRESET_PLATE);
rvb.setEnabled(true);
// create probe after reverb so that it is chained behind the reverb in the
// effect chain
probe = new EnergyProbe(0);
mp.prepare();
mp.start();
Thread.sleep(1000);
mp.stop();
Thread.sleep(200);
// measure energy around 1kHz after media player was stopped for 200 ms
int energy1000 = probe.capture(1000);
assertTrue(msg + ": reverb has no effect", energy1000 > 0);
result = true;
} catch (IllegalArgumentException e) {
msg = msg.concat(": Bad parameter value");
loge(msg, "Bad parameter value");
} catch (UnsupportedOperationException e) {
msg = msg.concat(": get parameter() rejected");
loge(msg, "get parameter() rejected");
} catch (IllegalStateException e) {
msg = msg.concat("get parameter() called in wrong state");
loge(msg, "get parameter() called in wrong state");
} catch (InterruptedException e) {
loge(msg, "sleep() interrupted");
} finally {
if (mp != null) {
mp.release();
}
if (vc != null) {
vc.release();
}
if (rvb != null) {
rvb.release();
}
if (probe != null) {
probe.release();
}
am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
am.setRingerMode(ringerMode);
}
assertTrue(msg, result);
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class PhoneWindow method onKeyUpPanel.
/**
* Called when the panel key is released.
* @param featureId The feature ID of the relevant panel (defaults to FEATURE_OPTIONS_PANEL}.
* @param event The key event.
*/
public final void onKeyUpPanel(int featureId, KeyEvent event) {
// The panel key was released, so clear the chording key
if (mPanelChordingKey != 0) {
mPanelChordingKey = 0;
final PanelFeatureState st = getPanelState(featureId, false);
if (event.isCanceled() || (mDecor != null && mDecor.mPrimaryActionMode != null) || (st == null)) {
return;
}
boolean playSoundEffect = false;
if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu() && !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) {
if (!mDecorContentParent.isOverflowMenuShowing()) {
if (!isDestroyed() && preparePanel(st, event)) {
playSoundEffect = mDecorContentParent.showOverflowMenu();
}
} else {
playSoundEffect = mDecorContentParent.hideOverflowMenu();
}
} else {
if (st.isOpen || st.isHandled) {
// Play the sound effect if the user closed an open menu (and not if
// they just released a menu shortcut)
playSoundEffect = st.isOpen;
// Close menu
closePanel(st, true);
} else if (st.isPrepared) {
boolean show = true;
if (st.refreshMenuContent) {
// Something may have invalidated the menu since we prepared it.
// Re-prepare it to refresh.
st.isPrepared = false;
show = preparePanel(st, event);
}
if (show) {
// Write 'menu opened' to event log
EventLog.writeEvent(50001, 0);
// Show menu
openPanel(st, event);
playSoundEffect = true;
}
}
}
if (playSoundEffect) {
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
} else {
Log.w(TAG, "Couldn't get audio manager");
}
}
}
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class SettingsHelper method applyAudioSettings.
/**
* Informs the audio service of changes to the settings so that
* they can be re-read and applied.
*/
void applyAudioSettings() {
AudioManager am = new AudioManager(mContext);
am.reloadAudioSettings();
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class VibratorService method shouldVibrateForRingtone.
private boolean shouldVibrateForRingtone() {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int ringerMode = audioManager.getRingerModeInternal();
// "Also vibrate for calls" Setting in Sound
if (Settings.System.getInt(mContext.getContentResolver(), Settings.System.VIBRATE_WHEN_RINGING, 0) != 0) {
return ringerMode != AudioManager.RINGER_MODE_SILENT;
} else {
return ringerMode == AudioManager.RINGER_MODE_VIBRATE;
}
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class HdmiControlService method setAudioStatus.
void setAudioStatus(boolean mute, int volume) {
AudioManager audioManager = getAudioManager();
boolean muted = audioManager.isStreamMute(AudioManager.STREAM_MUSIC);
if (mute) {
if (!muted) {
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
}
} else {
if (muted) {
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
}
// FLAG_HDMI_SYSTEM_AUDIO_VOLUME prevents audio manager from announcing
// volume change notification back to hdmi control service.
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_HDMI_SYSTEM_AUDIO_VOLUME);
}
}
Aggregations