0

ビデオ画面が必要で、ビデオ再生の下に、以下のような 2 行のテキストを表示したいと考えています。

モデル ビュー

そのために、次のコードを使用しています。

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

ビデオの高さである可能性があります。ビューはスクロールしており、テキストはスクロール後にのみ表示されます。画面サイズ 320X240px のデバイスを使用しています。320X150px のビデオでもテストしました。ただし、ビデオの上下には多くの空きスペースがありますが、スクロールしないとテキストは表示されません。私のコードの問題は何ですか? それを解決する方法は?

4

1 に答える 1

1

問題を解決するにはいくつかの方法があります。あなたのケースで最も簡単なのは、この画面のステータスセクションの内容を設定するMainScreen#setStatusを使用することです。

s を直接追加する代わりにLabelField、次の方法で追加します。

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


編集:別の解決策は、子フィールドを自分でレイアウトして配置することです。そのためにはsublayout()、PlayVideoScreen をオーバーライドするか、別のマネージャー ( 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());
    }
}
于 2012-03-14T15:26:21.333 に答える