@Override public void onClick(View view) { if (System.currentTimeMillis() - lastClickTime < CLICK_DELAY) { return; } else lastClickTime = System.currentTimeMillis(); if (Build.VERSION.SDK_INT > 15) { MediaActionSound sound = new MediaActionSound(); if (TAKE_PHOTO_STATE == currentState) { takePhoto(sound); } else if (READY_FOR_RECORD_STATE == currentState) { startRecording(sound); } else if (RECORD_IN_PROGRESS_STATE == currentState) { stopRecording(sound); } } else { if (TAKE_PHOTO_STATE == currentState) { takePhoto(); } else if (READY_FOR_RECORD_STATE == currentState) { startRecording(); } else if (RECORD_IN_PROGRESS_STATE == currentState) { stopRecording(); } } setIcon(); }
private void takeSnapshot() { // get the snapshot image Bitmap image = textureView.getBitmap(); // save the image SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss"); String name = camera.network + "_" + camera.name.replaceAll("\\s+", "") + "_" + sdf.format(new Date()) + ".jpg"; Utils.saveImage(getActivity().getContentResolver(), image, name, null); Log.info("takeSnapshot: " + name); // play the shutter sound MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); // display a message String msg = String.format(getString(R.string.image_saved), getString(R.string.app_name)); Toast toast = Toast.makeText(getActivity(), msg, Toast.LENGTH_SHORT); toast.show(); }
@Override public synchronized void play(int action) { switch(action) { case FOCUS_COMPLETE: mSound.play(MediaActionSound.FOCUS_COMPLETE); break; case START_VIDEO_RECORDING: mSound.play(MediaActionSound.START_VIDEO_RECORDING); break; case STOP_VIDEO_RECORDING: mSound.play(MediaActionSound.STOP_VIDEO_RECORDING); break; case SHUTTER_CLICK: mSound.play(MediaActionSound.SHUTTER_CLICK); break; default: Log.w(TAG, "Unrecognized action:" + action); } }
/** * capture the map as an image */ private void captureScreenshotAsync() { // export the image from the mMapView final ListenableFuture<Bitmap> export = mMapView.exportImageAsync(); export.addDoneListener(new Runnable() { @Override public void run() { try { Bitmap currentMapImage = export.get(); // play the camera shutter sound MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); Log.d(TAG,"Captured the image!!"); // save the exported bitmap to an image file SaveImageTask saveImageTask = new SaveImageTask(); saveImageTask.execute(currentMapImage); } catch (Exception e) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.map_export_failure) + e.getMessage(), Toast.LENGTH_SHORT).show(); Log.e(TAG, getResources().getString(R.string.map_export_failure) + e.getMessage()); } } }); }
protected void takePhoto(CameraFragmentResultListener callback, @Nullable String directoryPath, @Nullable String fileName) { if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) { new MediaActionSound().play(MediaActionSound.SHUTTER_CLICK); } setRecordState(Record.TAKE_PHOTO_STATE); this.cameraController.takePhoto(callback, directoryPath, fileName); if (cameraFragmentStateListener != null) { cameraFragmentStateListener.onRecordStatePhoto(); } }
protected void startRecording(@Nullable String directoryPath, @Nullable String fileName) { if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) { new MediaActionSound().play(MediaActionSound.START_VIDEO_RECORDING); } setRecordState(Record.RECORD_IN_PROGRESS_STATE); this.cameraController.startVideoRecord(directoryPath, fileName); if (cameraFragmentStateListener != null) { cameraFragmentStateListener.onRecordStateVideoInProgress(); } }
protected void stopRecording(CameraFragmentResultListener callback) { if (Build.VERSION.SDK_INT > MIN_VERSION_ICECREAM) { new MediaActionSound().play(MediaActionSound.STOP_VIDEO_RECORDING); } setRecordState(Record.READY_FOR_RECORD_STATE); this.cameraController.stopVideoRecord(callback); this.onStopVideoRecord(callback); if (cameraFragmentStateListener != null) { cameraFragmentStateListener.onRecordStateVideoReadyForRecord(); } }
/** * Standard constructor * * @param ctxt any Context will do */ public CameraTwoEngine(Context ctxt) { mgr=(CameraManager)ctxt. getApplicationContext(). getSystemService(Context.CAMERA_SERVICE); handlerThread.start(); handler=new Handler(handlerThread.getLooper()); shutter.load(MediaActionSound.SHUTTER_CLICK); }
void takePicture(){ if(mCameraSource != null){ mCameraSource.takePicture(new CameraSource.ShutterCallback() { @Override public void onShutter() { sound.play(MediaActionSound.SHUTTER_CLICK); } }, new CameraSource.PictureCallback() { @Override public void onPictureTaken(byte[] data) { detectDocumentManually(data); } }); } }
public MediaActionSoundPlayer() { mSound = new MediaActionSound(); mSound.load(MediaActionSound.START_VIDEO_RECORDING); mSound.load(MediaActionSound.STOP_VIDEO_RECORDING); mSound.load(MediaActionSound.FOCUS_COMPLETE); mSound.load(MediaActionSound.SHUTTER_CLICK); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onAutoFocus(boolean success, Camera camera) { if (success && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { new MediaActionSound().play(MediaActionSound.FOCUS_COMPLETE); } }
/** * Standard constructor * * @param ctxt any Context will do */ public CameraTwoEngine(Context ctxt) { this.ctxt=ctxt.getApplicationContext(); mgr=(CameraManager)this.ctxt. getSystemService(Context.CAMERA_SERVICE); handlerThread.start(); handler=new Handler(handlerThread.getLooper()); shutter.load(MediaActionSound.SHUTTER_CLICK); }
@Override public void onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp, long frameNumber) { super.onCaptureStarted(session, request, timestamp, frameNumber); shutter.play(MediaActionSound.SHUTTER_CLICK); }
private void playShutterSound() { MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); }
private void playFocusSound() { MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.FOCUS_COMPLETE); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void takePhoto(MediaActionSound sound) { //关闭声音 sound.play(MediaActionSound.SHUTTER_CLICK); takePhoto(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void startRecording(MediaActionSound sound) { //关闭声音 sound.play(MediaActionSound.START_VIDEO_RECORDING); startRecording(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void stopRecording(MediaActionSound sound) { //关闭声音 sound.play(MediaActionSound.STOP_VIDEO_RECORDING); stopRecording(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void takePhoto(MediaActionSound sound) { sound.play(MediaActionSound.SHUTTER_CLICK); takePhoto(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void startRecording(MediaActionSound sound) { sound.play(MediaActionSound.START_VIDEO_RECORDING); startRecording(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void stopRecording(MediaActionSound sound) { sound.play(MediaActionSound.STOP_VIDEO_RECORDING); stopRecording(); }
/** * Instantiates a new camera based on Camera 2 API. * * @param device The underlying Camera 2 device. * @param characteristics The device's characteristics. * @param pictureSize the size of the final image to be taken. */ OneCameraZslImpl(CameraDevice device, CameraCharacteristics characteristics, Size pictureSize) { Log.v(TAG, "Creating new OneCameraZslImpl"); mDevice = device; mCharacteristics = characteristics; mFullSizeAspectRatio = calculateFullSizeAspectRatio(characteristics); mCameraThread = new HandlerThread("OneCamera2"); // If this thread stalls, it will delay viewfinder frames. mCameraThread.setPriority(Thread.MAX_PRIORITY); mCameraThread.start(); mCameraHandler = new Handler(mCameraThread.getLooper()); mCameraListenerThread = new HandlerThread("OneCamera2-Listener"); mCameraListenerThread.start(); mCameraListenerHandler = new Handler(mCameraListenerThread.getLooper()); // TODO: Encoding on multiple cores results in preview jank due to // excessive GC. int numEncodingCores = CameraUtil.getNumCpuCores(); mImageSaverThreadPool = new ThreadPoolExecutor(numEncodingCores, numEncodingCores, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); mCaptureManager = new ImageCaptureManager(MAX_CAPTURE_IMAGES, mCameraListenerHandler, mImageSaverThreadPool); mCaptureManager.setCaptureReadyListener(new ImageCaptureManager.CaptureReadyListener() { @Override public void onReadyStateChange(boolean capturePossible) { mReadyStateManager.setInput(ReadyStateRequirement.CAPTURE_MANAGER_READY, capturePossible); } }); // Listen for changes to auto focus state and dispatch to // mFocusStateListener. mCaptureManager.addMetadataChangeListener(CaptureResult.CONTROL_AF_STATE, new ImageCaptureManager.MetadataChangeListener() { @Override public void onImageMetadataChange(Key<?> key, Object oldValue, Object newValue, CaptureResult result) { mFocusStateListener.onFocusStatusUpdate( AutoFocusHelper.stateFromCamera2State( result.get(CaptureResult.CONTROL_AF_STATE)), result.getFrameNumber()); } }); // Allocate the image reader to store all images received from the // camera. if (pictureSize == null) { // TODO The default should be selected by the caller, and // pictureSize should never be null. pictureSize = getDefaultPictureSize(); } mCaptureImageReader = ImageReader.newInstance(pictureSize.getWidth(), pictureSize.getHeight(), sCaptureImageFormat, MAX_CAPTURE_IMAGES); mCaptureImageReader.setOnImageAvailableListener(mCaptureManager, mCameraHandler); mMediaActionSound.load(MediaActionSound.SHUTTER_CLICK); }
private void onShutterInvokeUI(final PhotoCaptureParameters params) { // Tell CaptureModule shutter has occurred so it can flash the screen. params.callback.onQuickExpose(); // Play shutter click sound. mMediaActionSound.play(MediaActionSound.SHUTTER_CLICK); }
public void playActionSoundAutofocusComplete() { MediaActionSound player = getMediaActionSound(); if (player == null) return; if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return; player.play(MediaActionSound.FOCUS_COMPLETE); }
public void playActionSoundShutter() { MediaActionSound player = getMediaActionSound(); if (player == null) return; if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return; player.play(MediaActionSound.SHUTTER_CLICK); }
/** * Play the camera shutter shound */ private void playShutterSound() { MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); }