2012-03-14 68 views
0

我需要一個視頻屏幕,在視頻播放下,我想顯示兩行文字,如下所示。帶有文本顯示的黑莓視頻概率

model view

對於我使用下面的代碼。

public final class PlayVideoScreen extends MainScreen { 
    private Player player; 
    private VideoControl videoControl; 

    public PlayVideoScreen() { 

     // ms.setTitle(new LabelField("Let's play some video...")); 
     LabelField lf = new LabelField("Video Play"); 

     try { 
      // Create a new Player pointing to the video file. 
      // This can use any valid URL. 
      player = javax.microedition.media.Manager 
        .createPlayer("file:///SDCard/BlackBerry/videos/sample.avi"); 

      player.realize(); 

      // Create a new VideoControl. 
      videoControl = (VideoControl) player.getControl("VideoControl"); 
      // Initialize the video mode using a Field. 
      Field videoField = (Field) videoControl.initDisplayMode(
        VideoControl.USE_GUI_PRIMITIVE, 
        "net.rim.device.api.ui.Field"); 

      add(videoField); 

      VolumeControl volume = (VolumeControl) player 
        .getControl("VolumeControl"); 
      volume.setLevel(30); 


      player.start(); 

      // Set the video control to be visible. 
      // videoControl.setVisible(true); 
     } catch (MediaException me) { 
      Dialog.alert(me.toString()); 
     } catch (IOException ioe) { 
      Dialog.alert(ioe.toString()); 
     } 

     add(lf); 

     LabelField lf2 = new LabelField("How r you?"); 

     add(lf2); 
    } 

    public boolean onClose() { 
     // Clean up the player resources. 
     player.close(); 
     videoControl.setVisible(false); 
     close(); 
     return true; 
    } 
} 

現在什麼是可能的視頻高度,視圖正在滾動和文本只有在滾動後纔可見。我正在使用屏幕尺寸爲320X240像素的設備。我甚至用320X150像素的視頻進行測試。但是如果沒有滾動,文字就不可見,儘管視頻上方和下方都有很多可用空間。我的代碼中有什麼問題?如何解決它?

回答

1

有幾種方法可以解決您的問題。在你的情況最簡單的是使用MainScreen#setStatus它設置此屏幕的狀態部分的內容。

,而不是添加LabelField小號直接的,添加它們以下列方式:

VerticalFieldManager vfm = new VerticalFieldManager(); 
vfm.add(lf); 
vfm.add(lf2); 
setStatus(vfm); 


編輯:另一種解決辦法是佈局和自己定位子字段。爲此,您可以覆蓋PlayVideoScreen的sublayout()或引入另一個管理器(VerticalFieldManager),將所有字段(視頻和標籤)添加到它並覆蓋其sublayout()方法。

下面是與上述修改

public PlayVideoScreen() { 
    super(NO_VERTICAL_SCROLL); 

    // ms.setTitle(new LabelField("Let's play some video...")); 
    final LabelField lf = new LabelField("Video Play"); 

    try { 
     // Create a new Player pointing to the video file. 
     // This can use any valid URL. 
     player = javax.microedition.media.Manager 
       .createPlayer("file:///SDCard/BlackBerry/videos/sample.avi"); 

     player.realize(); 

     // Create a new VideoControl. 
     videoControl = (VideoControl) player.getControl("VideoControl"); 
     // Initialize the video mode using a Field. 
     final Field videoField = (Field) videoControl.initDisplayMode(
      VideoControl.USE_GUI_PRIMITIVE, 
      "net.rim.device.api.ui.Field"); 

      VolumeControl volume = (VolumeControl) player 
        .getControl("VolumeControl"); 
     volume.setLevel(30); 

     player.start(); 

     // Set the video control to be visible. 
     // videoControl.setVisible(true); 

     final LabelField lf2 = new LabelField("How r you?"); 

     VerticalFieldManager vfm = new VerticalFieldManager(NO_VERTICAL_SCROLL) { 
      protected void sublayout(int maxWidth, int maxHeight) { 
       int heightLeft = maxHeight; 

       // layout the children fields 
       layoutChild(lf, maxWidth, heightLeft); 
       heightLeft -= lf.getHeight(); 

       layoutChild(lf2, maxWidth, heightLeft); 
       heightLeft -= lf2.getHeight(); 

       layoutChild(videoField, maxWidth, heightLeft); 

       // position the children fields 
       int yPos = 0; 
       setPositionChild(videoField, 0, yPos); 
       yPos += videoField.getHeight(); 

       setPositionChild(lf, 0, yPos); 
       yPos += lf.getHeight(); 

       setPositionChild(lf2, 0, yPos); 

       setExtent(maxWidth, maxHeight); 
      }; 
     }; 
     vfm.add(videoField); 
     vfm.add(lf); 
     vfm.add(lf2); 

     add(vfm); 

    } catch (MediaException me) { 
     Dialog.alert(me.toString()); 
    } catch (IOException ioe) { 
     Dialog.alert(ioe.toString()); 
    } 
} 
+0

我想你的方式你的代碼。現在視頻和標籤同時顯示,但視頻不可見,只顯示白色塊,並且音頻在後臺播放。只要我向上滾動並且標籤不在屏幕上,視頻就會變得可見,即當標籤出現在屏幕中時,視頻停止移動。 – 2012-03-15 05:24:18

+0

@dalandroid檢查我的更新答案 – mrvincenzo 2012-03-15 11:30:38