cjt2325 / cameraview Goto Github PK
View Code? Open in Web Editor NEW仿微信拍照Android控件(轻触拍照,长按摄像)
License: Apache License 2.0
仿微信拍照Android控件(轻触拍照,长按摄像)
License: Apache License 2.0
1 android.hardware.Camera.native_getParameters(Native Method)
2 android.hardware.Camera.getParameters(Camera.java:1996)
3 com.cjt2325.cameralibrary.JCameraView.startRecord(JCameraView.java:462)
4 com.cjt2325.cameralibrary.JCameraView.access$900(JCameraView.java:31)
5 com.cjt2325.cameralibrary.JCameraView$1.record(JCameraView.java:143)
6 com.cjt2325.cameralibrary.CaptureButton$RecordRunnable.run(CaptureButton.java:349)
设备机型
三星 SM-A8000 真机测试
系统版本
Android 6.0.1,level 23
ROM
samsung/a8ltezc
CPU架构
armeabi-v7a
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder._start(Native Method)
at android.media.MediaRecorder.start(MediaRecorder.java:914)
at com.cjt2325.cameralibrary.JCameraView.startRecord(JCameraView.java:401)
at com.cjt2325.cameralibrary.JCameraView.access$1000(JCameraView.java:31)
at com.cjt2325.cameralibrary.JCameraView$1.record(JCameraView.java:132)
at com.cjt2325.cameralibrary.CaptureButton$RecordRunnable.run(CaptureButton.java:357)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6918)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
添加1.0.5依赖也没有缩放效果
用25的sdk编译会出现这样的问题。
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.takePicture(android.hardware.Camera$ShutterCallback, android.hardware.Camera$PictureCallback, android.hardware.Camera$PictureCallback)' on a null object reference
at com.camera.CameraInterface.takePicture(CameraInterface.java:220)
at com..camera.JCameraView$2.takePictures(JCameraView.java:220)
at com.camera.CaptureLayout$2.takePictures(CaptureLayout.java:149)
at com.camera.CaptureButton.handlerUnpressByState(CaptureButton.java:162)
at com.camera.CaptureButton.onTouchEvent(CaptureButton.java:148)
使用的是华为荣耀PE-CL00(android4.4.2)的手机,发现是设置的mediaRecorder.setVideoEncodingBitRate(1600000);没有生效,拍摄出来的视频尺寸很大,10s钟,内存占用17-25MB,在小米和魅族的手机上,就没有问题,拍出来的视频尺寸比较合理,10s钟,内存占用2.0-3.0MB。
版主什么时候能加入camera2
刚进入项目,摄像拍照区域显示黑屏。点击开始按钮,项目崩。
从后台应用进程中起开项目的话,才能看见,
请问怎么修改,谢谢~
FATAL EXCEPTION: Thread-5
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:692)
at android.hardware.Camera.open(Camera.java:488)
java.lang.RuntimeException: stop failed.
android.media.MediaRecorder.native_stop(Native Method)
崩溃日志如上!网上找说加mediaRecorder.setOnErrorListener(null);这些都无效。请问知道解决办法吗?
qq:285601517.麻烦知道的和我联系。谢谢
1 android.hardware.Camera.native_autoFocus(Native Method)
2 android.hardware.Camera.autoFocus(Camera.java:1347)
3 com.cjt2325.cameralibrary.JCameraView.onFocusBegin(JCameraView.java:563)
4 com.cjt2325.cameralibrary.JCameraView.onTouchEvent(JCameraView.java:591)
设备机型
三星 SM-A8000 真机测试
系统版本
Android 6.0.1,level 23
ROM
samsung/a8ltezc
CPU架构
armeabi-v7a
强制横屏录制,相机预览画面不正常
拍摄时手机媒体声音被强制关闭,到了看视频界面也没有声音,退出后demo后媒体声音才恢复
我在camera包中找了半天,感觉就是修改CaptureButton类中的duration,可是不管设置为多少,最后拍下来的视频也就十秒左右,不能再多了,这是不是有点问题?还是说我自己没有找到呢?求解答!!谢谢!!
因为不同的手机,摄像头的传感器是反的,最终的效果是有得手机正常,有得手机是反的。可以推荐使用camera2的api
在 7.0 系统上会崩溃 不妨测试下。
在真机ViVo Y66 android6.0上,首次运行,长按摄像的时候,会弹出录音权限提示框,这时候提示框会覆盖界面的最上层啊,然后点击授权,松开了手指,动画也会执行完duration。
当我去选择权限时,控件无法捕获ACTION_DOWN、ACTION_MOVE、ACTION_UP和ACTION_CANCEL事件,不能及时消除动画效果。
请问大神,这个有没有办法去解决啊。。。
三星A5 android版本4.4
切换前置摄像头时相机卡住不动 ,再次点击切换 就不卡了 但是还是 后置摄像头
三星的部分手机,比如去年的A系列SM-A7108,切换为前置摄像头的会导致预览之后大概一半。
然后这时候拍照,会奔溃。报 “y + height must be <= bitmap.height()”
具体位置为 com/yue/customcamera/activity/CameraActivity.java:440
也就是 saveBitmap = Bitmap.createBitmap(saveBitmap, 0, 0, screenWidth, screenWidth * 4/3);这行代码
应该就是首先预览比例和实际比例不符导致的
1 android.hardware.Camera.native_getParameters(Native Method)
2 android.hardware.Camera.getParameters(Camera.java:1888)
3 com.cjt2325.cameralibrary.JCameraView.setStartPreview(JCameraView.java:293)
4 com.cjt2325.cameralibrary.JCameraView.surfaceCreated(JCameraView.java:412)
设备机型
谷歌 NEXUS 5 真机测试
系统版本
Android 5.1.1,level 22
ROM
google/hammerhead
CPU架构
armeabi-v7a
如题。拍照后返回直接销毁本界面,(不重新显示拍照界面)怎么处理。
android 7.0 手机 第一次运行的时候闪退 第二次运行就正常
targetSdkVersion 25的情况下
前置摄像头点了没反映
测试版本 1.0.9
E/AndroidRuntime: FATAL EXCEPTION: Thread-19
java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.(Camera.java:571)
at android.hardware.Camera.open(Camera.java:415)
at com.cjt2325.cameralibrary.CameraInterface.openCamera(CameraInterface.java:253)
at com.cjt2325.cameralibrary.CameraInterface.doOpenCamera(CameraInterface.java:247)
at com.cjt2325.cameralibrary.JCameraView$6.run(JCameraView.java:572)
我的为什么拍完不能查看呢?
手机:oppo R9 5.1
把你的权限判断都注释掉了,开始进入还是会黑屏,切换摄像头会变好
初步测试结果,使用ffmpeg做出和楼主同样的界面,加入视频压缩,视频可缩小一倍以上并画质不变。
但是ffmpeg过大,希望楼主给出一个不需要添加ffmpeg库的视频压缩的方案,
下载的demo和我自己集成使用都存在
直接启动app黑屏(权限没问题)
点击前后置切换按钮可以显示画面
或者按Home键再切回来也可以显示画面
手机华为荣耀V8 android7.0
华为7.0手机上报错
我下载库下来使用,发现有时候拍照结束后,左边的取消按钮圆中间的那个黑色的勾,概率性的出现显示问题。 这个是动画太快,没有画笔没用反应过来么?
private static Rect calculateTapArea(float x, float y, float coefficient, Camera.Size previewSize) {
float focusAreaSize = 300;
int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();
int centerX = (int) (x / previewSize.width - 1000);
int centerY = (int) (y / previewSize.height - 1000);
int left = clamp(centerX - areaSize / 2, -1000, 1000);
int top = clamp(centerY - areaSize / 2, -1000, 1000);
RectF rectF = new RectF(left, top, left + areaSize, top + areaSize);
return new Rect(Math.round(rectF.left), Math.round(rectF.top), Math.round(rectF.right), Math.round(rectF
.bottom));
}
你好,这一部分代码 int centerX = (int) (x / previewSize.width - 1000);不需要加*2000么?即 int centerX = (int) (x / previewSize.width *2000 - 1000);
只是有一些卡顿的问题,比如拍照的时候按钮先变化,然后等一会图片才显示出来
点击切换摄像头时,程序崩溃
﹀ 可以替换成 × 吗 。
还有如果我依赖了最新的1.0.5的库,会报下面的错
D:\studiocode\Um\recordtest\build\intermediates\res\merged\debug\values-v24\values-v24.xml
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
Error:Execution failed for task ':recordtest:processDebugResources'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'D:\Android\sdk\build-tools\23.0.3\aapt.exe'' finished with non-zero exit value 1
后边我换了1.0.2的库就没有报这样的错了。是我这边配置的问题吗?
我测试使用的手机是魅蓝3(android5.1)和华为荣耀PE-CL00(android4.4.2)
点击进入之后后置摄像头的预览画面是黑屏的,需要调用一下切换摄像头按钮,切换成前置摄像头才可以看到前置摄像头的预览画面,再切换回后置摄像头,也可以看到后置摄像头的预览画面了。
private int determineDisplayOrientation() {
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
Camera.getCameraInfo(SELECTED_CAMERA, cameraInfo);
// Clockwise rotation needed to align the window display to the natural position
int rotation = ((Activity)getContext()).getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0;
switch (rotation) {
case Surface.ROTATION_0: {
degrees = 0;
break;
}
case Surface.ROTATION_90: {
degrees = 90;
break;
}
case Surface.ROTATION_180: {
degrees = 180;
break;
}
case Surface.ROTATION_270: {
degrees = 270;
break;
}
}
int displayOrientation;
// CameraInfo.Orientation is the angle relative to the natural position of the device
// in clockwise rotation (angle that is rotated clockwise from the natural position)
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
// Orientation is angle of rotation when facing the camera for
// the camera image to match the natural orientation of the device
displayOrientation = (cameraInfo.orientation + degrees) % 360;
displayOrientation = (360 - displayOrientation) % 360;
} else {
displayOrientation = (cameraInfo.orientation - degrees + 360) % 360;
}
// mCamera.setDisplayOrientation(mImageParameters.mDisplayOrientation);
return displayOrientation;
}
最后调用:
camera.setDisplayOrientation(determineDisplayOrientation());
因为是翻转camera的 生成的bitmap对象要翻转回来。
我是来提问题的。
我的nexus6 系统n; 一打开是黑屏的 点击屏幕就报错:
Exception in MessageQueue callback: handleReceiveCallback (JCameraView.java:643)
要点击翻转前置摄像头才能预览摄像头。
相机拍照横向拍的时候拿到的照片应该进行翻转
由于android6.0以上需要动态申请权限,调用此段代码会到时Activity的onPause调用,从而导致JCameraView类中的mCamera为null,所以当surfaceCreated执行时mCamera为null,导致无法预览。这里把JCameraView类中的onresume方法中的setStartPreview方法注释去掉即可
拍摄视频按住不放直到录制时间到了要弹到视频播放界面,会挂掉,在播放视频界面长按刚才那个位置也会挂掉,错误信息如下:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.setParameters(android.hardware.Camera$Parameters)' on a null object reference
at com.cjt2325.cameralibrary.JCameraView$1.scale(JCameraView.java:187)
at com.cjt2325.cameralibrary.CaptureButton.onTouchEvent(CaptureButton.java:272)
at android.view.View.dispatchTouchEvent(View.java:8614)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2523)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2175)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2530)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1786)
at android.app.Activity.dispatchTouchEvent(Activity.java:2819)
at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2487)
at android.view.View.dispatchPointerEvent(View.java:8820)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4756)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4613)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4103)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4156)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4122)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4259)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4130)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4316)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4103)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4156)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4122)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4130)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4103)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6565)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6539)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6492)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6745)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6683)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6771)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:570)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
at android.os.Handler.handleCallback(Handle
请问如何在预览的时候也是横着的
在录制视频的时候,频繁的按住松开会提示录制时间过短,几次之后就报如下error,不知道是不是我手机的问题。
Process: com.example.gridviewtest, PID: 3948
java.lang.RuntimeException: stop failed.
at android.media.MediaRecorder.stop(Native Method)
at com.cjt2325.cameralibrary.CameraInterface.stopRecord(CameraInterface.java:311)
at com.cjt2325.cameralibrary.JCameraView$2$2.run(JCameraView.java:245)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
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.