@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 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(); }
/** * 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; } }); }
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()); }
@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(); }
/** * 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); }
private void startRecording() { mRecordableSurfaceView.startRecording(); mIsRecording = true; mRecordBtn.setText("Stop"); }
private void stopRecording() { mRecordableSurfaceView.stopRecording(); mIsRecording = false; mBitmapHandler.postDelayed(new Runnable() { @Override public void run() { showRecordedFile(mOutputFile.getAbsolutePath()); } }, 250); }
mRecordableSurfaceView.getWidth(), mRecordableSurfaceView.getHeight()); mSurfaceTexture.setDefaultBufferSize(preViewSize.getWidth(), preViewSize.getHeight()); float screenAspect = mRecordableSurfaceView.getWidth() * 1.0f/ mRecordableSurfaceView.getHeight(); float previewAspect = preViewSize.getHeight() * 1.0f/ preViewSize.getWidth();
@Override protected void onResume() { super.onResume(); // The following call resumes a paused rendering thread. // If you de-allocated graphic objects for onPause() // this is a good place to re-allocate them. if (PermissionsHelper.hasPermissions(this)) { // 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); } } else { PermissionsHelper.requestPermissions(this); } }
private void stopRecording() { if (mIsRecording) { mTimeElapsedTextView.setText("0:00"); mRecordableSurfaceView.stopRecording(); try { mCurrentVideoFile = getVideoFile(); android.graphics.Point size = new android.graphics.Point(); getWindowManager().getDefaultDisplay().getRealSize(size); mRecordableSurfaceView.initRecorder(mCurrentVideoFile, size.x, size.y, null, null); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex); } mIsRecording = false; } mRecordButton.setBackgroundResource(R.drawable.record_off); mRecordButton.setEnabled(true); //restart the camera with anew surface Toast.makeText(this, "File recording complete: " + getVideoFile().getAbsolutePath(), Toast.LENGTH_LONG).show(); }
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.resume(); getWindowManager().getDefaultDisplay().getRealSize(size); try { mRecordableSurfaceView.initRecorder(mOutputFile, size.x, size.y, null, null); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex);
@Override protected void onPause() { super.onPause(); shutdownCamera(); mRecordableSurfaceView.pause(); }
mRecordableSurfaceView.startRecording();
mRecordableSurfaceView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) {
private void setReady() { getImage(getIntent()); android.graphics.Point size = new android.graphics.Point(); getWindowManager().getDefaultDisplay().getRealSize(size); //then setup our camera renderer mRenderer = new LipFlipRenderer(this, size.x, size.y); mBitmapHandler = new BitmapHandler(this); mRenderer.setBitmapHandler(mBitmapHandler); mRenderer.setInitialBitmap(mInitialBitmap); Bitmap theMap = mPaintView.getDrawingCopy(size.x, size.y); mRenderer.setPaintTexture(theMap); setupCameraFragment(mRenderer); //now that renderer is created and ready, await new bitmaps mPaintView.setOnNewBitmapReadyListener(this); mPaintView.hintSize(size.x, size.y); //initial config if needed mRecordableSurfaceView.resume(); try { mOutputFile = getFile("lipflip_"); mRecordableSurfaceView.initRecorder(mOutputFile, size.x, size.y, null, null); mVideoFragment.setVideoRenderer(mRenderer); } catch (IOException ioex) { Log.e(TAG, "Couldn't re-init recording", ioex); } }
@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(); }