2012-03-21 135 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