Results 1 to 5 of 5

Thread: javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

  1. #1
    Join Date
    Jan 2010
    Posts
    57

    javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

    Hi, I am getting problem while taking the picture from the Nokia Mobile Phone. When I try to do this, it simply give me error message as below:
    Code:
    the function videoControl.getSnapshot(null) throws MediaException: Failed to get Camera Snapshot data size
    If anyone is having the details from which I will able to solve the problem, then please provide that to me.

  2. #2
    Join Date
    Jan 2006
    Posts
    7,109

    Re: javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

    Hey, If you are getting this problem, then it may be possible that you are having problem of the software. Simply go to the Nokia Service center and they will simply update your software and then you will able to get the solution for your problem. So, simply do that and get the solution for your problem. As it is not much more big problem. You can simply solve that.

  3. #3
    Join Date
    May 2008
    Posts
    5,937

    Re: javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

    Hello, simply make use of the code below in your Midlet class:
    Code:
    import java.io.IOException;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.*;
    import javax.microedition.media.control.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.media.control.VideoControl;
    
    public class Video extends MIDlet implements CommandListener {
    private Display dis;
    private Form frm;
    private Command exit,back,capture,camera;
    private Player plr;
    private VideoControl vControl;
    private Video vid;
    public Video() {
    exit = new Command("Exit", Command.EXIT, 0);
    camera = new Command("Camera", Command.SCREEN, 0);
    back = new Command("Back", Command.BACK, 0);
    capture = new Command("Capture", Command.SCREEN, 0);
    frm = new Form("Capture ");
    frm.addCommand(camera);
    frm.setCommandListener(this);
    }
    
    public void start() {
    dis = Display.getDisplay(this);
    dis.setCurrent(frm);
    }
    
    public void pauseApp() {}
    
    public void remove(boolean unconditional) {}
    
    public void commandAction(Command c, Displayable s) {
    if (c == exit) {
    remove(true);
    notifyDestroyed();
    } else if (c == camera) {
    showCamera();
    } else if (c == back)
    dis.setCurrent(frm);
    else if (c == capture) {
    vid = new Video(this);
    vid.start();
    }
    }
    
    public void showCamera() {
    try {
    plr = Manager.createPlayer("capture://vid");
    plr.realize();
    
    vControl = (VideoControl)plr.getControl("VideoControl");
    Canvas canvas = new VideoCanvas(this, vControl);
    canvas.addCommand(back);
    canvas.addCommand(capture);
    canvas.setCommandListener(this);
    dis.setCurrent(canvas);
    plr.start();
    } catch (IOException ioe) {} catch (MediaException me) {}
    }
    
    class Video extends Thread {
    Video midlet;
    public Video(Video midlet) {
    this.midlet = midlet;
    }
    
    public void run() {
    captureVideo();
    
    }
    
    public void captureVideo() {
    try {
    byte[] bt = vControl.getSnapshot(null);
    Image pic = Image.createImage(bt, 0, bt.length);
    frm.append(pic);
    dis.setCurrent(frm);
    
    plr.close();
    plr = null;
    vControl = null;
    } catch (MediaException me) { }
    }
    };
    }
    And the code below in your Video Canvas subclass:
    Code:
    import javax.microedition.lcdui.*;
    import javax.microedition.edia.MediaException;
    import javax.microedition.edia.control.VideoControl;
    
    public class vCanvas extends Canvas
     {
    private VideoMIDlet mdt;
    
    public vCanvas(VideoMIDlet mdt, VideoControl control) 
    {
    int wdth = getWidth();
    int hgth = getHeight();
    this.mdt = mdt;
    
    control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
    try 
    {
    control.setDisplayLocation(2, 2);
    control.setDisplaySize(wdth - 4, hgth - 4);
    } 
    catch (MediaException e)
     {}
    control.setVisible(true);
    }
    
    public void paint(Graphics g) {
    int wdth = getWidth();
    int hgth = getHeight();
    
    g.setColor(0x00ff00);
    g.drawRect(0, 0, wdth - 1, hgth - 1);
    g.drawRect(1, 1, wdth - 3, hgth - 3);
    } 
    }
    This code had solved my same problem. So, you need to use it.

  4. #4
    Join Date
    Jan 2006
    Posts
    6,878

    Re: javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

    Hello, I would simply suggest you to make use of the updates for that particular application and the find out whether you are getting the same problem or you have solved that problem. It is just needed to make use of that updated files. Or you can simply make use of the new applications for getting the solution and then you will able to get your problem solved. So, simply do that and then you will get solved for your problem.

  5. #5
    Join Date
    May 2008
    Posts
    5,812

    Re: javax.microedition.media.MediaException: Failed To Get Camera Snapshot Data Size

    Hey, simply make use of the code below which will help you to solve your problem. I have got this on internet. You need to use it :
    Code:
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.Item;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.Image; 
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.control.VideoControl;
    import java.io.IOException;
     
    public class Capture extends MIDlet implements CommandListener {
         private Display dis;
        private Form camfrm;
        private Command command1;
        private Command command2;
        private Command command3;
        private Player player;
        private VideoControl videoControl;
        private Form imgFrm;
        private Image cpImg;
        private Alert alert;    
        public Capture() {
            Initializing();
        }
        private void Initializing() {
            dis = Display.getDisplay(this); 
            if(checkCameraSupport() == false) {
                showAlert("Error", "Camera is not supported!", null);
                return;
            } 
            if(checkPngEncodingSupport() == false) {
                showAlert("Error", "Png not supported!", null);
                return;
            } 
            try {
                createCameraForm();
                createCamera(); 
                addCameraToForm();
                startCamera();
            } catch(IOException ioExc) {
                showAlert("IO error", ioExc.getMessage(), null);
            } catch(MediaException mediaExc) {
                showAlert("Media error", mediaExc.getMessage(), null);
            }  
            createImageForm();
        }
        private void createCameraForm() {
            camfrm = new Form("Camera");
            command1 = new Command("Capture", Command.OK, 0);
            command2 = new Command("Exit", Command.EXIT, 0);
            camfrm.addCommand(command1);
            camfrm.addCommand(command2);
            camfrm.setCommandListener(this);
        } 
        private void createImageForm() {
            imgFrm = new Form("Captured image");
            command3 = new Command("Back", Command.BACK, 0);
            imgFrm.addCommand(command3);
            imgFrm.setCommandListener(this);
        }
        private boolean checkCameraSupport() {
            String propValue = System.getProperty("supports.video.capture");
            return (propValue != null) && propValue.equals("true");
        }
        private void createCamera() throws IOException, MediaException {
            player = Manager.createPlayer("capture://video");
            player.realize();
            player.prefetch(); 
            videoControl = (VideoControl)player.getControl("VideoControl");
        } 
        private void addCameraToForm() {
            camfrm.append((Item)videoControl.
                    initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
        }
        private void startCamera() throws IOException, MediaException  {
            if(player.getState() == Player.PREFETCHED) {
                player.start();
            }
        }
        private boolean checkPngEncodingSupport() {
            String encodings = System.getProperty("video.snapshot.encodings");
            return (encodings != null) && (encodings.indexOf("png") != -1);
        }    
        private boolean captureImage() {
            try {
                byte[] imageData;
                imageData = videoControl.getSnapshot("encoding=png");
                cpImg = Image.createImage(imageData, 0, imageData.length);
            } catch(MediaException exc) {
                showAlert("Error", exc.getMessage(), camfrm);
                return false;
            } catch(SecurityException secExc) {
                showAlert("Security error", secExc.getMessage(), camfrm);
                return false;
            } 
            return true;
        }    
        private void showCapturedImage() {
            imgFrm.deleteAll();
            if(cpImg != null) {
                imgFrm.append(cpImg);
            } 
            dis.setCurrent(imgFrm);
        } 
        public void startApp() {
            dis.setCurrent(camfrm);
        }    
        public void pauseApp() {
          }  
        public void exitMIDlet() {
            notifyDestroyed();
        }
        public void destroyApp(boolean unconditional) {
            if(player != null) {
                player.deallocate();
                player.close();
            }
        }
        private void showAlert(String title, String message, Displayable nextDisp) {
            alert = new Alert(title);
            alert.setString(message);
            alert.setTimeout(Alert.FOREVER);
             if(nextDisp != null) {
                dis.setCurrent(alert, nextDisp);
            } else {
                dis.setCurrent(alert);
                alert.setCommandListener(this);
            }
        }  
        public void commandAction(Command command, Displayable disable) {
            if(command == command1) {
                if(captureImage() == true) {
                    showCapturedImage();
                }
            }
           if(command == command3) {
                dis.setCurrent(camfrm);
            }
            if(command == command2) {
                exitMIDlet();
            }
            if(disable == alert) {
                exitMIDlet();
            }        
        }
    }

Similar Threads

  1. Replies: 5
    Last Post: 18-08-2010, 01:42 AM
  2. help: javax.speech
    By vinstar in forum Software Development
    Replies: 1
    Last Post: 22-02-2010, 03:50 PM
  3. Problem in JAR and javax.comm
    By Ash maker in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 12:30 PM
  4. need J2me source code for camera snapshot module
    By HoST in forum Windows Software
    Replies: 2
    Last Post: 11-01-2010, 01:38 PM
  5. Replies: 3
    Last Post: 04-11-2009, 05:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,187,989.45094 seconds with 16 queries