Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    20

    How to use Front Camera

    hi..

    i am using E71.. its front camera is only activated for video calls..

    please let me know if its possible using J2ME to know how many cameras are attached in the device and also to activate a particular camera..

    i would like to use the front camera for capturing images and videos..

    thnx
    kartik..

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to use Front Camera

    Hi,

    You should be able to use capture://devcam1 for the front camera.
    You might be interested in reading about Multimedia in Java ME, if you haven't already.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    20

    Re: How to use Front Camera

    thnx for ur reply..

    it would be gr8 if u can share with me a sample app which allows me to use the front camera..

    i wanted to develop an app for this but i am on a mac and i dont think so i can install the sdk on it..

    thnx again..

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to use Front Camera

    Well, here is an example but I haven't tested it because my phone is not available at the moment. Theoretically it should work.

    Main MIDlet class:
    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class MyMidlet extends MIDlet implements CommandListener {
        
        public Display display=Display.getDisplay(this);
        public VideoCanvas vc=new VideoCanvas(this);
        
        public void startApp() {
            display.setCurrent(vc);
        }
     
        public void pauseApp() {
        }
     
        public void destroyApp(boolean unconditional) {
        }
     
        public void commandAction(Command c, Displayable d) {
        }
    
    }
    VideoCanvas class:
    Code:
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.*;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.PlayerListener;
    import javax.microedition.media.control.RecordControl;
    import javax.microedition.media.control.VideoControl;
     
    public class VideoCanvas extends Canvas implements PlayerListener, CommandListener {
     
    	private MyMidlet midlet = null;
    	private Command start = new Command("Start",Command.OK,0);
    	private Command stop = new Command("Stop",Command.OK,1);
    	private Command exit = new Command("Exit",Command.BACK,0);
    	private Command play = new Command("Play",Command.OK,2);
    	private String status = "Not initialized";
    	private Player player = null;
    	private VideoControl control = null;
    	private RecordControl record = null;
    	private boolean recording = false;
    	private FileConnection conn = null;
    	private OutputStream stream = null;
    	private String PATH = System.getProperty("fileconn.dir.videos") + "vi.3gp"; 
    	
    	/**
    	 * Constructor
    	 * 
    	 * @param midlet 
    	 */
    	 
    	public VideoCanvas(MyMidlet midlet) {
                    System.out.println(PATH);
    		this.midlet = midlet;
    		addCommand(play);
    		addCommand(start);
    		addCommand(stop);
    		addCommand(exit);
    		setCommandListener(this);
    	}
    	
    	public void commandAction(Command c, Displayable arg1) {
                if(c == start) {
                    recording = true;
                    startRecording();
                }
                else if(c == stop) {
                    stop();
                    recording = false;
                }
                else if(c == play) {
                    recording = false;
                    repaint();
                    startPlaying();
                }
                else if(c == exit) {
                    midlet.notifyDestroyed();
                }
    	}
     
    	/**
    	 * Paint
    	 */
    	
    	protected void paint(Graphics g) {
                g.setColor(0,0,0);
                g.fillRect(0,0,getWidth(),getHeight());
    	}
     
            public void startRecording() {
                try {
                    player = Manager.createPlayer("capture://devcam1");
    		player.addPlayerListener(this);
    		player.realize();
                    
                    //setup recording
    		record = (RecordControl)player.getControl("RecordControl");
    		record.setRecordSizeLimit(300000);
    		conn = (FileConnection)Connector.open(PATH,Connector.READ_WRITE);
    		if(!conn.exists()) conn.create();
    		stream = conn.openOutputStream();
    		record.setRecordStream(stream);
                		
    		// Grab the video control and set it to the current display.
    		control = (VideoControl)player.getControl("VideoControl");
    		if (control != null) {
                        control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);
                        control.setDisplaySize(getWidth(),getHeight());
    		    control.setVisible(true);
                    }
    		    
                    player.start();
                    record.startRecord();
                }
                catch(Exception e) {
                    Alert erro = new Alert("Error",e.toString(),null,AlertType.ERROR);
                    Display.getDisplay(midlet).setCurrent(erro);
                    e.printStackTrace();
                }
    	}        
            
    	/**
    	 * Start
    	 *
    	 */
    	
    	public void startPlaying() {
                try {
                    player = Manager.createPlayer(PATH);
    		player.addPlayerListener(this);
    		player.realize();
                		
                    // Grab the video control and set it to the current display.
    		control = (VideoControl)player.getControl("VideoControl");
    		if (control != null) {
                        control.initDisplayMode(VideoControl.USE_DIRECT_VIDEO,this);
                        control.setDisplaySize(176,144);
                        control.setDisplayLocation((getWidth() - control.getDisplayWidth()) / 2,(getHeight() - control.getDisplayHeight()) / 2);
                        control.setVisible(true);
                    }
    		    
                    player.start();
                }
                catch(Exception e) {
                    Alert erro = new Alert("Error",e.getMessage(),null,AlertType.ERROR);
                    Display.getDisplay(midlet).setCurrent(erro);
                    e.printStackTrace();
                }
    	}
    	
    	public void stop() {
                if(player != null) {
                    try {
                        if(recording) {
                            record.stopRecord();
                            record.commit();				
                            stream.close();
                        }
                        player.stop();
                        player.deallocate();
                        player.close();
                        player = null;
                        if(recording) {
                            Alert alert = new Alert("Message","Saved to " + PATH,null,AlertType.INFO);
                            Display.getDisplay(midlet).setCurrent(alert,this);
                            stream = null;
                        }
                        
                        if(conn != null)
                            conn.close();
                    }
                    catch(Exception e) {
     
                    }
                }
    	}
     
    	public void playerUpdate(Player p, String s, Object o) {
                
                if(p.getState() == Player.STARTED) {
                    status = control.getDisplayHeight() + "=" + control.getDisplayWidth();
                    setTitle(status);
                }
                
    	}
     
    }
    All I really did was modify this example a little bit.

    Hope it helps
    Last edited by bogdan.galiceanu; 2008-11-20 at 21:37. Reason: Fixed code

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    20

    Re: How to use Front Camera

    thnx a lot for the code.. what i was looking for was a jar file as i m not able to compile the code on mac.

    thnx..

  6. #6
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to use Front Camera


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

    Smile Re: How to use Front Camera

    thanks.. a lot it worked on my nokia e71..

    but their was some error in recording video and i can't capture photo out of it..
    i will be very thankful to u if u solve this problem..!!

    one again thanks a lot..!!

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    20

    Re: How to use Front Camera

    thnx a lot.. nice to see the front camera work.. though the qualit was a disappointment..

  9. #9
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Re: How to use Front Camera

    Quote Originally Posted by bogdan.galiceanu View Post
    thanks.. a lot it worked on my nokia e71..

    but their was some error in recording video and i can't capture photo out of it..
    i will be very thankful to u if u solve this problem..!!

    one again thanks a lot..!!

  10. #10
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to use Front Camera

    What was the error? And it wasn't built to take photos, just to show that the front camera can be used (incidentally it also records video because that was in the example I modified).

  11. #11
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Re: How to use Front Camera

    Quote Originally Posted by bogdan.galiceanu View Post
    What was the error? And it wasn't built to take photos, just to show that the front camera can be used (incidentally it also records video because that was in the example I modified).
    but plz can u help me to give some software which can save of snaps also..

  12. #12
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to use Front Camera

    Here is a very good example for taking pictures:
    http://wiki.forum.nokia.com/index.ph...ure_in_Java_ME

    All you have to do is modify the line:
    Code:
    player = Manager.createPlayer("capture://video");
    to
    Code:
    player = Manager.createPlayer("capture://devcam1");
    in order to make it use the front camera.

    Quote Originally Posted by kush046 View Post
    but plz can u help me to give some software which can save of snaps also..
    The purpose of this forum is to help people learn, not do their projects for them. Anyway, since I've already built the application to test it, here it is:
    http://blogs.forum.nokia.com//data/b...rontCamera.jar

    Note that it just takes pictures, it doesn't save them. If you want to save them, read about the FileConnection API.

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Re: How to use Front Camera

    Quote Originally Posted by bogdan.galiceanu View Post
    Here is a very good example for taking pictures:
    http://wiki.forum.nokia.com/index.ph...ure_in_Java_ME

    All you have to do is modify the line:
    Code:
    player = Manager.createPlayer("capture://video");
    to
    Code:
    player = Manager.createPlayer("capture://devcam1");
    in order to make it use the front camera.



    The purpose of this forum is to help people learn, not do their projects for them. Anyway, since I've already built the application to test it, here it is:
    http://blogs.forum.nokia.com//data/b...rontCamera.jar

    Note that it just takes pictures, it doesn't save them. If you want to save them, read about the FileConnection API.
    thanks.. dude im really thankful to u..!!

  14. #14
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: How to use Front Camera

    ???
    are u able to compile now on ur mac ???
    cause he only gave the difference in source code...

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    5

    Re: How to use Front Camera

    Quote Originally Posted by bogdan.galiceanu View Post
    Here is a very good example for taking pictures:
    http://wiki.forum.nokia.com/index.ph...ure_in_Java_ME

    All you have to do is modify the line:
    Code:
    player = Manager.createPlayer("capture://video");
    to
    Code:
    player = Manager.createPlayer("capture://devcam1");
    in order to make it use the front camera.



    The purpose of this forum is to help people learn, not do their projects for them. Anyway, since I've already built the application to test it, here it is:
    http://blogs.forum.nokia.com//data/b...rontCamera.jar

    Note that it just takes pictures, it doesn't save them. If you want to save them, read about the FileConnection API.
    hey can u tell me hoe to off the camera sount and its flash..!!
    plz..

Similar Threads

  1. front camera not working on N70
    By galaktico in forum Symbian
    Replies: 7
    Last Post: 2010-04-30, 16:51
  2. Replies: 2
    Last Post: 2008-09-26, 18:40
  3. Nokia N-Series Complete Model Line-Up
    By Dopod in forum General Development Questions
    Replies: 6
    Last Post: 2008-07-22, 20:16
  4. Replies: 3
    Last Post: 2008-05-05, 16:08
  5. N73 front camera access
    By dudi in forum Symbian Media (Closed)
    Replies: 4
    Last Post: 2007-04-05, 16:42

Posting Permissions

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