2012-03-21 139 views
0

黑莓流音频/ STOP流

我是新手在编程和有问题。

我的代码:

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

而不是做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()

因为当音量键按下,你将需要改变音量:

  1. 实现一个KeyListener执行操作时,侧面的音量键按下
  2. 获取播放机的VolumeControlplayer.getControl("VolumeControl");
  3. 更新VolumeControl与新希望的体积
+0

非常感谢您对uour响应:)按“停止按钮”时,我有循环问题不停止这是一个beta OTA应用程序:http://goo.gl/EnPXH – kris 2012-03-26 16:33:25