1

I'm making an Android-only React Native app displaying audio.

I want users to be able to change their media volume while in the app instead of the default ringtone volume when pressing hardware buttons.

Is this possible using React Native only or do I have to bridge some native module, something like this ?

Antoine Auffray
  • 1,283
  • 1
  • 17
  • 33

1 Answers1

0

I made it work by adding this Android code to the MainActivity.java in my native Android code:

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

This makes the whole app use the media volume slider by default when pressing hardware volume buttons.

Antoine Auffray
  • 1,283
  • 1
  • 17
  • 33