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);
}
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class VolumeControlAction method shouldUpdateAudioVolume.
private boolean shouldUpdateAudioVolume(boolean mute) {
// Do nothing if in mute.
if (mute) {
return true;
}
// Update audio status if current volume position is edge of volume bar,
// i.e max or min volume.
AudioManager audioManager = tv().getService().getAudioManager();
int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
if (mIsVolumeUp) {
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
return currentVolume == maxVolume;
} else {
return currentVolume == 0;
}
}
use of android.media.AudioManager in project android_frameworks_base by ResurrectionRemix.
the class PhoneWindowManager method performAuditoryFeedbackForAccessibilityIfNeed.
private void performAuditoryFeedbackForAccessibilityIfNeed() {
if (!isGlobalAccessibilityGestureEnabled()) {
return;
}
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.isSilentMode()) {
return;
}
Ringtone ringTone = RingtoneManager.getRingtone(mContext, Settings.System.DEFAULT_NOTIFICATION_URI);
ringTone.setStreamType(AudioManager.STREAM_MUSIC);
ringTone.play();
}
use of android.media.AudioManager in project Aegis by Decad3nce.
the class AlarmService method alarmNotification.
@SuppressWarnings("deprecation")
private void alarmNotification(Context context) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
NotificationManager mManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, context.getResources().getString(R.string.receiver_alarm_override), System.currentTimeMillis());
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean vibrate = preferences.getBoolean(SMSAlarmFragment.PREFERENCES_ALARM_VIBRATE, Boolean.parseBoolean(context.getResources().getString(R.string.config_default_alarm_vibrate)));
int duration = Integer.parseInt(preferences.getString(SMSAlarmFragment.PREFERENCES_ALARM_DURATION, getResources().getString(R.string.config_default_alarm_duration)));
int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, maxVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_RING);
am.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Intent i = new Intent(context, AlarmService.class);
i.putExtra("stop", true);
PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
notification.setLatestEventInfo(context, "aeGis", context.getResources().getString(R.string.receiver_alarm_override), pi);
;
if (vibrate) {
notification.vibrate = new long[] { 100, 200, 100, 500 };
}
AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.alarm);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(true);
try {
mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mMediaPlayer.prepare();
} catch (IOException e) {
stopForeground(true);
mMediaPlayer.release();
return;
}
mMediaPlayer.start();
// Set duration time-out
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
stopMediaPlayer();
stopForeground(true);
}
}, duration * 1000);
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(1242, notification);
}
use of android.media.AudioManager in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class AdvancedSettingsFragment method setupKeypressSoundVolumeSettings.
private void setupKeypressSoundVolumeSettings() {
final SeekBarDialogPreference pref = (SeekBarDialogPreference) findPreference(Settings.PREF_KEYPRESS_SOUND_VOLUME);
if (pref == null) {
return;
}
final SharedPreferences prefs = getSharedPreferences();
final Resources res = getResources();
final AudioManager am = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
pref.setInterface(new SeekBarDialogPreference.ValueProxy() {
private static final float PERCENTAGE_FLOAT = 100.0f;
private float getValueFromPercentage(final int percentage) {
return percentage / PERCENTAGE_FLOAT;
}
private int getPercentageFromValue(final float floatValue) {
return (int) (floatValue * PERCENTAGE_FLOAT);
}
@Override
public void writeValue(final int value, final String key) {
prefs.edit().putFloat(key, getValueFromPercentage(value)).apply();
}
@Override
public void writeDefaultValue(final String key) {
prefs.edit().remove(key).apply();
}
@Override
public int readValue(final String key) {
return getPercentageFromValue(Settings.readKeypressSoundVolume(prefs, res));
}
@Override
public int readDefaultValue(final String key) {
return getPercentageFromValue(Settings.readDefaultKeypressSoundVolume(res));
}
@Override
public String getValueText(final int value) {
if (value < 0) {
return res.getString(R.string.settings_system_default);
}
return Integer.toString(value);
}
@Override
public void feedbackValue(final int value) {
am.playSoundEffect(AudioManager.FX_KEYPRESS_STANDARD, getValueFromPercentage(value));
}
});
}
Aggregations