You need to sign in or sign up before continuing.
提交 6620b5bd 编写于 作者: G Gloria

Update docs against 17738+18286+17995+16616+17842+17829

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