Search in sources :

Example 56 with AudioManager

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);
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 57 with AudioManager

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;
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 58 with AudioManager

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();
}
Also used : AudioManager(android.media.AudioManager) Ringtone(android.media.Ringtone)

Example 59 with AudioManager

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);
}
Also used : AssetFileDescriptor(android.content.res.AssetFileDescriptor) NotificationManager(android.app.NotificationManager) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) IOException(java.io.IOException) Notification(android.app.Notification) AudioManager(android.media.AudioManager) PendingIntent(android.app.PendingIntent) MediaPlayer(android.media.MediaPlayer)

Example 60 with AudioManager

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));
        }
    });
}
Also used : AudioManager(android.media.AudioManager) SharedPreferences(android.content.SharedPreferences) Resources(android.content.res.Resources)

Aggregations

AudioManager (android.media.AudioManager)157 MediaPlayer (android.media.MediaPlayer)49 AudioEffect (android.media.audiofx.AudioEffect)42 LargeTest (android.test.suitebuilder.annotation.LargeTest)42 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 Context (android.content.Context)8 IOException (java.io.IOException)7 Intent (android.content.Intent)6 Cea708CaptionRenderer (android.media.Cea708CaptionRenderer)5 ClosedCaptionRenderer (android.media.ClosedCaptionRenderer)5 MediaFormat (android.media.MediaFormat)5 Ringtone (android.media.Ringtone)5 SubtitleController (android.media.SubtitleController)5 TtmlRenderer (android.media.TtmlRenderer)5 WebVttRenderer (android.media.WebVttRenderer)5 InputStream (java.io.InputStream)5 PowerManager (android.os.PowerManager)4 Vibrator (android.os.Vibrator)4 SurfaceHolder (android.view.SurfaceHolder)4 SurfaceView (android.view.SurfaceView)4