Question

My current code is this:

int volume = Alert.getVolume(); // reads 100
Alert.setVolume(0);

It DOESN'T change the volume setting, like it would be supposed to do Even calling Alert.mute(true); doesn't produce any good effect. Audio.setVolume(0); also doesn't work!

I am running this on a Curve 8310. I have another software installed though that successfully manages to lower the volume setting a lot. o I suppose I'm doing something wrong. Any idea ?

Was it helpful?

Solution

If you want to play sound with Alert:

class Scr extends MainScreen implements FieldChangeListener {    
 ButtonField mVolumeUp;
 ButtonField mVolumeDown;
 ButtonField mPlay;
 LabelField mVolumeLabel;
 int mVolumeValue = 50;
 private static final short[] tune = new short[] { 466, 125, 10, 466 };

 public Scr() {
 mVolumeLabel = new LabelField("Volume: " + mVolumeValue);
     add(mVolumeLabel);
     mVolumeUp = new ButtonField("Vol Up", ButtonField.CONSUME_CLICK);
     mVolumeUp.setChangeListener(this);
     add(mVolumeUp);
     mVolumeDown = new ButtonField("Vol Down", ButtonField.CONSUME_CLICK);
     mVolumeDown.setChangeListener(this);
     add(mVolumeDown);
     mPlay = new ButtonField("Play", ButtonField.CONSUME_CLICK);
     mPlay.setChangeListener(this);
     add(mPlay);
 }

 public void fieldChanged(Field field, int context) {
     if (mVolumeUp == field) {
         if (mVolumeValue <= 90)
      mVolumeValue += 10;
      mVolumeLabel.setText("Volume: " + mVolumeValue);
  } else if (mVolumeDown == field) {
      if (mVolumeValue >= 10)
   mVolumeValue -= 10;
      mVolumeLabel.setText("Volume: " + mVolumeValue);
  } else if (mPlay == field) {
      Alert.startAudio(tune, mVolumeValue);
     }
 }
}

Tested on RIM 4.5 8310 simulator

OTHER TIPS

If you're using the class javax.microedition.lcdui.Alert, that may be your problem. Try taking a look at the net.rim.device.api.notification.NotificationsManager class and its other package classes/interfaces.

Though the simple/polite way is just to ask the user to change the user profiles manually. If I set my blackberry to silent and some application makes a crazy noise (or doesn't make a noise at all if I'm expecting an important call), I'll be removing that application asap.

Certain functions on the blackberry (but not the emulator) only work with signed code. I'm not sure if it is the case for volume, but I wouldn't be surprised when it was.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top