harmony 鸿蒙媒体子系统JS API变更Changelog

  • 2023-02-03
  • 浏览 (621)

媒体子系统JS API变更Changelog

OpenHarmony3.2 Beta4版本相较于OpenHarmony3.2 Beta3版本,媒体子系统camera部件API变更如下

camera接口变更

基于以下原因新增部分功能接口以及废弃部分接口: 1. 提升开发者使用相机接口的便利。 2. 帮助开发者快速掌握相机开发接口,快速投入到开发当中。 3. 易于后续版本中框架功能的扩展,降低框架模块之间的耦合度。

具体参考下方变更内容,开发者需要根据以下说明对应用进行适配。

变更影响

影响API9版本的JS接口,应用需要进行适配才可以在新版本SDK环境正常实现功能。

关键的接口/组件变更

模块名 类名 方法/属性/枚举/常量 变更类型
ohos.multimedia.camera Profile readonly format:CameraFormat; 新增
ohos.multimedia.camera Profile readonly size: Size; 新增
ohos.multimedia.camera FrameRateRange readonly min: number; 新增
ohos.multimedia.camera FrameRateRange readonly max: number; 新增
ohos.multimedia.camera VideoProfile readonly frameRateRange: FrameRateRange; 新增
ohos.multimedia.camera CameraOutputCapability readonly previewProfiles: Array; 新增
ohos.multimedia.camera CameraOutputCapability readonly photoProfiles: Array; 新增
ohos.multimedia.camera CameraOutputCapability readonly videoProfiles: Array; 新增
ohos.multimedia.camera CameraOutputCapability readonly supportedMetadataObjectTypes: Array; 新增
ohos.multimedia.camera CameraManager getSupportedCameras(callback: AsyncCallback>): void;
getSupportedCameras(): Promise>;
新增
ohos.multimedia.camera CameraManager getSupportedOutputCapability(camera: CameraDevice, callback: AsyncCallback): void;
getSupportedOutputCapability(camera: CameraDevice): Promise;
新增
ohos.multimedia.camera CameraManager isCameraMuted(): boolean; 新增
ohos.multimedia.camera CameraManager isCameraMuteSupported(): boolean; 新增
ohos.multimedia.camera CameraManager muteCamera(mute: boolean): void; 新增
ohos.multimedia.camera CameraManager createCameraInput(camera: CameraDevice, callback: AsyncCallback): void;
createCameraInput(camera: CameraDevice): Promise;
新增
ohos.multimedia.camera CameraManager createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void;
createPreviewOutput(profile: Profile, surfaceId: string): Promise;
新增
ohos.multimedia.camera CameraManager createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void;
createPhotoOutput(profile: Profile, surfaceId: string): Promise;
新增
ohos.multimedia.camera CameraManager createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback): void;
createVideoOutput(profile: VideoProfile, surfaceId: string): Promise;
新增
ohos.multimedia.camera CameraManager createMetadataOutput(metadataObjectTypes: Array, callback: AsyncCallback): void;
createMetadataOutput(metadataObjectTypes: Array): Promise;
新增
ohos.multimedia.camera CameraManager createCaptureSession(callback: AsyncCallback): void;
createCaptureSession(): Promise;
新增
ohos.multimedia.camera CameraManager on(type: ‘cameraMute’, callback: AsyncCallback): void; 新增
ohos.multimedia.camera CameraManager getCameras(callback: AsyncCallback>): void;
getCameras(): Promise>;
废弃
ohos.multimedia.camera CameraManager createCameraInput(cameraId: string, callback: AsyncCallback): void;
createCameraInput(cameraId: string): Promise;
废弃
ohos.multimedia.camera CameraManager createCaptureSession(context: Context, callback: AsyncCallback): void;
createCaptureSession(context: Context): Promise;
废弃
ohos.multimedia.camera CameraManager createPreviewOutput(surfaceId: string, callback: AsyncCallback): void;
createPreviewOutput(surfaceId: string): Promise;
废弃
ohos.multimedia.camera CameraManager CreatePhotoOutput(surfaceId: string, callback: AsyncCallback): void;
CreatePhotoOutput(surfaceId: string): Promise;
废弃
ohos.multimedia.camera CameraManager createVideoOutput(surfaceId: string, callback: AsyncCallback): void;
createVideoOutput(surfaceId: string): Promise;
废弃
ohos.multimedia.camera CameraManager createMetadataOutput(callback: AsyncCallback): void;
createVideoOutput(): Promise;
废弃
ohos.multimedia.camera CameraStatusInfo camera: CameraDevice; 新增
ohos.multimedia.camera CameraStatusInfo camera: Camera; 废弃
ohos.multimedia.camera CameraDevice interface CameraDevice 新增
ohos.multimedia.camera Camera interface Camera 废弃
ohos.multimedia.camera CameraInput open(callback: AsyncCallback): void;
open(): Promise;
新增
ohos.multimedia.camera CameraInput close(callback: AsyncCallback): void;
close(): Promise;
新增
ohos.multimedia.camera CameraInput on(type: ‘error’, camera: CameraDevice, callback: ErrorCallback): void; 新增
ohos.multimedia.camera CameraInput isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void;
isFocusModeSupported(afMode: FocusMode): Promise;
废弃
ohos.multimedia.camera CameraInput getFocusMode(callback: AsyncCallback): void;
getFocusMode(): Promise;
废弃
ohos.multimedia.camera CameraInput setFocusMode(afMode: FocusMode, callback: AsyncCallback): void;
setFocusMode(afMode: FocusMode): Promise;
废弃
ohos.multimedia.camera CameraInput getZoomRatioRange(callback: AsyncCallback>): void;
getZoomRatioRange(): Promise>;
废弃
ohos.multimedia.camera CameraInput getZoomRatio(callback: AsyncCallback): void;
getZoomRatio(): Promise;
废弃
ohos.multimedia.camera CameraInput setZoomRatio(zoomRatio: number, callback: AsyncCallback): void;
setZoomRatio(zoomRatio: number): Promise;
废弃
ohos.multimedia.camera CameraInput getCameraId(callback: AsyncCallback): void;
getCameraId(): Promise;
废弃
ohos.multimedia.camera CameraInput getExposurePoint(callback: AsyncCallback): void;
getExposurePoint(): Promise;
废弃
ohos.multimedia.camera CameraInput setExposurePoint(exposurePoint: Point, callback: AsyncCallback): void;
setExposurePoint(exposurePoint: Point): Promise;
废弃
ohos.multimedia.camera CameraInput hasFlash(callback: AsyncCallback): void;
hasFlash(): Promise;
废弃
ohos.multimedia.camera CameraInput isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void;
isFlashModeSupported(flashMode: FlashMode): Promise;
废弃
ohos.multimedia.camera CameraInput getFlashMode(callback: AsyncCallback): void;
getFlashMode(): Promise;
废弃
ohos.multimedia.camera CameraInput setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void;
setFlashMode(flashMode: FlashMode): Promise;
废弃
ohos.multimedia.camera CameraInput isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback): void;
isExposureModeSupported(aeMode: ExposureMode): Promise;
废弃
ohos.multimedia.camera CameraInput getExposureMode(callback: AsyncCallback): void;
getExposureMode(): Promise;
废弃
ohos.multimedia.camera CameraInput setExposureMode(aeMode: ExposureMode, callback: AsyncCallback): void;
setExposureMode(aeMode: ExposureMode): Promise;
废弃
ohos.multimedia.camera CameraInput getMeteringPoint(callback: AsyncCallback): void;
getMeteringPoint(): Promise;
废弃
ohos.multimedia.camera CameraInput setMeteringPoint(point: Point, callback: AsyncCallback): void;
setMeteringPoint(point: Point): Promise;
废弃
ohos.multimedia.camera CameraInput getExposureBiasRange(callback: AsyncCallback>): void;
getExposureBiasRange(): Promise>;
废弃
ohos.multimedia.camera CameraInput setExposureBias(exposureBias: number, callback: AsyncCallback): void;
setExposureBias(exposureBias: number): Promise;
废弃
ohos.multimedia.camera CameraInput getExposureValue(callback: AsyncCallback): void;
getExposureValue(): Promise;
废弃
ohos.multimedia.camera CameraInput isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void;
isFocusModeSupported(afMode: FocusMode): Promise;
废弃
ohos.multimedia.camera CameraInput getFocusMode(callback: AsyncCallback): void;
getFocusMode(): Promise;
废弃
ohos.multimedia.camera CameraInput setFocusMode(afMode: FocusMode, callback: AsyncCallback): void;
setFocusMode(afMode: FocusMode): Promise;
废弃
ohos.multimedia.camera CameraInput setFocusPoint(point: Point, callback: AsyncCallback): void;
setFocusPoint(point: Point): Promise;
废弃
ohos.multimedia.camera CameraInput getFocusPoint(callback: AsyncCallback): void;
getFocusPoint(): Promise;
废弃
ohos.multimedia.camera CameraInput getFocalLength(callback: AsyncCallback): void;
getFocalLength(): Promise;
废弃
ohos.multimedia.camera CameraInput getZoomRatioRange(callback: AsyncCallback>): void;
getZoomRatioRange(): Promise>;
废弃
ohos.multimedia.camera CameraInput getZoomRatio(callback: AsyncCallback): void;
getZoomRatio(): Promise;
废弃
ohos.multimedia.camera CameraInput setZoomRatio(zoomRatio: number, callback: AsyncCallback): void;
setZoomRatio(zoomRatio: number): Promise;
废弃
ohos.multimedia.camera CameraInput on(type: ‘focusStateChange’, callback: AsyncCallback): void; 废弃
ohos.multimedia.camera CameraInput on(type: ‘exposureStateChange’, callback: AsyncCallback): void; 废弃
ohos.multimedia.camera CameraInput on(type: ‘error’, callback: ErrorCallback): void; 废弃
ohos.multimedia.camera CameraInputErrorCode ERROR_NO_PERMISSION = 0 新增
ohos.multimedia.camera CameraInputErrorCode ERROR_DEVICE_PREEMPTED = 1 新增
ohos.multimedia.camera CameraInputErrorCode ERROR_DEVICE_DISCONNECTED = 2 新增
ohos.multimedia.camera CameraInputErrorCode ERROR_DEVICE_IN_USE = 3 新增
ohos.multimedia.camera CameraInputErrorCode ERROR_DRIVER_ERROR = 4 新增
ohos.multimedia.camera CameraFormat CAMERA_FORMAT_RGBA_8888 = 3 新增
ohos.multimedia.camera ExposureMode EXPOSURE_MODE_AUTO = 1 新增
ohos.multimedia.camera ExposureMode EXPOSURE_MODE_CONTINUOUS_AUTO = 2 新增
ohos.multimedia.camera ExposureMode EXPOSURE_MODE_AUTO 废弃
ohos.multimedia.camera ExposureMode EXPOSURE_MODE_CONTINUOUS_AUTO 废弃
ohos.multimedia.camera VideoStabilizationMode LOW = 1 新增
ohos.multimedia.camera VideoStabilizationMode MIDDLE = 2 新增
ohos.multimedia.camera VideoStabilizationMode HIGH = 3 新增
ohos.multimedia.camera VideoStabilizationMode AUTO = 4 新增
ohos.multimedia.camera VideoStabilizationMode LOW 废弃
ohos.multimedia.camera VideoStabilizationMode MIDDLE 废弃
ohos.multimedia.camera VideoStabilizationMode HIGH 废弃
ohos.multimedia.camera VideoStabilizationMode AUTO 废弃
ohos.multimedia.camera CaptureSession addOutput(cameraOutput: CameraOutput, callback: AsyncCallback): void;
addOutput(cameraOutput: CameraOutput): Promise;
新增
ohos.multimedia.camera CaptureSession removeOutput(cameraOutput: CameraOutput, callback: AsyncCallback): void;
removeOutput(cameraOutput: CameraOutput): Promise;
新增
ohos.multimedia.camera CaptureSession isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode, callback: AsyncCallback): void;
isVideoStabilizationModeSupported(vsMode: VideoStabilizationMode): Promise;
新增
ohos.multimedia.camera CaptureSession getActiveVideoStabilizationMode(callback: AsyncCallback): void;
getActiveVideoStabilizationMode(): Promise;
新增
ohos.multimedia.camera CaptureSession setVideoStabilizationMode(mode: VideoStabilizationMode, callback: AsyncCallback): void;
setVideoStabilizationMode(mode: VideoStabilizationMode): Promise;
新增
ohos.multimedia.camera CaptureSession on(type: ‘focusStateChange’, callback: AsyncCallback): void; 新增
ohos.multimedia.camera CaptureSession hasFlash(callback: AsyncCallback): void;
hasFlash(): Promise;
新增
ohos.multimedia.camera CaptureSession isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void;
isFlashModeSupported(flashMode: FlashMode): Promise;
新增
ohos.multimedia.camera CaptureSession getFlashMode(callback: AsyncCallback): void;
getFlashMode(): Promise;
新增
ohos.multimedia.camera CaptureSession setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void;
setFlashMode(flashMode: FlashMode): Promise;
新增
ohos.multimedia.camera CaptureSession isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback): void;
isExposureModeSupported(aeMode: ExposureMode): Promise;
新增
ohos.multimedia.camera CaptureSession getExposureMode(callback: AsyncCallback): void;
getExposureMode(): Promise;
新增
ohos.multimedia.camera CaptureSession setExposureMode(aeMode: ExposureMode, callback: AsyncCallback): void;
setExposureMode(aeMode: ExposureMode): Promise;
新增
ohos.multimedia.camera CaptureSession getMeteringPoint(callback: AsyncCallback): void;
getMeteringPoint(): Promise;
新增
ohos.multimedia.camera CaptureSession setMeteringPoint(point: Point, callback: AsyncCallback): void;
setMeteringPoint(point: Point): Promise;
新增
ohos.multimedia.camera CaptureSession getExposureBiasRange(callback: AsyncCallback>): void;
getExposureBiasRange(): Promise>;
新增
ohos.multimedia.camera CaptureSession setExposureBias(exposureBias: number, callback: AsyncCallback): void;
setExposureBias(exposureBias: number): Promise;
新增
ohos.multimedia.camera CaptureSession getExposureValue(callback: AsyncCallback): void;
getExposureValue(): Promise;
新增
ohos.multimedia.camera CaptureSession isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void;
isFocusModeSupported(afMode: FocusMode): Promise;
新增
ohos.multimedia.camera CaptureSession getFocusMode(callback: AsyncCallback): void;
getFocusMode(): Promise;
新增
ohos.multimedia.camera CaptureSession setFocusMode(afMode: FocusMode, callback: AsyncCallback): void;
setFocusMode(afMode: FocusMode): Promise;
新增
ohos.multimedia.camera CaptureSession setFocusPoint(point: Point, callback: AsyncCallback): void;
setFocusPoint(point: Point): Promise;
新增
ohos.multimedia.camera CaptureSession getFocusPoint(callback: AsyncCallback): void;
getFocusPoint(): Promise;
新增
ohos.multimedia.camera CaptureSession getFocalLength(callback: AsyncCallback): void;
getFocalLength(): Promise;
新增
ohos.multimedia.camera CaptureSession getZoomRatioRange(callback: AsyncCallback>): void;
getZoomRatioRange(): Promise>;
新增
ohos.multimedia.camera CaptureSession getZoomRatio(callback: AsyncCallback): void;
getZoomRatio(): Promise;
新增
ohos.multimedia.camera CaptureSession setZoomRatio(zoomRatio: number, callback: AsyncCallback): void;
setZoomRatio(zoomRatio: number): Promise;
新增
ohos.multimedia.camera CaptureSession addOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void;
addOutput(previewOutput: PreviewOutput): Promise;
addOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void;
addOutput(photoOutput: PhotoOutput): Promise;
addOutput(videoOutput: VideoOutput, callback: AsyncCallback): void;
addOutput(videoOutput: VideoOutput): Promise;
废弃
ohos.multimedia.camera CaptureSession removeOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void;
removeOutput(previewOutput: PreviewOutput): Promise;
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void;
removeOutput(photoOutput: PhotoOutput): Promise;removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void;
removeOutput(videoOutput: VideoOutput): Promise;
removeOutput(metadataOutput: MetadataOutput, callback: AsyncCallback): void;
removeOutput(metadataOutput: MetadataOutput): Promise;
废弃
ohos.multimedia.camera CaptureSessionErrorCode ERROR_INSUFFICIENT_RESOURCES = 0 新增
ohos.multimedia.camera CaptureSessionErrorCode ERROR_TIMEOUT = 1 新增
ohos.multimedia.camera CameraOutput release(callback: AsyncCallback): void;
release(): Promise;
新增
ohos.multimedia.camera PreviewOutput start(callback: AsyncCallback): void;
start(): Promise;
新增
ohos.multimedia.camera PreviewOutput stop(callback: AsyncCallback): void;
stop(): Promise;
新增
ohos.multimedia.camera PreviewOutput release(callback: AsyncCallback): void;
release(): Promise;
废弃
ohos.multimedia.camera PhotoOutput release(callback: AsyncCallback): void;
release(): Promise;
废弃
ohos.multimedia.camera VideoOutput release(callback: AsyncCallback): void;
release(): Promise;
废弃
ohos.multimedia.camera PhotoCaptureSetting mirror?: boolean; 新增
ohos.multimedia.camera PhotoOutputErrorCode ERROR_DRIVER_ERROR = 0 新增
ohos.multimedia.camera PhotoOutputErrorCode ERROR_INSUFFICIENT_RESOURCES = 1 新增
ohos.multimedia.camera PhotoOutputErrorCode ERROR_TIMEOUT = 2 新增
ohos.multimedia.camera VideoOutputErrorCode ERROR_DRIVER_ERROR = 0 新增
ohos.multimedia.camera MetadataObjectType FACE_DETECTION = 0 新增
ohos.multimedia.camera MetadataObjectType FACE = 0 废弃
ohos.multimedia.camera MetadataOutput on(type: ‘error’, callback: ErrorCallback): void; 新增
ohos.multimedia.camera MetadataOutput setCapturingMetadataObjectTypes(metadataObjectTypes: Array, callback: AsyncCallback): void;
setCapturingMetadataObjectTypes(metadataObjectTypes: Array): Promise;
废弃
ohos.multimedia.camera MetadataOutput getSupportedMetadataObjectTypes(callback: AsyncCallback>): void;
getSupportedMetadataObjectTypes(): Promise>;
废弃
ohos.multimedia.camera MetadataOutputErrorCode ERROR_UNKNOWN = -1 新增
ohos.multimedia.camera MetadataOutputErrorCode ERROR_INSUFFICIENT_RESOURCES = 0 新增
ohos.multimedia.camera MetadataOutputError code: MetadataOutputErrorCode; 新增

