0

I've got an app where Ii want to sound the alarm ringtone and raise the volume each second.

audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
player = MediaPlayer.create(getApplicationContext(), RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM));

After initializing AudioManager and MediaPlayer, I've got a method which is executed each second when some circumstances occur. The method is the next one:

private void sound() {
    if (!player.isPlaying()) {
        try {
            player.setLooping(true);
            player.setVolume(5,5);
        } catch (Exception e) {
            e.printStackTrace();
        }
        player.start();
    } else {
        audioManager.adjustStreamVolume(AudioManager.STREAM_NOTIFICATION,AudioManager.ADJUST_RAISE,0);
    }
}

As you can see, the first time the method is executed the sound begins, that works OK. But when is already started and I want to raise the volume, the adjustStreamVolume makes nothing.

Any help or advice?

Jon Zangitu
  • 957
  • 1
  • 15
  • 30

0 Answers0