2012-03-14 6 views
0

私はビデオ画面が必要で、ビデオプレイの下では、以下のように2行のテキストを表示したいと考えています。私は、次のコードを使用していますそのためにブラックベリービデオとテキスト表示のプローブ

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); 


EDIT:代替ソリューションは、自分で子フィールドをレイアウトして位置するだろうし。これを行うには、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

とあなたのコードです。ビデオとラベルは同時に表示されますが、ビデオは表示されず、白いブロックのみが表示され、オーディオはバックグラウンドで再生されます。上にスクロールしてラベルが画面外に出るとすぐに、動画が表示されます。つまり、ラベルが画面に表示されると、動画は停止します。 –

+0

@dalandroid更新された回答を確認する – mrvincenzo

関連する問題