适配指导

除新增接口,和废弃接口之外,开发者需要关注变更的接口的适配:

从Beta4版本开始,对以下接口进行调整:

新增接口

  1. Profile接口

属性1:readonly format,类型:CameraFormat;

属性2:readonly size,类型:Size;

  1. FrameRateRange接口

属性1:readonly min,类型:number;

属性2:readonly max,类型:number;

  1. VideoProfile接口,继承自Profile

属性:readonly frameRateRange,类型:FrameRateRange;

  1. CameraOutputCapability接口

属性1:readonly previewProfiles,类型:Array;

属性2:readonly photoProfiles,类型:Array;

属性3:readonly videoProfiles,类型:Array;

属性4:readonly supportedMetadataObjectTypes,类型:Array;

  1. CameraManager中新增

getSupportedOutputCapability(camera: CameraDevice, callback: AsyncCallback): void;

getSupportedOutputCapability(camera: CameraDevice): Promise;

参考代码如下:

   cameraManager.getSupportedCameras().then((cameras) => {
       let cameraDevice = cameras[0];
       cameraManager.getSupportedOutputCapability(cameraDevice, (err, CameraOutputCapability) => {
           if (err) {
               console.error(`Failed to get the outputCapability. ${err.message}`);
               return;
           }
           console.log('Callback returned with an array of supported outputCapability');
       })
   })
   cameraManager.getSupportedCameras().then((cameras) => {
       let cameraDevice = cameras[0];
       cameraManager.getSupportedOutputCapability(cameraDevice).then((cameraoutputcapability) => {
           console.log('Promise returned with an array of supported outputCapability');
       })
   })
  1. CameraManager中新增isCameraMuted(): boolean;

参考代码如下:

   let ismuted = cameraManager.isCameraMuted();
  1. CameraManager中新增isCameraMuteSupported(): boolean;

参考代码如下:

   let ismutesuppotred = cameraManager.isCameraMuteSupported();
  1. CameraManager中新增muteCamera(mute: boolean): void;

参考代码如下:

   let mute = true;
   cameraManager.muteCamera(mute);
  1. CameraManager中新增on(type: ‘cameraMute’, callback: AsyncCallback): void;

参考代码如下:

   cameraManager.on('cameraMute', (err, curMuetd) => {
       if (err) {
           console.error(`Failed to get cameraMute callback. ${err.message}`);
           return;
       }
   })
  1. CameraInput中新增open(callback: AsyncCallback): void;以及open(): Promise;

参考代码如下:

cameraInput.open((err) => {
    if (err) {
        console.error(`Failed to open the camera. ${err.message}`);
        return;
    }
    console.log('Callback returned with camera opened.');
})
cameraInput.open().then(() => {
    console.log('Promise returned with camera opened.');
})
  1. CameraInput中新增close(callback: AsyncCallback): void;以及close(): Promise;

    参考代码如下:

    cameraInput.close((err) => {
        if (err) {
            console.error(`Failed to close the cameras. ${err.message}`);
            return;
        }
        console.log('Callback returned with camera closed.');
    })
    
    cameraInput.close().then(() => {
        console.log('Promise returned with camera closed.');
    })
    
  2. 枚举CameraInputErrorCode中新增

    枚举值名称:ERROR_NO_PERMISSION,值:0;

    枚举值名称:ERROR_DEVICE_PREEMPTED,值:1;

    枚举值名称:ERROR_DEVICE_DISCONNECTED,值:2;

    枚举值名称:ERROR_DEVICE_IN_USE,值:3;

    枚举值名称:ERROR_DRIVER_ERROR,值:4;

  3. 枚举CameraFormat中新增

    枚举值名称:CAMERA_FORMAT_RGBA_8888,值:3;

  4. CaptureSession中新增getMeteringPoint(callback: AsyncCallback): void;以及getMeteringPoint(): Promise;

    参考代码如下:

    captureSession.getMeteringPoint((err, exposurePoint) => {
        if (err) {
            console.log(`Failed to get the current exposure point ${err.message}`);
            return ;
        }
        console.log(`Callback returned with current exposure point: ${exposurePoint}`);
    })
    
    captureSession.getMeteringPoint().then((exposurePoint) => {
        console.log(`Promise returned with current exposure point : ${exposurePoint}`);
    })
    
  5. CaptureSession中新增setMeteringPoint(point: Point, callback: AsyncCallback): void;以及setMeteringPoint(point: Point): Promise;

    参考代码如下:

    const Point1 = {x: 1, y: 1};
    
    
    captureSession.setMeteringPoint(Point1,(err) => {
        if (err) {
            console.log(`Failed to set the exposure point ${err.message}`);
            return ;
        }
        console.log('Callback returned with the successful execution of setMeteringPoint');
    })
    
    const Point2 = {x: 2, y: 2};
    
    
    captureSession.setMeteringPoint(Point2).then(() => {
        console.log('Promise returned with the successful execution of setMeteringPoint');
    })
    
  6. 枚举CaptureSessionErrorCode中新增

    枚举值名称:ERROR_INSUFFICIENT_RESOURCES,值:0;

    枚举值名称:ERROR_TIMEOUT,值:1;

  7. 新增接口CameraOutput,接口下有release(callback: AsyncCallback): void;以及release(): Promise;方法

    参考代码如下:用previewOutput做示例

    previewOutput.release((err) => {
        if (err) {
            console.error(`Failed to release the PreviewOutput instance ${err.message}`);
            return;
        }
        console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
    });
    
    previewOutput.release().then(() => {
        console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
    })
    
  8. PreviewOutput中新增start(callback: AsyncCallback): void;以及start(): Promise;

    参考代码如下

    previewOutput.start((err) => {
        if (err) {
            console.error(`Failed to start the previewOutput. ${err.message}`);
            return;
        }
        console.log('Callback returned with previewOutput started.');
    })
    
    previewOutput.start().then(() => {
        console.log('Promise returned with previewOutput started.');
    })
    
  9. PreviewOutput中新增stop(callback: AsyncCallback): void;以及stop(): Promise;

    参考代码如下

    previewOutput.stop((err) => {
        if (err) {
            console.error(`Failed to stop the previewOutput. ${err.message}`);
            return;
        }
        console.log('Callback returned with previewOutput stopped.');
    })
    
    previewOutput.stop().then(() => {
        console.log('Callback returned with previewOutput stopped.');
    })
    
  10. PhotoCaptureSetting接口

    属性1:mirror?,类型:boolean;

  11. 枚举PhotoOutputErrorCode中新增

    枚举值名称:ERROR_DRIVER_ERROR,值:0;

    枚举值名称:ERROR_INSUFFICIENT_RESOURCES,值:1;

    枚举值名称:ERROR_TIMEOUT,值:2;

  12. 枚举VideoOutputErrorCode中新增

    枚举值名称:ERROR_DRIVER_ERROR,值:0;

  13. MetadataOutput中新增on(type: ‘error’, callback: ErrorCallback): void;

    参考代码如下

    metadataOutput.on('error', (metadataOutputError) => {
        console.log(`Metadata output error code: ${metadataOutputError.code}`);
    })
    
  14. MetadataOutputErrorCode枚举

    枚举值名称:ERROR_UNKNOWN,值:-1;

    枚举值名称:ERROR_INSUFFICIENT_RESOURCES,值:0;

  15. MetadataOutputError接口

    属性名称:code,值:MetadataOutputErrorCode

