How to use Front Facing Camera on Samsung Galaxy S
Asked Answered
S

3

8

I've tried several answer I've found across the web, such as:

Camera.Parameters parameters = mCamera.getParameters();
parameters.set("camera-id", 2);
mCamera.setParameters(parameters);

or

mMediaRecorder.setVideoSource(2);

But it doesn't work. I've also set permissions on the manifest file:

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />

Am i missing out on something? I've searched StackOverflow and I know this has been asked before but there seem to be no confirmed solution on this, any kind of help would be appreciated.

Note: I'm using Galaxy S on the 2.1 platform

Seidler answered 22/11, 2010 at 0:29 Comment(0)
S
12

Anyway after a few trials and error, I figured it out how to do it:

Camera.Parameters parameters = mCamera.getParameters();
parameters.set("camera-id", 2);
parameters.setPreviewSize(640, 480); // or (800,480) this is supported front camera preview size @ Samsung Galaxy S
mCamera.setParameters(parameters);

Or, if you need to use it with MediaRecorder:

MediaRecorder mMediaRecorder = new MediaRecorder();
Camera mCamera = Camere.open();
Camera.Parameters parameters = mCamera.getParameters();
parameters.set("camera-id", 2);
parameters.setPreviewSize(640, 480); // or (800,480)
mCamera.setParameters(parameters);
mCamera.unlock(); // unlock, to give other process to access it otherwise it can't be used later
mMediaRecorder.setCamera(mCamera);
// continue with mMediaRecorder standard routines here

If you need to have a smaller preview size, you could set/scale down your SurfaceView size instead.

Seidler answered 23/11, 2010 at 4:45 Comment(0)
A
2

There currently isn't a standard API for front-facing cameras; you will need to rely on whatever (if any) documentation the hardware manufacturer has for using their extensions to access the front-facing camera. This will of course only work on those specific devices.

Note writing raw strings like "camera-id" is often a good sign you have wandered into the woods outside of the official SDK. :)

Aloke answered 22/11, 2010 at 2:2 Comment(1)
Yes, I already know that :). The "camera-id" parameter will only work of course in Samsung Galaxy S as it is not a part of the official SDK. But unfortunately, I haven't found any further helpful documentation using front camera on this model.Seidler
D
0

I think this is as good a place as any to add some details I've worked out.

In case you're using the front facing camera in portrait mode and the resulting file comes out cut up into squares with green blocks thrown in try inverting the width and height (both preview and recorder) and setting the encoder to H263...

This solved the problem on my Samsung Galaxy S on 2.3.3+...

Daft answered 10/10, 2012 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.