Search code examples
java-me

J2ME: How to set a volume of media?


I would like to know how to change, or set value to the media volume, I am currently making a game, that will use the audio volume changing.

It seems to me, that you need to use javax.microedition.media.Control, but I don't know how to use this library at all.

Please answer, I will be very grateful.


Solution

  • You must use VolumeControl https://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/media/control/VolumeControl.html

    import javax.microedition.media.control.*;
    
    VolumeControl vc = null;
    
    try {
      vc = (VolumeControl) yourPlayerObject.getControl("VolumeControl");
      vc.setLevel(80);
    } catch (Exception e) {}
    

    Levels goes from 0 to 100.