废弃接口

  1. CameraInput中废弃接口on(type: ‘exposureStateChange’, callback: AsyncCallback): void;

  2. previewOutput中废弃接口release(callback: AsyncCallback): void;以及release(): Promise;

  3. metadataOutput中废弃接口

setCapturingMetadataObjectTypes(metadataObjectTypes: Array, callback: AsyncCallback): void;
setCapturingMetadataObjectTypes(metadataObjectTypes: Array): Promise;

  1. metadataOutput中废弃接口

getSupportedMetadataObjectTypes(callback: AsyncCallback>): void;
getSupportedMetadataObjectTypes(): Promise>;

  1. PreviewOutput中废弃接口release(callback: AsyncCallback): void;以及release(): Promise;

  2. PhotoOutput中废弃接口release(callback: AsyncCallback): void;以及release(): Promise;

  3. VideoOutput中废弃接口release(callback: AsyncCallback): void;以及release(): Promise;

  4. CameraInput中废弃接口getCameraId(callback: AsyncCallback): void;以及getCameraId(): Promise;

  5. CameraInput中废弃接口getExposurePoint(callback: AsyncCallback): void;以及getExposurePoint(): Promise;

  6. CameraInput中废弃接口setExposurePoint(exposurePoint: Point, callback: AsyncCallback): void;以及setExposurePoint(exposurePoint: Point): Promise;

