How to embed the broadcast from the camera in the container in Codename1? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to embed the broadcast from the camera in the container in Codename1? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

In my application there is a video button. Here’s the code.

    @Override
    protected void onGUI1_Button1Action (Component c, ActionEvent event){


            try {
                String value = Capture.captureVideo();
                if (value != null) {
                    final Form previous = Display.getInstance().getCurrent();
                    Form preview = new Form("Preview");
                    preview.setLayout(new BorderLayout());
                    MediaPlayer pl = new MediaPlayer();
                    if (!value.startsWith("file:/")) {
                        value = "file:/" + value;
                    }
                    pl.setDataSource(value);
                    preview.addComponent(BorderLayout.CENTER, pl);
                    preview.setBackCommand(new Command("Back") {
                        public void actionPerformed(ActionEvent evt) {
                            previous.showBack();
                        }
                    });
                    preview.show();
                }
            } catch (Exception ex) {
                Log.e(ex);
                Dialog.show("Error", "" + ex, "OK", null);
            }
        } 

I picked up this code from github. I don’t want to broadcast the video on full screen. I need a video from camera was built into some container. That container must cover only part of the screen. I have built a GUI and put a container(Media Player) into some part of screen. How to change the code for this purpose?

Answer

You can place a camera view finder right into your app with a new cn1lib: https://github.com/codenameone/CameraKitCodenameOne

Overlaying native widgets has been possible for a year or so by now.

Original answer which was correct when it was written is below:

Embedding camera or overlaying component on the preview screen is not yet available in codename one.

This could be done using native interface with peer component. Have a look at how Native map was implemented here

We are here to answer your question about How to embed the broadcast from the camera in the container in Codename1? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji