Tip: How to control the media volume with keys on Android


#1

If the sound volume is too low and the volume buttons control the phone volume not the media volume add this to your activity onCreate and you will be OK: this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
Maybe the MODIFY_AUDIO_SETTINGS permission is needed too.


#2

Thanks for the tip man. Will try and see if it works for me.


#3

Thanks! It works for me!


#4

Thanks man!

And for all that came from C++ and are new to Java here is the complete solution.
The file (in cocos2d-x v3.6) is located here:

YourProject/proj.android/src/org/cocos2dx/cpp/AppActivity.java

And I think that after the necessary changes it should look like this.
Please Java experts correct me if I am wrong…

package org.cocos2dx.cpp;

import org.cocos2dx.lib.Cocos2dxActivity;
import android.os.Bundle;
import android.media.AudioManager;

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