×

Discussion Board

Results 1 to 3 of 3

Thread: camera and eSWT

  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Sweden, Stockholm
    Posts
    90

    camera and eSWT

    Hi,
    I Need some help, I don't know what i wrong, but I know my application crash because of takePicture().
    I have eSWT UI thread, in my application I also have a Controller class. The Camera UI is open like this:
    Code:
    testDryckListUI.setVisible(false);
    snapperUI.initialize();
    snapperUI.open();
    The snapperUI look like this:
    Code:
    package se.ojn.xxx.ui;
    
    
    import java.io.IOException;
    import javax.microedition.lcdui.Image;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    import javax.microedition.media.control.GUIControl;
    import javax.microedition.media.control.VideoControl;
    import org.eclipse.ercp.swt.mobile.Command;
    import org.eclipse.ercp.swt.mobile.TimedMessageBox;
    import org.eclipse.swt.SWT;
    import org.eclipse.swt.events.SelectionEvent;
    import org.eclipse.swt.events.SelectionListener;
    import org.eclipse.swt.graphics.Rectangle;
    import org.eclipse.swt.layout.FillLayout;
    import org.eclipse.swt.layout.FormLayout;
    import org.eclipse.swt.widgets.Composite;
    import org.eclipse.swt.widgets.Control;
    import org.eclipse.swt.widgets.Display;
    import org.eclipse.swt.widgets.Item;
    import org.eclipse.swt.widgets.Shell;
    import se.ojn.provning.util.Controller;
    import se.ojn.provning.util.EventID;
    import se.ojn.provning.util.UIConstant;
    
    
    public class SnapperUI implements SelectionListener {
    
    private static SnapperUI instance;
    
    static {
    		instance = new SnapperUI();
    	}
        private Shell snapperShell;
        private Composite snapperComposite;
        private VideoControl videoControl;
        private Player mPlayer;
        private VideoControl mVideoControl;
        private Image image;
        private Command takePictureCommand;
        private Command exitCommand;
        private Item item;
        
    public SnapperUI() {
    		//initialize();
    	}
    
    public static SnapperUI getInstance() {
    		return instance;
    	}
    
    public void initialize(){
                
                snapperShell = new Shell(SWT.MAX);
                snapperShell.setText(UIConstant.INFO);
                snapperShell.setLayout(new FillLayout(SWT.VERTICAL));
                
    
                snapperComposite = new Composite(snapperShell, SWT.NONE);
                snapperComposite.setLayout(new FormLayout());
                snapperShell.layout();
    
                exitCommand = new Command(snapperShell, Command.EXIT, 0);
                exitCommand.setText("Exit");
                exitCommand.addSelectionListener(this);
    
                takePictureCommand = new Command(snapperShell, Command.GENERAL, 10);
                takePictureCommand.setText("Snap!");
                takePictureCommand.addSelectionListener(this);
                takePictureCommand.setDefaultCommand();
    
                startCamera();
    
                snapperComposite.layout();
    
                
    
    	}
    
    
    	public void reset() {
    	}
    
    	/**
    	 * Release the acquired system resources to the operating system.
    	 */
    	public void close() {
                if ((null != snapperShell) && (!snapperShell.isDisposed())) {
                        Display display = snapperShell.getDisplay();
                        snapperShell.dispose();
                        display.dispose();
                }
    
    	}
    
            public final void open(){
                //infoShell.setSize(240, 350);
                snapperShell.open();
                snapperShell.setActive();
                Display display = snapperShell.getDisplay();
                while (!snapperShell.isDisposed()) {
                        if (!display.readAndDispatch()) {
                                display.sleep();
                        }
                }
                display.dispose();
    	}
    
        public void widgetSelected(SelectionEvent arg0) {
            if(arg0.widget == takePictureCommand){
    			takePicture();
           if(arg0.widget.equals(exitCommand)){
                Controller.handleEvent(EventID.EXIT,null);
            }
            }
        }
    
        public void widgetDefaultSelected(SelectionEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        /**
         * Let the shell disappear from the screen or show on the screen.
         *
         */
        public void setVisible(boolean visible){
                snapperShell.setVisible(visible);
        }
    
        private void takePicture(){
    
    
               byte[] snapshot;
               try {
    
                    // Get the image.
                    //byte[] raw = mVideoControl.getSnapshot(null);
                    //byte[] raw = mVideoControl.getSnapshot("width=80&height=60");
                    //byte[] raw = mVideoControl.getSnapshot("width=160&height=120");
                    snapshot = mVideoControl.getSnapshot("width=240&height=180");
                    
                    image = Image.createImage(snapshot, 0, snapshot.length);
    
    
                    // Shut down the player.
                    mPlayer.close();
                    mPlayer = null;
                    mVideoControl = null;
                } catch (MediaException e) {
                    showMessage(e.toString());
                }
        }
    
        public void startCamera() {
            mPlayer = null;
    
            try {
                mPlayer = Manager.createPlayer("capture://video");
                //mPlayer = Manager.createPlayer("capture://image");
                mPlayer.realize();
                mPlayer.prefetch();
                mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
    
                /** No support for flash
                FlashControl flashCntrl =
                (FlashControl) mPlayer.getControl("javax.microedition.amms.control.camera.FlashControl");
                flashCntrl.setMode(FlashControl.AUTO);
                 */
    
                Control vControl = (Control) videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, Control.class.getName());
                vControl.setParent(snapperShell);
                
                Rectangle r = vControl.getBounds();
                videoControl.setDisplaySize(r.width, r.height);
                videoControl.setVisible(true);
                 
                /**
                item = (Item) mVideoControl.initDisplayMode(
                        GUIControl.USE_GUI_PRIMITIVE, null);
               */
                mPlayer.start();
            } catch (IOException ioe) {
                System.out.println("Error: " + ioe);
                showMessage(ioe.toString());
                //errorMessage = "Error: " + ioe;
                //throw new IOException(errorMessage);
            } catch (MediaException me) {
                System.out.println("Error: " + me);
                showMessage(me.toString());
                //errorMessage = "Error: " + me;
                //throw new MediaException(errorMessage);
            } catch (Exception me) {
                System.out.println("Error: " + me);
                showMessage(me.toString());
                //errorMessage = "Error: " + me;
                //throw new Exception(errorMessage);
            }
        }
    
        private void showMessage(String message){
            TimedMessageBox box = new TimedMessageBox(snapperShell, SWT.ICON_ERROR);
            box.setMessage(message);
            box.open();
        }
    
    }

  2. #2
    Nokia Developer Expert
    Join Date
    Nov 2008
    Posts
    72

    Re: camera and eSWT

    There may be two problems here.
    (1) You are referencing to LCDUI image on the imports. This may cause problems during start up.
    (2) Also It looks like you have two VideoControl and one of them is probably not initialized corectly.
    --
    Gorkem

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Sweden, Stockholm
    Posts
    90

    Re: camera and eSWT

    Thanks I have now change what you found was wrong in my code.
    But it don't work anyway.

    My big big problem is the Nokia N97 SDK 1.0 emulator, it crash after a while when I run it, so I can't use it when develop eSWT applications.
    So I have to develop my application and then test it on my Nokia E75, this make it hard to find problems in the code

    I know where the problem is in the code, it is because of startCamera(), the code now look like this:
    Code:
    public void startCamera() {
            mPlayer = null;
            try {
                mPlayer = Manager.createPlayer("capture://video");
                mPlayer.realize();         
                mVideoControl = (VideoControl) mPlayer.getControl("VideoControl");
                Control vControl = (Control) mVideoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, Control.class.getName());
                vControl.setParent(snapperShell);
                Rectangle r = vControl.getBounds();
                mVideoControl.setDisplaySize(r.width, r.height);
                mVideoControl.setVisible(true);
                mPlayer.start();
            } catch (IOException ioe) {
                System.out.println("Error: " + ioe);
                showMessage(ioe.toString());
                //errorMessage = "Error: " + ioe;
                //throw new IOException(errorMessage);
            } catch (MediaException me) {
                System.out.println("Error: " + me);
                showMessage(me.toString());
                //errorMessage = "Error: " + me;
                //throw new MediaException(errorMessage);
            } catch (Exception me) {
                System.out.println("Error: " + me);
                showMessage(me.toString());
                //errorMessage = "Error: " + me;
                //throw new Exception(errorMessage);
            }
        }
    
        private void showMessage(String message){
            TimedMessageBox box = new TimedMessageBox(snapperShell, SWT.ICON_ERROR);
            box.setMessage(message);
            box.open();
        }
    I don't get any error, the application crash with no errors.
    What to do?

Similar Threads

  1. eswt MMAPI videocontrol issue on N97 phone.
    By thejakumarsk in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2009-08-31, 08:09
  2. JSR-135 (camera) and eSWT integration
    By jredfern in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2009-08-18, 13:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •