memfis19 / annca Goto Github PK
View Code? Open in Web Editor NEWAndroid library to simplify work with camera for video and photo with using different camera apis.
License: MIT License
Android library to simplify work with camera for video and photo with using different camera apis.
License: MIT License
Is there any way that image captured by this lib to store location information like stock camera app ?
Hi,
Thanks for this library!
I am using your library and most of devices that i have tried camera is full screen but on Samsung Galaxy Note5 camera is square screen. I want to use camera full screen all devices. How can i do this?
It would be nice to hear from you.
Merve
How to change zoom of the camera?
Hi,
Everything is OK, but I cannot get path of photo/video captured in Intent data in onActivityResult!
Please help me to find out...
Trying to add slider zoomer to Camera for photos.
Added to CameraController:
float getCurrentZoom();
void setCurrentZoom(float zoom);
float getMaxZoom();
Added to Camera1Controller
@Override
public float getCurrentZoom() {
return cameraManager.getCurrentZoom();
}
@Override
public float getMaxZoom() {
return cameraManager.getMaxZoom();
}
@Override
public void setCurrentZoom(float zoom) {
cameraManager.setCurrentZoom(zoom);
}
Added to Camera2Controller
@Override
public float getCurrentZoom() {
return camera2Manager.getCurrentZoom();
}
@Override
public float getMaxZoom() {
return camera2Manager.getMaxZoom();
}
@Override
public void setCurrentZoom(float zoom) {
camera2Manager.setCurrentZoom(zoom);
}
Added to CameraManager
float getCurrentZoom();
void setCurrentZoom(float zoom);
float getMaxZoom();
Added to AnncaCameraActivity
protected float getCurrentZoom() {
return getCameraController().getCurrentZoom();
}
protected float getMaxZoom() {
return getCameraController().getMaxZoom();
}
protected void setCurrentZoom(float zoom) {
getCameraController().setCurrentZoom(zoom);
}
I'm getting value of it by max zoom of camera1
Camera.Parameters parameter = camera.getParameters();
if(parameter.isZoomSupported()) {
return parameter.getMaxZoom();
}
and camera2
(manager.getCameraCharacteristics(this.currentCameraId).get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM))*10
SeekBar impementation:
minZoom = getMinZoom();
maxZoom = getMaxZoom() - 1;
final int step = 1;
seekBarBottom.setMax(Math.round(maxZoom - minZoom));
seekBarBottom.setOnSeekBarChangeListener(
new SeekBar.OnSeekBarChangeListener()
{
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
setCurrentZoom(Math.round(minZoom + (progress * step)));
}
}
);
I've added to Camera1Manager
public void setCurrentZoom(float zoom) {
Camera.Parameters parameter = camera.getParameters();
if(getCurrentZoom() < getMaxZoom()) {
parameter.setZoom(Math.round(zoom));
camera.setParameters(parameter);
}
}
Works fine.
I've added to Camera2Manager
protected int zoomLevel = 1;
public void setCurrentZoom(float zoomLevel) {
try {
CameraCharacteristics characteristics = manager.getCameraCharacteristics(this.currentCameraId);
float maxZoom = (characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM))*10;
Rect m = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
if((zoomLevel <= maxZoom) && (zoomLevel > 1)) {
int minW = (int) (m.width() / maxZoom);
int minH = (int) (m.height() / maxZoom);
int difW = m.width() - minW;
int difH = m.height() - minH;
int cropW = difW / 100 * (int) zoomLevel;
int cropH = difH / 100 * (int) zoomLevel;
cropW -= cropW & 3;
cropH -= cropH & 3;
Rect zoom = new Rect(cropW, cropH, m.width() - cropW, m.height() - cropH);
try {
previewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoom);
captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
} catch (Exception e) {
Log.e(TAG, "Error updating preview: ", e);
}
this.zoomLevel = (int) zoomLevel;
}
} catch (Exception e) {
Log.e(TAG, "Error during camera init");
}
}
It zooms but immediately returns to normal state. Is there some listener that changes its state back?
about this part of code in Camera2Manager
if (configurationProvider.getMediaAction() == AnncaConfiguration.MEDIA_ACTION_PHOTO
|| configurationProvider.getMediaAction() == AnncaConfiguration.MEDIA_ACTION_UNSPECIFIED) {
if (windowSize.getHeight() * windowSize.getWidth() > photoSize.getWidth() * photoSize.getHeight()) {
previewSize = CameraHelper.
getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), photoSize.getWidth(), photoSize.getHeight());
} else {
previewSize = CameraHelper.
getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), windowSize.getWidth(), windowSize.getHeight());
}
if (previewSize == null)
previewSize = CameraHelper.chooseOptimalSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), windowSize.getWidth(), windowSize.getHeight(), photoSize);
} else {
if (windowSize.getHeight() * windowSize.getWidth() > videoSize.getWidth() * videoSize.getHeight()) {
previewSize = CameraHelper.getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), videoSize.getWidth(), videoSize.getHeight());
} else {
previewSize = CameraHelper.getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), windowSize.getWidth(), windowSize.getHeight());
}
if (previewSize == null)
previewSize = CameraHelper.getSizeWithClosestRatio(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), videoSize.getWidth(), videoSize.getHeight());
}
It cuts the left and right parts of picture that will be created.
It will be better to live only
if (configurationProvider.getMediaAction() == AnncaConfiguration.MEDIA_ACTION_PHOTO
|| configurationProvider.getMediaAction() == AnncaConfiguration.MEDIA_ACTION_UNSPECIFIED) {
previewSize = CameraHelper.
getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), photoSize.getWidth(), photoSize.getHeight());
} else {
previewSize = CameraHelper.getOptimalPreviewSize(Size.fromArray2(map.getOutputSizes(SurfaceTexture.class)), videoSize.getWidth(), videoSize.getHeight());
}
HI!
this is not issue, i think it already exist.
How can I understand Photo or Video was captured? (of course I can check uri extension but...)
And also can I set Video settings without 'setMediaAction'? I mean that by default Photo mode will be shown , but when I select Video mode - restrictions will be applied. is it possible?
Привет, никак не могу понять как задать камере previewSize не переписывая библиотечный мотод. Есть какой нибудь способ?
Hi, I'm trying to record video but app crash.
This is the log:
12-27 17:32:01.052 6327-6327/io.github.memfis19.sample W/System: ClassLoader referenced unknown path: /data/app/io.github.memfis19.sample-1/lib/x86_64
12-27 17:32:01.070 6327-6327/io.github.memfis19.sample I/InstantRun: Instant Run Runtime started. Android package is io.github.memfis19.sample, real application class is null.
[ 12-27 17:32:01.072 1541: 1562 D/ ]
HostConnection::get() New Host Connection established 0x7bdee161e960, tid 1562
12-27 17:32:01.532 6327-6327/io.github.memfis19.sample W/System: ClassLoader referenced unknown path: /data/app/io.github.memfis19.sample-1/lib/x86_64
12-27 17:32:01.801 6327-6327/io.github.memfis19.sample W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
12-27 17:32:02.335 6327-6355/io.github.memfis19.sample I/OpenGLRenderer: Initialized EGL, version 1.4
12-27 17:32:02.335 6327-6355/io.github.memfis19.sample D/OpenGLRenderer: Swap behavior 1
12-27 17:32:02.477 6327-6355/io.github.memfis19.sample E/EGL_emulation: tid 6355: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-27 17:32:02.477 6327-6355/io.github.memfis19.sample W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7bdee667f100, error=EGL_BAD_MATCH
12-27 17:32:04.360 6327-6327/io.github.memfis19.sample I/CameraManagerGlobal: Connecting to camera service
12-27 17:32:04.517 6327-6355/io.github.memfis19.sample E/EGL_emulation: tid 6355: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-27 17:32:04.517 6327-6355/io.github.memfis19.sample W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7bdee667f280, error=EGL_BAD_MATCH
12-27 17:32:04.632 6327-6355/io.github.memfis19.sample E/EGL_emulation: tid 6355: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-27 17:32:04.632 6327-6355/io.github.memfis19.sample W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7bdee667f280, error=EGL_BAD_MATCH
12-27 17:32:04.736 6327-6355/io.github.memfis19.sample D/OpenGLRenderer: endAllActiveAnimators on 0x7bdee66bf400 (RippleDrawable) with handle 0x7bdee5b2e0a0
12-27 17:32:08.550 6327-6453/io.github.memfis19.sample E/WVMExtractor: Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found
12-27 17:32:08.555 6327-6454/io.github.memfis19.sample I/OMXClient: MuxOMX ctor
12-27 17:32:08.579 6327-6387/io.github.memfis19.sample I/MediaRecorderJNI: prepare: surface=0x7bdefd853e00
12-27 17:32:08.598 6327-6387/io.github.memfis19.sample E/MediaRecorder: start failed: -2147483648
12-27 17:32:08.599 6327-6387/io.github.memfis19.sample E/AndroidRuntime: FATAL EXCEPTION: BaseCameraManager
Process: io.github.memfis19.sample, PID: 6327
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at io.github.memfis19.annca.internal.manager.impl.Camera1Manager$4.run(Camera1Manager.java:143)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
12-27 17:32:08.614 6327-6464/io.github.memfis19.sample I/OMXClient: MuxOMX ctor
12-27 17:32:08.650 6327-6355/io.github.memfis19.sample E/EGL_emulation: tid 6355: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
12-27 17:32:08.650 6327-6355/io.github.memfis19.sample W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7bdee667f2c0, error=EGL_BAD_MATCH
12-27 17:32:08.716 6327-6327/io.github.memfis19.sample W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 16808
Hello.
Is it possible to open front camera if back camera is not available?
Currently there is error:
I/CameraManagerGlobal: getCameraService: Reconnecting to camera service
12-20 07:59:05.316 18385-22627/mobilepic.cvs_mobile.com.mobilepic D/Camera1Manager: Can't open camera: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
thank you
Awesome time working on your library, great work really.
But it would be so much useful if a feature of focus on touch is added in the library.
I tried myself but could not get a way around to successfully implement the feature.
when i call this code by fragment
AnncaConfiguration.Builder videoLimited = new AnncaConfiguration.Builder(activity, CAPTURE_MEDIA);
videoLimited.setMediaAction(AnncaConfiguration.MEDIA_ACTION_VIDEO);
videoLimited.setMediaQuality(AnncaConfiguration.MEDIA_QUALITY_AUTO);
videoLimited.setVideoFileSize(5 * 1024 * 1024);
videoLimited.setMinimumVideoDuration(1 * 30 * 1000);
videoLimited.setVideoDuration(1 * 30 * 1000);
new Annca(videoLimited.build()).launchCamera();
onActivityResult method not calling in fragment
Hello!
Sample app crashes when you tap "Take photo" on custom layout again:
Process: io.github.memfis19.sample, PID: 14415
java.lang.RuntimeException: takePicture failed
at android.hardware.Camera.native_takePicture(Native Method)
at android.hardware.Camera.takePicture(Camera.java:1833)
at android.hardware.Camera.takePicture(Camera.java:1778)
at io.github.memfis19.annca.internal.manager.impl.Camera1Manager$3.run(Camera1Manager.java:128)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.os.HandlerThread.run(HandlerThread.java:61)
Hi, I apologize in advance if my language is not good :)
https://drive.google.com/open?id=0B44cB1gVSzPLT3lJUnVhSFMzd3c
I'm making a video camera and try to record a video. The problem is every time I change the orientation of the smartphone, which previewed image does not have the same image ratio.
As Figures 1 and 2:
Please help me to improve my video :'(
When i'm using Annca library with a activity, it records only for 2 seconds. In fragment it works fine
I want to modify camera control layout design camera control button position and design. How can i do it.
taking photo at night is very painfull as the flash light in automode flashes once , initial for the focusing the view , but not when the actual camera takePhoto is called , thus require a second flashes , i realise it pass to android, to take care of this , but help would be appreciated .
Hi,
I am using your library. I want to change the camera's focus in CustomCameraActivity. Can you help me??
hello, is there any way to change the filename result of video and photo?
Camera is not giving any output sometimes on button click. takePhoto() is called but onPhotoTaken() is not getting called. Do u have any suggestions to resolve the issue.
Phone : Samsung S8
HI,can we change the path of photo?I see the method 'getoutputfile' is private.How to change the target floder?
Thanks.
After exporting to mp4, you open mp4 file in File Explorer : the audio plays but the images do not move, after a period of time the audio stops playing and the picture starts to move. Display time is also not normal (video about 10s but time show about >2h).
Code:
AnncaConfiguration.Builder builder = new AnncaConfiguration.Builder (context, CAPTURE_MEDIA);
builder.setMediaQuality (AnncaConfiguration.MEDIA_QUALITY_LOW);
builder.setMediaResultBehaviour (AnncaConfiguration.PREVIEW);
builder.setVideoDuration (2 * 60 * 1000);
new Annca (builder.build ()) launchCamera ();
Thanks!
Hello sir when i select auto , 19201080 or 720480 in setting then camera screen not cover full size and when i select 1280*720 camera screen cover full screen so i want full screen in auto size how it possible.
I'm trying to use Annca in my own app.
Taking photo work well. When I try to take video I ear sound, button change in stop but no timer showed and getting following error:
E/Camera1Manager: Error during preparing MediaRecorder: setAudioSource failed.
Samsung SM-J500FN running android 5.1.1.
I'm launching Annca with:
AnncaConfiguration.Builder builder = new AnncaConfiguration.Builder(this, CAPTURE_MEDIA);
builder.setMediaAction(AnncaConfiguration.MEDIA_ACTION_UNSPECIFIED);
new Annca(builder.build()).launchCamera();
Edit: sorry RECORD_AUDIO permission was missing
Hi,
Thanks for the the nice library.
We're facing issue with Flash when taking photo.
We set Flash mode ON, as below code. But not see Flash when taking photo.
AnncaConfiguration.Builder builder = new AnncaConfiguration.Builder(activity, CAPTURE_MEDIA); builder.setFlashMode(AnncaConfiguration.FLASH_MODE_ON); builder.setMediaResultBehaviour(AnncaConfiguration.CONTINUE); new Annca(builder.build()).launchCamera();
Flash working only when click on Flash button on Screen to turn it ON. Then It works only for first photo. And then it wont flash again later even its kept still ON, unless we click on button again to turn it ON.
I try to analyze the code to fix it, but couldn't able fix it. Could you please let us know how to fix this issue.
Thank you.
I want to open camera capture image / video preview according 1:1 ration and square layout
I'm not sure that that;s really a bug. Maybe that's only on my device. After saving of picture I get it by file path. I using the function for getting image orientation from it's properties
public static int getRotation(String filePath, String title, Context context) {
int rotation =-1;
Cursor mediaCursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[] {MediaStore.Images.ImageColumns.ORIENTATION, MediaStore.MediaColumns.SIZE },
MediaStore.MediaColumns.DATE_ADDED + ">=?",
new String[]{title},
MediaStore.MediaColumns.DATE_ADDED + " desc");
try {
if (mediaCursor != null && mediaCursor.getCount() != 0) {
while (mediaCursor.moveToNext()){
rotation = mediaCursor.getInt(0);
break;
}
} else {
rotation = getExifOrientationAttribute(filePath);
}
return rotation;
}
finally {
try {
mediaCursor.close();
} catch (NullPointerException e) {
}
}
}
In camera1 it returns correct value of picture orientation to rotate. But when I'm using camera2, this function always returns 0. Try it. Maybe you should set orientation property or rotate bitmap before it's saving in camera2.
That's why I'm using the function:
private int getAdditionalCamera2Rotation() {
if(isCamera2) {
int angle;
if(degrees == 0) {
angle = 90;
} else if(degrees == 270) {
angle = 180;
} else if(degrees == 180) {
angle = 270;
} else {
angle = 0;
}
return angle;
} else {
return 0;
}
}
If photo is taken vertically the photo is displayed horizontally.
Hi,
How i can hide setting icon option?
been using the library in test app for a while, am noticing on samsung phone , the quality doesnt match the phone capability , during onTake photo ,image is clear but on preview ,it at a lower resolution than expected always using lower resolution
Would appreciate any help. Thank You.
Hi, presently front camera layout is not full screen, how to change this, it is showing a small picture. should be back camera layout.
Hello,
Thanks for providing this awesome code,
Sir, I need flash in video mode. In this code flash is only enable in camera, but when i switch to the videoCapture mode flash icon is not visible. Please guide me or provide a code snippet to enable flash while capturing video.
Thanks
Dear All
i faced a problem when using the CameraFagment Library on Samsung Tab 9",
the problem is when preview the camera before take photo or record video the aspect ratio is fine, but the preview not full the screen,
but when record video, while recording the aspect-ratio is stretched, but the saved video is fine
Best,
Hello,
its a great library to record videos. I want to start video recorder directly when user click on buttton, I want to open full screen view which will record video, user can stop video by pressing stop button. Can you suggest if i can do it with this library ?
When I start recording, camera preview orientation is changed into the landscape . how to fix to have it portrait mode, the issue is occurring on Mi 4 device while its working fine on Samsung j5
Hi there, thanks alot for your work =)
I am newbie, is there any way to setPreviewCallback ?
Hi there,
first - thanks for providing this library to everyone it'll save me a lot of time.
I am using your library and currently it provides english and I assume danish locales only. Is there any way to change/add locales e.g. for the different textViews within activity_preview
or for the dialog you create within onSettingsClick(...)
?
Currently I get your library via Gradle and actually I don't want to import it manually and modify it myself.
It would be nice to hear from you.
Alex
flash button not showing how can i enable it.
Hello, how can I put the front camera by default when I start the camera?
Thanks.
Trying to open camera on Nexus 5X (Android 7.1.1 API 25)
E/Camera2Controller: onCameraOpenError
hi awesome library , but current autofocus take too long on samsung tested on s6 , tried adding the autofocus on code using a a viewOnclickListener , on the main baseAnncaActivity , but it i can grab Camera instance , and also i realise it uses surfaceview and base camera for camera2,camera1 currently this code is for camera1 , where i assume Camera instance is available
code is as follows
private Camera mCamera;
mIsAutoFocusing =false; // can be used as a flag , autofocus is already implemented
@Override // onviewClicklistener
public void onClick(View view) {
if (mCamera == null || mIsAutoFocusing) return;
try {
mIsAutoFocusing = true;
mCamera.cancelAutoFocus();
mCamera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
mIsAutoFocusing = false;
if (!success)
Toast.makeText(getActivity(), "Unable to auto-focus!", Toast.LENGTH_SHORT).show();
}
});
} catch (Throwable t) {
t.printStackTrace();
}
} else {
super.onClick(view);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.