本地录制相关 API

本文介绍了与本地音视频录制相关的 API。

使用本地相机

<com.mpaas.idrs.video.MPCameraView
  android:id="@+id/cameraview_tack_recoder"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_alignParentRight="true"
  android:background="#000"
  android:layout_centerVertical="true"/>

开启录制

public void startRecord()

请求参数

返回值

代码示例

final String vidoiFilePath = ConfigurationFile.getInstance().createVidoiFilePath(this);

cameraView.init(vidoiFilePath, new MPCameraView.InitCallback() {
    @Override
    public void initSuccess(int width, int height) {
        cameraView.post(new Runnable() {
            @Override
            public void run() {
                cameraView.startRecord();
            }
        });
        
    }
});

设置监听摄像头

public void setCameraFrameListener(MPCameraView.CameraFrameListener 
                                    cameraFrameListener)

请求参数

参数

类型

说明

是否必须

cameraFrameListener

MPCameraView.CameraFrameListener

数据回调接口

返回值

代码示例

 cameraView.setCameraFrameListener(new CameraFrameListener() {
            @Override
            public void onCameraFrame(byte[] data, int imageWidth, 
                                      int imageHeight, int angle, 
                                      int degree, boolean needFlipX) {
                
            }

        });

设置音频监听

 public void setAudioListener(MPCameraView.AudioListener audioListener)

请求参数

参数

类型

说明

是否必须

audioListener

MPCameraView.AudioListener

音频数据回调接口

返回值

代码示例

 cameraView.setAudioListener(new AudioListener() {
            @Override
            public void onAudioFrame(byte[] audioFrame) {
                if (isRecognize) {
                    ArrayQueue.getInstance().add(audioFrame);
                }
            }
        });

设置录制监听

public void setRecordListener(MPCameraView.RecordListener recordListener)

请求参数

参数

类型

说明

是否必须

recordListener

MPCameraView.RecordListener

录制监听回调接口

返回值

代码示例

        cameraView.setRecordListener(new RecordListener() {
            @Override
            public void onFinish(String filePath) {
            }

            @Override
            public void onFail(int code) {
                Toast.makeText(RecordTestActivity.this, "录制失败", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onStart() {

            }

            @Override
            public Object[] onCheckFrameExtraData() {
                if (mNeedWaterMarker) {
                    Bitmap bitmap = Bitmap.createBitmap(270, 100, Config.ARGB_8888);
                    Canvas canvas = new Canvas(bitmap);
                    canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG|Paint.FILTER_BITMAP_FLAG));
                    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
                    paint.setTextSize(
                        28);
                    paint.setColor(Color.WHITE);
                    canvas.drawText(getTimeStr(), 0, 30, paint);
                    canvas.drawText("北京市丰台区", 0, 60, paint);

                    Rect rect = new Rect(20, 50, 290, 150);
                    Object[] objects = new Object[2];
                    objects[0] = bitmap;
                    objects[1] = rect;
                    return objects;
                } else {
                    return null;
                }
            }
        });

结束录制

public void stopRecord()

请求参数

返回值

代码示例

cameraView.stopRecord();
cameraView.release();