×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2007
    Location
    Paris, France
    Posts
    41

    *Sometimes* getSnapshot throws MediaException, RecordControl Error

    Hi all

    I have a midlet that allow the user to take photos.

    *Sometimes*, but not always, getSnapshot throws a MediaException with the message 'RecordControl Error'

    What could be causing this ? Why only sometimes ? Could the phone be defective?

    This is on a Nokia 3120.

    Thanks

  2. #2
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: *Sometimes* getSnapshot throws MediaException, RecordControl Error

    Hi,
    It was due to some error in coding. Can u post ur code here?
    thanks,
    jitu_goldie..

    KEEP TRYING..

  3. #3
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    Re: *Sometimes* getSnapshot throws MediaException, RecordControl Error

    I am getting this error everytime.
    Code is as follows



    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 CaptureMidlet extends MIDlet implements CommandListener {

    private Display display;

    // Form where camera viewfinder is placed.
    private Form cameraForm;

    // Command for capturing image by camera. Placed in cameraForm.
    private Command cmdCapture;
    // Command for exiting from midlet. Placed in cameraForm.
    private Command cmdExit;
    // Command for returning from imageForm to cameraForm.
    // Placed in imageForm.
    private Command cmdBack;

    // Player for camera
    private Player player;
    // Video control of camera
    private VideoControl videoControl;

    // Form where captured image is placed
    private Form imageForm;
    // Image captured by camera.
    private Image capturedImage;

    // Alert to be displayed if error occurs.
    private Alert alert;

    /**
    * Constructor.
    */
    public CaptureMidlet() {
    InitializeComponents();
    }

    /**
    * Initializes components of midlet.
    */
    private void InitializeComponents() {
    display = Display.getDisplay(this);

    if(checkCameraSupport() == false) {
    showAlert("Error", "Camera is not supported!", null);
    return;
    }

    if(checkPngEncodingSupport() == false) {
    showAlert("Error", "Png encoding is 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();
    }

    /**
    * Creates form where the camera control will be placed.
    */
    private void createCameraForm() {
    // Create camera form
    cameraForm = new Form("Camera");
    // Create commands for this form
    cmdCapture = new Command("Capture", Command.OK, 0);
    cmdExit = new Command("Exit", Command.EXIT, 0);
    // Add commands to form
    cameraForm.addCommand(cmdCapture);
    cameraForm.addCommand(cmdExit);
    // Set midlet as command listener for this form
    cameraForm.setCommandListener(this);
    }

    /**
    * Creates form where the captured image will be placed.
    */
    private void createImageForm() {
    // Create camera form
    imageForm = new Form("Captured image");
    // Create commands for this form
    cmdBack = new Command("Back", Command.BACK, 0);
    // Add commands to form
    imageForm.addCommand(cmdBack);
    // Set midlet as command listener for this form
    imageForm.setCommandListener(this);
    }

    /**
    * Check camera support.
    * @return true if camera is supported, false otherwise.
    */
    private boolean checkCameraSupport() {
    String propValue = System.getProperty("supports.video.capture");
    return (propValue != null) && propValue.equals("true");
    }

    /**
    * Creates camera control and places it to cameraForm.
    * @throws IOException if creation of player is failed.
    * @throws MediaException if creation of player is failed.
    */
    private void createCamera() throws IOException, MediaException {
    player = Manager.createPlayer("capture://video");
    player.realize();
    player.prefetch();

    videoControl = (VideoControl)player.getControl("VideoControl");
    }

    /**
    * Adds created camera as item to cameraForm.
    */
    private void addCameraToForm() {
    cameraForm.append((Item)videoControl.
    initDisplayMode(VideoControl.USE_GUI_PRIMITIVE, null));
    }

    /**
    * Start camera player
    * @throws IOException if starting of player is failed.
    * @throws MediaException if starting of player is failed.
    */
    private void startCamera() throws IOException, MediaException {
    if(player.getState() == Player.PREFETCHED) {
    player.start();
    }
    }

    /**
    * Checks png encoding support
    * @return true if png encoding is supported false otherwise.
    */
    private boolean checkPngEncodingSupport() {
    String encodings = System.getProperty("video.snapshot.encodings");
    return (encodings != null) && (encodings.indexOf("png") != -1);
    }

    /**
    * Captures image data from camera in jpeg-encoding
    * and creates image from it.
    */
    private boolean captureImage() {
    try {
    byte[] imageData;
    imageData = videoControl.getSnapshot("encoding=png");
    capturedImage = Image.createImage(imageData, 0, imageData.length);
    } catch(MediaException exc) {
    showAlert("Error", exc.getMessage(), cameraForm);
    return false;
    } catch(SecurityException secExc) {
    showAlert("Security error", secExc.getMessage(), cameraForm);
    return false;
    }

    return true;
    }

    /**
    * Creates imageForm, places captured image as item on it
    * and displays form.
    */
    private void showCapturedImage() {
    imageForm.deleteAll();
    if(capturedImage != null) {
    imageForm.append(capturedImage);
    }

    display.setCurrent(imageForm);
    }

    /**
    * From MIDlet.
    * Signals the MIDlet that it has entered the Active state.
    */
    public void startApp() {
    display.setCurrent(cameraForm);
    }

    /**
    * From MIDlet.
    * Signals the MIDlet to enter the Paused state.
    */
    public void pauseApp() {
    // TODO: pause player if it is running.
    }

    /**
    * From MIDlet.
    * Performs exit from midlet.
    */
    public void exitMIDlet() {
    notifyDestroyed();
    }

    /**
    * From MIDlet.
    * Signals the MIDlet to terminate and enter the Destroyed state.
    */
    public void destroyApp(boolean unconditional) {
    if(player != null) {
    player.deallocate();
    player.close();
    }
    }

    /**
    * Shows alert with specified title and text. If next displayable is not
    * specified then application will be closed after alert closing.
    * @param title - Title of alert.
    * @param message - text of alert.
    * @param nextDisp - next displayable. Can be null.
    */
    private void showAlert(String title, String message, Displayable nextDisp) {
    alert = new Alert(title);
    alert.setString(message);
    alert.setTimeout(Alert.FOREVER);

    if(nextDisp != null) {
    display.setCurrent(alert, nextDisp);
    } else {
    display.setCurrent(alert);
    alert.setCommandListener(this);
    }
    }

    /**
    * From CommandListener.
    * Indicates that a command event has occurred on Displayable displayable.
    * @param command - a Command object identifying the command.
    * @param displayable - the Displayable on which this event has occurred.
    */
    public void commandAction(Command command, Displayable displayable) {
    // Handles "Capture image" command from cameraForm
    if(command == cmdCapture) {
    if(captureImage() == true) {
    showCapturedImage();
    }
    }
    // Handles "back" command from imageForm
    if(command == cmdBack) {
    display.setCurrent(cameraForm);
    }
    // Handles "exit" command from forms
    if(command == cmdExit) {
    exitMIDlet();
    }
    // Handle "ok" command from alert
    if(displayable == alert) {
    exitMIDlet();
    }
    }
    }

Similar Threads

  1. Replies: 7
    Last Post: 2009-03-21, 19:54
  2. Browser monitoring
    By NevePankaj in forum Symbian
    Replies: 19
    Last Post: 2008-08-12, 10:06
  3. carbide build problem help please
    By berkcekisbas in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2006-09-26, 19:41
  4. Replies: 0
    Last Post: 2002-09-24, 13:11
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

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