Karry
Karry

Reputation: 153

How do you show a video in it's correct dimensions in codenameOne?

I am displaying videos on a form but the video is always stretched to a square. I can't get hold of any video component to get it's true size. This is the code to display video:

   imageVideoContainer = new Container(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE)) {
        protected Dimension calcPreferredSize() {
            return new Dimension(Display.getInstance().getDisplayWidth(), Display.getInstance().getDisplayWidth());
        }
    };
    media = MediaManager.createMedia(FileSystemStorage.getInstance().getAppHomePath() + movePath, true);
    mp = new MediaPlayer(media);
    mp.setAutoplay(true);
    imageVideoContainer.add(BorderLayout.CENTER, mp);
    container = new Container(new BoxLayout(BoxLayout.Y_AXIS));
    container.add(BorderLayout.centerAbsolute(imageVideoContainer));

If I don't overwrite the calcPreferredSize it doesn't display at all. Any help appreciated. I've tried debugging to look into Media Player to get something that has a size but can't find anything.

Upvotes: 1

Views: 75

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

The problem is that until the video is loaded the size isn't there. So when you add it to the form it's preferred size will be 0.

You then add it to center absolute which requires preferred size to position/size the video. A solution can be to start the video then call revalidate() to redo the layout and position the video correctly.

Upvotes: 0

Related Questions