接口变更

  1. CameraManager中接口getCameras返回值由Array变更为Array,接口名由getCameras 更换为 getSupportedCameras,因此旧接口getCameras(callback: AsyncCallback>): void;以及getCameras(): Promise>;变更为getSupportedCameras(callback: AsyncCallback>): void和getSupportedCameras(): Promise>;

参考代码如下:

   cameraManager.getSupportedCameras((err, cameras) => {
       if (err) {
           console.error(`Failed to get the cameras. ${err.message}`);
           return;
       }
       console.log(`Callback returned with an array of supported cameras: ${cameras.length}`);
   })
   cameraManager.getSupportedCameras().then((cameras) => {
       console.log(`Promise returned with an array of supported cameras: ${cameras.length}`);
   })
  1. CameraManager中接口createCameraInput传递参数由原来cameraId: string变更为camera: CameraDevice,因此旧接口createCameraInput(cameraId: string, callback: AsyncCallback): void;以及createCameraInput(cameraId: string): Promise;变更为createCameraInput(camera: CameraDevice, callback: AsyncCallback): void;和createCameraInput(camera: CameraDevice): Promise;

参考代码如下:

   let cameraDevice = cameras[0];
   cameraManager.createCameraInput(cameraDevice, (err, cameraInput) => {
       if (err) {
           console.error(`Failed to create the CameraInput instance. ${err.message}`);
           return;
       }
       console.log('Callback returned with the CameraInput instance.');
   })
   let cameraDevice = cameras[0];
   cameraManager.createCameraInput(cameraDevice).then((cameraInput) => {
       console.log('Promise returned with the CameraInput instance');
   })
  1. CameraManager中接口createPreviewOutput新增传递参数profile: Profile,profile参数由getSupportedOutputCapability接口获取,因此旧接口createPreviewOutput(surfaceId: string, callback: AsyncCallback): void;以及createPreviewOutput(surfaceId: string): Promise;变更为createPreviewOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void;createPreviewOutput(profile: Profile, surfaceId: string): Promise;

