2012-03-14 3 views
0

비디오 화면이 필요하고 비디오 재생 아래에 아래와 같이 두 줄의 텍스트를 표시하고 싶습니다. 나는 다음과 같은 코드를 사용하고이를 위해텍스트 디스플레이 문제가있는 Blackberry 비디오

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을 사용하는 것입니다. 대안 솔루션을 레이아웃하는 것하고 직접 자식 필드를 위치 :

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


편집 : 대신 LabelField의 직접 추가

, 다음과 같은 방법으로 추가합니다. 이렇게하려면 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