×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    VideoControl.getSnapshot(null) returns null-value

    In the MIDlet I am working on 'VideoControl.getSnapshot(null)' returns a null-value.

    I followed the standard procedure for setting up a 'Player' and a 'VideoControl'.
    No exceptions are thrown, everything seems to work, just VideoControl.getSnapshot(null) returns null.

    So far, I have tried to change 'getSnapshot(null)' to 'getSnapshot("encoding=png")' | 'getSnapshot("encoding=jpeg")' and
    'Manager.createPlayer("capture://video")' to 'Manager.createPlayer("capture://image")'
    ... always the same result: No exceptions are thrown, no obvious errors, but VideoControl.getSnapshot(null) returns null.

    I am at my wit's end! I hope someone can help me.

    Here are the relevant parts of the code (respectively, the parts I assume as relevant):

    Below I have also attached the whole MIDlet


    Thanks for any help!

    Roman
    --------------------------------------------------------------------------------------------------------

    ACMIDlet.java (fragments)
    Code:
    // import .....
    
    public class ACMIDlet extends MIDlet implements CommandListener {
    
        private Player player = null;
        private VideoControl videoControl = null;
        private Command cmdCapture = null;
        // ...
    
        public ACMIDlet(){
    
            try {
               // ...
                
               player = Manager.createPlayer("capture://video");
               // Alternatively: 'createPlayer("capture://video");' .... didn't work!
               player.prefetch();
    
               videoControl = (VideoControl)player.getControl("VideoControl");
    
               screen.append((Item)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
               player.start();
    
            } catch(AnyException e) {
                // ....
            }
        }
    
        private void makeSnapshot(){
    
            byte[] imageData = null;
    
            try {
    
               imageData = videoControl.getSnapshot(null);
               // Alternatively: 'getSnapshot("encoding=png");' .... didn't work!
               // Alternatively: 'getSnapshot("encoding=jpeg");' .... didn't work!
    
            } catch(AnyException e) {
                // ....
            }
    
            if(imageData == null){
                showAlert("Error", "imageData == null");
            }
        }
    
        public void commandAction(Command command, Displayable displayable) {
    
            if(command == cmdCapture){
                makeSnapshot();
            }
            // ...
        }
        
        public void startApp() {
            display.setCurrent(screen);
        }
        // ...
        // ...
    }
    --------------------------------------------------------------------------------

    ACMIDlet.java
    Code:
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.VideoControl;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.io.Connector;
    import java.io.*;
    
    /**
     * @author Roman
     */
    public class ACMIDlet extends MIDlet implements CommandListener {
    
        public static final boolean ABORT = true;
        private String errorIndex = "1";
    
        // --------------------------------------------------------
        private Form screen = null;
        private Display display = null;
        private Command cmdCapture = null;; // capturing-command, Placed in cameraForm.
        private Command cmdExit = null;; // exit-command, Placed in cameraForm.
    
        private Player player = null;
        private VideoControl videoControl = null;
    
        // -----------------------------------------------------
        // private ArtClassifier artClassifier = null;
    
    
        public ACMIDlet(){
    
    
            try {
    
               display = Display.getDisplay(this);
    
               screen = new Form("screen");
               cmdCapture = new Command("Capture", Command.OK, 0);
               cmdExit = new Command("Exit", Command.EXIT, 0);
    
               screen.addCommand(cmdCapture);
               screen.addCommand(cmdExit);
               screen.setCommandListener(this);
    
               player = Manager.createPlayer("capture://video");                    errorIndex = "2";
               player.prefetch();                                                   errorIndex = "3";
    
               videoControl = (VideoControl)player.getControl("VideoControl");      errorIndex = "4";
    
               screen.append((Item)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));   errorIndex = "5";
               player.start();                                                      errorIndex = "6";
    
            } catch(MediaException e) {
                e.printStackTrace();
                showAlert("MediaException(" + errorIndex + ")", e.getMessage() /*, ABORT*/);
            } catch(IOException e) {
                e.printStackTrace();
                showAlert("IOException(" + errorIndex + ")", e.getMessage());
            }catch(IllegalStateException e) {
                e.printStackTrace();
                showAlert("IllegalStateException(" + errorIndex + ")", e.getMessage() /*, ABORT*/);
            }catch(Exception e) {
                e.printStackTrace();
                showAlert("Exception (" + errorIndex + ")", e.getMessage() /*, ABORT*/);
            }
    
            // artClassifier = new ArtClassifier();
        }
    
        private void makeSnapshot(){
    
            byte[] imageData = null;
    
            errorIndex = "6";
    
            try {
    
               imageData = videoControl.getSnapshot(null);  /*png format*/               errorIndex = "7";
    
            } catch(MediaException mediaExc) {
                showAlert("MediaException(" + errorIndex + ")", mediaExc.getMessage());
            } catch(IllegalStateException illegalStateException) {
                showAlert("IllegalStateException(" + errorIndex + ")", illegalStateException.getMessage());
            }catch(Exception exception) {
                showAlert("Exception (" + errorIndex + ")", exception.getMessage());
            }
    
            if(imageData == null){
                showAlert("Error", "imageData == null");
            }else{
                showAlert("Hooray!!", "imageData contains bits and bytes");
            }
    
    
            // showAlert("Processing data ...", "TODO: implement this part");
    
            /*
            artClassifier.setImageDate(imageData);
    
            if(!artClassifier.checkImage()){
                showAlert("Unproper image", "The image is impractical for classification. " +
                        "Station the camera normal to the painting and care for proper lightning");
                return;
            }
    
            artClassifier.extractAllFeatures();
    
            artClassifier.classify();
    
            showAlert("Classification result", artClassifier.getClassName());
    
             */
            // storeImage(imageData, artClassifier.getClassName());
    
        }
    
        ////////// UTILITY METHODS ///////////////////////////
    
        private void storeImage(byte[] imageData, String imageFolder){
            
            
            String imageDir = System.getProperty("fileconn.dir.photos");
    
            if(imageDir == null){
                showAlert("Error", "unable to loacte image folder. Image will be stored in current folder");
                imageDir = "";
            }
    
            FileConnection file = null;
            OutputStream outStream = null;
    
            String fileName = imageDir + "capturedImg.png";
    
    
            try{
                file = (FileConnection)Connector.open(fileName, Connector.READ_WRITE); errorIndex = "8";
                // If there is no file then create it
                if(file.exists() == false) {
                    errorIndex = "9";
                    file.create(); errorIndex = "10";
                }
                // Write data received from camera while making snapshot to file
                outStream = file.openOutputStream(); errorIndex = "11";
                outStream.write(imageData); errorIndex = "12";
    
            }catch(IOException e){
                showAlert("IOException (" + errorIndex + ")", e.getMessage());
            }
    
            catch(Exception e){
                e.printStackTrace();
                showAlert("Exception (" + errorIndex + ")", e.getMessage());
            }
        }
    
        private void showAlert(String title, String message, boolean abort, int duration) {
    
            Alert alert = new Alert(title);
            alert.setString(message);
            
            // TODO:  Hier stimmt was nicht
            if(abort){
                alert.setTimeout(Alert.FOREVER);
                display.setCurrent(alert);
                alert.setCommandListener(this);
                return;
            }
            
            if(duration > 0){
                alert.setTimeout(duration);
            }else{
                alert.setTimeout(Alert.FOREVER);
            }
            
            display.setCurrent(alert, screen);
        }
        
        private void showAlert(String title, String message) {
            
            showAlert(title, message, false, -1);
        }
        private void showAlert(String title, String message, int duration) {
            
            showAlert(title, message, false, duration);
        }
    
        private void showAlert(String title, String message, boolean abort) {
            
            showAlert(title, message, abort, -1);
        }
    
    
        ////////// LISTENER METHODS //////////////////////////
    
        public void commandAction(Command command, Displayable displayable) {
    
            if(command == cmdCapture){
                makeSnapshot();
            }
            if(command == cmdExit){
                notifyDestroyed();
            }
        }
    
        ///////// MIDLET METHODS //////////////////////////
    
        public void startApp() {
    
            display.setCurrent(screen);
        }
    
        public void pauseApp() { }
    
        public void destroyApp(boolean unconditional) {
            player.deallocate();
            player.close();
        }
    }

  2. #2
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Re: VideoControl.getSnapshot(null) returns null-value

    anyone ..?

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    3

    Re: VideoControl.getSnapshot(null) returns null-value

    anyone? .

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    8

    Re: VideoControl.getSnapshot(null) returns null-value

    I have same issue. Do you solve this issue?

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    7

    Re: VideoControl.getSnapshot(null) returns null-value

    Maybe you should call the snapshot-function by passing it a number:
    Code:
    snapshotControl.start(1);
    Here's an example of creating snapshots:
    http://wiki.forum.nokia.com/index.ph...t_using_JSR234

Similar Threads

  1. OBEX/Bluetooth: getReceivedHeaders() returns null
    By schoenke in forum Mobile Java General
    Replies: 5
    Last Post: 2009-01-30, 16:18
  2. Please its veru urgent on nokia 3250
    By siva_guduru in forum Mobile Java General
    Replies: 8
    Last Post: 2008-05-01, 10:24
  3. Video playback with sound but nothing on Screen
    By abdullah829 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-11-30, 14:04
  4. openinputstream() returns null
    By linne345 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-06-08, 15:16
  5. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52

Posting Permissions

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