Skip to content

非常简单的安卓屏幕录制功能,录制停止,开启关闭

Notifications You must be signed in to change notification settings

etcparking/ScreenCapture

Repository files navigation

ScreenCapture

android 录屏软件

android 合并多个视频软件

Use MediaProjection to get Screen Capture.

项目地址

https://github.com/etcparking/ScreenCapture

如果对你有帮助,请Star,谢谢!

Gradle 引用

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);
        }
    }

最后记得cleanup

    @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

VideoComposer

  public VideoComposer(ArrayList<String> videoList, String outFilename) {
        mVideoList = videoList;
        this.mOutFilename = outFilename;
        mReadBuf = ByteBuffer.allocate(1048576);
    }
    
    /**
    **拼接视频的方法
    */
    public boolean joinVideo(){
    }

About

非常简单的安卓屏幕录制功能,录制停止,开启关闭

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages