@Override public void surfaceCreated(SurfaceHolder surfaceHolder) { if (!this.isAlive() && !this.isInterrupted() && this.getState() != State.TERMINATED) { this.start(); } }
/** * Resumes a paused render thread, or in the case of an interrupted or terminated * render thread, re-calls {@link #doSetup()} to build/start the GL context again. * * This method is useful for use in conjunction with the Activity lifecycle */ public void resume() { doSetup(); mPaused = false; }
/** * add a listener for touch on our surface view that will pass raw values to our renderer for * use in our shader to control color channels. */ private void setupInteraction() { mRecordableSurfaceView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mVideoFragment.getVideoRenderer() instanceof ExampleVideoRenderer) { ((ExampleVideoRenderer) mVideoFragment.getVideoRenderer()) .setTouchPoint(event.getRawX(), event.getRawY()); return true; } return false; } }); }
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mIsRecording) { mGLView.stopRecording(); Uri contentUri = FileProvider.getUriForFile(this, "com.example.android.opengl.fileprovider", mOutputFile); share(contentUri); mIsRecording = false; mIsRecording = false; mOutputFile = createVideoOutputFile(); try { int screenWidth = mGLView.getWidth(); int screenHeight = mGLView.getHeight(); mGLView.initRecorder(mOutputFile, (int) screenWidth, (int) screenHeight, null, null); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex); } item.setTitle("Record"); } else { mGLView.startRecording(); Log.v(TAG, "Recording Started"); item.setTitle("Stop"); mIsRecording = true; } return true; }
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); // Note that order matters - see the note in onPause(), the reverse applies here. mGLView.resume(); try { mOutputFile = createVideoOutputFile(); android.graphics.Point size = new android.graphics.Point(); getWindowManager().getDefaultDisplay().getRealSize(size); mGLView.initRecorder(mOutputFile, size.x, size.y, null, null); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex); } }
private void stopRecording() { mRecordBtn.setText("Record"); Log.e(TAG, "Stopping"); mRecordableSurfaceView.stopRecording(); try { mOutputFile = getVideoFile(); android.graphics.Point size = new android.graphics.Point(); getWindowManager().getDefaultDisplay().getRealSize(size); mRecordableSurfaceView.initRecorder(mOutputFile, size.x, size.y, null, null); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex); } mIsRecording = false; Toast.makeText(this, "File recording complete: " + getVideoFile().getAbsolutePath(), Toast.LENGTH_LONG).show(); }
@Override protected void onPause() { mIsPaused = true; if (mRenderer != null && mIsRecording) { mRecordableSurfaceView.stopRecording(); } mRecordableSurfaceView.pause(); mRecordButton.setBackgroundResource(R.drawable.record_off); shutdownCamera(); AndroidUtils.cleanUpFileStubs(); mIsRecording = false; super.onPause(); }
@Override protected void onPause() { super.onPause(); // The following call pauses the rendering thread. // If your OpenGL application is memory intensive, // you should consider de-allocating objects that // consume significant memory here. mGLView.pause(); }
private void startRecording() { mRecordableSurfaceView.startRecording(); mIsRecording = true; mRecordBtn.setText("Stop"); }
/** * Iitializes the {@link MediaRecorder} ad relies on its lifecycle and requirements. * * @param saveToFile the File object to record into. Assumes the calling program has * permission to write to this file * @param displayWidth the Width of the display * @param displayHeight the Height of the display * @param errorListener optional {@link MediaRecorder.OnErrorListener} for recording state callbacks * @param infoListener optional {@link MediaRecorder.OnInfoListener} for info callbacks * @see MediaRecorder */ @SuppressWarnings({"all"}) public void initRecorder(File saveToFile, int displayWidth, int displayHeight, MediaRecorder.OnErrorListener errorListener, MediaRecorder.OnInfoListener infoListener) throws IOException { initRecorder(saveToFile, displayWidth, displayHeight, 0, errorListener, infoListener); }
public void setVideoRenderer(VideoRenderer videoRenderer) { mVideoRenderer = videoRenderer; if (mVideoRenderer == null) { return; } mVideoRenderer.setVideoFragment(VideoFragment.getInstance()); mVideoRenderer.setOnRendererReadyListener(this); mRecordableSurfaceView.setRendererCallbacks(mVideoRenderer); mVideoRenderer.onSurfaceChanged(mRecordableSurfaceView.getWidth(), mRecordableSurfaceView.getHeight()); }
private void stopRecording() { mRecordableSurfaceView.stopRecording(); mIsRecording = false; mBitmapHandler.postDelayed(new Runnable() { @Override public void run() { showRecordedFile(mOutputFile.getAbsolutePath()); } }, 250); }
/** * Performs necessary setup operations such as creating a MediaCodec persistent surface and * setting up initial state. * * Also links the SurfaceHolder that manages the Surface View to the render thread for lifecycle * callbacks * * @see MediaCodec * @see SurfaceHolder.Callback */ public void doSetup() { if (!mHasGLContext.get()) { mSurface = MediaCodec.createPersistentInputSurface(); mARRenderThread = new ARRenderThread(); } this.getHolder().addCallback(mARRenderThread); if (getHolder().getSurface().isValid()) { mARRenderThread.surfaceCreated(null); } mPaused = true; }
@Override public void onPause() { super.onPause(); closeCamera(); stopBackgroundThread(); mRecordableSurfaceView.setRendererCallbacks(null); }
@Override protected void onPause() { super.onPause(); shutdownCamera(); mRecordableSurfaceView.pause(); }
private void startRecording() { /** * hack for the spamming record button bug where if u tap the button quickly shit goes wrong * disable button on click then wait 250ms and re-enable it to stop. */ mRecordBtn.setEnabled(false); mBitmapHandler.postDelayed(new Runnable() { @Override public void run() { mRecordBtn.setEnabled(true); } }, 250); mRecordableSurfaceView.startRecording(); mIsRecording = true; }
mRecordableSurfaceView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) {
@Override protected void onPause() { mPaintView.setOnNewBitmapReadyListener(null); if (mIsRecording) { stopRecording(); } else { //if paused, make sure we shutdown and restart cam on resume mRestartCamera = true; } mRecordableSurfaceView.pause(); shutdownCamera(); FileUtils.cleanUpFileStubs(); super.onPause(); }
mRecordableSurfaceView.startRecording();