android.view.SurfaceHolder Java Examples

The following examples show how to use android.view.SurfaceHolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContinuousCaptureActivity.java    From grafika with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_continuous_capture);

    SurfaceView sv = (SurfaceView) findViewById(R.id.continuousCapture_surfaceView);
    SurfaceHolder sh = sv.getHolder();
    sh.addCallback(this);

    mHandler = new MainHandler(this);
    mHandler.sendEmptyMessageDelayed(MainHandler.MSG_BLINK_TEXT, 1500);

    mOutputFile = new File(getFilesDir(), "continuous-capture.mp4");
    mSecondsOfVideo = 0.0f;
    updateControls();
}
 
Example #2
Source File: LiveStuffH4.java    From goprohero with MIT License 6 votes vote down vote up
@Override
 public void surfaceCreated(SurfaceHolder sh) {
     _mediaPlayer = new MediaPlayer();
     _mediaPlayer.setDisplay(_surfaceHolder);

     Context context = getApplicationContext();
//     Map<String, String> headers = getRtspHeaders();
     Uri source = Uri.parse(RTSP_URL);

     try {
         // Specify the IP camera's URL and auth headers.
      //   _mediaPlayer.setDataSource(context, source, headers);

         // Begin the process of setting up a video stream.
         _mediaPlayer.setOnPreparedListener(this);
         _mediaPlayer.prepareAsync();
     }
     catch (Exception e) {}
 }
 
Example #3
Source File: BinaryWatchFaceService.java    From WearBinaryWatchFace with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(SurfaceHolder holder) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "onCreate");
    }
    super.onCreate(holder);

    mTime = new Time();

    dotXOffest = -1;
    dotYOffest = -1;

    doBackgroundComputation();

    init();
}
 
Example #4
Source File: VideoView.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
  mSurfaceWidth = w;
  mSurfaceHeight = h;
  boolean isValidState = (mTargetState == STATE_PLAYING);
  boolean hasValidSize = (mVideoWidth == w && mVideoHeight == h);
  if (mMediaPlayer != null && isValidState && hasValidSize) {
    if (mSeekWhenPrepared != 0)
      seekTo(mSeekWhenPrepared);
    start();
    if (mMediaController != null) {
      if (mMediaController.isShowing())
        mMediaController.hide();
      mMediaController.show();
    }
  }
}
 
Example #5
Source File: CameraBridgeViewBase.java    From Document-Scanner with GNU General Public License v3.0 6 votes vote down vote up
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    Log.d(TAG, "call surfaceChanged event");
    synchronized(mSyncObject) {
        if (!mSurfaceExist) {
            mSurfaceExist = true;
            checkCurrentState();
        } else {
            /** Surface changed. We need to stop camera and restart with new parameters */
            /* Pretend that old surface has been destroyed */
            mSurfaceExist = false;
            checkCurrentState();
            /* Now use new surface. Say we have it now */
            mSurfaceExist = true;
            checkCurrentState();
        }
    }
}
 
Example #6
Source File: ARCamera.java    From ar-location-based-android with MIT License 6 votes vote down vote up
public void surfaceCreated(SurfaceHolder holder) {
    try {
        if (camera != null) {

            parameters = camera.getParameters();

            int orientation = getCameraOrientation();

            camera.setDisplayOrientation(orientation);
            camera.getParameters().setRotation(orientation);

            camera.setPreviewDisplay(holder);
        }
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
}
 
Example #7
Source File: MediaShootActivity.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
	getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
			WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.zg_activity_video_shoot);
	mFacing = (TextView) findViewById(R.id.tv_facing);
	mSurfaceView = (SurfaceView) findViewById(R.id.surfaceview_shoot);
	mShoot = (ImageView) findViewById(R.id.img_shoot);
	mChronometer = (Chronometer) findViewById(R.id.video_chronometer);
	mFacing.setOnClickListener(this);
	mShoot.setOnClickListener(this);

	initToggle();
	findViewById(R.id.iv_left).setOnClickListener(this);

	SurfaceHolder mHolder = mSurfaceView.getHolder();
	mHolder.addCallback(this);
	mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example #8
Source File: OpenGlRtmpActivity.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 6 votes vote down vote up
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
  if (rtmpCamera1.isRecording()) {
    rtmpCamera1.stopRecord();
    bRecord.setText(R.string.start_record);
    Toast.makeText(this,
        "file " + currentDateAndTime + ".mp4 saved in " + folder.getAbsolutePath(),
        Toast.LENGTH_SHORT).show();
    currentDateAndTime = "";
  }
  if (rtmpCamera1.isStreaming()) {
    rtmpCamera1.stopStream();
    button.setText(getResources().getString(R.string.start_button));
  }
  rtmpCamera1.stopPreview();
}
 
