@Override @TargetApi(21) protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) { String uri = data.toUri(0); MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Activity.MEDIA_PROJECTION_SERVICE); MediaProjection mediaProjection = projectionManager.getMediaProjection(resultCode, data); ScreenCaptureService.setMediaProjection(mediaProjection); startService(new Intent(ScreenCaptureService.ACTION_START, null, this, ScreenCaptureService.class)); fab.setSelected(true); } if (requestCode == REQUEST_CODE_MAKE_SMING && resultCode == RESULT_OK) { loadSmings(); checkEmpty(); } }
private void showYZBRecordDialog(MediaProjection mediaProjection, String path, boolean isRecordAudio) { if (mYZBRecordScreenDialog == null) { mYZBRecordScreenDialog = new YZBRecordScreenDialog(getContext(), R.style.record_dialog); mYZBRecordScreenDialog.setFilePath(path); Window window = mYZBRecordScreenDialog.getWindow(); window.setGravity(Gravity.BOTTOM); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; window.setAttributes(layoutParams); mYZBRecordScreenDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // showSystemUI(); } }); } //第二个参数表述是否录制音频数据 mYZBRecordScreenDialog.setActivityResult(mediaProjection, isRecordAudio); mYZBRecordScreenDialog.setIShareLivePlayer(mIShareLivePlayer); mYZBRecordScreenDialog.setCallback(mCallback); mYZBRecordScreenDialog.show(); }
private void showRecordDialog(MediaProjection mediaProjection, String filePath, boolean isRecordAudio) { if (mRecordDialog == null) { mRecordDialog = new RecordScreenDialog(getContext(), R.style.record_dialog); mRecordDialog.setFilePath(filePath); Window window = mRecordDialog.getWindow(); window.setGravity(Gravity.BOTTOM); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; window.setAttributes(layoutParams); mRecordDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // showSystemUI(); } }); } //第二个参数表述是否录制音频数据 mRecordDialog.setActivityResult(mediaProjection, isRecordAudio); mRecordDialog.setIShareLivePlayer(mIShareLivePlayer); mRecordDialog.setCallback(mCallback); mRecordDialog.show(); }
public void initCapture(Context context, MediaProjection mediaProjection, final String path, final IRecordShotCallback callback){ int screenWidth = context.getResources().getDisplayMetrics().widthPixels; int screenHeight = context.getResources().getDisplayMetrics().heightPixels; // thread for image checking mCheckThread = new HandlerThread("CheckHandler"); mCheckThread.start(); mCheckHandler = new Handler(mCheckThread.getLooper()); try { mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2); mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() { @Override public void onImageAvailable(ImageReader reader) { imageAvailable(reader, path, callback); } }, mCheckHandler); mSurface = mImageReader.getSurface(); }finally { } mVirtualDisplay = mediaProjection.createVirtualDisplay("mediaprojection", screenWidth, screenHeight, 1, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mSurface, null, null); }
public ProjectionManager(Context context, DisplayMetrics metrics, int permissionsResultCode, Intent permissionsData, final MediaRouter router) { mDensity = metrics.densityDpi; mProjection = ((MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE)) .getMediaProjection(permissionsResultCode, permissionsData); if (mProjection == null) { throw new IllegalStateException("Null media projection manager - " + CastScreenActivity.PLEASE_REPORT_BUG); } // When the MediaProjection is stopped, deselect the active route to ensure casting stops mProjection.registerCallback(new MediaProjection.Callback() { @Override public void onStop() { router.selectRoute(router.getDefaultRoute()); } }, null); }
@TargetApi(Build.VERSION_CODES.M) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_MEDIAPROJECTION) { if (resultCode == RESULT_OK) { MediaProjection projection = mProjectionManager.getMediaProjection(resultCode, data); mScreenCapture = new ScreenCapture(this, projection); } } else { if (!android.provider.Settings.canDrawOverlays(this)) { Snackbar.make(contentView, getString(R.string.pleaseEnablePermissions), Snackbar.LENGTH_LONG).show(); } else { tryToLaunchGame(); } } }
@TargetApi(Build.VERSION_CODES.M) @Override /** * Called when another activity has sent a result to this activity. For example when this activity starts the * activity which calls for the projectionmanager, which tells this class if the screen capture has been enabled. */ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == OVERLAY_PERMISSION_REQ_CODE) { updateLaunchButtonText(false); } else if (requestCode == SCREEN_CAPTURE_REQ_CODE) { if (resultCode == RESULT_OK) { MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService( Context.MEDIA_PROJECTION_SERVICE); MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data); screen = ScreenGrabber.init(mProjection, rawDisplayMetrics); startPokeFly(); } else { updateLaunchButtonText(false); } } }
public Session(int type,String mVideoPath,String mDestination,int mDestinationPort, VideoQuality mVideoQuality,int mTimeToLive, String mOrigin,int mOriginPort,MediaProjection mMediaProjection){ this.sessionType = type; this.mVideoPath = mVideoPath; this.mDestination = mDestination; this.mDestinationPort = mDestinationPort; this.mVideoQuality = mVideoQuality; this.mTimeToLive = mTimeToLive; this.mOrigin = mOrigin; this.mOriginPort = mOriginPort; this.mMediaProjection = mMediaProjection; try { mDestinationAddress = InetAddress.getByName(mDestination); } catch (UnknownHostException e) { e.printStackTrace(); } long uptime = System.currentTimeMillis(); HandlerThread thread = new HandlerThread("com.example.ljd.mylibstreaming.LibRTSP.session.Session"); thread.start(); mHandler = new Handler(thread.getLooper()); mMainHandler = new Handler(Looper.getMainLooper()); mTimestamp = (uptime/1000)<<32 & (((uptime-((uptime/1000)*1000))>>32)/1000); // NTP timestamp }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); String ip = mReceiverIpEditText.getText().toString(); final SharedPreferences sharedPreferences = getSharedPreferences(PREF_NAME, 0); final SharedPreferences.Editor edit = sharedPreferences.edit(); edit.putString(RECEIVER_IP_KEY,ip); edit.commit(); if(resultCode == RESULT_OK && requestCode==GET_MEDIA_PROJECTION_CODE){ try { @SuppressWarnings("ResourceType") MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); final MediaProjection mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data); mEncoderAsyncTask = new EncoderAsyncTask(this, mediaProjection, mMediaCodecFactory); mEncoderAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); mSenderAsyncTask = new SenderAsyncTask(ip); mSenderAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } catch (IOException e) { mStartButton.setEnabled(false); mStartButton.setText(getString(R.string.mediacodec_error)); e.printStackTrace(); } } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE) { if (resultCode != RESULT_OK) { return; } MediaProjection mediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data); mScreenRecorder = new EasyScreenRecorder(this, generatePath(getDateTimeString()), mediaProjection); mScreenRecorder.start(); } }
public MediaScreenEncoder(final MediaMuxerWrapper muxer, final MediaEncoderListener listener, final MediaProjection projection, final int width, final int height, final int density, final int _bitrate, final int _fps) { super(muxer, listener, width, height); mMediaProjection = projection; mDensity = density; fps = (_fps > 0 && _fps <= 30) ? _fps : FRAME_RATE; bitrate = (_bitrate > 0) ? _bitrate : calcBitRate(_fps); final HandlerThread thread = new HandlerThread(TAG); thread.start(); mHandler = new Handler(thread.getLooper()); }
@TargetApi(21) private VideoCapturer createScreenCapturer() { if (mediaProjectionPermissionResultCode != Activity.RESULT_OK) { reportError("User didn't give permission to capture the screen."); return null; } return new ScreenCapturerAndroid( mediaProjectionPermissionResultData, new MediaProjection.Callback() { @Override public void onStop() { reportError("User revoked permission to capture the screen."); } }); }
/** * 设置开始后的ActivityResult回掉 */ public void setActivityResult(int resultCode, Intent data, String filePath) { if (mMediaProjectionManager == null) { return; } MediaProjection mediaProjection = mMediaProjectionManager.getMediaProjection(resultCode, data); TotalController.getInstance().captureScreenImage(getContext(), mFilePath, mediaProjection, mCallback); }
/** * onActivityResult(XXXX)回掉之后就该调用这个方法 * * @param context * @param mediaProjection * @param isAudience */ public void start(Context context, MediaProjection mediaProjection, Boolean isAudience) { if (mYixiaMuxerWrapper != null) { mYixiaMuxerWrapper.setIsRecordAudio(isAudience); } isRecording = true; mVideoHandlerThread.prepar(context, mediaProjection, mYixiaMuxerWrapper); mVideoHandlerThread.startRecording(); mAudioHandlerThread.prepar(mYixiaMuxerWrapper); mAudioHandlerThread.startRecording(); }
public ProjectionThread(MediaProjection mediaProjection, Context context, ProjectionThreadRunner runner) { this.mediaProjection = mediaProjection; this.context = context.getApplicationContext(); this.runner = runner; state = runner.getState(); handler = new Handler(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private ScreenGrabber(MediaProjection mediaProjection, DisplayMetrics raw) { rawDisplayMetrics = raw; projection = mediaProjection; imageReader = ImageReader.newInstance(rawDisplayMetrics.widthPixels, rawDisplayMetrics.heightPixels, PixelFormat.RGBA_8888, 2); virtualDisplay = projection.createVirtualDisplay("screen-mirror", rawDisplayMetrics.widthPixels, rawDisplayMetrics.heightPixels, rawDisplayMetrics.densityDpi, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, imageReader.getSurface(), null, null); }
public Session(int type, VideoQuality mVideoQuality,int mTimeToLive, int mOriginPort,MediaProjection mMediaProjection){ this.sessionType = type; this.mVideoQuality = mVideoQuality; this.mTimeToLive = mTimeToLive; this.mOriginPort = mOriginPort; this.mMediaProjection = mMediaProjection; }
@Override public Session CreatSession(int type,String mVideoPath, String mDestination, int mDestinationPort, VideoQuality mVideoQuality, int mTimeToLive, String mOrigin, int mOriginPort, MediaProjection mMediaProjection) { Session session = mSessions.get(type); if(session == null) { Log.i(TAG,"新建一个session"); session = new Session(type, mVideoPath, mDestination, mDestinationPort, mVideoQuality, mTimeToLive, mOrigin, mOriginPort, mMediaProjection); mSessions.put(type,session); } return session; }
private void requestPermission(final PermissionCallback callback) { if (mMediaProjection != null) { callback.onAllowed(); } else { Intent intent = new Intent(); intent.setClass(mContext, PermissionReceiverActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(EXTRA_CALLBACK, new ResultReceiver(new Handler(Looper.getMainLooper())) { @Override protected void onReceiveResult(final int resultCode, final Bundle resultData) { if (resultCode == Activity.RESULT_OK) { Intent data = resultData.getParcelable(RESULT_DATA); if (data != null) { mMediaProjection = mManager.getMediaProjection(resultCode, data); mMediaProjection.registerCallback(new MediaProjection.Callback() { @Override public void onStop() { clean(); } }, new Handler(Looper.getMainLooper())); } } if (mMediaProjection != null) { callback.onAllowed(); } else { callback.onDisallowed(); } } }); mContext.startActivity(intent); } }
EncoderAsyncTask(MediaCodecListener listener, MediaProjection projection, MediaCodecFactory factory) throws IOException { mListener = listener; mEncoder = factory.createVideoEncoder(); Surface surface = mEncoder.createInputSurface(); mEncoder.start(); mVirtualDisplay = projection.createVirtualDisplay(LOG_TAG, factory.getWidth(), factory.getHeight(), DisplayMetrics.DENSITY_MEDIUM, 0, surface, null, null); }
public ScreenRecorder(int width, int height, int bitrate, int dpi, MediaProjection mp, String dstPath) { super(TAG); mWidth = width; mHeight = height; mBitRate = bitrate; mDpi = dpi; mMediaProjection = mp; mDstPath = dstPath; }
public ScreenRecorder(MediaProjection mp) { // 480p 2Mbps this(640, 480, 2000000, 1, mp, "/sdcard/test.mp4"); }
public static void setMediaProjection(MediaProjection mediaProjection) { if (mediaProjection == null) { return; } sMediaProjection = mediaProjection; }
public EasyScreenRecorder(Context context, String path, MediaProjection mediaProjection) { this.mContext = context; this.mPath = path; this.mMediaProjection = mediaProjection; }
public void prepar(Context context, MediaProjection mp, YXMuxerWrapper muxer) { mYixiaScreenEncoder.prepar(context, mp, muxer); }
public void prepar(Context context, MediaProjection mp, YXMuxerWrapper muxer) { mDpi = context.getResources().getDisplayMetrics().densityDpi; mWeakMuxer = muxer; mMediaProjection = mp; }
public void setMediaProject(MediaProjection project) { mediaProjection = project; }
public static ScreenGrabber init(MediaProjection mediaProjection, DisplayMetrics raw) { if (instance == null) { instance = new ScreenGrabber(mediaProjection, raw); } return instance; }
public MediaProjection getMediaProjection() { return mMediaProjection; }
public void setMediaProjection(MediaProjection mMediaProjection) { this.mMediaProjection = mMediaProjection; }
public abstract Session CreatSession(int type,String mVideoPath, String mDestination, int mDestinationPort, VideoQuality mVideoQuality, int mTimeToLive, String mOrigin, int mOriginPort, MediaProjection mMediaProjection);
public H264Encorder( VideoQuality mRequestedQuality, MediaProjection mMediaProjection ) { this.mRequestedQuality = mRequestedQuality; this.mMediaProjection = mMediaProjection; }
public MediaProjection getProjection(MediaProjectionManager manager) { return manager.getMediaProjection(resultCode, projectionIntent); }
/** * Constructs a new Screen Capturer. * * @param mediaProjectionPermissionResultData the result data of MediaProjection permission * activity; the calling app must validate that result code is Activity.RESULT_OK before * calling this method. * @param mediaProjectionCallback MediaProjection callback to implement application specific * logic in events such as when the user revokes a previously granted capture permission. **/ public ScreenCapturerAndroid(Intent mediaProjectionPermissionResultData, MediaProjection.Callback mediaProjectionCallback) { this.mediaProjectionPermissionResultData = mediaProjectionPermissionResultData; this.mediaProjectionCallback = mediaProjectionCallback; }
/** * 设置开始后的ActivityResult回掉 * * @param mediaProjection * @param isAudience 是否录制音频数据 */ public void setActivityResult(MediaProjection mediaProjection, Boolean isAudience) { mMediaProjection = mediaProjection; this.isAudience = isAudience; }
/** * android 5.0以上屏幕截图 * * @param mediaProjection * @param callback */ public void captureScreenImage(Context context, String path, MediaProjection mediaProjection, IRecordShotCallback callback) { CaptureScreenImage.getInstance().initCapture(context, mediaProjection, path, callback); }