@SuppressLint("NewApi") private void setupMediaProjection() { mMediaProjection = mMediaProjectionManager.getMediaProjection( MainActivity.mResultCode, MainActivity.mResultData); }
private void stopCapture() { if (projection!=null) { projection.stop(); vdisplay.release(); projection=null; } }
private void startCapture() { projection=mgr.getMediaProjection(resultCode, resultData); it=new ImageTransmogrifier(this); MediaProjection.Callback cb=new MediaProjection.Callback() { @Override public void onStop() { vdisplay.release(); } }; vdisplay=projection.createVirtualDisplay("andshooter", it.getWidth(), it.getHeight(), getResources().getDisplayMetrics().densityDpi, VIRT_DISPLAY_FLAGS, it.getSurface(), null, handler); projection.registerCallback(cb, handler); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mgr=(MediaProjectionManager)getSystemService(MEDIA_PROJECTION_SERVICE); startActivityForResult(mgr.createScreenCaptureIntent(), REQUEST_SCREENSHOT); }
@Override public void start() { mEncoder = new ScreenRecordEncoder(mVideoConfiguration); Surface surface = mEncoder.getSurface(); mEncoder.start(); mEncoder.setOnVideoEncodeListener(mListener); mMediaProjection = mManager.getMediaProjection(resultCode, resultData); int width = VideoMediaCodec.getVideoSize(mVideoConfiguration.width); int height = VideoMediaCodec.getVideoSize(mVideoConfiguration.height); mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenRecoder", width, height, 1, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, surface, null, null); }
@SuppressLint("NewApi") private void setupVirtualDisplay() { mVirtualDisplay = mMediaProjection.createVirtualDisplay( "ScreenCapture", sreenWindowWidth, screenWindowHeight, mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mImageReader.getSurface(), null, null); mImageReader.setOnImageAvailableListener( new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { Image image = mImageReader.acquireLatestImage(); if (image != null) { processScreenImage(image); image.close(); } } }, null); }
static void start(int resultCode, Intent data) { mediaProjectionCallback = new MediaProjectionCallback(); mediaProjection = projectionManager.getMediaProjection(resultCode, data); mediaProjection.registerCallback(mediaProjectionCallback, null); virtualDisplay = createVirtualDisplay(); mediaRecorder.start(); setRecording(true); }
private static void destroyMediaProjection() { if (mediaProjection != null) { mediaProjection.unregisterCallback(mediaProjectionCallback); mediaProjection.stop(); mediaProjection = null; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mgr=(MediaProjectionManager)getSystemService(MEDIA_PROJECTION_SERVICE); startActivityForResult(mgr.createScreenCaptureIntent(), REQUEST_SCREENCAST); }
void start() { recorder=new MediaRecorder(); recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setVideoFrameRate(config.frameRate); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); recorder.setVideoSize(config.width, config.height); recorder.setVideoEncodingBitRate(config.bitRate); recorder.setOutputFile(output.getAbsolutePath()); try { recorder.prepare(); vdisplay=projection.createVirtualDisplay("andcorder", config.width, config.height, config.density, VIRT_DISPLAY_FLAGS, recorder.getSurface(), null, null); beeper.startTone(ToneGenerator.TONE_PROP_ACK); recorder.start(); } catch (IOException e) { throw new RuntimeException("Exception preparing recorder", e); } }
synchronized private void startRecorder() { if (session==null) { MediaProjectionManager mgr= (MediaProjectionManager)getSystemService(MEDIA_PROJECTION_SERVICE); MediaProjection projection= mgr.getMediaProjection(resultCode, resultData); session= new RecordingSession(this, new RecordingConfig(this), projection); session.start(); } }
void stop() { projection.stop(); recorder.stop(); recorder.release(); vdisplay.release(); MediaScannerConnection.scanFile(ctxt, new String[]{output.getAbsolutePath()}, null, this); }
@SuppressLint("NewApi") @Override public void onClick(View v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mMediaProjectionManager = (MediaProjectionManager) getApplicationContext() .getSystemService(MEDIA_PROJECTION_SERVICE); startActivityForResult(mMediaProjectionManager .createScreenCaptureIntent(), REQUEST_MEDIA_PROJECTION); } } });
private static VirtualDisplay createVirtualDisplay() { return mediaProjection.createVirtualDisplay("HyperionRecorder", displayMetrics.widthPixels, displayMetrics.heightPixels, displayMetrics.densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mediaRecorder.getSurface(), null /* Callbacks */, null /* Handler */); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void onReceive(Context context, Intent intent) { unregisterRequestCaptureReceiver(); int resultCode = intent.getIntExtra(RequestCaptureActivity.RESULT_EXTRA_CODE, Activity.RESULT_CANCELED); Intent data = intent.getParcelableExtra(RequestCaptureActivity.RESULT_EXTRA_DATA); final MediaProjection mediaProjection = projectionManager.getMediaProjection(resultCode, data); if (mediaProjection == null) { captureCanvasScreenshot(); return; } if (intent.getBooleanExtra(RequestCaptureActivity.RESULT_EXTRA_PROMPT_SHOWN, true)) { // Delay capture until after the permission dialog is gone. postDelayed(new Runnable() { @Override public void run() { captureNativeScreenshot(mediaProjection); } }, 500); } else { captureNativeScreenshot(mediaProjection); } } };
@Override public void stop() { if(mEncoder != null) { mEncoder.setOnVideoEncodeListener(null); mEncoder.stop(); mEncoder = null; } if (mMediaProjection != null) { mMediaProjection.stop(); mMediaProjection = null; } if (mVirtualDisplay != null) { mVirtualDisplay.release(); mVirtualDisplay = null; } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) protected void requestRecording() { if(!SopCastUtils.isOverLOLLIPOP()) { SopCastLog.d(TAG, "Device don't support screen recording."); return; } mMediaProjectionManage = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); Intent captureIntent = mMediaProjectionManage.createScreenCaptureIntent(); startActivityForResult(captureIntent, RECORD_REQUEST_CODE); }
projection.createVirtualDisplay("telescope", width, height, displayMetrics.densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESENTATION, surface, null, null);
static void requestStart(ActivityResults activityResults, int requestCode) { activityResults.startActivityForResult(projectionManager.createScreenCaptureIntent(), requestCode); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void requestCapture() { MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); Intent intent = projectionManager.createScreenCaptureIntent(); requestStartTime = System.currentTimeMillis(); startActivityForResult(intent, REQUEST_CODE); }