1、背景
必行面访项目中,经纪人需要给客户录制屏幕内容介绍房源资料,因此用到了腾讯云的录屏能力,后续如果有项目仅需要录屏功能的话集成腾讯云SDK显然不是合适的方案,腾讯云SDK业务过重,集成方会依赖过多、包体积也会显著增大,因此直播中台有必要提供录屏能力。
2、接口设计
2.1、录屏接口
录屏SDK需要提供注册监听器、启动录屏、停止录屏、反注册监听器这些接口,如下所示:
public void registerListener(ScreenCaptureListener screenCaptureListener) {
if (!mScreenCaptureListenerList.contains(screenCaptureListener)) {
mScreenCaptureListenerList.add(screenCaptureListener);
}
}
public void unregisterListener(ScreenCaptureListener screenCaptureListener) {
if (mScreenCaptureListenerList.contains(screenCaptureListener)) {
mScreenCaptureListenerList.remove(screenCaptureListener);
}
}
public void startScreenCapture() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
onError(ErrorCode.ERROR_PERMISSION_LOW_VERSION_SYSTEM, ErrorMessage.ERROR_PERMISSION_LOW_VERSION_SYSTEM);
return;
}
Activity activity = getActivity();
if (activity != null) {
Intent intent = new Intent(activity, ScreenCaptureActivity.class);
activity.startActivity(intent);
}
}
public void stopScreenCapture() {
VideoManager.getInstance().stopScreenCapture();
if (Build.VERSION.SDK_INT >= 29) {
if (ServiceUtil.isServiceRunning(mContext.getApplicationContext(), ScreenCaptureService.class.getClass().getName())) {
Intent intent = new Intent(mContext, ScreenCaptureService.class);
mContext.stopService(intent);
}
}
}
2.2、回调接口
public interface ScreenCaptureListener {
void onScreenCaptureStarted();
void onScreenCaptureStopped(String videoPath);
void onScreenCaptureError(int errorCode, String errorMsg);
void onScreenCaptureBitmap(Bitmap bitmap);
}
2.3、错误码
public interface ErrorCode {
int ERROR_PERMISSION_DENIED = 1000;
int ERROR_PERMISSION_LOW