use of android.media.AudioManager in project CameraView by CJT2325.
the class AudioUtil method setAudioManage.
public static void setAudioManage(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
}
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));
}
});
}
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 Gadgetbridge by Freeyourgadget.
the class GBMusicControlReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
GBDeviceEventMusicControl.Event musicCmd = GBDeviceEventMusicControl.Event.values()[intent.getIntExtra("event", 0)];
int keyCode = -1;
int volumeAdjust = AudioManager.ADJUST_LOWER;
switch(musicCmd) {
case NEXT:
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
break;
case PREVIOUS:
keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
break;
case PLAY:
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY;
break;
case PAUSE:
keyCode = KeyEvent.KEYCODE_MEDIA_PAUSE;
break;
case PLAYPAUSE:
keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
break;
case VOLUMEUP:
// change default and fall through, :P
volumeAdjust = AudioManager.ADJUST_RAISE;
case VOLUMEDOWN:
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, volumeAdjust, 0);
break;
default:
return;
}
if (keyCode != -1) {
Prefs prefs = GBApplication.getPrefs();
String audioPlayer = prefs.getString("audio_player", "default");
long eventtime = SystemClock.uptimeMillis();
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
if (!"default".equals(audioPlayer)) {
downIntent.setPackage(audioPlayer);
}
context.sendOrderedBroadcast(downIntent, null);
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
if (!"default".equals(audioPlayer)) {
upIntent.setPackage(audioPlayer);
}
context.sendOrderedBroadcast(upIntent, null);
}
}
use of android.media.AudioManager in project AndroidChromium by JackyAndroid.
the class TabWebContentsDelegateAndroid method handleMediaKey.
/**
* Redispatches unhandled media keys. This allows bluetooth headphones with play/pause or
* other buttons to function correctly.
*/
@TargetApi(19)
private void handleMediaKey(KeyEvent e) {
if (Build.VERSION.SDK_INT < 19)
return;
switch(e.getKeyCode()) {
case KeyEvent.KEYCODE_MUTE:
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_NEXT:
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
case KeyEvent.KEYCODE_MEDIA_REWIND:
case KeyEvent.KEYCODE_MEDIA_RECORD:
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
case KeyEvent.KEYCODE_MEDIA_CLOSE:
case KeyEvent.KEYCODE_MEDIA_EJECT:
case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
AudioManager am = (AudioManager) mTab.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
am.dispatchMediaKeyEvent(e);
break;
default:
break;
}
}
Aggregations