Camera setPreviewCallback - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Camera setPreviewCallback method.

This code example shows how to use the following methods:setPreviewCallback
    if (camera != null && previewing) {
      previewCallback.setHandler(handler, message);
      if (useOneShotPreviewCallback) {
        camera.setOneShotPreviewCallback(previewCallback);
      } else { 
        camera.setPreviewCallback(previewCallback);
      } 
    } 
  } 
 
  /** 
   * Asks the camera hardware to perform an autofocus. 
   * 
   * @param handler The Handler to notify when the autofocus completes. 
   * @param message The message to deliver. 
   */ 
  public void requestAutoFocus(Handler handler, int message) {
    if (camera != null && previewing) {
      autoFocusCallback.setHandler(handler, message);
      //Log.d(TAG, "Requesting auto-focus callback"); 
9
CodeRank
This code example shows how to use the following methods:setPreviewCallback
  public void testSetPreviewCallbacks() throws Exception { 
    TestPreviewCallback callback = new TestPreviewCallback();
    assertThat(callback.camera).isNull();
    assertThat(callback.data).isNull();
 
    camera.setPreviewCallback(callback);
    shadowCamera.invokePreviewCallback("foobar".getBytes());
 
    assertThat(callback.camera).isSameAs(camera);
    assertThat(callback.data).isEqualTo("foobar".getBytes());
  } 
 
  @Test 
  public void testSetOneShotPreviewCallbacks() throws Exception { 
    TestPreviewCallback callback = new TestPreviewCallback();
    assertThat(callback.camera).isNull();
    assertThat(callback.data).isNull();
 
    camera.setOneShotPreviewCallback(callback);
    shadowCamera.invokePreviewCallback("foobar".getBytes());
7
CodeRank
This code example shows how to use the following methods:setPreviewCallback, stopPreview
        try { 
            previewBufferLock.lock();
            isRunning = false;
            previewBufferLock.unlock();
 
            camera.stopPreview();
 
            if(android.os.Build.VERSION.SDK_INT > 7) {
                camera.setPreviewCallbackWithBuffer(null);
            } 
            else { 
                camera.setPreviewCallback(null);
            } 
        } 
        catch (Exception ex) {
            Log.e("*WEBRTC*", "Failed to stop camera");
            return -1; 
        } 
 
        if(DEBUG) {
7
CodeRank
This code example shows how to use the following methods:setPreviewCallback
    if (camera != null && previewing) {
      previewCallback.setHandler(handler, message);
      if (useOneShotPreviewCallback) {
        camera.setOneShotPreviewCallback(previewCallback);
      } else { 
        camera.setPreviewCallback(previewCallback);
      } 
    } 
  } 
 
  /** 
   * Asks the camera hardware to perform an autofocus. 
   * 
   * @param handler The Handler to notify when the autofocus completes. 
   * @param message The message to deliver. 
   */ 
  public void requestAutoFocus(Handler handler, int message) {
    if (camera != null && previewing) {
      autoFocusCallback.setHandler(handler, message);
      //Log.d(TAG, "Requesting auto-focus callback"); 
8
CodeRank
This code example shows how to use the following methods:release, setPreviewCallback, stopPreview
 
	private void closeCamera() { 
		lock.lock();
		try { 
			if (camera != null) {
				camera.stopPreview();
				camera.setPreviewCallback(null);
				camera.release();
				camera = null;
			} 
		} finally { 
			lock.unlock();
		} 
	} 
	public String getLocalIpAddress() {
	    try { 
	        for (Enumeration<NetworkInterface> en = NetworkInterface
	                .getNetworkInterfaces(); en.hasMoreElements();) {
	            NetworkInterface intf = en.nextElement();
	            for (Enumeration<InetAddress> enumIpAddr = intf
7
CodeRank
This code example shows how to use the following methods:release, setPreviewCallback, setPreviewDisplay
      // The Surface has been created, acquire the camera and tell it where 
      // to draw. 
      mCamera = Camera.open();
      try 
      { 
         mCamera.setPreviewDisplay(holder);
         mCamera.setPreviewCallback(this);//added by zjl
      } 
      catch (IOException exception)
      { 
          mCamera.setPreviewCallback(null);//added by zjl
          mCamera.release();
          mCamera = null;           
          // TODO: add more exception handling logic here 
      } 
  } 
 
  public void surfaceDestroyed(SurfaceHolder holder)
  { 
      // Surface will be destroyed when we return, so stop the preview. 
7
CodeRank
This code example shows how to use the following methods:setPreviewCallback, stopPreview
   * Tells the camera to stop drawing preview frames. 
   */ 
  public void stopPreview() { 
    if (camera != null && previewing) {
      if (!useOneShotPreviewCallback) {
        camera.setPreviewCallback(null);
      } 
      camera.stopPreview();
      previewCallback.setHandler(null, 0);
      autoFocusCallback.setHandler(null, 0);
      previewing = false;
    } 
  } 
 
  /** 
   * A single preview frame will be returned to the handler supplied. The data will arrive as byte[] 
   * in the message.obj field, with width and height encoded as message.arg1 and message.arg2, 
   * respectively. 
   * 
   * @param handler The handler to send the message to. 
7
CodeRank
This code example shows how to use the following methods:release, setPreviewCallback, setPreviewDisplay, startPreview
        // preview callbacks in the queue after quit is called. The preview 
        // callback still uses the camera object (setHasPreviewCallback). 
        // After camera is released, RuntimeException will be thrown from 
        // the method. So we need to join the looper thread here. 
        mLooper.getThread().join();
        mCamera.release();
    } 
     
    //Implement the previewCallback 
    private final class RawPreviewCallback implements PreviewCallback { 
        public void onPreviewFrame(byte [] rawData, Camera camera) {         
            Log.v(TAG, "Preview callback start");            
            int rawDataLength = 0;
            if (rawData != null) {
                rawDataLength = rawData.length;
            } 
            if (rawDataLength > 0) {
                rawPreviewCallbackResult = true;
            } else { 
                rawPreviewCallbackResult = false;

8
CodeRank
This code example shows how to use the following methods:setPreviewCallback, setPreviewDisplay
  public void surfaceCreated(SurfaceHolder holder) {  // <7>
    // The Surface has been created, acquire the camera and tell it where 
    // to draw. 
    camera = Camera.open(); // <8>
    try { 
      camera.setPreviewDisplay(holder);  // <9>
 
      camera.setPreviewCallback(new PreviewCallback() { // <10>
        // Called for each frame previewed 
        public void onPreviewFrame(byte[] data, Camera camera) {  // <11>
          Log.d(TAG, "onPreviewFrame called at: " + System.currentTimeMillis());
          Preview.this.invalidate();  // <12>
        } 
      }); 
    } catch (IOException e) { // <13>
      e.printStackTrace();
    } 
  } 
 
  // Called when the holder is destroyed 
7
CodeRank
This code example shows how to use the following methods:release, setPreviewCallback, stopPreview
	} 
 
	@Override 
	public void surfaceDestroyed(SurfaceHolder holder) {
//		Log.e(TAG, "surfaceDestroyed"); 
		mCamera.stopPreview();
		mCameraRunning = false;
		mCamera.setPreviewCallback(null);
		mCamera.release();
//		Log.d(TAG, "finish surfaceDestroyed"); 
	} 
//	/** 
//	 * choose best supported preview size  
//	 * @param previewSizes 
//	 * @return 
//	 */ 
//	private Size getProperSize(List<Size> previewSizes) { 
//		int minWidth = 640; 
//		int minHeight = 320; 
//		int numberOfSize = 0; 
7
CodeRank

Related Camera setPreviewCallback Questions & Answers:

setPreviewCallback Method Overview
Installs a callback to be invoked for every preview frame in addition to displaying them on the screen.
See Code Examples for other Android Camera Methods: