Domanda

Ho bisogno di uno schermo video e sotto il video play, voglio mostrare due righe di testo come sotto.

Visualizza modello

Per quello che sto usando il seguente codice.

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

Ora ciò che è può essere l'altezza del video, la vista sta prendendo scorrimento e il testo è visibile solo dopo lo scorrimento.Sto usando un dispositivo di dimensioni dello schermo 320x240px.Ho persino provato con un video di 320x150px.Ma il testo non è visibile senza scorrere, anche se c'è un sacco di spazio libero sopra e inferiore del video.Qual è il problema nel mio codice?Come risolverlo?

È stato utile?

Soluzione

Ci sono diversi modi per risolvere il tuo problema.Il più semplice nel tuo caso è usare il Mainscreen # setstatus che imposta il contenuto della sezione di stato della schermata.

Invece di aggiungere direttamente i LabelFields, aggiungerli nel modo seguente:

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



Modifica: Una soluzione alternativa sarebbe il layout e posizionare il campo figlio da solo.Per fare ciò, è possibile scadere sublayout() del playvideoScreen o introdurre un altro gestore (VerticalFieldManager), aggiungere tutti i campi (video ed etichette) e sovrascrivere il suo metodo sublayout().

Di seguito è il tuo codice con le modifiche sopra menzionate

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());
    }
}
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top