Search in sources :

Example 1 with ErrorListener

use of com.cjt2325.cameralibrary.listener.ErrorListener in project CameraView by CJT2325.

the class CameraActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.activity_camera);
    jCameraView = (JCameraView) findViewById(R.id.jcameraview);
    // 设置视频保存路径
    jCameraView.setSaveVideoPath(Environment.getExternalStorageDirectory().getPath() + File.separator + "JCamera");
    jCameraView.setFeatures(JCameraView.BUTTON_STATE_BOTH);
    jCameraView.setTip("JCameraView Tip");
    jCameraView.setMediaQuality(JCameraView.MEDIA_QUALITY_MIDDLE);
    jCameraView.setErrorLisenter(new ErrorListener() {

        @Override
        public void onError() {
            // 错误监听
            Log.i("CJT", "camera error");
            Intent intent = new Intent();
            setResult(103, intent);
            finish();
        }

        @Override
        public void AudioPermissionError() {
            Toast.makeText(CameraActivity.this, "给点录音权限可以?", Toast.LENGTH_SHORT).show();
        }
    });
    // JCameraView监听
    jCameraView.setJCameraLisenter(new JCameraListener() {

        @Override
        public void captureSuccess(Bitmap bitmap) {
            // 获取图片bitmap
            // Log.i("JCameraView", "bitmap = " + bitmap.getWidth());
            String path = FileUtil.saveBitmap("JCamera", bitmap);
            Intent intent = new Intent();
            intent.putExtra("path", path);
            setResult(101, intent);
            finish();
        }

        @Override
        public void recordSuccess(String url, Bitmap firstFrame) {
            // 获取视频路径
            String path = FileUtil.saveBitmap("JCamera", firstFrame);
            Log.i("CJT", "url = " + url + ", Bitmap = " + path);
            Intent intent = new Intent();
            intent.putExtra("path", path);
            setResult(101, intent);
            finish();
        }
    });
    jCameraView.setLeftClickListener(new ClickListener() {

        @Override
        public void onClick() {
            CameraActivity.this.finish();
        }
    });
    jCameraView.setRightClickListener(new ClickListener() {

        @Override
        public void onClick() {
            Toast.makeText(CameraActivity.this, "Right", Toast.LENGTH_SHORT).show();
        }
    });
    Log.i("CJT", DeviceUtil.getDeviceModel());
}
Also used : ErrorListener(com.cjt2325.cameralibrary.listener.ErrorListener) Bitmap(android.graphics.Bitmap) JCameraListener(com.cjt2325.cameralibrary.listener.JCameraListener) Intent(android.content.Intent) ClickListener(com.cjt2325.cameralibrary.listener.ClickListener)

Aggregations

Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ClickListener (com.cjt2325.cameralibrary.listener.ClickListener)1 ErrorListener (com.cjt2325.cameralibrary.listener.ErrorListener)1 JCameraListener (com.cjt2325.cameralibrary.listener.JCameraListener)1