0

I have a google-tv application that should play some sort of media (hls)
i am trying to control the volume but thought it is not working i am using the following code in the oncreate:
setVolumeControlStream(AudioManager.STREAM_MUSIC);

and then when trying to modify the volume: audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumedown, AudioManager.FLAG_SHOW_UI);
where volumedown is the desired new volumne. the volumne control is appearing on the screen and moving forward and backward but the volume is not functional.
can anyone tell me what is wrong with that and how could i solve this issue?

S.Najjar
  • 65
  • 1
  • 9
  • Have you set the android.permission.MODIFY_AUDIO_SETTINGS permission? – brimil01 Nov 16 '12 at 16:22
  • Have you configured the audio device for your Google TV device? It could be the TV or an AVR. You can confirm this is correct by using the Google TV Remote app and changing the volume with the mobile physical volume buttons. – Leon Nicholls Nov 16 '12 at 16:27

1 Answers1

1

Try this, works for me

@Override
public void VolumeUp()
{
    AudioManager audioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
    int actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume + 1, AudioManager.FLAG_SHOW_UI);
}

// Decrease volume
@Override
public void VolumeDown()
{
    AudioManager audioManager = (AudioManager) getSystemService(getApplicationContext().AUDIO_SERVICE);
    int actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, actualVolume - 1, AudioManager.FLAG_SHOW_UI);
}
Hruskozrout
  • 569
  • 6
  • 23