The full audio playback process includes creating an instance, setting the URI, playing audio, seeking to the playback position, setting the volume, pausing playback, obtaining track information, stopping playback, resetting resources, and releasing resources.
For details about the **src** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
During audio recording, audio signals are captured, encoded, and saved to files. You can specify parameters such as the sampling rate, number of audio channels, encoding format, encapsulation format, and file path for audio recording.
The full audio recording process includes creating an instance, setting recording parameters, starting, pausing, resuming, and stopping recording, and releasing resources.
console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`);
console.info(`audio error called, errMessage is ${error.message}`);
});
});
}
}
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// 1.创建实例
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
audioRecorder.stop();// The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
audioRecorder.stop();// The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes the following video playback development scenarios: full-process, normal playback, video switching, and loop playback.
The full video playback process includes creating an instance, setting the URL, setting the surface ID, preparing for video playback, playing video, pausing playback, obtaining track information, seeking to a playback position, setting the volume, setting the playback speed, stopping playback, resetting the playback configuration, and releasing resources.
For details about the **url** media source input types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes).
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
letvideoPlayer=undefined;// Used to store instances created by calling the createVideoPlayer method.
letsurfaceID=undefined;// Used to save the surface ID returned by the Xcomponent interface.
// The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
if="{{isFlush}}"// Refresh the surface ID. To enable automatic loading of the Xcomponent and obtain the new surface ID, assign **false** to **isFlush** and then assign **true** to **isFlush**.
type='surface'
onload='LoadXcomponent'// Default interface for loading the Xcomponent.
style="width:720px;height:480px;border-color:red;border-width:5px;">// Set the window width, height, and other attributes.
During video recording, audio and video signals are captured, encoded, and saved to files. You can specify parameters such as the encoding format, encapsulation format, and file path for video recording.
The full video recording process includes creating an instance, setting recording parameters, recording video, pausing, resuming, and stopping recording, and releasing resources.
// pathName indicates the passed recording file name, for example, 01.mp4. The generated file address is /storage/media/100/local/files/Movies/01.mp4.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
// Video recording depends on camera-related interfaces. The following operations can be performed only after the video output start interface is invoked.
// 视频录制依赖相机相关接口,以下需要先调用相机起流接口后才能继续执行
// Start video recording.
// 视频录制启动接口
awaitvideoRecorder.start().then(()=>{
awaitvideoRecorder.start().then(()=>{
console.info('start success');
console.info('start success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// Pause video playback before the video output stop interface is invoked.
// 调用pause接口时需要暂停camera出流
awaitvideoRecorder.pause().then(()=>{
awaitvideoRecorder.pause().then(()=>{
console.info('pause success');
console.info('pause success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// Resume video playback after the video output start interface is invoked.
// 调用resume接口时需要恢复camera出流
awaitvideoRecorder.resume().then(()=>{
awaitvideoRecorder.resume().then(()=>{
console.info('resume success');
console.info('resume success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// Stop video recording after the video output stop interface is invoked.
// 停止camera出流后,停止视频录制
awaitvideoRecorder.stop().then(()=>{
awaitvideoRecorder.stop().then(()=>{
console.info('stop success');
console.info('stop success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// Reset the recording configuration.
// 重置录制相关配置
awaitvideoRecorder.reset().then(()=>{
awaitvideoRecorder.reset().then(()=>{
console.info('reset success');
console.info('reset success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// Release the video recording resources and camera object resources.
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources.
媒体子系统包含了音视频相关媒体业务,提供以下常用功能:
This subsystem offers various media services covering audio and video, which provide the following capabilities:
- Video recording ([VideoRecorder](#VideoRecorder<sup>8+</sup>))
The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query.
## 导入模块
## Modules to Import
```js
```js
importmediafrom'@ohos.multimedia.media';
importmediafrom'@ohos.multimedia.media';
...
@@ -24,41 +21,94 @@ import media from '@ohos.multimedia.media';
...
@@ -24,41 +21,94 @@ import media from '@ohos.multimedia.media';
createAudioPlayer(): [AudioPlayer](#audioplayer)
createAudioPlayer(): [AudioPlayer](#audioplayer)
Creates an **AudioPlayer** instance in synchronous mode.
| [AudioPlayer](#audioplayer) | Returns the **AudioPlayer** instance if the operation is successful; returns **null** otherwise. After the instance is created, you can start, pause, or stop audio playback.|
| MSERR_OK | 0 | The operation is successful.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_OK | 0 | 表示操作成功。 |
| MSERR_NO_MEMORY | 1 | Failed to allocate memory. The system may have no available memory.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_NO_MEMORY | 1 | 表示申请内存失败,系统可能无可用内存。 |
| MSERR_OPERATION_NOT_PERMIT | 2 | No permission to perform this operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_TRACK_TYPE | "track_type" | Track type, which is a number. For details, see [MediaType](#mediatype8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_FRAME_RATE | "frame_rate" | Video frame rate, which is a number, in units of 100 fps.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | Number of audio channels, which is a number.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_AUD_SAMPLE_RATE | "sample_rate" | Sampling rate, which is a number, in units of Hz.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
Provides methods to manage and play audio. Before calling a method of **AudioPlayer**, you must use [createAudioPlayer()](#mediacreateaudioplayer) to create an **AudioPlayer** instance.
| src | string | Yes | Yes | Audio media URI. The mainstream audio formats (MP4, AAC, MP3, and OGG) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xxx<br><br>2. HTTP network playback path (under development)<br>3. HLS network playback path (under development)<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
Starts to play audio resources. This method can be called only after the [dataLoad](#on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')) event is triggered.
| type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| type | string | 是 | 音频缓存事件回调类型,支持的事件:'bufferingUpdate'。 |
| callback | (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
| type | string | Yes | Type of the event to subscribe to. The following events are supported: 'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'<br>- The 'play' event is triggered when the [play()](#play) method is called and audio playback starts.<br>- The 'pause' event is triggered when the [pause()](#pause) method is called and audio playback is paused.<br>- The 'stop' event is triggered when the [stop()](#stop) method is called and audio playback stops.<br>- The 'reset' event is triggered when the [reset()](#reset7) method is called and audio playback is reset.<br>- The 'dataLoad' event is triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- The 'finish' event is triggered when the audio playback is finished.<br>- The 'volumeChange' event is triggered when the [setVolume()](#setvolume) method is called and the playback volume is changed.|
| type | string | Yes | Type of the event to subscribe to, which is 'timeUpdate' in this method.<br>The 'timeUpdate' event is triggered when the [seek()](#seek) method is called.|
| type | string | 是 | 播放事件回调类型,支持的事件包括:'timeUpdate'。<br>- 'timeUpdate':[seek()](#seek)调用完成,触发该事件。 |
| callback | Callback\<number> | Yes | Callback invoked when the event is triggered. The input parameter of the callback is the time when the seek operation is successful. |
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during audio playback.|
| type | string | 是 | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':音频播放中发生错误,触发该事件。 |
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
| callback | ErrorCallback | 是 | 播放错误事件回调方法。 |
**Example**
**示例:**
```js
```js
audioPlayer.on('error',(error)=>{// Set the error event callback.
audioPlayer.on('error',(error)=>{//设置'error'事件回调
console.info(`audio error called, errName is ${error.name}`);// Print the error name.
console.info(`audio error called, errName is ${error.name}`);//打印错误类型名称
console.info(`audio error called, errCode is ${error.code}`);// Print the error code.
console.info(`audio error called, errCode is ${error.code}`);//打印错误码
console.info(`audio error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
console.info(`audio error called, errMessage is ${error.message}`);//打印错误类型详细描述
});
});
audioPlayer.setVolume(3);// Set volume to an invalid value to trigger the 'error' event.
| error<sup>8+</sup> | string | Audio playback is in the error state.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| error<sup>8+</sup> | string | 错误状态。 |
## VideoPlayer<sup>8+</sup>
## VideoPlayer<sup>8+</sup>
Provides methods to manage and play video. Before calling a method of the **VideoPlayer** class, you must call [createVideoPlayer()](#media.createvideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
| url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xxx<br><br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| loop<sup>8+</sup> | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| currentTime<sup>8+</sup> | number | Yes | No | Current video playback position.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| currentTime | number | 是 | 否 | 视频的当前播放位置。 |
| duration<sup>8+</sup> | number | Yes | No | Video duration. The value **-1** indicates the live streaming mode.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| duration | number | 是 | 否 | 视频时长,返回-1表示直播模式 |
| state<sup>8+</sup> | [VideoPlayState](#videoplaystate8) | Yes | No | Video playback state.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
Seeks to the specified playback position. If **mode** is not specified, the next key frame at the specified position is played. This API uses a promise to return the result.
| type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| type | string | 是 | 视频缓存事件回调类型,支持的事件:'bufferingUpdate'。 |
| callback | function | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
| callback | function | 是 | 视频缓存事件回调方法。<br>[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 |
| type | string | Yes | Type of the event to subscribe to, which is 'videoSizeChanged' in this example.|
| type | string | 是 | 视频播放宽高变化事件回调类型,支持的事件:'videoSizeChanged'。 |
| callback | function | Yes | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height. |
| callback | function | 是 | 视频播放宽高变化事件回调方法,width表示宽,height表示高。 |
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during video playback.|
| type | string | 是 | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':视频播放中发生错误,触发该事件。 |
| callback | function | Yes | Callback invoked when the event is triggered. |
| callback | function | 是 | 播放错误事件回调方法。 |
**Example**
**示例:**
```js
```js
videoPlayer.on('error',(error)=>{// Set the 'error' event callback.
videoPlayer.on('error',(error)=>{// 设置'error'事件回调
console.info(`video error called, errName is ${error.name}`);// Print the error name.
console.info(`video error called, errName is ${error.name}`);// 打印错误类型名称
console.info(`video error called, errCode is ${error.code}`);// Print the error code.
console.info(`video error called, errCode is ${error.code}`);// 打印错误码
console.info(`video error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
console.info(`video error called, errMessage is ${error.message}`);// 打印错误类型详细描述
});
});
videoPlayer.setVolume(3);// Set volume to an invalid value to trigger the 'error' event.
| SEEK_NEXT_SYNC | 0 | Seeks to the next key frame at the specified position. You are advised to use this value for the rewind operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| SEEK_PREV_SYNC | 1 | Seeks to the previous key frame at the specified position. You are advised to use this value for the fast-forward operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| key | string | Key of the media information. For details about the keys, see [MediaDescriptionKey](#mediadescriptionkey8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| value | any | Value of the key. For details about the values, see [MediaDescriptionKey](#mediadescriptionkey8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| value | any | 对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey](#mediadescriptionkey8)的描述信息。 |
**Example**
**示例:**
```js
```js
functionprintfItemDescription(obj,key){
functionprintfItemDescription(obj,key){
...
@@ -1517,7 +1520,7 @@ function printfItemDescription(obj, key) {
...
@@ -1517,7 +1520,7 @@ function printfItemDescription(obj, key) {
Implements audio recording. Before calling a method of the **AudioRecorder** class, you must call [createAudioRecorder()](#media.createaudiorecorder) to create an [AudioRecorder](#audiorecorder) instance.
Before resetting audio recording, you must call [stop()](#audiorecorder_stop) to stop recording. After audio recording is reset, you must call [prepare()](#audiorecorder_prepare) to set the recording parameters for another recording.
| type | string | Yes | Type of the event to subscribe to. The following events are supported: 'prepare'\|'start'\| 'pause' \| 'resume' \|'stop'\|'release'\|'reset'<br>- The 'prepare' event is triggered when the [prepare](#audiorecorder_prepare) method is called and the audio recording parameters are set.<br>- The 'start' event is triggered when the [start](#audiorecorder_start) method is called and audio recording starts.<br>- The 'pause' event is triggered when the [pause](#audiorecorder_pause) method is called and audio recording is paused.<br>- The 'resume' event is triggered when the [resume](#audiorecorder_resume) method is called and audio recording is resumed.<br>- The 'stop' event is triggered when the [stop](#audiorecorder_stop) method is called and audio recording stops.<br>- The 'release' event is triggered when the [release](#audiorecorder_release) method is called and the recording resource is released.<br>- The 'reset' event is triggered when the [reset](#audiorecorder_reset) method is called and audio recording is reset.|
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during audio recording.|
| type | string | 是 | 录制错误事件回调类型'error'。<br/>- 'error':音频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 |
**Example**
**示例:**
```js
```js
audioRecorder.on('error',(error)=>{// Set the 'error' event callback.
| audioEncoder | [AudioEncoder](#audioencoder) | No | Audio encoding format. The default value is **AAC_LC**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| audioEncodeBitRate | number | No | Audio encoding bit rate. The default value is **48000**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| audioEncodeBitRate | number | 否 | 音频编码比特率,默认值为48000。 |
| audioSampleRate | number | No | Audio sampling rate. The default value is **48000**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| audioSampleRate | number | 否 | 音频采集采样率,默认值为48000。 |
| numberOfChannels | number | No | Number of audio channels. The default value is **2**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。 |
| format | [AudioOutputFormat](#audiooutputformat) | No | Audio output format. The default value is **MPEG_4**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| format | [AudioOutputFormat](#audiooutputformat) | 否 | 音量输出封装格式,默认设置为MPEG_4。 |
| location<sup>8+</sup> | [Location](#location8) | No | Geographical location of the recorded audio.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| uri | string | Yes | Audio output URI. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| uri | string | 是 | 音频输出URI。支持:<br/>1. 文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4<br/>2. 文件的fd路径:file://1 (fd number)<br/> 文件需要由调用者创建,并赋予适当的权限。 |
| DEFAULT | 0 | Default audio encoding format, which is Adaptive Multi Rate-Narrow Band Speech Codec (AMR-NB).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| DEFAULT | 0 | Default audio encoding format is AMR_NB。本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:**SystemCapability.Multimedia.Media.AudioRecorder |
| AMR_NB | 1 | AMR-NB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_NB | 1 | AMR-NB(Adaptive Multi Rate-Narrow Band Speech Codec) 编码格式。本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:**SystemCapability.Multimedia.Media.AudioRecorder |
| AMR_WB | 2 | Adaptive Multi Rate-Wide Band Speech Codec (AMR-WB).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_WB | 2 | AMR-WB(Adaptive Multi Rate-Wide Band Speech Codec) 编码格式。本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:**SystemCapability.Multimedia.Media.AudioRecorder |
| HE_AAC | 4 | High-Efficiency Advanced Audio Coding (HE_AAC).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| DEFAULT | 0 | Default encapsulation format, which is MPEG-4.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_NB | 3 | AMR_NB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_WB | 4 | AMR_WB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AAC_ADTS | 6 | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
Implements video recording. Before calling a method of the **VideoRecorder** class, you must call [createVideoRecorder()](#media.createvideorecorder8) to create a [VideoRecorder](#videorecorder8) instance.
Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
Starts video recording in asynchronous mode. This API uses a callback to return the result.
异步方式开始视频录制。通过注册回调函数获取返回值。
This method can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
Starts video recording in asynchronous mode. This API uses a promise to return the result.
异步方式开始视频录制。通过Promise获取返回值。
This method can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
Pauses video recording in asynchronous mode. This API uses a callback to return the result.
异步方式暂停视频录制。通过注册回调函数获取返回值。
This method can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
Pauses video recording in asynchronous mode. This API uses a promise to return the result.
异步方式暂停视频录制。通过Promise获取返回值。
This method can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
| type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during video recording.|
| type | string | 是 | 录制错误事件回调类型'error'。<br/>- 'error':音频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 |
**Example**
**示例:**
```js
```js
videoRecorder.on('error',(error)=>{// Set the 'error' event callback.
| audioSourceType | [AudioSourceType](#audiosourcetype<sup>8+</sup>) | Yes | Type of the audio source for video recording.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| videoSourceType | [VideoSourceType](#videosourcetype<sup>8+</sup>) | Yes | Type of the video source for video recording.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| orientationHint | number | No | Rotation angle of the recorded video.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| orientationHint | number | 否 | 录制视频的旋转角度。 |
| location | [Location](#location8) | No | Geographical location of the recorded video.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| url | string | Yes | Video output URL. Supported: fd://xx (fd number)<br><br>The file must be created by the caller and granted with proper permissions.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| uri | string | 是 | 视频输出URI。支持:<br/>1. 文件的绝对路径:file:///data/data/ohos.xxx.xxx/cache/test.mp4<br/>2. 文件的fd路径:file://1 (fd number)<br/> 文件需要由调用者创建,并赋予适当的权限。 |
## AudioSourceType<sup>8+</sup>
## AudioSourceType<sup>8+</sup>
Enumerates the audio source types for video recording.
| fileFormat | [ContainerFormatType](#containerformattype8) | Yes | Container format of a file.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|