参考代码如下:

   let profile = cameraoutputcapability.previewProfiles[0];
   cameraManager.createPreviewOutput(profile, surfaceId, (err, previewOutput) => {
       if (err) {
           console.error(`Failed to gcreate previewOutput. ${err.message}`);
           return;
       }
       console.log('Callback returned with previewOutput created.');
   })
   let profile = cameraoutputcapability.previewProfiles[0];
   cameraManager.createPreviewOutput(profile, surfaceId).then((previewOutput) => {
       console.log('Promise returned with previewOutput created.');
   })
  1. CameraManager中接口createPhotoOutput新增传递参数profile: Profile,profile参数由getSupportedOutputCapability接口获取,因此旧接口CreatePhotoOutput(surfaceId: string, callback: AsyncCallback): void;以及CreatePhotoOutput(surfaceId: string): Promise;变更为createPhotoOutput(profile: Profile, surfaceId: string, callback: AsyncCallback): void;和createPhotoOutput(profile: Profile, surfaceId: string): Promise;

参考代码如下:

   let profile = cameraoutputcapability.photoProfiles[0];
   cameraManager.createPhotoOutput(profile, surfaceId, (err, photoOutput) => {
       if (err) {
           console.error(`Failed to create photoOutput. ${err.message}`);
           return;
       }
       console.log('Callback returned with photoOutput created.');
   })
   let profile = cameraoutputcapability.photoProfiles[0];
   cameraManager.createPhotoOutput(profile, surfaceId).then((photoOutput) => {
       console.log('Promise returned with photoOutput created.');
   })
  1. CameraManager中接口createVideoOutput新增传递参数profile: Profile,profile参数由getSupportedOutputCapability接口获取,因此旧接口createVideoOutput(surfaceId: string, callback: AsyncCallback): void;以及createVideoOutput(surfaceId: string): Promise;变更为createVideoOutput(profile: VideoProfile, surfaceId: string, callback: AsyncCallback): void;和createVideoOutput(profile: VideoProfile, surfaceId: string): Promise;

