Use MediaProjection to get Screen Capture.
https://github.com/etcparking/ScreenCapture
如果对你有帮助,请Star,谢谢!
compile 'com.shark:screencapture:1.0.0'
ScreenCapture mScreenCapture = ScreenCapture.newInstance(this);
mScreenCapture.setCaptureListener(new ScreenCapture.OnCaptureListener() {
@Override
public void onScreenCaptureSuccess(Bitmap bitmap, String savePath) {
Log.d(TAG, "onScreenCaptureSuccess savePath:" + savePath);
}
@Override
public void onScreenCaptureFailed(String errorMsg) {
Log.d(TAG, "onScreenCaptureFailed errorMsg:" + errorMsg);
}
@Override
public void onScreenRecordStart() {
Log.d(TAG, "onScreenRecordStart");
}
@Override
public void onScreenRecordStop() {
Log.d(TAG, "onScreenRecordStop");
}
@Override
public void onScreenRecordSuccess(String savePath) {
Log.d(TAG, "onScreenRecordSuccess savePath:" + savePath);
}
@Override
public void onScreenRecordFailed(String errorMsg) {
Log.d(TAG, "onScreenRecordFailed errorMsg:" + errorMsg);
}
});
可不设置,即使用默认路径
mScreenCapture.setImagePath(Environment.getExternalStorageDirectory().getPath() + "/ScreenCapture/screen_capture/", "image_screen.png");
mScreenCapture.setRecordPath(Environment.getExternalStorageDirectory().getPath() + "/ScreenCapture/record/", "recording_screen.mp4");
if (mScreenCapture != null) {
mScreenCapture.screenCapture();
}
if (mScreenCapture != null) {
mScreenCapture.record();
}
/**
* Handle permission here which caused by MediaProjectionManager.createScreenCaptureIntent()
* @param requestCode
* @param resultCode
* @param data
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mScreenCapture != null) {
mScreenCapture.onActivityResult(requestCode, resultCode, data);
}
}
/**
* Handle permission here. Like Manifest.permission.WRITE_EXTERNAL_STORAGE
* @param requestCode
* @param permissions
* @param grantResults
*/
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (mScreenCapture != null) {
mScreenCapture.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mScreenCapture != null) {
mScreenCapture.cleanup();
mScreenCapture = null;
}
}
将2个视频文件,拼接为一个文件,拼接前提是,2个文件的编码信息一样,包括video codec(H264的话,包括profile/level) video width/height, audio codec, audio sample rate, channel number
public VideoComposer(ArrayList<String> videoList, String outFilename) {
mVideoList = videoList;
this.mOutFilename = outFilename;
mReadBuf = ByteBuffer.allocate(1048576);
}
/**
**拼接视频的方法
*/
public boolean joinVideo(){
}