)
我是编程新手并且有问题。
我的代码:
choiceFieldANTYFM = new ObjectChoiceField("Wybierz stację(6)", new String[]{"Warszawa [96kb]"});
choiceFieldANTYFM.setChangeListener(this);
btnSelectantyfm = new ButtonField("Słuchaj!", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
btnSelectantyfm.setChangeListener(this);
stopplaying = new ButtonField("STOP", FIELD_HCENTER | ButtonField.CONSUME_CLICK);
stopplaying.setChangeListener(this);
add(choiceFieldANTYFM);
add(btnSelectantyfm);
add(stopplaying);
和其他:
public void fieldChanged(Field field, int context) {
if (field == btnSelectantyfm)
{
System.out.println("Selected item: " + Integer.toString(choiceField.getSelectedIndex()));
}if (field == btnSelect)
{
switch (choiceField.getSelectedIndex())
{
case 0:
try {
String url = "http://94.23.220.75:6000;deviceside=false;ConnectionUID=GPMDSEU01";
Player player;
player = javax.microedition.media.Manager.createPlayer(url);
player.start();
}
catch (Exception e) {
Dialog.alert(e.toString());
}
break;
好的,当我推播时它会在应用程序中播放音乐。
当它再次推回时。这是第二个问题:)
我想在按下停止按钮时停止流,即使可以更改音量键+和 - :)
JDE 5.0:)
问候。
答案 0 :(得分:0)
而不是btnSelectantyfm.setChangeListener(this);
暗示您的屏幕正在实施FieldChangeListener
,而是为每个按钮声明单独的FieldChangeListener
个对象,如下所示:
btnSelectantyfm.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//start playing code here
player.start();
}
});
stopplaying.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context){
//stop playing code here
player.stop();
}
});
现在您需要将Player
对象声明为成员变量,以便播放和暂停FieldChangeListeners可以访问它。要停止播放播放器,请执行player.stop()
。
要在按下音量键时更改音量,您需要:
KeyListener
以在按下侧音量键时执行操作VolumeControl
player.getControl("VolumeControl");
VolumeControl
醇>