参考代码如下:

   let profile = cameraoutputcapability.videoProfiles[0];
   cameraManager.createVideoOutput(profile, surfaceId, (err, videoOutput) => {
       if (err) {
           console.error(`Failed to create videoOutput. ${err.message}`);
           return;
       }
       console.log('Callback returned with an array of supported outputCapability' );
   })
   let profile = cameraoutputcapability.videoProfiles[0];
   cameraManager.createVideoOutput(profile, surfaceId).then((videoOutput) => {
       console.log('Promise returned with videoOutput created.');
   })
  1. CameraManager中接口createMetadataOutput新增传递参数metadataObjectTypes: Array,metadataObjectTypes参数由getSupportedOutputCapability接口获取,因此旧接口function createMetadataOutput(callback: AsyncCallback): void;以及function createMetadataOutput(): Promise;变更为createMetadataOutput(metadataObjectTypes: Array, callback: AsyncCallback): void;和createMetadataOutput(metadataObjectTypes: Array): Promise;

参考代码如下:

   let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes;
   cameraManager.createMetadataOutput(metadataObjectTypes, (err, metadataOutput) => {
       if (err) {
           console.error(`Failed to create metadataOutput. ${err.message}`);
           return;
       }
       console.log('Callback returned with metadataOutput created.');
   })
   let metadataObjectTypes = cameraoutputcapability.supportedMetadataObjectTypes;
   cameraManager.createMetadataOutput(metadataObjectTypes).then((metadataOutput) => {
       console.log('Promise returned with metadataOutput created.');
   })
  1. CameraManager中createCaptureSession不需要考虑context属性,因此旧接口createCaptureSession(context: Context, callback: AsyncCallback): void;以及createCaptureSession(context: Context): Promise;改为createCaptureSession(callback: AsyncCallback): void;和createCaptureSession(): Promise;

参考代码如下:

   cameraManager.createCaptureSession((err, captureSession) => {
       if (err) {
           console.error(`Failed to create captureSession. ${err.message}`);
           return;
       }
       console.log('Callback returned with captureSession created.');
   })
   cameraManager.createCaptureSession().then((captureSession) => {
       console.log('Promise returned with captureSession created.');
   })
  1. CameraStatusInfo接口下属性camera类型由Camera变更为CameraDevice

  2. CameraInput中接口on(type: ‘error’)新增传递参数camera: CameraDevice,因此旧接口on(type: ‘error’, callback: ErrorCallback): void;变更为on(type: ‘error’, camera: CameraDevice, callback: ErrorCallback): void;