Example #9
Source File: QRCodeReaderView.java    From DanDanPlayForAndroid with MIT License 6 votes vote down vote up
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    SimpleLog.d(TAG, "surfaceChanged");

    if (holder.getSurface() == null) {
        SimpleLog.e(TAG, "Error: preview surface does not exist");
        return;
    }

    if (mCameraManager.getPreviewSize() == null) {
        SimpleLog.e(TAG, "Error: preview size does not exist");
        return;
    }

    mPreviewWidth = mCameraManager.getPreviewSize().x;
    mPreviewHeight = mCameraManager.getPreviewSize().y;

    mCameraManager.stopPreview();

    // Fix the camera sensor rotation
    mCameraManager.setPreviewCallback(this);
    mCameraManager.setDisplayOrientation(getCameraDisplayOrientation());

    mCameraManager.startPreview();
}
 
Example #10
Source File: CaptureActivity.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
    public void surfaceCreated(SurfaceHolder holder) {
        if (holder == null) {
            Log.e(TAG_LOG, "*** WARNING *** surfaceCreated() gave us a null surface!");
        }
        if (!hasSurface) {
            hasSurface = true;
//            initCamera(holder);
        }
    }
 
Example #11
Source File: VideoViewH264m3u8Hw.java    From letv with Apache License 2.0 5 votes vote down vote up
public void surfaceDestroyed(SurfaceHolder holder) {
    LogTag.i(VideoViewH264m3u8Hw.TAG, "mSHCallback:surfaceDestroyed()");
    VideoViewH264m3u8Hw.this.mSurfaceHolder = null;
    if (VideoViewH264m3u8Hw.this.mMediaController != null) {
        VideoViewH264m3u8Hw.this.mMediaController.hide();
    }
    VideoViewH264m3u8Hw.this.lastSeekWhenDestoryed = VideoViewH264m3u8Hw.this.getCurrentPosition();
    VideoViewH264m3u8Hw.this.release(false);
}
 
Example #12
Source File: AndroidMediaPlayerFacadeTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Test
public void givenSurfaceRequesterReturnsSurface_whenPreparing_thenSetsSurface() {
    Surface surface = mock(Surface.class);
    Either<Surface, SurfaceHolder> eitherSurface = Either.left(surface);
    givenSurfaceRequesterReturns(eitherSurface);

    givenMediaPlayerIsPreparedWith(eitherSurface);

    verify(mediaPlayer).setSurface(surface);
}
 
Example #13
Source File: RecordFBOActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    Log.d(TAG, "surfaceDestroyed holder=" + holder);

    // We need to wait for the render thread to shut down before continuing because we
    // don't want the Surface to disappear out from under it mid-render.  The frame
    // notifications will have been stopped back in onPause(), but there might have
    // been one in progress.
    //
    // TODO: the RenderThread doesn't currently wait for the encoder / muxer to stop,
    //       so we can't use this as an indication that the .mp4 file is complete.

    RenderHandler rh = mRenderThread.getHandler();
    if (rh != null) {
        rh.sendShutdown();
        try {
            mRenderThread.join();
        } catch (InterruptedException ie) {
            // not expected
            throw new RuntimeException("join was interrupted", ie);
        }
    }
    mRenderThread = null;
    mRecordingEnabled = false;

    // If the callback was posted, remove it.  Without this, we could get one more
    // call on doFrame().
    Choreographer.getInstance().removeFrameCallback(this);
    Log.d(TAG, "surfaceDestroyed complete");
}
 
Example #14
Source File: JCameraView.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
    LogUtil.i("JCameraView SurfaceCreated");
    new Thread() {
        @Override
        public void run() {
            CameraInterface.getInstance().doOpenCamera(JCameraView.this);
        }
    }.start();
}
 
Example #15
Source File: AnimCube.java    From AnimCubeAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
    synchronized (animThreadLock) {
        if (animThreadInactive || interrupted) {
            animThread.interrupt();
            animThread = new Thread(animRunnable);
            animThread.start();
        }
        repaint();
    }
}
 
Example #16
Source File: AWindow.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private SurfaceHelper(int id, Surface surface, SurfaceHolder surfaceHolder) {
    mId = id;
    mSurfaceView = null;
    mTextureView = null;
    mSurfaceHolder = surfaceHolder;
    mSurface = surface;
}
 
Example #17
Source File: ScannerActivity.java    From Tesseract-OCR-Scanner with Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (!mHasSurface) {
        mHasSurface = true;
        initCamera(holder);
    }
}
 
Example #18
Source File: GameView.java    From wearabird with MIT License 5 votes vote down vote up
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
	boolean retry = true;
	thread.setRunning(false);
	while (retry) {
		try {
			thread.join();
			retry = false;
		} catch (InterruptedException ignore) {
		}
	}
}
 
Example #19
Source File: IjkBaseMedia.java    From QSVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void setDisplay(SurfaceHolder surfaceHolder) {
    try {
        if (mediaPlayer != null)
            mediaPlayer.setDisplay(surfaceHolder);
        if (surfaceHolder != null)
            this.surface = surfaceHolder.getSurface();
    } catch (Exception e) {
        e.printStackTrace();
        iMediaCallback.onError(this, MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_UNKNOWN);
    }
}
 
