Java Code Examples for android.view.SurfaceHolder

The following examples show how to use android.view.SurfaceHolder. These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: DanDanPlayForAndroid   Source File: QRCodeReaderView.java    License: 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 2
@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 3
Source Project: goprohero   Source File: LiveStuffH4.java    License: 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 4
Source Project: grafika   Source File: ContinuousCaptureActivity.java    License: 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 5
@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 6
Source Project: MyHearts   Source File: VideoView.java    License: 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 7
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 8
Source Project: ar-location-based-android   Source File: ARCamera.java    License: 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 9
@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 10
Source Project: androidtestdebug   Source File: CameraFragment.java    License: 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 11
Source Project: dttv-android   Source File: MediaPlayer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the SurfaceHolder to use for displaying the video portion of the
 * media. This call is optional. Not calling it when playing back a video will
 * result in only the audio track being played.
 *
 * @param sh the SurfaceHolder to use for video display
 */
public void setDisplay(SurfaceHolder sh) {
    if (sh == null) {
        releaseDisplay();
        return;
    }
    mSurfaceHolder = sh;
    mSurface = sh.getSurface();
    native_set_video_surface(mSurface);
    updateSurfaceScreenOn();
}
 
Example 12
Source Project: wearabird   Source File: GameView.java    License: 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 13
public void surfaceCreated(SurfaceHolder holder) {
    try {
        Camera.Parameters parameters = mCamera.getParameters();
        parameters.set("orientation", "portrait");
        mCamera.setParameters(parameters);
        mCamera.setDisplayOrientation(90);
        mCamera.setPreviewDisplay(holder);
        mCamera.startPreview();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 14
Source Project: AnimCubeAndroid   Source File: AnimCube.java    License: 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 15
Source Project: JPPF   Source File: FractalSurfaceView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  try {
    while (!stopped.get()) {
      if (!queue.isEmpty() || firstDraw.get()) {
        SurfaceHolder holder = getHolder();
        if (holder != null) {
          Canvas canvas = null;
          try {
            canvas = holder.lockCanvas();
            synchronized(holder) {
              doDraw(canvas);
            }
          } finally {
            if (canvas != null) holder.unlockCanvasAndPost(canvas);
          }
        }
      } else {
        synchronized(this) {
          wait(100L);
        }
      }
    }
  } catch(Exception e) {
    Log.e(LOG_TAG, "Exception in ViewThread.run()", e);
  }
}
 
Example 16
Source Project: SimplePomodoro-android   Source File: BGSurfaceView.java    License: MIT License 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
	// TODO Auto-generated method stub
	_thread = new MainThread();
	_thread.setRunning(true);
	_thread.start();
}
 
Example 17
Source Project: Slide   Source File: MediaVideoViewOld.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void initVideoView() {
    mVideoWidth = 0;
    mVideoHeight = 0;
    getHolder().addCallback(mSHCallback);
    getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
    mPendingSubtitleTracks = new Vector<>();
    mCurrentState = STATE_IDLE;
    mTargetState = STATE_IDLE;
}
 
Example 18
Source Project: imsdk-android   Source File: JCameraView.java    License: 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 19
Source Project: SimplifyReader   Source File: CaptureActivity.java    License: 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 20
Source Project: letv   Source File: VideoViewH264m3u8Hw.java    License: 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 21
Source Project: grafika   Source File: RecordFBOActivity.java    License: 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 22
Source Project: VCL-Android   Source File: AWindow.java    License: 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 23
Source Project: Tesseract-OCR-Scanner   Source File: ScannerActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void surfaceCreated(SurfaceHolder holder) {
    if (!mHasSurface) {
        mHasSurface = true;
        initCamera(holder);
    }
}
 
Example 24
Source Project: QSVideoPlayer   Source File: IjkBaseMedia.java    License: 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 25
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 26
Source Project: no-player   Source File: AndroidMediaPlayerFacadeTest.java    License: 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 27
Source Project: buffer_bci   Source File: BubbleSurfaceView.java    License: 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 28
Source Project: wearabird   Source File: GameView.java    License: 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 29
Source Project: IDCardCamera   Source File: CameraPreview.java    License: 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 30
Source Project: handwriter   Source File: MainActivity.java    License: 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;
}