Skip to content

Commit

Permalink
fix volume override for android N
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Apr 21, 2017
1 parent 893a9cd commit fad62c9
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;

import static android.os.Build.VERSION.SDK;
import static android.os.Build.VERSION.SDK_INT;

/**
* Created by the-scrabi on 27.09.15.
*
Expand Down Expand Up @@ -187,7 +190,14 @@ private MediaPlayer setupNewMediaPlayer(Alarm alarm) {
boolean overrideVolume = PreferenceManager.getDefaultSharedPreferences(this)
.getBoolean(getString(R.string.overrideAlarmVolume), false);
if(overrideVolume) {
mediaPlayer.setVolume(1.0f, 1.0f);
if(SDK_INT >= 21) {
AudioManager audioManager =
(AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVol = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVol, 0);
} else {
mediaPlayer.setVolume(1.0f, 1.0f);
}
}
mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mediaPlayer.setLooping(true);
Expand Down

0 comments on commit fad62c9

Please sign in to comment.