Question

I need a video screen and under the video play, I want to show two lines of text like below.

model view

For that I am using following code.

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

Now what is may be the height of video, the view is taking scroll and the text is only visible after scrolling. I am using a device of screen size 320X240px. I have even test with a video of 320X150px. But the text is not visible without scrolling, although there is lots of free space above and bottom of the video. What is problem in my code? How to solve it?

Was it helpful?

Solution

There are several ways to solve your issue. The easiest in your case is to use the MainScreen#setStatus which sets the contents of this screen's status section.

Instead of adding the LabelFields directly, add them in the following way:

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


EDIT: An alternative solution would be to layout and positions the child field by yourself. In order to do so, you can override sublayout() of the PlayVideoScreen or introduce another manager (VerticalFieldManager), add all fields (video and labels) to it and override its sublayout() method.

Below is your code with the aforementioned modifications

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());
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top