External volume keys

From S60 3rd Edition Feature Pack 2 and Series 40 5th Edition Feature Pack 1 onwards, external volume buttons can be used to change the volume level of MMAPI players in mobile devices that have the volume buttons present.

External volume keys control global volume, and VolumeControl controls the MIDlet’s own volume. The actual volume that is heard by the user is the VolumeControl's proportion of global volume. For example, if the global volume is 6 on a scale of 1-10, and VolumeControl is 50, the resulting output volume is 3.

The keys work when a MIDlet that uses MMAPI is on foreground. They change the volume level for MMAPI Players globally, that is, the volume level of every Player in every MIDlet is altered.

The external keys do not send normal VOLUME_CHANGED events. Instead, a Nokia proprietary event is used to notify the MIDlet when volume is changed. The notification is made via PlayerListener.playerUpdate(eventData) callback with the event com.nokia.external.volume.Event.

On Series 40 devices, a visible indicator is shown to the user when volume is adjusted by using external volume keys.

For more information about volume control, see article MIDlet volume control in Series 40 and S60 devices in the Nokia Developer Wiki.

The event can be decoded to know the current global volume level as shown below:

// Effective volume considering both midlet volume and global volume
int actualVolume = 0;
int globalVolume = 0;

public void playerUpdate(Player p, String event, Object eventData) { 
  // get the current midlet volume level
  int midletVolume = vc.getLevel();

  if(event.equals("com.nokia.external.volume.Event")) {
     // get the current global volume level
     globalVolume = Integer.parseInt(eventData.toString());
  }

  // This event is generated when midlet volume level is changed
  if(event.equals("volumeChanged")) {
    midletVolume = vc.getLevel();
  }
  
  actualVolume = (globalVolume/100) * midletVolume; 
}