Example #20
Source File: CameraFragment.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    // Now that the size is known, set up the camera parameters and begin
    // the preview.
    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
    requestLayout();

    mCamera.setParameters(parameters);
    mCamera.startPreview();
}
 
Example #21
Source File: CameraFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
Preview(Context context) {
    super(context);

    mSurfaceView = new SurfaceView(context);
    addView(mSurfaceView);

    // Install a SurfaceHolder.Callback so we get notified when the
    // underlying surface is created and destroyed.
    mHolder = mSurfaceView.getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
 
Example #22
Source File: BubbleSurfaceView.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
public void surfaceCreated(SurfaceHolder holder) {
    Canvas canvas = sh.lockCanvas();
    canvas.drawColor(Color.BLACK);
    canvas.drawCircle(100, 200, 50, paint);

    sh.unlockCanvasAndPost(canvas);

    visualizeBufferThread = new VisualizeBufferThread("localhost", 1972);
    visualizeBufferThread.setRunning(true);
    visualizeBufferThread.start();

    drawThread = new DrawThread(sh, ctx, null, visualizeBufferThread);
    drawThread.setRunning(true);
    drawThread.start();
}
 
Example #23
Source File: GameView.java    From wearabird with MIT License 5 votes vote down vote up
private void init(@SuppressWarnings("UnusedParameters") Context context) {
	SurfaceHolder holder = getHolder();
	holder.addCallback(this);
	holder.setFormat(PixelFormat.RGBA_8888);
	setKeepScreenOn(true);
	mainThreadHandler = new Handler(Looper.getMainLooper());
}
 
Example #24
Source File: CameraPreview.java    From IDCardCamera with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    mContext = context;
    mSurfaceHolder = getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setKeepScreenOn(true);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    mSensorControler = SensorControler.getInstance(context.getApplicationContext());
}
 
Example #25
Source File: MainActivity.java    From handwriter with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    resultDestroy(result);
    characterDestroy(character);
    recognizerDestroy(recognizer);
    mThread = null;
}
 
Example #26
Source File: CameraPreview.java    From privacy-friendly-shopping-list with Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder)
{
    try
    {
        mCamera.setPreviewDisplay(holder);
        mCamera.startPreview();
    }
    catch ( IOException e )
    {
        // ignore
    }
}
 
Example #27
Source File: GLSurfaceView.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
private void init() {
	// Install a SurfaceHolder.Callback so we get notified when the
	// underlying surface is created and destroyed
	SurfaceHolder holder = getHolder();
	holder.addCallback(this);
	// setFormat is done by SurfaceView in SDK 2.3 and newer. Uncomment
	// this statement if back-porting to 2.2 or older:
	// holder.setFormat(PixelFormat.RGB_565);
	//
	// setType is not needed for SDK 2.0 or newer. Uncomment this
	// statement if back-porting this code to older SDKs.
	// holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
}
 
Example #28
Source File: MainActivity.java    From OpenCvFaceDetect with Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (isCheckPermissionOk) {
        Log.e(TAG, "surfaceCreated: ");
        CameraApi.getInstance().setCameraId(CameraApi.CAMERA_INDEX_BACK);
        CameraApi.getInstance().initCamera(this, this);
        CameraApi.getInstance().setPreviewSize(new Size(previewWidth, previewHeight));
        CameraApi.getInstance().setFps(30).configCamera();
    }
}
 
Example #29
Source File: MainActivity.java    From augmentedreality with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	
	//display setup stuff
       tv_alt = (TextView) findViewById(R.id.altitudeValue);
       tv_lat = (TextView) findViewById(R.id.latitudeValue);
       tv_long = (TextView) findViewById(R.id.longitudeValue);
       
       tv_head = (TextView) findViewById(R.id.headingValue);
       tv_pitch = (TextView) findViewById(R.id.pitchValue);
       tv_roll = (TextView) findViewById(R.id.rollValue);
       
	tv_x = (TextView) findViewById(R.id.xAxisValue);
       tv_y = (TextView) findViewById(R.id.yAxisValue);
       tv_z = (TextView) findViewById(R.id.zAxisValue);

	//we need the sensor manager and the gps manager, the 
	//registration is all in onpause and onresume;
	mgr = (SensorManager) this.getSystemService(SENSOR_SERVICE);
	//orientation 
	orient = mgr.getDefaultSensor(Sensor.TYPE_ORIENTATION);
	//acceleraometer
	accel = mgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
	//gps location information
	myL = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	//setup the location listener.


	//all the camera preivew information
       inPreview = false;
       cameraPreview = (SurfaceView)findViewById(R.id.cameraPreview);
       previewHolder = cameraPreview.getHolder();
       previewHolder.addCallback(this);
       previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
	
}
 
Example #30
Source File: CapturePreview.java    From VideoCamera with Apache License 2.0 5 votes vote down vote up
public CapturePreview(CapturePreviewInterface capturePreviewInterface, CameraWrapper cameraWrapper,
		SurfaceHolder holder) {
	mInterface = capturePreviewInterface;
	mCameraWrapper = cameraWrapper;

	initalizeSurfaceHolder(holder);
}