参考代码如下:

   let cameraDevice = cameras[0];
   cameraInput.on('error', cameraDevice, (cameraInputError) => {
       console.log(`Camera input error code: ${cameraInputError.code}`);
   })
  1. CameraInput中以下接口调整到CaptureSession中

    hasFlash(callback: AsyncCallback): void;
    hasFlash(): Promise;

    isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void;
    isFlashModeSupported(flashMode: FlashMode): Promise;

    getFlashMode(callback: AsyncCallback): void;
    getFlashMode(): Promise;

    setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void;
    setFlashMode(flashMode: FlashMode): Promise;

    isExposureModeSupported(aeMode: ExposureMode, callback: AsyncCallback): void;
    isExposureModeSupported(aeMode: ExposureMode): Promise;

    getExposureMode(callback: AsyncCallback): void;
    getExposureMode(): Promise;

    setExposureMode(aeMode: ExposureMode, callback: AsyncCallback): void;
    setExposureMode(aeMode: ExposureMode): Promise;

    getMeteringPoint(callback: AsyncCallback): void;
    getMeteringPoint(): Promise;

    setMeteringPoint(point: Point, callback: AsyncCallback): void;
    setMeteringPoint(point: Point): Promise;

    getExposureBiasRange(callback: AsyncCallback>): void;
    getExposureBiasRange(): Promise>;

    setExposureBias(exposureBias: number, callback: AsyncCallback): void;
    setExposureBias(exposureBias: number): Promise;

    getExposureValue(callback: AsyncCallback): void;
    getExposureValue(): Promise;

    isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void;
    isFocusModeSupported(afMode: FocusMode): Promise;

    getFocusMode(callback: AsyncCallback): void;
    getFocusMode(): Promise;

    setFocusMode(afMode: FocusMode, callback: AsyncCallback): void;
    setFocusMode(afMode: FocusMode): Promise;

    setFocusPoint(point: Point, callback: AsyncCallback): void;
    setFocusPoint(point: Point): Promise;

    getFocusPoint(callback: AsyncCallback): void;
    getFocusPoint(): Promise;

    getFocalLength(callback: AsyncCallback): void;
    getFocalLength(): Promise;

    getZoomRatioRange(callback: AsyncCallback>): void;
    getZoomRatioRange(): Promise>;

    getZoomRatio(callback: AsyncCallback): void;
    getZoomRatio(): Promise;

    setZoomRatio(zoomRatio: number, callback: AsyncCallback): void;
    setZoomRatio(zoomRatio: number): Promise;

  2. CameraInput中接口on(type: ‘focusStateChange’, callback: AsyncCallback): void;调整到CaptureSession中,对应接口on(type: ‘focusStateChange’, callback: AsyncCallback): void;

    参考代码如下:

    captureSession.on('focusStateChange', (focusState) => {
        console.log(`Focus state  : ${focusState}`);
    })
    
  3. 枚举ExposureMode中

    枚举值名称:EXPOSURE_MODE_AUTO,初值由默认变更为1;

    枚举值名称:EXPOSURE_MODE_CONTINUOUS_AUTO,初值由默认变更为2;

  4. 枚举VideoStabilizationMode中

    枚举值名称:LOW,初值由默认变更为1;

    枚举值名称:MIDDLE,初值由默认变更为2;

    枚举值名称:HIGH,初值由默认变更为3;

    枚举值名称:AUTO,初值由默认变更为4;

  5. CaptureSession中接口addOutput参数由原来子类类型(PreviewOutput,PhotoOutput,VideoOutput,MetadataOutput)统一修改为基类类型(CameraOutput),变更后由原来8个接口缩减为2个接口。

    改变前接口为:

    addOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void;
    addOutput(previewOutput: PreviewOutput): Promise;
    addOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void;
    addOutput(photoOutput: PhotoOutput): Promise;
    addOutput(videoOutput: VideoOutput, callback: AsyncCallback): void;
    addOutput(videoOutput: VideoOutput): Promise;
    addOutput(metadataOutput: MetadataOutput, callback: AsyncCallback): void;
    addOutput(metadataOutput: MetadataOutput): Promise;

    改变后接口为:

    addOutput(cameraOutput: CameraOutput, callback: AsyncCallback): void;
    addOutput(cameraOutput: CameraOutput): Promise;

    参考代码如下:以PreviewOutput为例

    captureSession.addOutput(previewOutput, (err) => {
        if (err) {
            console.error(`Failed to add output. ${err.message}`);
            return;
        }
        console.log('Callback returned with output added.');
    })
    
    captureSession.addOutput(previewOutput).then(() => {
        console.log('Promise returned with cameraOutput added.');
    })
    
  6. CaptureSession中接口removeOutput参数由原来子类类型(PreviewOutput,PhotoOutput,VideoOutput,MetadataOutput)统一修改为基类类型(CameraOutput),变更后由原来8个接口缩减为2个接口。

    改变前接口为:

    removeOutput(previewOutput: PreviewOutput, callback: AsyncCallback): void;
    removeOutput(previewOutput: PreviewOutput): Promise;
    removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void;
    removeOutput(photoOutput: PhotoOutput): Promise;
    removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void;
    removeOutput(videoOutput: VideoOutput): Promise;
    removeOutput(metadataOutput: MetadataOutput, callback: AsyncCallback): void;
    removeOutput(metadataOutput: MetadataOutput): Promise;

    改变后接口为:

    removeOutput(cameraOutput: CameraOutput, callback: AsyncCallback): void;
    removeOutput(cameraOutput: CameraOutput): Promise;

    参考代码如下:以PreviewOutput为例

    captureSession.removeOutput(previewOutput, (err) => {
        if (err) {
            console.error(`Failed to remove the CameraOutput instance. ${err.message}`);
            return;
        }
        console.log('Callback invoked to indicate that the CameraOutput instance is removed.');
    });
    
    captureSession.removeOutput(previewOutput).then(() => {
        console.log('Promise returned to indicate that the CameraOutput instance is removed.');
    })
    
  7. 枚举MetadataObjectType中

    枚举值名称由FACE变更为FACE_DETECTION;

  8. 接口Camera名称更改为CameraDevice

你可能感兴趣的鸿蒙文章

harmony 鸿蒙帐号子系统changeLog

harmony 鸿蒙设备管理changeLog

harmony 鸿蒙USB管理 changeLog

harmony 鸿蒙软总线子系统Changelog

harmony 鸿蒙文件管理子系统ChangeLog

harmony 鸿蒙全球化子系统ChangeLog

harmony 鸿蒙输入法框架changeLog

harmony 鸿蒙多模输入changeLog

harmony 鸿蒙电源子系统ChangeLog

harmony 鸿蒙上传下载子系统ChangeLog

0  赞