2012-03-14 88 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