feat: Video Codec Option for recording video (#645)

* add video codec value

* add types

* use `recommendedVideoSettings` method instead

* lint

* refactor for better readability

* add a method to get available codecs (ios)

* imrove tsDoc description of the videoCodec option

Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com>

* ios format

Co-authored-by: Marc Rousavy <marcrousavy@hotmail.com>
This commit is contained in:
Paul Rostorp
2021-12-30 10:47:23 +01:00
committed by GitHub
parent 7460560323
commit d96c5863c9
5 changed files with 73 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { requireNativeComponent, NativeModules, NativeSyntheticEvent, findNodeHandle, NativeMethods, Platform } from 'react-native';
import type { FrameProcessorPerformanceSuggestion } from '.';
import type { FrameProcessorPerformanceSuggestion, VideoFileType } from '.';
import type { CameraDevice } from './CameraDevice';
import type { ErrorWithCause } from './CameraError';
import { CameraCaptureError, CameraRuntimeError, tryParseNativeCameraError, isErrorWithCause } from './CameraError';
@@ -9,7 +9,7 @@ import type { Frame } from './Frame';
import type { PhotoFile, TakePhotoOptions } from './PhotoFile';
import type { Point } from './Point';
import type { TakeSnapshotOptions } from './Snapshot';
import type { RecordVideoOptions, VideoFile } from './VideoFile';
import type { CameraVideoCodec, RecordVideoOptions, VideoFile } from './VideoFile';
//#region Types
export type CameraPermissionStatus = 'authorized' | 'not-determined' | 'denied' | 'restricted';
@@ -238,6 +238,22 @@ export class Camera extends React.PureComponent<CameraProps> {
}
//#endregion
/**
* Get a list of video codecs the current camera supports for a given file type. Returned values are ordered by efficiency (descending).
* @example
* ```ts
* const codecs = await camera.current.getAvailableVideoCodecs("mp4")
* ```
* @throws {@linkcode CameraRuntimeError} When any kind of error occured while getting available video codecs. Use the {@linkcode ParameterError.code | code} property to get the actual error
*/
public async getAvailableVideoCodecs(fileType?: VideoFileType): Promise<CameraVideoCodec[]> {
try {
return await CameraModule.getAvailableVideoCodecs(this.handle, fileType);
} catch (e) {
throw tryParseNativeCameraError(e);
}
}
//#region Static Functions (NativeModule)
/**
* Get a list of all available camera devices on the current phone.