@Override public void run() { try { try { prepareEncode(); mediaMuxer = new MediaMuxer(filePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4); } catch (IOException e) { throw new RuntimeException(e); } mVirtualDisplay = displayManager.createVirtualDisplay( TAG, mWidth, mHeight, mDpi, mSurface, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC); // Log.d(TAG, "created virtual display: " + mVirtualDisplay); recordVideo(); } finally { try { release(); } catch (Exception e) { e.printStackTrace(); } } }
@TargetApi(19) public void startDisplayManager() { DisplayManager mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE); Surface encoderInputSurface = null; try { encoderInputSurface = createDisplaySurface(); } catch (IOException e) { e.printStackTrace(); } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { virtualDisplay = mDisplayManager.createVirtualDisplay( "Remote Droid", CodecUtils.WIDTH, CodecUtils.HEIGHT, 50, encoderInputSurface, DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE); } else { if (MainActivity.mMediaProjection != null) { virtualDisplay = MainActivity.mMediaProjection.createVirtualDisplay( "Remote Droid", CodecUtils.WIDTH, CodecUtils.HEIGHT, 50, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, encoderInputSurface, null, null); } else { showToast("Something went wrong. Please restart the app."); } } encoder.start(); }