PlayerListener.CLOSED
import javax.microedition.lcdui.StringItem;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import javax.microedition.media.control.VolumeControl;
public class EventHandler implements PlayerListener {
private StringItem item;
public EventHandler(StringItem item) {
this.item = item;
}
public void playerUpdate(Player player, String event, Object eventData) {
if (event == (PlayerListener.VOLUME_CHANGED)) {
VolumeControl vc = (VolumeControl) eventData;
updateDisplay("Volume Changed to: " + vc.getLevel());
if (vc.getLevel() > 60) {
updateDisplay("Volume higher than 60 is too loud");
vc.setLevel(60);
}
} else if (event == (PlayerListener.STOPPED)) {
updateDisplay("Player paused at: " + (Long) eventData);
} else if (event == (PlayerListener.STARTED)) {
updateDisplay("Player started at: " + (Long) eventData);
} else if (event == (PlayerListener.END_OF_MEDIA)) {
updateDisplay("Player reached end of loop.");
} else if (event == (PlayerListener.CLOSED)) {
updateDisplay("Player closed.");
} else if (event == (PlayerListener.ERROR)) {
updateDisplay("Error Message: " + (String) eventData);
}
}
public void updateDisplay(String text) {
item.setText(text);
System.err.println(text);
}
}
Related examples in the same category