How to get external volume buttons events
Article Metadata
External volume buttons
From S60 3rd Edition FP 2 onwards, external volume buttons can be used to change the volume level of MMAPI players in mobile devices that have the volume buttons present.
The buttons work in this way 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.
A Nokia proprietary event is used to notify the MIDlet when volume is changed with External volume keys. The notification is made via PlayerListener.playerUpdate(Evendata) callback with the event com.nokia.external.volume.Event.
Code Sample
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;
}


26 Sep
2009
It becomes most important to get updated with new technology.As this article name suggest that How to get External Media Buttons Events. Now a days all devices having external buttons. The external buttons working are explained clearly.MIDlet change the volume level globally so all the players will be affected.Nokia has developed unique event for its devices to notify the MIDlet when volume is changed.
Code Example on how to get notified while external volume buttons are pressed is written perfectly and code works fine without errors.Code is easy to understand and implement.
Skalogir - Correction
The correct event name when modifying the volume is
com.nokia.external.volume.event
not
com.nokia.external.volume.Event
I have updated the code accordingly. Unfortunately I don't get a volumeChanged event in neither S60 3rd Edition FP2 (E52), nor Nokia Belle (PureView 808).skalogir 15:23, 22 August 2012 (EEST)