From 6620b5bdb0ec9a5ee0526347fa33b6e4bf92c478 Mon Sep 17 00:00:00 2001 From: Gloria Date: Wed, 24 May 2023 10:19:20 +0800 Subject: [PATCH] Update docs against 17738+18286+17995+16616+17842+17829 Signed-off-by: wusongqing --- .../reference/apis/js-apis-media.md | 1178 +++++++++-------- 1 file changed, 591 insertions(+), 587 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-media.md b/en/application-dev/reference/apis/js-apis-media.md index 75b5cba5c9..52178a666a 100644 --- a/en/application-dev/reference/apis/js-apis-media.md +++ b/en/application-dev/reference/apis/js-apis-media.md @@ -46,15 +46,15 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let avPlayer +let avPlayer; media.createAVPlayer((error, video) => { - if (video != null) { - avPlayer = video; - console.info('createAVPlayer success'); - } else { - console.info(`createAVPlayer fail, error:${error}`); - } + if (video != null) { + avPlayer = video; + console.info('createAVPlayer success'); + } else { + console.error(`createAVPlayer fail, error message:${error.message}`); + } }); ``` @@ -83,17 +83,17 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let avPlayer +let avPlayer; media.createAVPlayer().then((video) => { - if (video != null) { - avPlayer = video; - console.info('createAVPlayer success'); - } else { - console.info('createAVPlayer fail'); - } + if (video != null) { + avPlayer = video; + console.info('createAVPlayer success'); + } else { + console.error('createAVPlayer fail'); + } }).catch((error) => { - console.info(`AVPlayer catchCallback, error:${error}`); + console.error(`AVPlayer catchCallback, error message:${error.message}`); }); ``` @@ -123,15 +123,15 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let avRecorder +let avRecorder; media.createAVRecorder((error, recorder) => { - if (recorder != null) { - avRecorder = recorder; - console.info('createAVRecorder success'); - } else { - console.info(`createAVRecorder fail, error:${error}`); - } + if (recorder != null) { + avRecorder = recorder; + console.info('createAVRecorder success'); + } else { + console.error(`createAVRecorder fail, error message:${error.message}`); + } }); ``` @@ -161,17 +161,17 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let avRecorder +let avRecorder; media.createAVRecorder().then((recorder) => { - if (recorder != null) { - avRecorder = recorder; - console.info('createAVRecorder success'); - } else { - console.info('createAVRecorder fail'); - } + if (recorder != null) { + avRecorder = recorder; + console.info('createAVRecorder success'); + } else { + console.error('createAVRecorder fail'); + } }).catch((error) => { - console.info(`createAVRecorder catchCallback, error:${error}`); + console.error(`createAVRecorder catchCallback, error message:${error.message}`); }); ``` @@ -203,15 +203,15 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let videoRecorder +let videoRecorder; media.createVideoRecorder((error, video) => { - if (video != null) { - videoRecorder = video; - console.info('video createVideoRecorder success'); - } else { - console.info(`video createVideoRecorder fail, error:${error}`); - } + if (video != null) { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.error(`video createVideoRecorder fail, error message:${error.message}`); + } }); ``` @@ -243,17 +243,17 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -let videoRecorder +let videoRecorder; media.createVideoRecorder().then((video) => { - if (video != null) { - videoRecorder = video; - console.info('video createVideoRecorder success'); - } else { - console.info('video createVideoRecorder fail'); - } + if (video != null) { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.error('video createVideoRecorder fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error message:${error.message}`); }); ``` @@ -360,15 +360,15 @@ For details about the audio and video playback demo, see [Audio Playback](../../ | Name | Type | Readable| Writable| Description | | --------------------------------------------------- | ------------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ | | url9+ | string | Yes | Yes | URL of the media asset. It is a static attribute and can be set only when the AVPlayer is in the idle state.
The video formats MP4, MPEG-TS, WebM, and MKV are supported.
The audio formats M4A, AAC, MP3, OGG, and WAV are supported.
**Examples of supported URLs**:
1. FD: fd://xx
![](figures/en-us_image_url.png)
2. HTTP: http://xx
3. HTTPS: https://xx
4. HLS: http://xx or https://xx| -| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | FD of the media asset. It is a static attribute and can be set only when the AVPlayer is in the idle state.
This attribute is required when media assets of an application are continuously stored in a file.
**Example:**
Assume that a media file that stores continuous assets consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent media file, use **src=fd://xx**.| -| dataSrc10+ | [AVDataSrcDescriptor](#avdatasrcdescriptor10) | Yes | Yes | Descriptor of a streaming media asset. It is a static attribute and can be set only when the AVPlayer is in the idle state.
Use scenario: An application starts playing a media file while the file is still being downloaded from the remote to the local host.
**Example:**
A user is obtaining an audio and video file from a remote server and wants to play the downloaded file content. To implement this scenario, do as follows:
1. Obtain the total file size, in bytes. If the total size cannot be obtained or the live mode is expected, set **fileSize** to **-1**.
2. Implement the **func** callback to fill in data. If **fileSize** is **-1**, the format of **func** is **func(buffer: ArrayBuffer, length: number)**; otherwise, the format is **func(buffer: ArrayBuffer, length: number, pos: number)**.
3. Set **AVDataSrcDescriptor {fileSize = size, callback = func}**.| +| fdSrc9+ | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | FD of the media asset. It is a static attribute and can be set only when the AVPlayer is in the idle state.
This attribute is required when media assets of an application are continuously stored in a file.
The video formats MP4, MPEG-TS, WebM, and MKV are supported.
The audio formats M4A, AAC, MP3, OGG, and WAV are supported.
**Example:**
Assume that a media file that stores continuous assets consists of the following:
Video 1 (address offset: 0, byte length: 100)
Video 2 (address offset: 101; byte length: 50)
Video 3 (address offset: 151, byte length: 150)
1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }
2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }
3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }
To play an independent media file, use **src=fd://xx**.| +| dataSrc10+ | [AVDataSrcDescriptor](#avdatasrcdescriptor10) | Yes | Yes | Descriptor of a streaming media asset. It is a static attribute and can be set only when the AVPlayer is in the idle state.
Use scenario: An application starts playing a media file while the file is still being downloaded from the remote to the local host.
The video formats MP4, MPEG-TS, WebM, and MKV are supported.
The audio formats M4A, AAC, MP3, OGG, and WAV are supported.
**Example:**
A user is obtaining an audio and video file from a remote server and wants to play the downloaded file content. To implement this scenario, do as follows:
1. Obtain the total file size, in bytes. If the total size cannot be obtained, set **fileSize** to **-1**.
2. Implement the **func** callback to fill in data. If **fileSize** is **-1**, the format of **func** is **func(buffer: ArrayBuffer, length: number)**, and the AVPlayer obtains data in sequence; otherwise, the format is **func(buffer: ArrayBuffer, length: number, pos: number)**, and the AVPlayer seeks and obtains data in the required positions.
3. Set **AVDataSrcDescriptor {fileSize = size, callback = func}**.
**Notes:**
If the media file to play is in MP4/M4A format, ensure that the **moov** field (specifying the media information) is before the **mdat** field (specifying the media data) or the fields before the **moov** field is less than 10 MB. Otherwise, the parsing fails and the media file cannot be played.| | surfaceId9+ | string | Yes | Yes | Video window ID. By default, there is no video window. It is a static attribute and can be set only when the AVPlayer is in the initialized state.
It is used to render the window for video playback and therefore is not required in audio-only playback scenarios.
**Example:**
[Create a surface ID through XComponent](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid).| -| loop9+ | boolean | Yes | Yes | Whether to loop playback. The value **true** means to loop playback, and **false** (default) means the opposite. It is a dynamic attribute
and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.| +| loop9+ | boolean | Yes | Yes | Whether to loop playback. The value **true** means to loop playback, and **false** (default) means the opposite. It is a dynamic attribute
and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.
This setting is not supported in the live mode.| | videoScaleType9+ | [VideoScaleType](#videoscaletype9) | Yes | Yes | Video scaling type. The default value is **VIDEO_SCALE_TYPE_FIT_CROP**. It is a dynamic attribute
and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.| | audioInterruptMode9+ | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. The default value is **SHARE_MODE**. It is a dynamic attribute
and can be set only when the AVPlayer is in the prepared, playing, paused, or completed state.| | audioRendererInfo10+ | [audio.AudioRendererInfo](js-apis-audio.md#audiorendererinfo8) | Yes | Yes | Audio renderer information. The default value of **contentType** is **CONTENT_TYPE_MUSIC**, and the default value of **streamUsage** is **STREAM_USAGE_MEDIA**.
It can be set only when the AVPlayer is in the initialized state.| | state9+ | [AVPlayerState](#avplayerstate9) | Yes | No | AVPlayer state. It can be used as a query parameter when the AVPlayer is in any state. | -| currentTime9+ | number | Yes | No | Current video playback position, in ms. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.
The value **-1** indicates an invalid value.| +| currentTime9+ | number | Yes | No | Current video playback position, in ms. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.
The value **-1** indicates an invalid value.
In the live mode, **-1** is returned by default.| | duration9+ | number | Yes | No | Video duration, in ms. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.
The value **-1** indicates an invalid value.
In live streaming scenarios, **-1** is returned by default.| | width9+ | number | Yes | No | Video width, in pixels. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.
The value **0** indicates an invalid value.| | height9+ | number | Yes | No | Video height, in pixels. It can be used as a query parameter when the AVPlayer is in the prepared, playing, paused, or completed state.
The value **0** indicates an invalid value.| @@ -396,38 +396,38 @@ Subscribes to AVPlayer state changes. ```js avPlayer.on('stateChange', async (state, reason) => { - switch (state) { - case 'idle': - console.info('state idle called') - break; - case 'initialized': - console.info('initialized prepared called') - break; - case 'prepared': - console.info('state prepared called') - break; - case 'playing': - console.info('state playing called') - break; - case 'paused': - console.info('state paused called') - break; - case 'completed': - console.info('state completed called') - break; - case 'stopped': - console.info('state stopped called') - break; - case 'released': - console.info('state released called') - break; - case 'error': - console.info('state error called') - break; - default: - console.info('unkown state :' + state) - break; - } + switch (state) { + case 'idle': + console.info('state idle called') + break; + case 'initialized': + console.info('initialized prepared called') + break; + case 'prepared': + console.info('state prepared called') + break; + case 'playing': + console.info('state playing called') + break; + case 'paused': + console.info('state paused called') + break; + case 'completed': + console.info('state completed called') + break; + case 'stopped': + console.info('state stopped called') + break; + case 'released': + console.info('state released called') + break; + case 'error': + console.info('state error called') + break; + default: + console.info('unkown state :' + state) + break; + } }) ``` @@ -484,8 +484,8 @@ The AVPlayer provides the following error types: ```js avPlayer.on('error', (error) => { - console.info('error happened,and error message is :' + error.message) - console.info('error happened,and error code is :' + error.code) + console.error('error happened,and error message is :' + error.message) + console.error('error happened,and error code is :' + error.code) }) ``` @@ -536,11 +536,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.prepare((err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.error('prepare filed,error message is :' + err.message) - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare filed,error message is :' + err.message) + } }) ``` @@ -571,9 +571,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.prepare().then(() => { - console.info('prepare success'); + console.info('prepare success'); }, (err) => { - console.error('prepare filed,error message is :' + err.message) + console.error('prepare filed,error message is :' + err.message) }) ``` @@ -603,11 +603,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.play((err) => { - if (err == null) { - console.info('play success'); - } else { - console.error('play filed,error message is :' + err.message) - } + if (err == null) { + console.info('play success'); + } else { + console.error('play filed,error message is :' + err.message) + } }) ``` @@ -637,9 +637,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.play().then(() => { - console.info('play success'); + console.info('play success'); }, (err) => { - console.error('play filed,error message is :' + err.message) + console.error('play filed,error message is :' + err.message) }) ``` @@ -669,11 +669,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.pause((err) => { - if (err == null) { - console.info('pause success'); - } else { - console.error('pause filed,error message is :' + err.message) - } + if (err == null) { + console.info('pause success'); + } else { + console.error('pause filed,error message is :' + err.message) + } }) ``` @@ -703,9 +703,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.pause().then(() => { - console.info('pause success'); + console.info('pause success'); }, (err) => { - console.error('pause filed,error message is :' + err.message) + console.error('pause filed,error message is :' + err.message) }) ``` @@ -735,11 +735,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.stop((err) => { - if (err == null) { - console.info('stop success'); - } else { - console.error('stop filed,error message is :' + err.message) - } + if (err == null) { + console.info('stop success'); + } else { + console.error('stop filed,error message is :' + err.message) + } }) ``` @@ -769,9 +769,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.stop().then(() => { - console.info('stop success'); + console.info('stop success'); }, (err) => { - console.error('stop filed,error message is :' + err.message) + console.error('stop filed,error message is :' + err.message) }) ``` @@ -801,11 +801,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.reset((err) => { - if (err == null) { - console.info('reset success'); - } else { - console.error('reset filed,error message is :' + err.message) - } + if (err == null) { + console.info('reset success'); + } else { + console.error('reset filed,error message is :' + err.message) + } }) ``` @@ -835,9 +835,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.reset().then(() => { - console.info('reset success'); + console.info('reset success'); }, (err) => { - console.error('reset filed,error message is :' + err.message) + console.error('reset filed,error message is :' + err.message) }) ``` @@ -867,11 +867,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.release((err) => { - if (err == null) { - console.info('reset success'); - } else { - console.error('release filed,error message is :' + err.message) - } + if (err == null) { + console.info('reset success'); + } else { + console.error('release filed,error message is :' + err.message) + } }) ``` @@ -901,9 +901,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avPlayer.release().then(() => { - console.info('release success'); + console.info('release success'); }, (err) => { - console.error('release filed,error message is :' + err.message) + console.error('release filed,error message is :' + err.message) }) ``` @@ -932,22 +932,22 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco **Example** ```js -printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } +function printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } avPlayer.getTrackDescription((error, arrList) => { - if ((arrList) != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`video getTrackDescription fail, error:${error}`); + if ((arrList) != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`video getTrackDescription fail, error:${error}`); + } }); ``` @@ -978,24 +978,24 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js let arrayDescription; -printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } +function printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } avPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('video getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('video getTrackDescription fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.info(`video catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -1004,6 +1004,7 @@ for (let i = 0; i < arrayDescription.length; i++) { seek(timeMs: number, mode?:SeekMode): void Seeks to the specified playback position. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the seek operation takes effect by subscribing to the [seekDone](#seekDone_on) event. +This API is not supported in the live mode. **System capability**: SystemCapability.Multimedia.Media.AVPlayer @@ -1012,7 +1013,7 @@ Seeks to the specified playback position. This API can be called only when the A | Name| Type | Mandatory| Description | | ------ | ---------------------- | ---- | ------------------------------------------------------------ | | timeMs | number | Yes | Position to seek to, in ms. The value range is [0, [duration](#avplayer_duration)].| -| mode | [SeekMode](#seekmode8) | No | Seek mode based on the video I frame. **Set this parameter only for video playback.** | +| mode | [SeekMode](#seekmode8) | No | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. **Set this parameter only for video playback.**| **Example** @@ -1040,7 +1041,7 @@ Subscribes to the event to check whether the seek operation takes effect. ```js avPlayer.on('seekDone', (seekDoneTime:number) => { - console.info('seekDone success,and seek time is:' + seekDoneTime) + console.info('seekDone success,and seek time is:' + seekDoneTime) }) ``` @@ -1069,6 +1070,7 @@ avPlayer.off('seekDone') setSpeed(speed: PlaybackSpeed): void Sets the playback speed. This API can be called only when the AVPlayer is in the prepared, playing, paused, or completed state. You can check whether the setting takes effect by subscribing to the [speedDone](#speedDone_on) event. +This API is not supported in the live mode. **System capability**: SystemCapability.Multimedia.Media.AVPlayer @@ -1103,7 +1105,7 @@ Subscribes to the event to check whether the playback speed is successfully set. ```js avPlayer.on('speedDone', (speed:number) => { - console.info('speedDone success,and speed value is:' + speed) + console.info('speedDone success,and speed value is:' + speed) }) ``` @@ -1167,7 +1169,7 @@ Subscribes to the event to check whether the bit rate is successfully set. ```js avPlayer.on('bitrateDone', (bitrate:number) => { - console.info('bitrateDone success,and bitrate value is:' + bitrate) + console.info('bitrateDone success,and bitrate value is:' + bitrate) }) ``` @@ -1210,7 +1212,7 @@ Subscribes to available bit rates of HLS streams. This event is reported only af ```js avPlayer.on('availableBitrates', (bitrates: Array) => { - console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length) + console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length) }) ``` @@ -1274,7 +1276,7 @@ Subscribes to the event to check whether the volume is successfully set. ```js avPlayer.on('volumeChange', (vol:number) => { - console.info('volumeChange success,and new volume is :' + vol) + console.info('volumeChange success,and new volume is :' + vol) }) ``` @@ -1317,7 +1319,7 @@ Subscribes to the event that indicates the end of the stream being played. If ** ```js avPlayer.on('endOfStream', () => { - console.info('endOfStream success') + console.info('endOfStream success') }) ``` @@ -1346,6 +1348,7 @@ avPlayer.off('endOfStream') on(type: 'timeUpdate', callback: Callback\): void Subscribes to playback position changes. It is used to refresh the current position of the progress bar. By default, this event is reported every 1 second. However, it is reported immediately upon a successful seek operation. +The **'timeUpdate'** event is not supported in the live mode. **System capability**: SystemCapability.Multimedia.Media.AVPlayer @@ -1360,7 +1363,7 @@ Subscribes to playback position changes. It is used to refresh the current posit ```js avPlayer.on('timeUpdate', (time:number) => { - console.info('timeUpdate success,and new time is :' + time) + console.info('timeUpdate success,and new time is :' + time) }) ``` @@ -1389,6 +1392,7 @@ avPlayer.off('timeUpdate') on(type: 'durationUpdate', callback: Callback\): void Subscribes to media asset duration changes. It is used to refresh the length of the progress bar. By default, this event is reported once when the AVPlayer switches to the prepared state. However, it can be repeatedly reported for special streams that trigger duration changes. +The **'durationUpdate'** event is not supported in the live mode. **System capability**: SystemCapability.Multimedia.Media.AVPlayer @@ -1403,7 +1407,7 @@ Subscribes to media asset duration changes. It is used to refresh the length of ```js avPlayer.on('durationUpdate', (duration) => { - console.info('durationUpdate success,new duration is :' + duration) + console.info('durationUpdate success,new duration is :' + duration) }) ``` @@ -1446,7 +1450,7 @@ Subscribes to audio and video buffer changes. This subscription is supported onl ```js avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { - console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value) + console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value) }) ``` @@ -1489,7 +1493,7 @@ Subscribes to the event that indicates rendering starts for the first frame. Thi ```js avPlayer.on('startRenderFrame', () => { - console.info('startRenderFrame success') + console.info('startRenderFrame success') }) ``` @@ -1532,7 +1536,7 @@ Subscribes to video size (width and height) changes. This subscription is suppor ```js avPlayer.on('videoSizeChange', (width: number, height: number) => { - console.info('videoSizeChange success,and width is:' + width + ', height is :' + height) + console.info('videoSizeChange success,and width is:' + width + ', height is :' + height) }) ``` @@ -1577,7 +1581,7 @@ Subscribes to the audio interruption event. When multiple audio and video assets import audio from '@ohos.multimedia.audio'; avPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => { - console.info('audioInterrupt success,and InterruptEvent info is:' + info) + console.info('audioInterrupt success,and InterruptEvent info is:' + info) }) ``` @@ -1690,19 +1694,19 @@ Defines media information in key-value mode. ```js import media from '@ohos.multimedia.media' function printfItemDescription(obj, key) { - let property = obj[key]; - console.info('audio key is ' + key); // Specify a key. For details about the keys, see [MediaDescriptionKey]. - console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey]. + let property = obj[key]; + console.info('audio key is ' + key); // Specify a key. For details about the keys, see [MediaDescriptionKey]. + console.info('audio value is ' + property); // Obtain the value of the key. The value can be any type. For details about the types, see [MediaDescriptionKey]. } let audioPlayer = media.createAudioPlayer(); audioPlayer.getTrackDescription((error, arrList) => { - if (arrList != null) { - for (let i = 0; i < arrList.length; i++) { - printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. - } - } else { - console.log(`audio getTrackDescription fail, error:${error}`); + if (arrList != null) { + for (let i = 0; i < arrList.length; i++) { + printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track. } + } else { + console.log(`audio getTrackDescription fail, error:${error}`); + } }); ``` @@ -1761,32 +1765,32 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // Configure the parameters based on those supported by the hardware device. let AVRecorderProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : media.CodecMimeType.AUDIO_AAC, - audioSampleRate : 48000, - fileFormat : media.ContainerFormatType.CFT_MPEG_4, - videoBitrate : 2000000, - videoCodec : media.CodecMimeType.VIDEO_AVC, - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : media.CodecMimeType.AUDIO_AAC, + audioSampleRate : 48000, + fileFormat : media.ContainerFormatType.CFT_MPEG_4, + videoBitrate : 2000000, + videoCodec : media.CodecMimeType.VIDEO_AVC, + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let AVRecorderConfig = { - audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, - videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, - profile : AVRecorderProfile, - url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45. - rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error. - location : { latitude : 30, longitude : 130 } + audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, + profile : AVRecorderProfile, + url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45. + rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error. + location : { latitude : 30, longitude : 130 } } avRecorder.prepare(AVRecorderConfig, (err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.info('prepare failed and error is ' + err.message); - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare failed and error is ' + err.message); + } }) ``` @@ -1832,30 +1836,30 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // Configure the parameters based on those supported by the hardware device. let AVRecorderProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : media.CodecMimeType.AUDIO_AAC, - audioSampleRate : 48000, - fileFormat : media.ContainerFormatType.CFT_MPEG_4, - videoBitrate : 2000000, - videoCodec : media.CodecMimeType.VIDEO_AVC, - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : media.CodecMimeType.AUDIO_AAC, + audioSampleRate : 48000, + fileFormat : media.ContainerFormatType.CFT_MPEG_4, + videoBitrate : 2000000, + videoCodec : media.CodecMimeType.VIDEO_AVC, + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let AVRecorderConfig = { - audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, - videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, - profile : AVRecorderProfile, - url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45. - rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error. - location : { latitude : 30, longitude : 130 } + audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, + profile : AVRecorderProfile, + url : 'fd://', // Before passing in an FD to this parameter, the file must be created by the caller and granted with the read and write permissions. Example value: eg.fd://45. + rotation: 0, // The value can be 0, 90, 180, or 270. If any other value is used, prepare() reports an error. + location : { latitude : 30, longitude : 130 } } avRecorder.prepare(AVRecorderConfig).then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); + console.error('prepare failed and catch error is ' + err.message); }); ``` @@ -1894,12 +1898,12 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco let surfaceID = null; // The surfaceID is transferred to the camera API to create a videoOutput instance. avRecorder.getInputSurface((err, surfaceId) => { - if (err == null) { - console.info('getInputSurface success'); - surfaceID = surfaceId; - } else { - console.info('getInputSurface failed and error is ' + err.message); - } + if (err == null) { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.error('getInputSurface failed and error is ' + err.message); + } }); ``` @@ -1938,10 +1942,10 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco let surfaceID = null; // The surfaceID is transferred to the camera API to create a videoOutput instance. avRecorder.getInputSurface().then((surfaceId) => { - console.info('getInputSurface success'); - surfaceID = surfaceId; + console.info('getInputSurface success'); + surfaceID = surfaceId; }).catch((err) => { - console.info('getInputSurface failed and catch error is ' + err.message); + console.error('getInputSurface failed and catch error is ' + err.message); }); ``` @@ -1975,11 +1979,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.start((err) => { - if (err == null) { - console.info('start AVRecorder success'); - } else { - console.info('start AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('start AVRecorder success'); + } else { + console.error('start AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2013,9 +2017,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.start().then(() => { - console.info('start AVRecorder success'); + console.info('start AVRecorder success'); }).catch((err) => { - console.info('start AVRecorder failed and catch error is ' + err.message); + console.error('start AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2049,11 +2053,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.pause((err) => { - if (err == null) { - console.info('pause AVRecorder success'); - } else { - console.info('pause AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('pause AVRecorder success'); + } else { + console.error('pause AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2087,9 +2091,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.pause().then(() => { - console.info('pause AVRecorder success'); + console.info('pause AVRecorder success'); }).catch((err) => { - console.info('pause AVRecorder failed and catch error is ' + err.message); + console.error('pause AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2123,11 +2127,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.resume((err) => { - if (err == null) { - console.info('resume AVRecorder success'); - } else { - console.info('resume AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('resume AVRecorder success'); + } else { + console.error('resume AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2161,9 +2165,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.resume().then(() => { - console.info('resume AVRecorder success'); + console.info('resume AVRecorder success'); }).catch((err) => { - console.info('resume AVRecorder failed and catch error is ' + err.message); + console.error('resume AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2199,11 +2203,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.stop((err) => { - if (err == null) { - console.info('stop AVRecorder success'); - } else { - console.info('stop AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('stop AVRecorder success'); + } else { + console.error('stop AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2239,9 +2243,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.stop().then(() => { - console.info('stop AVRecorder success'); + console.info('stop AVRecorder success'); }).catch((err) => { - console.info('stop AVRecorder failed and catch error is ' + err.message); + console.error('stop AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2274,11 +2278,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.reset((err) => { - if (err == null) { - console.info('reset AVRecorder success'); - } else { - console.info('reset AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('reset AVRecorder success'); + } else { + console.error('reset AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2311,9 +2315,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.reset().then(() => { - console.info('reset AVRecorder success'); + console.info('reset AVRecorder success'); }).catch((err) => { - console.info('reset AVRecorder failed and catch error is ' + err.message); + console.error('reset AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2345,11 +2349,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.release((err) => { - if (err == null) { - console.info('release AVRecorder success'); - } else { - console.info('release AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('release AVRecorder success'); + } else { + console.error('release AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2381,9 +2385,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.release().then(() => { - console.info('release AVRecorder success'); + console.info('release AVRecorder success'); }).catch((err) => { - console.info('release AVRecorder failed and catch error is ' + err.message); + console.error('release AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2406,7 +2410,7 @@ Subscribes to AVRecorder state changes. An application can subscribe to only one ```js avRecorder.on('stateChange', async (state, reason) => { - console.info('case state has changed, new state is :' + state + ',and new reason is : ' + reason); + console.info('case state has changed, new state is :' + state + ',and new reason is : ' + reason); }); ``` @@ -2460,7 +2464,7 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js avRecorder.on('error', (err) => { - console.info('case avRecorder.on(error) called, errMessage is ' + err.message); + console.error('case avRecorder.on(error) called, errMessage is ' + err.message); }); ``` @@ -2521,8 +2525,8 @@ Describes the audio and video recording parameters. | videoSourceType | [VideoSourceType](#videosourcetype9) | No | Type of the video source to record. This parameter is mandatory for video recording. | | profile | [AVRecorderProfile](#avrecorderprofile9) | Yes | Recording profile. This parameter is mandatory. | | url | string | Yes | Recording output URL: fd://xx (fd number).
![img](figures/en-us_image_url.png)
This parameter is mandatory.| -| rotation | number | No | Rotation angle of the recorded video. The value can only be 0, 90, 180, or 270. | -| location | [Location](#location) | No | Geographical location of the recorded video. | +| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | +| location | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. | The **audioSourceType** and **videoSourceType** parameters are used to distinguish audio-only recording, video-only recording, and audio and video recording. For audio-only recording, set only **audioSourceType**. For video-only recording, set only **videoSourceType**. For audio and video recording, set both **audioSourceType** and **videoSourceType**. @@ -2642,34 +2646,34 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // Configure the parameters based on those supported by the hardware device. let videoProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : 'audio/mp4a-latm', - audioSampleRate : 48000, - fileFormat : 'mp4', - videoBitrate : 2000000, - videoCodec : 'video/avc', - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 2000000, + videoCodec : 'video/avc', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let videoConfig = { - audioSourceType : 1, - videoSourceType : 0, - profile : videoProfile, - url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. - orientationHint : 0, - location : { latitude : 30, longitude : 130 }, + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, } // asyncallback videoRecorder.prepare(videoConfig, (err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.info('prepare failed and error is ' + err.message); - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare failed and error is ' + err.message); + } }) ``` @@ -2713,32 +2717,32 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // Configure the parameters based on those supported by the hardware device. let videoProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : 'audio/mp4a-latm', - audioSampleRate : 48000, - fileFormat : 'mp4', - videoBitrate : 2000000, - videoCodec : 'video/avc', - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 2000000, + videoCodec : 'video/avc', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let videoConfig = { - audioSourceType : 1, - videoSourceType : 0, - profile : videoProfile, - url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. - orientationHint : 0, - location : { latitude : 30, longitude : 130 }, + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, } // promise videoRecorder.prepare(videoConfig).then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); + console.error('prepare failed and catch error is ' + err.message); }); ``` @@ -2778,12 +2782,12 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco // asyncallback let surfaceID = null; // Surface ID passed to the external system. videoRecorder.getInputSurface((err, surfaceId) => { - if (err == null) { - console.info('getInputSurface success'); - surfaceID = surfaceId; - } else { - console.info('getInputSurface failed and error is ' + err.message); - } + if (err == null) { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.error('getInputSurface failed and error is ' + err.message); + } }); ``` @@ -2823,10 +2827,10 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco // promise let surfaceID = null; // Surface ID passed to the external system. videoRecorder.getInputSurface().then((surfaceId) => { - console.info('getInputSurface success'); - surfaceID = surfaceId; + console.info('getInputSurface success'); + surfaceID = surfaceId; }).catch((err) => { - console.info('getInputSurface failed and catch error is ' + err.message); + console.error('getInputSurface failed and catch error is ' + err.message); }); ``` @@ -2863,11 +2867,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.start((err) => { - if (err == null) { - console.info('start videorecorder success'); - } else { - console.info('start videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('start videorecorder success'); + } else { + console.error('start videorecorder failed and error is ' + err.message); + } }); ``` @@ -2904,9 +2908,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.start().then(() => { - console.info('start videorecorder success'); + console.info('start videorecorder success'); }).catch((err) => { - console.info('start videorecorder failed and catch error is ' + err.message); + console.error('start videorecorder failed and catch error is ' + err.message); }); ``` @@ -2943,11 +2947,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.pause((err) => { - if (err == null) { - console.info('pause videorecorder success'); - } else { - console.info('pause videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('pause videorecorder success'); + } else { + console.error('pause videorecorder failed and error is ' + err.message); + } }); ``` @@ -2984,9 +2988,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.pause().then(() => { - console.info('pause videorecorder success'); + console.info('pause videorecorder success'); }).catch((err) => { - console.info('pause videorecorder failed and catch error is ' + err.message); + console.error('pause videorecorder failed and catch error is ' + err.message); }); ``` @@ -3021,11 +3025,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.resume((err) => { - if (err == null) { - console.info('resume videorecorder success'); - } else { - console.info('resume videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('resume videorecorder success'); + } else { + console.error('resume videorecorder failed and error is ' + err.message); + } }); ``` @@ -3060,9 +3064,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.resume().then(() => { - console.info('resume videorecorder success'); + console.info('resume videorecorder success'); }).catch((err) => { - console.info('resume videorecorder failed and catch error is ' + err.message); + console.error('resume videorecorder failed and catch error is ' + err.message); }); ``` @@ -3099,11 +3103,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.stop((err) => { - if (err == null) { - console.info('stop videorecorder success'); - } else { - console.info('stop videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('stop videorecorder success'); + } else { + console.error('stop videorecorder failed and error is ' + err.message); + } }); ``` @@ -3140,9 +3144,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.stop().then(() => { - console.info('stop videorecorder success'); + console.info('stop videorecorder success'); }).catch((err) => { - console.info('stop videorecorder failed and catch error is ' + err.message); + console.error('stop videorecorder failed and catch error is ' + err.message); }); ``` @@ -3175,11 +3179,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.release((err) => { - if (err == null) { - console.info('release videorecorder success'); - } else { - console.info('release videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('release videorecorder success'); + } else { + console.error('release videorecorder failed and error is ' + err.message); + } }); ``` @@ -3212,9 +3216,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.release().then(() => { - console.info('release videorecorder success'); + console.info('release videorecorder success'); }).catch((err) => { - console.info('release videorecorder failed and catch error is ' + err.message); + console.error('release videorecorder failed and catch error is ' + err.message); }); ``` @@ -3250,11 +3254,11 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // asyncallback videoRecorder.reset((err) => { - if (err == null) { - console.info('reset videorecorder success'); - } else { - console.info('reset videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('reset videorecorder success'); + } else { + console.error('reset videorecorder failed and error is ' + err.message); + } }); ``` @@ -3290,9 +3294,9 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // promise videoRecorder.reset().then(() => { - console.info('reset videorecorder success'); + console.info('reset videorecorder success'); }).catch((err) => { - console.info('reset videorecorder failed and catch error is ' + err.message); + console.error('reset videorecorder failed and catch error is ' + err.message); }); ``` @@ -3325,7 +3329,7 @@ For details about the error codes, see [Media Error Codes](../errorcodes/errorco ```js // This event is reported when an error occurs during the retrieval of videoRecordState. videoRecorder.on('error', (error) => { // Set the 'error' event callback. - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }) ``` @@ -3359,9 +3363,9 @@ Describes the video recording parameters. | audioSourceType | [AudioSourceType](#audiosourcetype9) | Yes | Type of the audio source for video recording. | | videoSourceType | [VideoSourceType](#videosourcetype9) | Yes | Type of the video source for video recording. | | profile | [VideoRecorderProfile](#videorecorderprofile9) | Yes | Video recording profile. | -| rotation | number | No | Rotation angle of the recorded video. | -| location | [Location](#location) | No | Geographical location of the recorded video. | -| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png) | +| rotation | number | No | Rotation angle of the recorded video. The value can only be 0 (default), 90, 180, or 270. | +| location | [Location](#location) | No | Geographical location of the recorded video. By default, the geographical location information is not recorded. | +| url | string | Yes | Video output URL. Supported: fd://xx (fd number)
![](figures/en-us_image_url.png) | ## VideoRecorderProfile9+ @@ -3429,15 +3433,15 @@ Creates a **VideoPlayer** instance. This API uses an asynchronous callback to re **Example** ```js -let videoPlayer +let videoPlayer; media.createVideoPlayer((error, video) => { - if (video != null) { - videoPlayer = video; - console.info('video createVideoPlayer success'); - } else { - console.info(`video createVideoPlayer fail, error:${error}`); - } + if (video != null) { + videoPlayer = video; + console.info('video createVideoPlayer success'); + } else { + console.error(`video createVideoPlayer fail, error:${error}`); + } }); ``` @@ -3462,17 +3466,17 @@ Creates a **VideoPlayer** instance. This API uses a promise to return the result **Example** ```js -let videoPlayer +let videoPlayer; media.createVideoPlayer().then((video) => { - if (video != null) { - videoPlayer = video; - console.info('video createVideoPlayer success'); - } else { - console.info('video createVideoPlayer fail'); - } + if (video != null) { + videoPlayer = video; + console.info('video createVideoPlayer success'); + } else { + console.error('video createVideoPlayer fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -3558,7 +3562,7 @@ Starts to play an audio asset. This API can be called only after the [dataLoad]( ```js audioPlayer.on('play', () => { // Set the 'play' event callback. - console.log('audio play success'); + console.log('audio play success'); }); audioPlayer.play(); ``` @@ -3575,7 +3579,7 @@ Pauses audio playback. ```js audioPlayer.on('pause', () => { // Set the 'pause' event callback. - console.log('audio pause success'); + console.log('audio pause success'); }); audioPlayer.pause(); ``` @@ -3592,7 +3596,7 @@ Stops audio playback. ```js audioPlayer.on('stop', () => { // Set the 'stop' event callback. - console.log('audio stop success'); + console.log('audio stop success'); }); audioPlayer.stop(); ``` @@ -3609,7 +3613,7 @@ Resets the audio asset to be played. ```js audioPlayer.on('reset', () => { // Set the 'reset' event callback. - console.log('audio reset success'); + console.log('audio reset success'); }); audioPlayer.reset(); ``` @@ -3632,11 +3636,11 @@ Seeks to the specified playback position. ```js audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback. - if (seekDoneTime == null) { - console.info('audio seek fail'); - return; - } - console.log('audio seek success. seekDoneTime: ' + seekDoneTime); + if (seekDoneTime == null) { + console.info('audio seek fail'); + return; + } + console.log('audio seek success. seekDoneTime: ' + seekDoneTime); }); audioPlayer.seek(30000); // Seek to 30000 ms. ``` @@ -3659,7 +3663,7 @@ Sets the volume. ```js audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback. - console.log('audio volumeChange success'); + console.log('audio volumeChange success'); }); audioPlayer.setVolume(1); // Set the volume to 100%. ``` @@ -3697,21 +3701,21 @@ Obtains the audio track information. This API uses an asynchronous callback to r ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } audioPlayer.getTrackDescription((error, arrList) => { - if (arrList != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`audio getTrackDescription fail, error:${error}`); + if (arrList != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`audio getTrackDescription fail, error:${error}`); + } }); ``` @@ -3733,25 +3737,25 @@ Obtains the audio track information. This API uses a promise to return the resul ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } let arrayDescription = null audioPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('audio getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('audio getTrackDescription fail'); + } }).catch((error) => { - console.info(`audio catchCallback, error:${error}`); + console.info(`audio catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -3774,8 +3778,8 @@ Subscribes to the audio buffering update event. This API works only under online ```js audioPlayer.on('bufferingUpdate', (infoType, value) => { - console.log('audio bufferingInfo type: ' + infoType); - console.log('audio bufferingInfo value: ' + value); + console.log('audio bufferingInfo type: ' + infoType); + console.log('audio bufferingInfo value: ' + value); }); ``` @@ -3801,40 +3805,40 @@ import fs from '@ohos.file.fs'; let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance. audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully. - console.info('audio set source success'); - audioPlayer.play(); // Start the playback and trigger the 'play' event callback. + console.info('audio set source success'); + audioPlayer.play(); // Start the playback and trigger the 'play' event callback. }); audioPlayer.on('play', () => { // Set the 'play' event callback. - console.info('audio play success'); - audioPlayer.seek(30000); // Call the seek() API and trigger the 'timeUpdate' event callback. + console.info('audio play success'); + audioPlayer.seek(30000); // Call the seek() API and trigger the 'timeUpdate' event callback. }); audioPlayer.on('pause', () => { // Set the 'pause' event callback. - console.info('audio pause success'); - audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback. + console.info('audio pause success'); + audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback. }); audioPlayer.on('reset', () => { // Set the 'reset' event callback. - console.info('audio reset success'); - audioPlayer.release(); // Release the AudioPlayer instance. - audioPlayer = undefined; + console.info('audio reset success'); + audioPlayer.release(); // Release the AudioPlayer instance. + audioPlayer = undefined; }); audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback. - if (seekDoneTime == null) { - console.info('audio seek fail'); - return; - } - console.info('audio seek success, and seek time is ' + seekDoneTime); - audioPlayer.setVolume(0.5); // Set the volume to 50% and trigger the 'volumeChange' event callback. + if (seekDoneTime == null) { + console.info('audio seek fail'); + return; + } + console.info('audio seek success, and seek time is ' + seekDoneTime); + audioPlayer.setVolume(0.5); // Set the volume to 50% and trigger the 'volumeChange' event callback. }); audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback. - console.info('audio volumeChange success'); - audioPlayer.pause(); // Pause the playback and trigger the 'pause' event callback. + console.info('audio volumeChange success'); + audioPlayer.pause(); // Pause the playback and trigger the 'pause' event callback. }); audioPlayer.on('finish', () => { // Set the 'finish' event callback. - console.info('audio play finish'); - audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback. + console.info('audio play finish'); + audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback. }); audioPlayer.on('error', (error) => { // Set the 'error' event callback. - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); // Set the FD (local playback) of the audio file selected by the user. @@ -3842,13 +3846,13 @@ let fdPath = 'fd://'; // The stream in the path can be pushed to the device by running the "hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" command. let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; fs.open(path).then((file) => { - fdPath = fdPath + '' + file.fd; - console.info('open fd success fd is' + fdPath); - audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback. + fdPath = fdPath + '' + file.fd; + console.info('open fd success fd is' + fdPath); + audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback. }, (err) => { - console.info('open fd failed err is' + err); + console.info('open fd failed err is' + err); }).catch((err) => { - console.info('open fd failed err is' + err); + console.info('open fd failed err is' + err); }); ``` @@ -3871,11 +3875,11 @@ Subscribes to the **'timeUpdate'** event. This event is reported every second wh ```js audioPlayer.on('timeUpdate', (newTime) => { // Set the 'timeUpdate' event callback. - if (newTime == null) { - console.info('audio timeUpadate fail'); - return; - } - console.log('audio timeUpadate success. seekDoneTime: ' + newTime); + if (newTime == null) { + console.info('audio timeUpadate fail'); + return; + } + console.log('audio timeUpadate success. seekDoneTime: ' + newTime); }); audioPlayer.play(); // The 'timeUpdate' event is triggered when the playback starts. ``` @@ -3899,7 +3903,7 @@ Subscribes to audio playback error events. After an error event is reported, you ```js audioPlayer.on('error', (error) => { // Set the 'error' event callback. - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); audioPlayer.setVolume(3); // Set volume to an invalid value to trigger the 'error' event. ``` @@ -3969,11 +3973,11 @@ Sets **SurfaceId**. This API uses an asynchronous callback to return the result. ```js let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId, (err) => { - if (err == null) { - console.info('setDisplaySurface success!'); - } else { - console.info('setDisplaySurface fail!'); - } + if (err == null) { + console.info('setDisplaySurface success!'); + } else { + console.error('setDisplaySurface fail!'); + } }); ``` @@ -4004,9 +4008,9 @@ Sets **SurfaceId**. This API uses a promise to return the result. ```js let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId).then(() => { - console.info('setDisplaySurface success'); + console.info('setDisplaySurface success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4028,11 +4032,11 @@ Prepares for video playback. This API uses an asynchronous callback to return th ```js videoPlayer.prepare((err) => { - if (err == null) { - console.info('prepare success!'); - } else { - console.info('prepare fail!'); - } + if (err == null) { + console.info('prepare success!'); + } else { + console.error('prepare fail!'); + } }); ``` @@ -4054,9 +4058,9 @@ Prepares for video playback. This API uses a promise to return the result. ```js videoPlayer.prepare().then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4078,11 +4082,11 @@ Starts to play video assets. This API uses an asynchronous callback to return th ```js videoPlayer.play((err) => { - if (err == null) { - console.info('play success!'); - } else { - console.info('play fail!'); - } + if (err == null) { + console.info('play success!'); + } else { + console.error('play fail!'); + } }); ``` @@ -4104,9 +4108,9 @@ Starts to play video assets. This API uses a promise to return the result. ```js videoPlayer.play().then(() => { - console.info('play success'); + console.info('play success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4128,11 +4132,11 @@ Pauses video playback. This API uses an asynchronous callback to return the resu ```js videoPlayer.pause((err) => { - if (err == null) { - console.info('pause success!'); - } else { - console.info('pause fail!'); - } + if (err == null) { + console.info('pause success!'); + } else { + console.info('pause fail!'); + } }); ``` @@ -4154,9 +4158,9 @@ Pauses video playback. This API uses a promise to return the result. ```js videoPlayer.pause().then(() => { - console.info('pause success'); + console.info('pause success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4178,11 +4182,11 @@ Stops video playback. This API uses an asynchronous callback to return the resul ```js videoPlayer.stop((err) => { - if (err == null) { - console.info('stop success!'); - } else { - console.info('stop fail!'); - } + if (err == null) { + console.info('stop success!'); + } else { + console.error('stop fail!'); + } }); ``` @@ -4204,9 +4208,9 @@ Stops video playback. This API uses a promise to return the result. ```js videoPlayer.stop().then(() => { - console.info('stop success'); + console.info('stop success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4228,11 +4232,11 @@ Resets the video asset to be played. This API uses an asynchronous callback to r ```js videoPlayer.reset((err) => { - if (err == null) { - console.info('reset success!'); - } else { - console.info('reset fail!'); - } + if (err == null) { + console.info('reset success!'); + } else { + console.error('reset fail!'); + } }); ``` @@ -4254,9 +4258,9 @@ Resets the video asset to be played. This API uses a promise to return the resul ```js videoPlayer.reset().then(() => { - console.info('reset success'); + console.info('reset success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4280,11 +4284,11 @@ Seeks to the specified playback position. The previous key frame at the specifie ```js let seekTime = 5000; videoPlayer.seek(seekTime, (err, result) => { - if (err == null) { - console.info('seek success!'); - } else { - console.info('seek fail!'); - } + if (err == null) { + console.info('seek success!'); + } else { + console.error('seek fail!'); + } }); ``` @@ -4310,11 +4314,11 @@ Seeks to the specified playback position. This API uses an asynchronous callback import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err, result) => { - if (err == null) { - console.info('seek success!'); - } else { - console.info('seek fail!'); - } + if (err == null) { + console.info('seek success!'); + } else { + console.error('seek fail!'); + } }); ``` @@ -4331,7 +4335,7 @@ Seeks to the specified playback position. If **mode** is not specified, the prev | Name| Type | Mandatory| Description | | ------ | ---------------------- | ---- | ------------------------------------------------------------ | | timeMs | number | Yes | Position to seek to, in ms. The value range is [0, duration].| -| mode | [SeekMode](#seekmode8) | No | Seek mode. | +| mode | [SeekMode](#seekmode8) | No | Seek mode based on the video I frame. The default value is **SEEK_PREV_SYNC**. | **Return value** @@ -4345,15 +4349,15 @@ Seeks to the specified playback position. If **mode** is not specified, the prev import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete. - console.info('seek success'); + console.info('seek success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { - console.info('seek success'); + console.info('seek success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4377,11 +4381,11 @@ Sets the volume. This API uses an asynchronous callback to return the result. ```js let vol = 0.5; videoPlayer.setVolume(vol, (err, result) => { - if (err == null) { - console.info('setVolume success!'); - } else { - console.info('setVolume fail!'); - } + if (err == null) { + console.info('setVolume success!'); + } else { + console.error('setVolume fail!'); + } }); ``` @@ -4410,9 +4414,9 @@ Sets the volume. This API uses a promise to return the result. ```js let vol = 0.5; videoPlayer.setVolume(vol).then(() => { - console.info('setVolume success'); + console.info('setVolume success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4434,11 +4438,11 @@ Releases the video playback resources. This API uses an asynchronous callback to ```js videoPlayer.release((err) => { - if (err == null) { - console.info('release success!'); - } else { - console.info('release fail!'); - } + if (err == null) { + console.info('release success!'); + } else { + console.error('release fail!'); + } }); ``` @@ -4460,9 +4464,9 @@ Releases the video playback resources. This API uses a promise to return the res ```js videoPlayer.release().then(() => { - console.info('release success'); + console.info('release success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4484,21 +4488,21 @@ Obtains the video track information. This API uses an asynchronous callback to r ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('video key is ' + item); - console.info('video value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('video key is ' + item); + console.info('video value is ' + property); + } } videoPlayer.getTrackDescription((error, arrList) => { - if ((arrList) != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`video getTrackDescription fail, error:${error}`); + if ((arrList) != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`video getTrackDescription fail, error:${error}`); + } }); ``` @@ -4520,25 +4524,25 @@ Obtains the video track information. This API uses a promise to return the resul ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('video key is ' + item); - console.info('video value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('video key is ' + item); + console.info('video value is ' + property); + } } let arrayDescription; videoPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('video getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('video getTrackDescription fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.info(`video catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -4564,11 +4568,11 @@ import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; videoPlayer.setSpeed(speed, (err, result) => { - if (err == null) { - console.info('setSpeed success!'); - } else { - console.info('setSpeed fail!'); - } + if (err == null) { + console.info('setSpeed success!'); + } else { + console.error('setSpeed fail!'); + } }); ``` @@ -4599,9 +4603,9 @@ import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; videoPlayer.setSpeed(speed).then(() => { - console.info('setSpeed success'); + console.info('setSpeed success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4624,7 +4628,7 @@ Subscribes to the video playback completion event. ```js videoPlayer.on('playbackCompleted', () => { - console.info('playbackCompleted success!'); + console.info('playbackCompleted success!'); }); ``` @@ -4647,8 +4651,8 @@ Subscribes to the video buffering update event. Only network playback supports t ```js videoPlayer.on('bufferingUpdate', (infoType, value) => { - console.log('video bufferingInfo type: ' + infoType); - console.log('video bufferingInfo value: ' + value); + console.log('video bufferingInfo type: ' + infoType); + console.log('video bufferingInfo value: ' + value); }); ``` @@ -4671,7 +4675,7 @@ Subscribes to the frame rendering start event. ```js videoPlayer.on('startRenderFrame', () => { - console.info('startRenderFrame success!'); + console.info('startRenderFrame success!'); }); ``` @@ -4694,8 +4698,8 @@ Subscribes to the video width and height change event. ```js videoPlayer.on('videoSizeChanged', (width, height) => { - console.log('video width is: ' + width); - console.log('video height is: ' + height); + console.log('video width is: ' + width); + console.log('video height is: ' + height); }); ``` @@ -4718,7 +4722,7 @@ Subscribes to video playback error events. After an error event is reported, you ```js videoPlayer.on('error', (error) => { // Set the 'error' event callback. - console.info(`video error called, error: ${error}`); + console.error(`video error called, error: ${error}`); }); videoPlayer.url = 'fd://error'; // Set an incorrect URL to trigger the 'error' event. ``` @@ -4770,16 +4774,16 @@ Prepares for recording. ```js let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://1', // The file must be created by the caller and granted with proper permissions. - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://1', // The file must be created by the caller and granted with proper permissions. + location : { latitude : 30, longitude : 130}, } audioRecorder.on('prepare', () => { // Set the 'prepare' event callback. - console.log('prepare success'); + console.log('prepare success'); }); audioRecorder.prepare(audioRecorderConfig); ``` @@ -4797,7 +4801,7 @@ Starts audio recording. This API can be called only after the [prepare](#audiore ```js audioRecorder.on('start', () => { // Set the 'start' event callback. - console.log('audio recorder start success'); + console.log('audio recorder start success'); }); audioRecorder.start(); ``` @@ -4814,7 +4818,7 @@ Pauses audio recording. This API can be called only after the [start](#audioreco ```js audioRecorder.on('pause', () => { // Set the 'pause' event callback. - console.log('audio recorder pause success'); + console.log('audio recorder pause success'); }); audioRecorder.pause(); ``` @@ -4831,7 +4835,7 @@ Resumes audio recording. This API can be called only after the [pause](#audiorec ```js audioRecorder.on('resume', () => { // Set the 'resume' event callback. - console.log('audio recorder resume success'); + console.log('audio recorder resume success'); }); audioRecorder.resume(); ``` @@ -4848,7 +4852,7 @@ Stops audio recording. ```js audioRecorder.on('stop', () => { // Set the 'stop' event callback. - console.log('audio recorder stop success'); + console.log('audio recorder stop success'); }); audioRecorder.stop(); ``` @@ -4865,7 +4869,7 @@ Releases the audio recording resources. ```js audioRecorder.on('release', () => { // Set the 'release' event callback. - console.log('audio recorder release success'); + console.log('audio recorder release success'); }); audioRecorder.release(); audioRecorder = undefined; @@ -4885,7 +4889,7 @@ Before resetting audio recording, you must call [stop()](#audiorecorder_stop) to ```js audioRecorder.on('reset', () => { // Set the 'reset' event callback. - console.log('audio recorder reset success'); + console.log('audio recorder reset success'); }); audioRecorder.reset(); ``` @@ -4910,38 +4914,38 @@ Subscribes to the audio recording events. ```js let audioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + location : { latitude : 30, longitude : 130}, } audioRecorder.on('error', (error) => { // Set the 'error' event callback. - console.info(`audio error called, error: ${error}`); + console.info(`audio error called, error: ${error}`); }); audioRecorder.on('prepare', () => { // Set the 'prepare' event callback. - console.log('prepare success'); - audioRecorder.start(); // Start recording and trigger the 'start' event callback. + console.log('prepare success'); + audioRecorder.start(); // Start recording and trigger the 'start' event callback. }); audioRecorder.on('start', () => { // Set the 'start' event callback. - console.log('audio recorder start success'); + console.log('audio recorder start success'); }); audioRecorder.on('pause', () => { // Set the 'pause' event callback. - console.log('audio recorder pause success'); + console.log('audio recorder pause success'); }); audioRecorder.on('resume', () => { // Set the 'resume' event callback. - console.log('audio recorder resume success'); + console.log('audio recorder resume success'); }); audioRecorder.on('stop', () => { // Set the 'stop' event callback. - console.log('audio recorder stop success'); + console.log('audio recorder stop success'); }); audioRecorder.on('release', () => { // Set the 'release' event callback. - console.log('audio recorder release success'); + console.log('audio recorder release success'); }); audioRecorder.on('reset', () => { // Set the 'reset' event callback. - console.log('audio recorder reset success'); + console.log('audio recorder reset success'); }); audioRecorder.prepare(audioRecorderConfig) // Set recording parameters and trigger the 'prepare' event callback. ``` @@ -4965,16 +4969,16 @@ Subscribes to audio recording error events. After an error event is reported, yo ```js let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions. + location : { latitude : 30, longitude : 130}, } audioRecorder.on('error', (error) => { // Set the 'error' event callback. - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); audioRecorder.prepare(audioRecorderConfig); // Do no set any parameter in prepare and trigger the 'error' event callback. ``` -- GitLab