未验证 提交 bc91bf39 编写于 作者: O openharmony_ci 提交者: Gitee

!10558 翻译完成:9469+9462+9470+9555+9583+9608+9638+9655+9828+9943+10393 js-apis-audio.md

Merge pull request !10558 from wusongqing/TR9469
...@@ -7,6 +7,7 @@ This module provides the following common audio-related functions: ...@@ -7,6 +7,7 @@ This module provides the following common audio-related functions:
- [AudioManager](#audiomanager): audio management. - [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data. - [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data. - [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
- [TonePlayer](#toneplayer9): tone player, used to manage and play Dual Tone Multi Frequency (DTMF) tones, such as dial tones and ringback tones.
> **NOTE** > **NOTE**
> >
...@@ -55,65 +56,11 @@ Obtains an **AudioManager** instance. ...@@ -55,65 +56,11 @@ Obtains an **AudioManager** instance.
var audioManager = audio.getAudioManager(); var audioManager = audio.getAudioManager();
``` ```
## audio.getStreamManager<sup>9+</sup>
getStreamManager(callback: AsyncCallback\<AudioStreamManager>): void
Obtains an **AudioStreamManager** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<[AudioStreamManager](#audiostreammanager9)> | Yes | **AudioStreamManager** instance.|
**Example**
```js
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
let audioStreamManager = data;
}
});
```
## audio.getStreamManager<sup>9+</sup>
getStreamManager(): Promise<AudioStreamManager\>
Obtains an **AudioStreamManager** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Return value**
| Type | Description |
| ---------------------------------------------------- | ---------------- |
| Promise<[AudioStreamManager](#audiostreammanager9)> | **AudioStreamManager** instance.|
**Example**
```js
var audioStreamManager;
audio.getStreamManager().then((data) => {
audioStreamManager = data;
console.info('getStreamManager: Success!');
}).catch((err) => {
console.error(`getStreamManager: ERROR : ${err}`);
});
```
## audio.createAudioRenderer<sup>8+</sup> ## audio.createAudioRenderer<sup>8+</sup>
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result. Creates an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
...@@ -160,7 +107,7 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => { ...@@ -160,7 +107,7 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => {
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\> createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
Obtains an **AudioRenderer** instance. This API uses a promise to return the result. Creates an **AudioRenderer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
...@@ -212,10 +159,12 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => { ...@@ -212,10 +159,12 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result. Creates an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Required permissions**: ohos.permission.MICROPHONE
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -258,10 +207,12 @@ audio.createAudioCapturer(audioCapturerOptions, (err, data) => { ...@@ -258,10 +207,12 @@ audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
Obtains an **AudioCapturer** instance. This API uses a promise to return the result. Creates an **AudioCapturer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Required permissions**: ohos.permission.MICROPHONE
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
...@@ -305,6 +256,78 @@ audio.createAudioCapturer(audioCapturerOptions).then((data) => { ...@@ -305,6 +256,78 @@ audio.createAudioCapturer(audioCapturerOptions).then((data) => {
}); });
``` ```
## audio.createTonePlayer<sup>9+</sup>
createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback&lt;TonePlayer&gt;): void
Creates a **TonePlayer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | -------------- |
| options | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
| callback | AsyncCallback<[TonePlayer](#toneplayer9)> | Yes | Callback used to return the **TonePlayer** instance.|
**Example**
```js
import audio from '@ohos.multimedia.audio';
var audioRendererInfo = {
"contentType": audio.ContentType.CONTENT_TYPE_MUSIC,
"streamUsage": audio.StreamUsage.STREAM_USAGE_MEDIA,
"rendererFlags": 0
}
var tonePlayer;
audio.createTonePlayer(audioRendererInfo, (err, data) => {
console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
if (err) {
console.error(`callback call createTonePlayer return error: ${err.message}`);
} else {
console.info(`callback call createTonePlayer return data: ${data}`);
tonePlayer = data;
}
});
```
## audio.createTonePlayer<sup>9+</sup>
createTonePlayer(options: AudioRendererInfo): Promise&lt;TonePlayer&gt;
Creates a **TonePlayer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory| Description |
| :------ | :---------------------------------------------| :--- | :----------- |
| options | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
**Return value**
| Type | Description |
| ----------------------------------------- | -------------------------------- |
| Promise<[TonePlayer](#toneplayer9)> | Promise used to return the **TonePlayer** instance. |
**Example**
```js
import audio from '@ohos.multimedia.audio';
async function createTonePlayer(){
var audioRendererInfo = {
"contentType": audio.ContentType.CONTENT_TYPE_MUSIC,
"streamUsage": audio.StreamUsage.STREAM_USAGE_MEDIA,
"rendererFlags": 0
}
let tonePlayer = await audio.createTonePlayer(this.audioRendererInfo);
}
```
## AudioVolumeType ## AudioVolumeType
Enumerates the audio stream types. Enumerates the audio stream types.
...@@ -338,13 +361,13 @@ Enumerates the audio device flags. ...@@ -338,13 +361,13 @@ Enumerates the audio device flags.
| Name | Default Value | Description | | Name | Default Value | Description |
| ------------------------------- | ------ | ------------------------------------------------- | | ------------------------------- | ------ | ------------------------------------------------- |
| NONE_DEVICES_FLAG<sup>9+</sup> | 0 | No flag.<br>This is a system API and cannot be called by third-party applications. | | NONE_DEVICES_FLAG<sup>9+</sup> | 0 | No device.<br>This is a system API and cannot be called by third-party applications. |
| OUTPUT_DEVICES_FLAG | 1 | Output device.| | OUTPUT_DEVICES_FLAG | 1 | Output device.|
| INPUT_DEVICES_FLAG | 2 | Input device.| | INPUT_DEVICES_FLAG | 2 | Input device.|
| ALL_DEVICES_FLAG | 3 | All devices.| | ALL_DEVICES_FLAG | 3 | All devices.|
| DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4 | Distributed output device.<br>This is a system API and cannot be called by third-party applications. | | DISTRIBUTED_OUTPUT_DEVICES_FLAG<sup>9+</sup> | 4 | Distributed output device.<br>This is a system API and cannot be called by third-party applications. |
| DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup> | 8 | Distributed input device.<br>This is a system API and cannot be called by third-party applications. | | DISTRIBUTED_INPUT_DEVICES_FLAG<sup>9+</sup> | 8 | Distributed input device.<br>This is a system API and cannot be called by third-party applications. |
| ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup> | 12 | Distributed input and output devices.<br>This is a system API and cannot be called by third-party applications. | | ALL_DISTRIBUTED_DEVICES_FLAG<sup>9+</sup> | 12 | Distributed input and output device.<br>This is a system API and cannot be called by third-party applications. |
## DeviceRole ## DeviceRole
...@@ -480,10 +503,11 @@ Enumerates the audio stream usage. ...@@ -480,10 +503,11 @@ Enumerates the audio stream usage.
**System capability**: SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- | | ------------------------------------------| ------ | ---------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.| | STREAM_USAGE_UNKNOWN | 0 | Unknown usage.|
| STREAM_USAGE_MEDIA | 1 | Used for media. | | STREAM_USAGE_MEDIA | 1 | Used for media. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.| | STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_VOICE_ASSISTANT<sup>9+</sup> | 3 | Used for voice assistant.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.| | STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
## FocusType<sup>9+</sup> ## FocusType<sup>9+</sup>
...@@ -668,6 +692,8 @@ Describes the event received by the application when the volume is changed. ...@@ -668,6 +692,8 @@ Describes the event received by the application when the volume is changed.
Enumerates the types of connected devices. Enumerates the types of connected devices.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value| Description | | Name | Default Value| Description |
...@@ -689,7 +715,7 @@ Describes the volume group information. ...@@ -689,7 +715,7 @@ Describes the volume group information.
| groupId<sup>9+</sup> | number | Yes | No | Group ID of the device.| | groupId<sup>9+</sup> | number | Yes | No | Group ID of the device.|
| mappingId<sup>9+</sup> | number | Yes | No | Group mapping ID.| | mappingId<sup>9+</sup> | number | Yes | No | Group mapping ID.|
| groupName<sup>9+</sup> | number | Yes | No | Group name.| | groupName<sup>9+</sup> | number | Yes | No | Group name.|
| ConnectType<sup>9+</sup> | [ConnectType](#connecttype9)| Yes | No | Type of the connected device.| | type<sup>9+</sup> | [ConnectType](#connecttype9)| Yes | No | Type of the connected device.|
## VolumeGroupInfos<sup>9+</sup> ## VolumeGroupInfos<sup>9+</sup>
...@@ -762,9 +788,10 @@ Enumerates the audio source types. ...@@ -762,9 +788,10 @@ Enumerates the audio source types.
**System capability**: SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value| Description | | Name | Default Value| Description |
| :------------------------------ | :----- | :--------------------- | | :------------------------------------------- | :----- | :--------------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid audio source. | | SOURCE_TYPE_INVALID | -1 | Invalid audio source. |
| SOURCE_TYPE_MIC | 0 | Mic source. | | SOURCE_TYPE_MIC | 0 | Mic source. |
| SOURCE_TYPE_VOICE_RECOGNITION<sup>9+</sup> | 1 | Voice recognition source. |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7 | Voice communication source.| | SOURCE_TYPE_VOICE_COMMUNICATION | 7 | Voice communication source.|
## AudioScene<sup>8+</sup><a name="audioscene"></a> ## AudioScene<sup>8+</sup><a name="audioscene"></a>
...@@ -780,7 +807,6 @@ Enumerates the audio scenes. ...@@ -780,7 +807,6 @@ Enumerates the audio scenes.
| AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.| | AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | | AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
## AudioManager ## AudioManager
Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance. Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
...@@ -801,7 +827,7 @@ Obtains an **AudioRoutingManager** instance. This API uses an asynchronous callb ...@@ -801,7 +827,7 @@ Obtains an **AudioRoutingManager** instance. This API uses an asynchronous callb
**Example** **Example**
```js ```js
await audioManager.getRoutingManager((err, callback) => { audioManager.getRoutingManager((err, callback) => {
if (err) { if (err) {
console.error(`Result ERROR: ${err}`); console.error(`Result ERROR: ${err}`);
} }
...@@ -827,12 +853,15 @@ Obtains an **AudioRoutingManager** instance. This API uses a promise to return t ...@@ -827,12 +853,15 @@ Obtains an **AudioRoutingManager** instance. This API uses a promise to return t
**Example** **Example**
```js ```js
await audioManager.getRoutingManager().then((value) => { var audioManager = audio.getAudioManager();
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
var routingManager = value; var routingManager = value;
console.info('getRoutingManager Promise SUCCESS.'); console.info('getRoutingManager Promise SUCCESS.');
}).catch((err) => { }).catch((err) => {
console.error(`Result ERROR: ${err}`); console.error(`Result ERROR: ${err}`);
}); });
}
``` ```
### setVolume ### setVolume
...@@ -1951,6 +1980,7 @@ Sets an audio scene. This API uses an asynchronous callback to return the result ...@@ -1951,6 +1980,7 @@ Sets an audio scene. This API uses an asynchronous callback to return the result
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
if (err) { if (err) {
console.error(`Failed to set the audio scene mode.​ ${err}`); console.error(`Failed to set the audio scene mode.​ ${err}`);
...@@ -1985,6 +2015,7 @@ Sets an audio scene. This API uses a promise to return the result. ...@@ -1985,6 +2015,7 @@ Sets an audio scene. This API uses a promise to return the result.
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
console.info('Promise returned to indicate a successful setting of the audio scene mode.'); console.info('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => { }).catch ((err) => {
...@@ -2009,6 +2040,7 @@ Obtains the audio scene. This API uses an asynchronous callback to return the re ...@@ -2009,6 +2040,7 @@ Obtains the audio scene. This API uses an asynchronous callback to return the re
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getAudioScene((err, value) => { audioManager.getAudioScene((err, value) => {
if (err) { if (err) {
console.error(`Failed to obtain the audio scene mode.​ ${err}`); console.error(`Failed to obtain the audio scene mode.​ ${err}`);
...@@ -2036,6 +2068,7 @@ Obtains the audio scene. This API uses a promise to return the result. ...@@ -2036,6 +2068,7 @@ Obtains the audio scene. This API uses a promise to return the result.
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getAudioScene().then((value) => { audioManager.getAudioScene().then((value) => {
console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`); console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
}).catch ((err) => { }).catch ((err) => {
...@@ -2062,6 +2095,7 @@ Obtains the volume groups. This API uses an asynchronous callback to return the ...@@ -2062,6 +2095,7 @@ Obtains the volume groups. This API uses an asynchronous callback to return the
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID, (err, value) => { audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID, (err, value) => {
if (err) { if (err) {
console.error(`Failed to obtain the volume group infos list. ${err}`); console.error(`Failed to obtain the volume group infos list. ${err}`);
...@@ -2091,7 +2125,7 @@ Obtains the volume groups. This API uses a promise to return the result. ...@@ -2091,7 +2125,7 @@ Obtains the volume groups. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------------- | ----------------------------- | | ------------------- | ----------------------------- |
| Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information list.| | Promise&lt;[VolumeGroupInfos](#volumegroupinfos9)&gt; | Volume group information array.|
**Example** **Example**
...@@ -2116,12 +2150,14 @@ Obtains the audio group manager. This API uses an asynchronous callback to retur ...@@ -2116,12 +2150,14 @@ Obtains the audio group manager. This API uses an asynchronous callback to retur
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- | | ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| networkId | string | Yes | Network ID of the device. | | groupId | number | Yes | Volume group ID. |
| callback | AsyncCallback&lt; [AudioGroupManager](#audiogroupmanager9) &gt; | Yes | Callback used to return the audio group manager.| | callback | AsyncCallback&lt; [AudioGroupManager](#audiogroupmanager9) &gt; | Yes | Callback used to return the audio group manager.|
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
var audioGroupManager;
async function getGroupManager(){ async function getGroupManager(){
let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID); let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
if (value.length > 0) { if (value.length > 0) {
...@@ -2151,8 +2187,8 @@ Obtains the audio group manager. This API uses a promise to return the result. ...@@ -2151,8 +2187,8 @@ Obtains the audio group manager. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ---------------------------------------- | ---- | -------------- -- | | ---------- | ---------------------------------------- | ---- | ---------------- |
| networkId | string | Yes | Network ID of the device. | | groupId | number | Yes | Volume group ID. |
**Return value** **Return value**
...@@ -2163,15 +2199,74 @@ Obtains the audio group manager. This API uses a promise to return the result. ...@@ -2163,15 +2199,74 @@ Obtains the audio group manager. This API uses a promise to return the result.
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
async function getGroupManager(){ async function getGroupManager(){
let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID); let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
if (value.length > 0) { if (value.length > 0) {
let groupid = value[0].groupId; let groupid = value[0].groupId;
let audioGroupManager = await audioManager.getGroupManager(audio.LOCAL_NETWORK_ID) let audioGroupManager = await audioManager.getGroupManager(groupid)
console.info('Callback invoked to indicate that the volume group infos list is obtained.'); console.info('Callback invoked to indicate that the volume group infos list is obtained.');
} }
} }
``` ```
### getStreamManager<sup>9+</sup>
getStreamManager(callback: AsyncCallback\<AudioStreamManager>): void
Obtains an **AudioStreamManager** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ---------------- |
| callback | AsyncCallback<[AudioStreamManager](#audiostreammanager9)> | Yes | **AudioStreamManager** instance.|
**Example**
```js
var audioManager = audio.getAudioManager();
let audioStreamManager;
audioManager.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
```
### getStreamManager<sup>9+</sup>
getStreamManager(): Promise<AudioStreamManager\>
Obtains an **AudioStreamManager** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Return value**
| Type | Description |
| ---------------------------------------------------- | ---------------- |
| Promise<[AudioStreamManager](#audiostreammanager9)> | **AudioStreamManager** instance.|
**Example**
```js
var audioManager = audio.getAudioManager();
var audioStreamManager;
audioManager.getStreamManager().then((data) => {
audioStreamManager = data;
console.info('getStreamManager: Success!');
}).catch((err) => {
console.error(`getStreamManager: ERROR : ${err}`);
});
```
### requestIndependentInterrupt<sup>9+</sup> ### requestIndependentInterrupt<sup>9+</sup>
requestIndependentInterrupt(focusType: FocusType, callback: AsyncCallback<boolean\>\): void requestIndependentInterrupt(focusType: FocusType, callback: AsyncCallback<boolean\>\): void
...@@ -2203,7 +2298,7 @@ async function requestIndependentInterrupt(){ ...@@ -2203,7 +2298,7 @@ async function requestIndependentInterrupt(){
``` ```
### requestIndependentInterrupt<sup>9+</sup> ### requestIndependentInterrupt<sup>9+</sup>
requestIndependentInterrupt(focusType: FocusType: Promise<boolean\> requestIndependentInterrupt(focusType: FocusType): Promise<boolean\>
Requests independent interruption and obtains an interruption session ID. This API uses a promise to return the result. Requests independent interruption and obtains an interruption session ID. This API uses a promise to return the result.
...@@ -2265,7 +2360,7 @@ async function abandonIndependentInterrupt(){ ...@@ -2265,7 +2360,7 @@ async function abandonIndependentInterrupt(){
``` ```
### abandonIndependentInterrupt<sup>9+</sup> ### abandonIndependentInterrupt<sup>9+</sup>
abandonIndependentInterrupt(focusType: FocusType]: Promise<boolean\> abandonIndependentInterrupt(focusType: FocusType): Promise<boolean\>
Abandons independent interruption. This API uses a promise to return the result. Abandons independent interruption. This API uses a promise to return the result.
...@@ -2313,6 +2408,8 @@ Sets the volume for a stream. This API uses an asynchronous callback to return t ...@@ -2313,6 +2408,8 @@ Sets the volume for a stream. This API uses an asynchronous callback to return t
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2345,6 +2442,8 @@ Sets the volume for a stream. This API uses a promise to return the result. ...@@ -2345,6 +2442,8 @@ Sets the volume for a stream. This API uses a promise to return the result.
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2374,6 +2473,8 @@ getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): v ...@@ -2374,6 +2473,8 @@ getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): v
Obtains the volume of a stream. This API uses an asynchronous callback to return the result. Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2401,6 +2502,8 @@ getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt; ...@@ -2401,6 +2502,8 @@ getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the volume of a stream. This API uses a promise to return the result. Obtains the volume of a stream. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2429,6 +2532,8 @@ getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;) ...@@ -2429,6 +2532,8 @@ getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;)
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result. Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2456,6 +2561,8 @@ getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt; ...@@ -2456,6 +2561,8 @@ getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the minimum volume allowed for a stream. This API uses a promise to return the result. Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2484,6 +2591,8 @@ getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;) ...@@ -2484,6 +2591,8 @@ getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;)
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result. Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2511,6 +2620,8 @@ getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt; ...@@ -2511,6 +2620,8 @@ getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the maximum volume allowed for a stream. This API uses a promise to return the result. Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2543,6 +2654,8 @@ Mutes or unmutes a stream. This API uses an asynchronous callback to return the ...@@ -2543,6 +2654,8 @@ Mutes or unmutes a stream. This API uses an asynchronous callback to return the
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2575,6 +2688,8 @@ Mutes or unmutes a stream. This API uses a promise to return the result. ...@@ -2575,6 +2688,8 @@ Mutes or unmutes a stream. This API uses a promise to return the result.
This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**. This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2604,6 +2719,8 @@ isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): voi ...@@ -2604,6 +2719,8 @@ isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): voi
Checks whether a stream is muted. This API uses an asynchronous callback to return the result. Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2631,6 +2748,8 @@ isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt; ...@@ -2631,6 +2748,8 @@ isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is muted. This method uses a promise to return the result. Checks whether a stream is muted. This method uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters** **Parameters**
...@@ -2655,7 +2774,7 @@ audioGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -2655,7 +2774,7 @@ audioGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
## AudioStreamManager<sup>9+</sup> ## AudioStreamManager<sup>9+</sup>
Implements audio stream management. Before calling any API of **AudioStreamManager**, you must use **[getStreamManager](#audiogetstreammanager9)** to obtain an **AudioStreamManager** instance. Implements audio stream management. Before calling any API in **AudioStreamManager**, you must use [getStreamManager](#getstreammanager9) to obtain an **AudioStreamManager** instance.
### getCurrentAudioRendererInfoArray<sup>9+</sup> ### getCurrentAudioRendererInfoArray<sup>9+</sup>
...@@ -2674,16 +2793,6 @@ Obtains the information about the current audio renderers. This API uses an asyn ...@@ -2674,16 +2793,6 @@ Obtains the information about the current audio renderers. This API uses an asyn
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => { audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****'); console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
if (err) { if (err) {
...@@ -2731,17 +2840,8 @@ Obtains the information about the current audio renderers. This API uses a promi ...@@ -2731,17 +2840,8 @@ Obtains the information about the current audio renderers. This API uses a promi
**Example** **Example**
```js ```js
let audioStreamManager; async function getCurrentAudioRendererInfoArray(){
audio.getStreamManager((err, data) => { await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`); console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
if (AudioRendererChangeInfoArray != null) { if (AudioRendererChangeInfoArray != null) {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
...@@ -2764,9 +2864,10 @@ await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (Audi ...@@ -2764,9 +2864,10 @@ await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (Audi
} }
} }
} }
}).catch((err) => { }).catch((err) => {
console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`); console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
}); });
}
``` ```
### getCurrentAudioCapturerInfoArray<sup>9+</sup> ### getCurrentAudioCapturerInfoArray<sup>9+</sup>
...@@ -2786,16 +2887,6 @@ Obtains the information about the current audio capturers. This API uses an asyn ...@@ -2786,16 +2887,6 @@ Obtains the information about the current audio capturers. This API uses an asyn
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => { audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****'); console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
if (err) { if (err) {
...@@ -2841,17 +2932,8 @@ Obtains the information about the current audio capturers. This API uses a promi ...@@ -2841,17 +2932,8 @@ Obtains the information about the current audio capturers. This API uses a promi
**Example** **Example**
```js ```js
let audioStreamManager; async function getCurrentAudioCapturerInfoArray(){
audio.getStreamManager((err, data) => { await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****'); console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
if (AudioCapturerChangeInfoArray != null) { if (AudioCapturerChangeInfoArray != null) {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
...@@ -2872,9 +2954,10 @@ await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (Audi ...@@ -2872,9 +2954,10 @@ await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (Audi
} }
} }
} }
}).catch((err) => { }).catch((err) => {
console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`); console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
}); });
}
``` ```
### on('audioRendererChange')<sup>9+</sup> ### on('audioRendererChange')<sup>9+</sup>
...@@ -2895,16 +2978,6 @@ Subscribes to audio renderer change events. ...@@ -2895,16 +2978,6 @@ Subscribes to audio renderer change events.
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => { audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i]; let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
...@@ -2946,16 +3019,6 @@ Unsubscribes from audio renderer change events. ...@@ -2946,16 +3019,6 @@ Unsubscribes from audio renderer change events.
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.off('audioRendererChange'); audioStreamManager.off('audioRendererChange');
console.info('######### RendererChange Off is called #########'); console.info('######### RendererChange Off is called #########');
``` ```
...@@ -2978,19 +3041,9 @@ Subscribes to audio capturer change events. ...@@ -2978,19 +3041,9 @@ Subscribes to audio capturer change events.
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => { audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
console.info(`## CapChange on is called for element ${i} ##'); console.info(`## CapChange on is called for element ${i} ##`);
console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`); console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`); console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`); console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
...@@ -3028,23 +3081,13 @@ Unsubscribes from audio capturer change events. ...@@ -3028,23 +3081,13 @@ Unsubscribes from audio capturer change events.
**Example** **Example**
```js ```js
let audioStreamManager;
audio.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
audioStreamManager.off('audioCapturerChange'); audioStreamManager.off('audioCapturerChange');
console.info('######### CapturerChange Off is called #########'); console.info('######### CapturerChange Off is called #########');
``` ```
## AudioRoutingManager<sup>9+</sup> ## AudioRoutingManager<sup>9+</sup>
Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to create an **AudioRoutingManager** instance. Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance.
### getDevices<sup>9+</sup> ### getDevices<sup>9+</sup>
...@@ -3064,11 +3107,11 @@ Obtains the audio devices with a specific flag. This API uses an asynchronous ca ...@@ -3064,11 +3107,11 @@ Obtains the audio devices with a specific flag. This API uses an asynchronous ca
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getRoutingManager((err,AudioRoutingManager)=>{ audioManager.getRoutingManager((err,AudioRoutingManager)=>{
if (err) { if (err) {
console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`); console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
} } else {
else {
AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) { if (err) {
console.error(`Failed to obtain the device list. ${err}`); console.error(`Failed to obtain the device list. ${err}`);
...@@ -3103,6 +3146,7 @@ Obtains the audio devices with a specific flag. This API uses a promise to retur ...@@ -3103,6 +3146,7 @@ Obtains the audio devices with a specific flag. This API uses a promise to retur
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getRoutingManager((err,AudioRoutingManager)=>{ audioManager.getRoutingManager((err,AudioRoutingManager)=>{
if (err) { if (err) {
console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`); console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
...@@ -3134,6 +3178,7 @@ Subscribes to device change events. When a device is connected or disconnected, ...@@ -3134,6 +3178,7 @@ Subscribes to device change events. When a device is connected or disconnected,
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getRoutingManager((err,AudioRoutingManager)=>{ audioManager.getRoutingManager((err,AudioRoutingManager)=>{
if (err) { if (err) {
console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`); console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
...@@ -3162,24 +3207,108 @@ Unsubscribes from device change events. ...@@ -3162,24 +3207,108 @@ Unsubscribes from device change events.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ | | -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.| | type | string | Yes | Event type. The value **deviceChange** means the device change event, which is triggered when a device connection status change is detected.|
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to return the device update details. | | callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to return the device update details. |
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
audioManager.getRoutingManager((err,AudioRoutingManager)=>{ audioManager.getRoutingManager((err,AudioRoutingManager)=>{
if (err) { if (err) {
console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`); console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
} } else {
else { AudioRoutingManager.off('deviceChange', (deviceChanged) => {
AudioRoutingManager.off('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
console.info('Should be no callback.'); console.info('Should be no callback.');
}); });
} }
}); });
``` ```
### selectInputDevice<sup>9+</sup>
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
Selects an audio input device. Currently, only one input device can be selected. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters**
| Name | Type | Mandatory| Description |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Input device. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example**
```js
var audioManager = audio.getAudioManager();
let inputAudioDeviceDescriptor = [{
"deviceRole":audio.DeviceRole.INPUT_DEVICE,
"networkId":audio.LOCAL_NETWORK_ID,
"interruptGroupId":1,
"volumeGroupId":1 }];
var audioRoutingManager;
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value;
audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
if (err) {
console.error(`Result ERROR: ${err}`);
} else {
console.info('Select input devices result callback: SUCCESS'); }
});
});
}
```
### selectInputDevice<sup>9+</sup>
selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise&lt;void&gt;
**System API**: This is a system API.
Selects an audio input device. Currently, only one input device can be selected. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters**
| Name | Type | Mandatory| Description |
| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Input device. |
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
**Example**
```js
var audioManager = audio.getAudioManager();
let inputAudioDeviceDescriptor =[{
"deviceRole":audio.DeviceRole.INPUT_DEVICE,
"networkId":audio.LOCAL_NETWORK_ID,
"interruptGroupId":1,
"volumeGroupId":1 }];
var audioRoutingManager;
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value;
audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
console.info('Select input devices result promise: SUCCESS');
}).catch((err) => {
console.error(`Result ERROR: ${err}`);
});
});
}
```
### selectOutputDevice<sup>9+</sup> ### selectOutputDevice<sup>9+</sup>
selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback&lt;void&gt;): void
...@@ -3199,13 +3328,16 @@ Selects an audio output device. Currently, only one output device can be selecte ...@@ -3199,13 +3328,16 @@ Selects an audio output device. Currently, only one output device can be selecte
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
let outputAudioDeviceDescriptor = [{ let outputAudioDeviceDescriptor = [{
"deviceRole":audio.DeviceRole.OUTPUT_DEVICE, "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
"networkId":audio.LOCAL_NETWORK_ID, "networkId":audio.LOCAL_NETWORK_ID,
"interruptGroupId":1, "interruptGroupId":1,
"volumeGroupId":1 }]; "volumeGroupId":1 }];
var audioRoutingManager; var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value; audioRoutingManager = value;
audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => { audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
if (err) { if (err) {
...@@ -3213,7 +3345,8 @@ await audioManager.getRoutingManager().then((value) => { ...@@ -3213,7 +3345,8 @@ await audioManager.getRoutingManager().then((value) => {
} else { } else {
console.info('Select output devices result callback: SUCCESS'); } console.info('Select output devices result callback: SUCCESS'); }
}); });
}); });
}
``` ```
### selectOutputDevice<sup>9+</sup> ### selectOutputDevice<sup>9+</sup>
...@@ -3241,20 +3374,24 @@ Selects an audio output device. Currently, only one output device can be selecte ...@@ -3241,20 +3374,24 @@ Selects an audio output device. Currently, only one output device can be selecte
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
let outputAudioDeviceDescriptor =[{ let outputAudioDeviceDescriptor =[{
"deviceRole":audio.DeviceRole.OUTPUT_DEVICE, "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
"networkId":audio.LOCAL_NETWORK_ID, "networkId":audio.LOCAL_NETWORK_ID,
"interruptGroupId":1, "interruptGroupId":1,
"volumeGroupId":1 }]; "volumeGroupId":1 }];
var audioRoutingManager; var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value; audioRoutingManager = value;
audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => { audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
console.info('Select output devices result promise: SUCCESS'); console.info('Select output devices result promise: SUCCESS');
}).catch((err) => { }).catch((err) => {
console.error(`Result ERROR: ${err}`); console.error(`Result ERROR: ${err}`);
}); });
}); });
}
``` ```
### selectOutputDeviceByFilter<sup>9+</sup> ### selectOutputDeviceByFilter<sup>9+</sup>
...@@ -3277,6 +3414,7 @@ Selects an audio output device based on the filter criteria. Currently, only one ...@@ -3277,6 +3414,7 @@ Selects an audio output device based on the filter criteria. Currently, only one
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
let outputAudioRendererFilter = { let outputAudioRendererFilter = {
"uid":20010041, "uid":20010041,
"rendererInfo": { "rendererInfo": {
...@@ -3290,7 +3428,9 @@ let outputAudioDeviceDescriptor = [{ ...@@ -3290,7 +3428,9 @@ let outputAudioDeviceDescriptor = [{
"interruptGroupId":1, "interruptGroupId":1,
"volumeGroupId":1 }]; "volumeGroupId":1 }];
var audioRoutingManager; var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value; audioRoutingManager = value;
audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => { audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
if (err) { if (err) {
...@@ -3298,7 +3438,8 @@ await audioManager.getRoutingManager().then((value) => { ...@@ -3298,7 +3438,8 @@ await audioManager.getRoutingManager().then((value) => {
} else { } else {
console.info('Select output devices by filter result callback: SUCCESS'); } console.info('Select output devices by filter result callback: SUCCESS'); }
}); });
}); });
}
``` ```
### selectOutputDeviceByFilter<sup>9+</sup> ### selectOutputDeviceByFilter<sup>9+</sup>
...@@ -3327,6 +3468,7 @@ Selects an audio output device based on the filter criteria. Currently, only one ...@@ -3327,6 +3468,7 @@ Selects an audio output device based on the filter criteria. Currently, only one
**Example** **Example**
```js ```js
var audioManager = audio.getAudioManager();
let outputAudioRendererFilter = { let outputAudioRendererFilter = {
"uid":20010041, "uid":20010041,
"rendererInfo": { "rendererInfo": {
...@@ -3340,14 +3482,17 @@ let outputAudioDeviceDescriptor = [{ ...@@ -3340,14 +3482,17 @@ let outputAudioDeviceDescriptor = [{
"interruptGroupId":1, "interruptGroupId":1,
"volumeGroupId":1 }]; "volumeGroupId":1 }];
var audioRoutingManager; var audioRoutingManager;
await audioManager.getRoutingManager().then((value) => {
async function getRoutingManager(){
await audioManager.getRoutingManager().then((value) => {
audioRoutingManager = value; audioRoutingManager = value;
audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => { audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
console.info('Select output devices by filter result promise: SUCCESS'); console.info('Select output devices by filter result promise: SUCCESS');
}).catch((err) => { }).catch((err) => {
console.error(`Result ERROR: ${err}`); console.error(`Result ERROR: ${err}`);
}) })
}); });
}
``` ```
## AudioRendererChangeInfo<sup>9+</sup> ## AudioRendererChangeInfo<sup>9+</sup>
...@@ -3356,12 +3501,12 @@ Describes the audio renderer change event. ...@@ -3356,12 +3501,12 @@ Describes the audio renderer change event.
**System capability**: SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Readable| Writable| Description | | Name | Type | Readable | Writable | Description |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- | | ------------- | ---------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
| streamId | number | Yes | No | Unique ID of an audio stream. | | streamId | number | Yes | No | Unique ID of an audio stream. |
| clientUid | number | Yes | No | UID of the audio renderer client.<br>This is a system API and cannot be called by third-party applications.| | clientUid | number | Yes | No | UID of the audio renderer client.<br>This is a system API and cannot be called by third-party applications. |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | No | Audio renderer information. | | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | No | Audio renderer information. |
| rendererState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API and cannot be called by third-party applications.| | rendererState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API and cannot be called by third-party applications. |
## AudioRendererChangeInfoArray<sup>9+</sup> ## AudioRendererChangeInfoArray<sup>9+</sup>
...@@ -3375,26 +3520,19 @@ Describes the **AudioRenderChangeInfo** array, which is read-only. ...@@ -3375,26 +3520,19 @@ Describes the **AudioRenderChangeInfo** array, which is read-only.
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
var audioStreamManager; var audioStreamManager;
var audioStreamManagerCB;
var resultFlag = false; var resultFlag = false;
var audioManager = audio.getAudioManager();
await audioManager.getStreamManager().then(async function (data) {
audioStreamManager = data;
console.info('Get AudioStream Manager : Success');
}).catch((err) => {
console.error(`Get AudioStream Manager : ERROR : ${err}`);
});
audioManager.getStreamManager((err, data) => { audioManager.getStreamManager((err, data) => {
if (err) { if (err) {
console.error(`Get AudioStream Manager : ERROR : ${err}`); console.error(`Get AudioStream Manager : ERROR : ${err}`);
} else { } else {
audioStreamManagerCB = data; audioStreamManager = data;
console.info('Get AudioStream Manager : Success'); console.info('Get AudioStream Manager : Success');
} }
}); });
audioStreamManagerCB.on('audioRendererChange', (AudioRendererChangeInfoArray) => { audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) { for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
console.info(`## RendererChange on is called for ${i} ##`); console.info(`## RendererChange on is called for ${i} ##`);
console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`); console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
...@@ -3428,12 +3566,12 @@ Describes the audio capturer change event. ...@@ -3428,12 +3566,12 @@ Describes the audio capturer change event.
**System capability**: SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Readable| Writable| Description | | Name | Type | Readable | Writable | Description |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- | | ------------- | ---------------------------------------- | -------- | -------- | ------------------------------------------------------------ |
| streamId | number | Yes | No | Unique ID of an audio stream. | | streamId | number | Yes | No | Unique ID of an audio stream. |
| clientUid | number | Yes | No | UID of the audio capturer client.<br>This is a system API and cannot be called by third-party applications.| | clientUid | number | Yes | No | UID of the audio capturer client.<br>This is a system API and cannot be called by third-party applications. |
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | No | Audio capturer information. | | capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | No | Audio capturer information. |
| capturerState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API and cannot be called by third-party applications.| | capturerState | [AudioState](#audiostate) | Yes | No | Audio state.<br>This is a system API and cannot be called by third-party applications. |
## AudioCapturerChangeInfoArray<sup>9+</sup> ## AudioCapturerChangeInfoArray<sup>9+</sup>
...@@ -3447,6 +3585,16 @@ Describes the **AudioCapturerChangeInfo** array, which is read-only. ...@@ -3447,6 +3585,16 @@ Describes the **AudioCapturerChangeInfo** array, which is read-only.
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
const audioManager = audio.getAudioManager(); const audioManager = audio.getAudioManager();
let audioStreamManager;
audioManager.getStreamManager((err, data) => {
if (err) {
console.error(`getStreamManager : Error: ${err}`);
} else {
console.info('getStreamManager : Success : SUCCESS');
audioStreamManager = data;
}
});
var resultFlag = false; var resultFlag = false;
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => { audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) { for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
...@@ -3481,19 +3629,19 @@ Describes an audio device. ...@@ -3481,19 +3629,19 @@ Describes an audio device.
**System capability**: SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Readable| Writable| Description | | Name | Type | Readable | Writable | Description |
| ----------------------------- | -------------------------- | ---- | ---- | ---------- | | ----------------------------- | ------------------------- | -------- | -------- | ------------------------------------------------------------ |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.| | deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role. |
| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.| | deviceType | [DeviceType](#devicetype) | Yes | No | Device type. |
| id<sup>9+</sup> | number | Yes | No | Device ID. | | id<sup>9+</sup> | number | Yes | No | Device ID. |
| name<sup>9+</sup> | string | Yes | No | Device name.| | name<sup>9+</sup> | string | Yes | No | Device name. |
| address<sup>9+</sup> | string | Yes | No | Device address.| | address<sup>9+</sup> | string | Yes | No | Device address. |
| sampleRates<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported sampling rates.| | sampleRates<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported sampling rates. |
| channelCounts<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Number of channels supported.| | channelCounts<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Number of channels supported. |
| channelMasks<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported channel masks.| | channelMasks<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported channel masks. |
| networkId<sup>9+</sup> | string | Yes | No | ID of the device network.<br>This is a system API and cannot be called by third-party applications.| | networkId<sup>9+</sup> | string | Yes | No | ID of the device network.<br>This is a system API and cannot be called by third-party applications. |
| interruptGroupId<sup>9+</sup> | number | Yes | No | ID of the interruption group to which the device belongs.<br>This is a system API and cannot be called by third-party applications.| | interruptGroupId<sup>9+</sup> | number | Yes | No | ID of the interruption group to which the device belongs.<br>This is a system API and cannot be called by third-party applications. |
| volumeGroupId<sup>9+</sup> | number | Yes | No | ID of the volume group to which the device belongs.<br>This is a system API and cannot be called by third-party applications.| | volumeGroupId<sup>9+</sup> | number | Yes | No | ID of the volume group to which the device belongs.<br>This is a system API and cannot be called by third-party applications. |
## AudioDeviceDescriptors ## AudioDeviceDescriptors
...@@ -3529,13 +3677,11 @@ Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you m ...@@ -3529,13 +3677,11 @@ Implements filter criteria. Before calling **selectOutputDeviceByFilter**, you m
**System API**: This is a system API. **System API**: This is a system API.
**System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------| ---------------------------------------- | ---- | -------------- | | ------------ | ---------------------------------------- | --------- | ------------------------------------------------------------ |
| uid | number | Yes | Application ID.<br> System capability: SystemCapability.Multimedia.Audio.Core| | uid | number | Yes | Application ID.<br>**System capability**: SystemCapability.Multimedia.Audio.Core |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No | Audio renderer information.<br> System capability: SystemCapability.Multimedia.Audio.Renderer| | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | No | Audio renderer information.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
| rendererId | number | No | Unique ID of an audio stream.<br> System capability: SystemCapability.Multimedia.Audio.Renderer| | rendererId | number | No | Unique ID of an audio stream.<br>**System capability**: SystemCapability.Multimedia.Audio.Renderer |
**Example** **Example**
...@@ -3557,9 +3703,9 @@ Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, ...@@ -3557,9 +3703,9 @@ Provides APIs for audio rendering. Before calling any API in **AudioRenderer**,
**System capability**: SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Readable| Writable| Description | | Name | Type | Readable | Writable | Description |
| ----- | -------------------------- | ---- | ---- | ------------------ | | ------------------ | -------------------------- | -------- | -------- | --------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio renderer state.| | state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio renderer state. |
**Example** **Example**
...@@ -3577,9 +3723,9 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us ...@@ -3577,9 +3723,9 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------------------------------------------- | :--- | :--------------------- | | :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information.| | callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information. |
**Example** **Example**
...@@ -3603,8 +3749,8 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us ...@@ -3603,8 +3749,8 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------------------------------------- | ------------------------------- | | -------------------------------------------------- | ------------------------------------------------ |
| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.| | Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information. |
**Example** **Example**
...@@ -3629,9 +3775,9 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses ...@@ -3629,9 +3775,9 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :--------------------------------------------------- | :--- | :------------------- | | :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.| | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. |
**Example** **Example**
...@@ -3656,8 +3802,8 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses ...@@ -3656,8 +3802,8 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------------------------------------- | :--------------------- | | :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.| | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
**Example** **Example**
...@@ -3671,6 +3817,7 @@ audioRenderer.getStreamInfo().then((streamInfo) => { ...@@ -3671,6 +3817,7 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -3683,9 +3830,9 @@ Starts the renderer. This API uses an asynchronous callback to return the result ...@@ -3683,9 +3830,9 @@ Starts the renderer. This API uses an asynchronous callback to return the result
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------- | | -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -3697,6 +3844,7 @@ audioRenderer.start((err) => { ...@@ -3697,6 +3844,7 @@ audioRenderer.start((err) => {
console.info('Renderer start success.'); console.info('Renderer start success.');
} }
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -3710,8 +3858,8 @@ Starts the renderer. This API uses a promise to return the result. ...@@ -3710,8 +3858,8 @@ Starts the renderer. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -3721,6 +3869,7 @@ audioRenderer.start().then(() => { ...@@ -3721,6 +3869,7 @@ audioRenderer.start().then(() => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
...@@ -3733,9 +3882,9 @@ Pauses rendering. This API uses an asynchronous callback to return the result. ...@@ -3733,9 +3882,9 @@ Pauses rendering. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------- | | -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -3747,6 +3896,7 @@ audioRenderer.pause((err) => { ...@@ -3747,6 +3896,7 @@ audioRenderer.pause((err) => {
console.info('Renderer paused.'); console.info('Renderer paused.');
} }
}); });
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
...@@ -3760,8 +3910,8 @@ Pauses rendering. This API uses a promise to return the result. ...@@ -3760,8 +3910,8 @@ Pauses rendering. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -3771,6 +3921,7 @@ audioRenderer.pause().then(() => { ...@@ -3771,6 +3921,7 @@ audioRenderer.pause().then(() => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### drain<sup>8+</sup> ### drain<sup>8+</sup>
...@@ -3783,9 +3934,9 @@ Drains the playback buffer. This API uses an asynchronous callback to return the ...@@ -3783,9 +3934,9 @@ Drains the playback buffer. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------- | | -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -3797,6 +3948,7 @@ audioRenderer.drain((err) => { ...@@ -3797,6 +3948,7 @@ audioRenderer.drain((err) => {
console.info('Renderer drained.'); console.info('Renderer drained.');
} }
}); });
``` ```
### drain<sup>8+</sup> ### drain<sup>8+</sup>
...@@ -3810,8 +3962,8 @@ Drains the playback buffer. This API uses a promise to return the result. ...@@ -3810,8 +3962,8 @@ Drains the playback buffer. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -3821,6 +3973,7 @@ audioRenderer.drain().then(() => { ...@@ -3821,6 +3973,7 @@ audioRenderer.drain().then(() => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
...@@ -3833,9 +3986,9 @@ Stops rendering. This API uses an asynchronous callback to return the result. ...@@ -3833,9 +3986,9 @@ Stops rendering. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------- | | -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -3847,6 +4000,7 @@ audioRenderer.stop((err) => { ...@@ -3847,6 +4000,7 @@ audioRenderer.stop((err) => {
console.info('Renderer stopped.'); console.info('Renderer stopped.');
} }
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
...@@ -3860,8 +4014,8 @@ Stops rendering. This API uses a promise to return the result. ...@@ -3860,8 +4014,8 @@ Stops rendering. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -3871,6 +4025,7 @@ audioRenderer.stop().then(() => { ...@@ -3871,6 +4025,7 @@ audioRenderer.stop().then(() => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
...@@ -3883,9 +4038,9 @@ Releases the renderer. This API uses an asynchronous callback to return the resu ...@@ -3883,9 +4038,9 @@ Releases the renderer. This API uses an asynchronous callback to return the resu
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------- | | -------- | -------------------- | --------- | ----------------------------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -3897,6 +4052,7 @@ audioRenderer.release((err) => { ...@@ -3897,6 +4052,7 @@ audioRenderer.release((err) => {
console.info('Renderer released.'); console.info('Renderer released.');
} }
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
...@@ -3910,8 +4066,8 @@ Releases the renderer. This API uses a promise to return the result. ...@@ -3910,8 +4066,8 @@ Releases the renderer. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -3921,6 +4077,7 @@ audioRenderer.release().then(() => { ...@@ -3921,6 +4077,7 @@ audioRenderer.release().then(() => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### write<sup>8+</sup> ### write<sup>8+</sup>
...@@ -3933,52 +4090,27 @@ Writes the buffer. This API uses an asynchronous callback to return the result. ...@@ -3933,52 +4090,27 @@ Writes the buffer. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | --------------------------------------------------- | | -------- | ---------------------- | --------- | ------------------------------------------------------------ |
| buffer | ArrayBuffer | Yes | Buffer to be written. | | buffer | ArrayBuffer | Yes | Buffer to be written. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned.| | callback | AsyncCallback\<number> | Yes | Callback used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
**Example** **Example**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility'
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data)=> {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.error(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err}`);
});
var bufferSize; var bufferSize;
audioRenderer.getBufferSize().then((data)=> { audioRenderer.getBufferSize().then((data)=> {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
bufferSize = data; bufferSize = data;
}).catch((err) => { }).catch((err) => {
console.error.(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
}); });
console.info(`Buffer size: ${bufferSize}`); console.info(`Buffer size: ${bufferSize}`);
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var path = await context.getCacheDir(); var path;
async function getCacheDir(){
path = await context.getCacheDir();
}
var filePath = path + '/StarWars10s-2C-48000-4SW.wav'; var filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r'); let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize); let buf = new ArrayBuffer(bufferSize);
...@@ -3990,6 +4122,7 @@ audioRenderer.write(buf, (err, writtenbytes) => { ...@@ -3990,6 +4122,7 @@ audioRenderer.write(buf, (err, writtenbytes) => {
console.info(`Actual written bytes: ${writtenbytes}`); console.info(`Actual written bytes: ${writtenbytes}`);
} }
}); });
``` ```
### write<sup>8+</sup> ### write<sup>8+</sup>
...@@ -4004,39 +4137,11 @@ Writes the buffer. This API uses a promise to return the result. ...@@ -4004,39 +4137,11 @@ Writes the buffer. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ---------------- | ------------------------------------------------------------ | | ---------------- | ------------------------------------------------------------ |
| Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned.| | Promise\<number> | Promise used to return the result. If the operation is successful, the number of bytes written is returned; otherwise, an error code is returned. |
**Example** **Example**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility'
var audioStreamInfo = {
samplingRate:audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels:audio.AudioChannel.CHANNEL_2,
sampleFormat:audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
encodingType:audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.error(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err}`);
});
var bufferSize; var bufferSize;
audioRenderer.getBufferSize().then((data) => { audioRenderer.getBufferSize().then((data) => {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
...@@ -4046,8 +4151,11 @@ audioRenderer.getBufferSize().then((data) => { ...@@ -4046,8 +4151,11 @@ audioRenderer.getBufferSize().then((data) => {
}); });
console.info(`BufferSize: ${bufferSize}`); console.info(`BufferSize: ${bufferSize}`);
var context = featureAbility.getContext(); var context = featureAbility.getContext();
var path = await context.getCacheDir(); var path;
var filePath = 'data/StarWars10s-2C-48000-4SW.wav'; async function getCacheDir(){
path = await context.getCacheDir();
}
var filePath = path + '/StarWars10s-2C-48000-4SW.wav';
let ss = fileio.createStreamSync(filePath, 'r'); let ss = fileio.createStreamSync(filePath, 'r');
let buf = new ArrayBuffer(bufferSize); let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf); ss.readSync(buf);
...@@ -4060,6 +4168,7 @@ audioRenderer.write(buf).then((writtenbytes) => { ...@@ -4060,6 +4168,7 @@ audioRenderer.write(buf).then((writtenbytes) => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### getAudioTime<sup>8+</sup> ### getAudioTime<sup>8+</sup>
...@@ -4072,9 +4181,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4072,9 +4181,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------- | | -------- | ---------------------- | --------- | -------------------------------------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp.| | callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp. |
**Example** **Example**
...@@ -4082,6 +4191,7 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4082,6 +4191,7 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
audioRenderer.getAudioTime((err, timestamp) => { audioRenderer.getAudioTime((err, timestamp) => {
console.info(`Current timestamp: ${timestamp}`); console.info(`Current timestamp: ${timestamp}`);
}); });
``` ```
### getAudioTime<sup>8+</sup> ### getAudioTime<sup>8+</sup>
...@@ -4095,8 +4205,8 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4095,8 +4205,8 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | ----------------------- | | ---------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the timestamp.| | Promise\<number> | Promise used to return the timestamp. |
**Example** **Example**
...@@ -4106,6 +4216,7 @@ audioRenderer.getAudioTime().then((timestamp) => { ...@@ -4106,6 +4216,7 @@ audioRenderer.getAudioTime().then((timestamp) => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
...@@ -4118,9 +4229,9 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -4118,9 +4229,9 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | -------------------- | | -------- | ---------------------- | --------- | ---------------------------------------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size.| | callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size. |
**Example** **Example**
...@@ -4130,6 +4241,7 @@ var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => { ...@@ -4130,6 +4241,7 @@ var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
console.error('getBufferSize error'); console.error('getBufferSize error');
} }
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
...@@ -4143,39 +4255,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -4143,39 +4255,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------- | --------------------------- | | ---------------- | --------------------------------------- |
| Promise\<number> | Promise used to return the buffer size.| | Promise\<number> | Promise used to return the buffer size. |
**Example** **Example**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S32LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ${err}`);
});
var bufferSize; var bufferSize;
audioRenderer.getBufferSize().then((data) => { audioRenderer.getBufferSize().then((data) => {
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`); console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
...@@ -4183,6 +4268,7 @@ audioRenderer.getBufferSize().then((data) => { ...@@ -4183,6 +4268,7 @@ audioRenderer.getBufferSize().then((data) => {
}).catch((err) => { }).catch((err) => {
console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`); console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
}); });
``` ```
### setRenderRate<sup>8+</sup> ### setRenderRate<sup>8+</sup>
...@@ -4195,10 +4281,10 @@ Sets the render rate. This API uses an asynchronous callback to return the resul ...@@ -4195,10 +4281,10 @@ Sets the render rate. This API uses an asynchronous callback to return the resul
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------ | | -------- | ---------------------------------------- | --------- | ----------------------------------- |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -4210,6 +4296,7 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => ...@@ -4210,6 +4296,7 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
console.info('Callback invoked to indicate a successful render rate setting.'); console.info('Callback invoked to indicate a successful render rate setting.');
} }
}); });
``` ```
### setRenderRate<sup>8+</sup> ### setRenderRate<sup>8+</sup>
...@@ -4222,15 +4309,15 @@ Sets the render rate. This API uses a promise to return the result. ...@@ -4222,15 +4309,15 @@ Sets the render rate. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| ------ | ---------------------------------------- | ---- | ------------ | | ---- | ---------------------------------------- | --------- | ------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate.| | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------- | ------------------------- | | -------------- | ---------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void> | Promise used to return the result. |
**Example** **Example**
...@@ -4240,6 +4327,7 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() ...@@ -4240,6 +4327,7 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(()
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### getRenderRate<sup>8+</sup> ### getRenderRate<sup>8+</sup>
...@@ -4252,9 +4340,9 @@ Obtains the current render rate. This API uses an asynchronous callback to retur ...@@ -4252,9 +4340,9 @@ Obtains the current render rate. This API uses an asynchronous callback to retur
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------------------------------- | ---- | ------------------ | | -------- | ------------------------------------------------------- | --------- | ---------------------------------------------- |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate.| | callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate. |
**Example** **Example**
...@@ -4262,6 +4350,7 @@ Obtains the current render rate. This API uses an asynchronous callback to retur ...@@ -4262,6 +4350,7 @@ Obtains the current render rate. This API uses an asynchronous callback to retur
audioRenderer.getRenderRate((err, renderrate) => { audioRenderer.getRenderRate((err, renderrate) => {
console.info(`getRenderRate: ${renderrate}`); console.info(`getRenderRate: ${renderrate}`);
}); });
``` ```
### getRenderRate<sup>8+</sup> ### getRenderRate<sup>8+</sup>
...@@ -4275,8 +4364,8 @@ Obtains the current render rate. This API uses a promise to return the result. ...@@ -4275,8 +4364,8 @@ Obtains the current render rate. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------------------- | ------------------------- | | ------------------------------------------------- | --------------------------------------------- |
| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.| | Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate. |
**Example** **Example**
...@@ -4286,7 +4375,9 @@ audioRenderer.getRenderRate().then((renderRate) => { ...@@ -4286,7 +4375,9 @@ audioRenderer.getRenderRate().then((renderRate) => {
}).catch((err) => { }).catch((err) => {
console.error(`ERROR: ${err}`); console.error(`ERROR: ${err}`);
}); });
``` ```
### setInterruptMode<sup>9+</sup> ### setInterruptMode<sup>9+</sup>
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt; setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
...@@ -4298,41 +4389,27 @@ Sets the audio interruption mode for the application. This API uses a promise to ...@@ -4298,41 +4389,27 @@ Sets the audio interruption mode for the application. This API uses a promise to
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---------- | ---------------------------------- | ------ | ---------- | | ---- | -------------------------------- | --------- | ------------------------ |
| mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. | | mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------- | | ------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned.| | Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, **undefined** is returned. Otherwise, **error** is returned. |
**Example** **Example**
```js ```js
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_MUSIC,
usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
let audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
let mode = 0; let mode = 0;
audioRenderer.setInterruptMode(mode).then(data=>{ audioRenderer.setInterruptMode(mode).then(data=>{
console.info('setInterruptMode Success!'); console.info('setInterruptMode Success!');
}).catch((err) => { }).catch((err) => {
console.error(`setInterruptMode Fail: ${err}`); console.error(`setInterruptMode Fail: ${err}`);
}); });
``` ```
### setInterruptMode<sup>9+</sup> ### setInterruptMode<sup>9+</sup>
setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void setInterruptMode(mode: InterruptMode, callback: AsyncCallback\<void>): void
...@@ -4344,29 +4421,13 @@ Sets the audio interruption mode for the application. This API uses a callback t ...@@ -4344,29 +4421,13 @@ Sets the audio interruption mode for the application. This API uses a callback t
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------------------------------- | ------ | -------------- | | -------- | -------------------------------- | --------- | ----------------------------------- |
|mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode.| | mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. |
|callback | AsyncCallback\<void> | Yes |Callback used to return the result.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example** **Example**
```js ```js
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_48000,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_MUSIC,
usage: audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags: 0
}
var audioRendererOptions = {
streamInfo: audioStreamInfo,
rendererInfo: audioRendererInfo
}
let audioRenderer = await audio.createAudioRenderer(audioRendererOptions);
let mode = 1; let mode = 1;
audioRenderer.setInterruptMode(mode, (err, data)=>{ audioRenderer.setInterruptMode(mode, (err, data)=>{
if(err){ if(err){
...@@ -4374,7 +4435,9 @@ audioRenderer.setInterruptMode(mode, (err, data)=>{ ...@@ -4374,7 +4435,9 @@ audioRenderer.setInterruptMode(mode, (err, data)=>{
} }
console.info('setInterruptMode Success!'); console.info('setInterruptMode Success!');
}); });
``` ```
### on('interrupt')<sup>9+</sup> ### on('interrupt')<sup>9+</sup>
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
...@@ -4385,9 +4448,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru ...@@ -4385,9 +4448,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------------- | --------- | ------------------------------------------------------------ |
| type | string | Yes | Event type. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.| | type | string | Yes | Event type. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted. |
| callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. | | callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. |
**Example** **Example**
...@@ -4438,11 +4501,12 @@ audioRenderer.on('interrupt', async(interruptEvent) => { ...@@ -4438,11 +4501,12 @@ audioRenderer.on('interrupt', async(interruptEvent) => {
} }
} }
}); });
``` ```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: "markReach", frame: number, callback: Callback<number>): void on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
...@@ -4450,9 +4514,9 @@ Subscribes to mark reached events. When the number of frames rendered reaches th ...@@ -4450,9 +4514,9 @@ Subscribes to mark reached events. When the number of frames rendered reaches th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :----------------------- | :--- | :---------------------------------------- | | :------- | :--------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.| | type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback<number> | Yes | Callback invoked when the event is triggered. | | callback | Callback<number> | Yes | Callback invoked when the event is triggered. |
...@@ -4464,6 +4528,7 @@ audioRenderer.on('markReach', 1000, (position) => { ...@@ -4464,6 +4528,7 @@ audioRenderer.on('markReach', 1000, (position) => {
console.info('ON Triggered successfully'); console.info('ON Triggered successfully');
} }
}); });
``` ```
...@@ -4477,19 +4542,20 @@ Unsubscribes from mark reached events. ...@@ -4477,19 +4542,20 @@ Unsubscribes from mark reached events.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :----- | :----- | :--- | :------------------------------------------------ | | :--- | :----- | :-------- | :----------------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **markReach**.| | type | string | Yes | Event type. The value is fixed at **markReach**. |
**Example** **Example**
```js ```js
audioRenderer.off('markReach'); audioRenderer.off('markReach');
``` ```
### on('periodReach') <sup>8+</sup> ### on('periodReach') <sup>8+</sup>
on(type: "periodReach", frame: number, callback: Callback<number>): void on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked. Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
...@@ -4497,9 +4563,9 @@ Subscribes to period reached events. When the period of frame rendering reaches ...@@ -4497,9 +4563,9 @@ Subscribes to period reached events. When the period of frame rendering reaches
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :----------------------- | :--- | :------------------------------------------ | | :------- | :--------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.| | type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback<number> | Yes | Callback invoked when the event is triggered. | | callback | Callback<number> | Yes | Callback invoked when the event is triggered. |
...@@ -4511,6 +4577,7 @@ audioRenderer.on('periodReach', 1000, (position) => { ...@@ -4511,6 +4577,7 @@ audioRenderer.on('periodReach', 1000, (position) => {
console.info('ON Triggered successfully'); console.info('ON Triggered successfully');
} }
}); });
``` ```
### off('periodReach') <sup>8+</sup> ### off('periodReach') <sup>8+</sup>
...@@ -4523,14 +4590,15 @@ Unsubscribes from period reached events. ...@@ -4523,14 +4590,15 @@ Unsubscribes from period reached events.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :----- | :----- | :--- | :-------------------------------------------------- | | :--- | :----- | :-------- | :------------------------------------------------- |
| type | string | Yes | Event type. The value is fixed at **periodReach**.| | type | string | Yes | Event type. The value is fixed at **periodReach**. |
**Example** **Example**
```js ```js
audioRenderer.off('periodReach') audioRenderer.off('periodReach')
``` ```
### on('stateChange')<sup>8+</sup> ### on('stateChange')<sup>8+</sup>
...@@ -4543,9 +4611,9 @@ Subscribes to state change events. ...@@ -4543,9 +4611,9 @@ Subscribes to state change events.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------------- | :--- | :------------------------------------------ | | :------- | :------------------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **stateChange** means the state change event.| | type | string | Yes | Event type. The value **stateChange** means the state change event. |
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example** **Example**
...@@ -4559,6 +4627,7 @@ audioRenderer.on('stateChange', (state) => { ...@@ -4559,6 +4627,7 @@ audioRenderer.on('stateChange', (state) => {
console.info('audio renderer state is: STATE_RUNNING'); console.info('audio renderer state is: STATE_RUNNING');
} }
}); });
``` ```
## AudioCapturer<sup>8+</sup> ## AudioCapturer<sup>8+</sup>
...@@ -4569,14 +4638,15 @@ Provides APIs for audio capture. Before calling any API in **AudioCapturer**, yo ...@@ -4569,14 +4638,15 @@ Provides APIs for audio capture. Before calling any API in **AudioCapturer**, yo
**System capability**: SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Readable| Writable| Description | | Name | Type | Readable | Writable | Description |
| :---- | :------------------------- | :--- | :--- | :--------------- | | :----------------- | :------------------------- | :------- | :------- | :-------------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes| No | Audio capturer state.| | state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio capturer state. |
**Example** **Example**
```js ```js
var state = audioCapturer.state; var state = audioCapturer.state;
``` ```
### getCapturerInfo<sup>8+</sup> ### getCapturerInfo<sup>8+</sup>
...@@ -4589,9 +4659,9 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us ...@@ -4589,9 +4659,9 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :-------------------------------- | :--- | :----------------------------------- | | :------- | :-------------------------------- | :-------- | :------------------------------------------------ |
| callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information.| | callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information. |
**Example** **Example**
...@@ -4605,6 +4675,7 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => { ...@@ -4605,6 +4675,7 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
console.info(`Capturer flags: ${capturerInfo.capturerFlags}`); console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
} }
}); });
``` ```
...@@ -4619,8 +4690,8 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us ...@@ -4619,8 +4690,8 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------------------------------------------ | :---------------------------------- | | :------------------------------------------------ | :----------------------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.| | Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. |
**Example** **Example**
...@@ -4637,6 +4708,7 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => { ...@@ -4637,6 +4708,7 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`); console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
...@@ -4649,9 +4721,9 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses ...@@ -4649,9 +4721,9 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :--------------------------------------------------- | :--- | :------------------------------- | | :------- | :--------------------------------------------------- | :-------- | :---------------------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.| | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. |
**Example** **Example**
...@@ -4667,6 +4739,7 @@ audioCapturer.getStreamInfo((err, streamInfo) => { ...@@ -4667,6 +4739,7 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
console.info(`Capturer encoding type: ${streamInfo.encodingType}`); console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
} }
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
...@@ -4680,8 +4753,8 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses ...@@ -4680,8 +4753,8 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------------------------------------- | :------------------------------ | | :--------------------------------------------- | :--------------------------------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.| | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. |
**Example** **Example**
...@@ -4695,6 +4768,7 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => { ...@@ -4695,6 +4768,7 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.error(`getStreamInfo :ERROR: ${err}`); console.error(`getStreamInfo :ERROR: ${err}`);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -4707,9 +4781,9 @@ Starts capturing. This API uses an asynchronous callback to return the result. ...@@ -4707,9 +4781,9 @@ Starts capturing. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------- | :--- | :----------------------------- | | :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -4721,6 +4795,7 @@ audioCapturer.start((err) => { ...@@ -4721,6 +4795,7 @@ audioCapturer.start((err) => {
console.info('Capturer start success.'); console.info('Capturer start success.');
} }
}); });
``` ```
...@@ -4735,34 +4810,12 @@ Starts capturing. This API uses a promise to return the result. ...@@ -4735,34 +4810,12 @@ Starts capturing. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------- | | :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result.| | Promise<void\> | Promise used to return the result. |
**Example** **Example**
```js ```js
import audio from '@ohos.multimedia.audio';
import fileio from '@ohos.fileio';
var audioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_2,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioCapturerInfo = {
source: audio.SourceType.SOURCE_TYPE_MIC,
capturerFlags: 0
}
var audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
audioCapturer = data;
console.info('AudioFrameworkRecLog: AudioCapturer Created: SUCCESS');
}).catch((err) => {
console.info(`AudioFrameworkRecLog: AudioCapturer Created: ERROR: ${err}`);
});
audioCapturer.start().then(() => { audioCapturer.start().then(() => {
console.info('AudioFrameworkRecLog: ---------START---------'); console.info('AudioFrameworkRecLog: ---------START---------');
console.info('AudioFrameworkRecLog: Capturer started: SUCCESS'); console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
...@@ -4774,6 +4827,7 @@ audioCapturer.start().then(() => { ...@@ -4774,6 +4827,7 @@ audioCapturer.start().then(() => {
}).catch((err) => { }).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`); console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
...@@ -4786,9 +4840,9 @@ Stops capturing. This API uses an asynchronous callback to return the result. ...@@ -4786,9 +4840,9 @@ Stops capturing. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------- | :--- | :----------------------------- | | :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result.| | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -4800,6 +4854,7 @@ audioCapturer.stop((err) => { ...@@ -4800,6 +4854,7 @@ audioCapturer.stop((err) => {
console.info('Capturer stopped.'); console.info('Capturer stopped.');
} }
}); });
``` ```
...@@ -4814,8 +4869,8 @@ Stops capturing. This API uses a promise to return the result. ...@@ -4814,8 +4869,8 @@ Stops capturing. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------- | | :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result.| | Promise<void\> | Promise used to return the result. |
**Example** **Example**
...@@ -4829,6 +4884,7 @@ audioCapturer.stop().then(() => { ...@@ -4829,6 +4884,7 @@ audioCapturer.stop().then(() => {
}).catch((err) => { }).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`); console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
...@@ -4841,8 +4897,8 @@ Releases this **AudioCapturer** instance. This API uses an asynchronous callback ...@@ -4841,8 +4897,8 @@ Releases this **AudioCapturer** instance. This API uses an asynchronous callback
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------- | :--- | :---------------------------------- | | :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -4855,6 +4911,7 @@ audioCapturer.release((err) => { ...@@ -4855,6 +4911,7 @@ audioCapturer.release((err) => {
console.info('capturer released.'); console.info('capturer released.');
} }
}); });
``` ```
...@@ -4869,8 +4926,8 @@ Releases this **AudioCapturer** instance. This API uses a promise to return the ...@@ -4869,8 +4926,8 @@ Releases this **AudioCapturer** instance. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------- | | :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result.| | Promise<void\> | Promise used to return the result. |
**Example** **Example**
...@@ -4884,6 +4941,7 @@ audioCapturer.release().then(() => { ...@@ -4884,6 +4941,7 @@ audioCapturer.release().then(() => {
}).catch((err) => { }).catch((err) => {
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`); console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
}); });
``` ```
...@@ -4897,11 +4955,11 @@ Reads the buffer. This API uses an asynchronous callback to return the result. ...@@ -4897,11 +4955,11 @@ Reads the buffer. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------------- | :-------------------------- | :--- | :------------------------------- | | :------------- | :-------------------------- | :-------- | :----------------------------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether to block the read operation. | | isBlockingRead | boolean | Yes | Whether to block the read operation. |
| callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer.| | callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer. |
**Example** **Example**
...@@ -4918,6 +4976,7 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ...@@ -4918,6 +4976,7 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
console.info('Success in reading the buffer data'); console.info('Success in reading the buffer data');
} }
}); });
``` ```
...@@ -4931,16 +4990,16 @@ Reads the buffer. This API uses a promise to return the result. ...@@ -4931,16 +4990,16 @@ Reads the buffer. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------------- | :------ | :--- | :--------------- | | :------------- | :------ | :-------- | :----------------------------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether to block the read operation.| | isBlockingRead | boolean | Yes | Whether to block the read operation. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :-------------------- | :----------------------------------------------------- | | :-------------------- | :----------------------------------------------------------- |
| Promise<ArrayBuffer\> | Promise used to return the result. If the operation is successful, the buffer data read is returned; otherwise, an error code is returned.| | Promise<ArrayBuffer\> | Promise used to return the result. If the operation is successful, the buffer data read is returned; otherwise, an error code is returned. |
**Example** **Example**
...@@ -4958,6 +5017,7 @@ audioCapturer.read(bufferSize, true).then((buffer) => { ...@@ -4958,6 +5017,7 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
}).catch((err) => { }).catch((err) => {
console.info(`ERROR : ${err}`); console.info(`ERROR : ${err}`);
}); });
``` ```
...@@ -4971,9 +5031,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4971,9 +5031,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :--------------------- | :--- | :----------------------------- | | :------- | :--------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the result.| | callback | AsyncCallback<number\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -4981,6 +5041,7 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4981,6 +5041,7 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
audioCapturer.getAudioTime((err, timestamp) => { audioCapturer.getAudioTime((err, timestamp) => {
console.info(`Current timestamp: ${timestamp}`); console.info(`Current timestamp: ${timestamp}`);
}); });
``` ```
...@@ -4995,8 +5056,8 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). ...@@ -4995,8 +5056,8 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :---------------------------- | | :--------------- | :------------------------------------ |
| Promise<number\> | Promise used to return the timestamp.| | Promise<number\> | Promise used to return the timestamp. |
**Example** **Example**
...@@ -5006,6 +5067,7 @@ audioCapturer.getAudioTime().then((audioTime) => { ...@@ -5006,6 +5067,7 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => { }).catch((err) => {
console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`); console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
}); });
``` ```
...@@ -5019,9 +5081,9 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a ...@@ -5019,9 +5081,9 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :--------------------- | :--- | :----------------------------------- | | :------- | :--------------------- | :-------- | :--------------------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size.| | callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. |
**Example** **Example**
...@@ -5036,6 +5098,7 @@ audioCapturer.getBufferSize((err, bufferSize) => { ...@@ -5036,6 +5098,7 @@ audioCapturer.getBufferSize((err, bufferSize) => {
}); });
} }
}); });
``` ```
...@@ -5050,8 +5113,8 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a ...@@ -5050,8 +5113,8 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :---------------------------------- | | :--------------- | :-------------------------------------- |
| Promise<number\> | Promise used to return the buffer size.| | Promise<number\> | Promise used to return the buffer size. |
**Example** **Example**
...@@ -5063,12 +5126,13 @@ audioCapturer.getBufferSize().then((data) => { ...@@ -5063,12 +5126,13 @@ audioCapturer.getBufferSize().then((data) => {
}).catch((err) => { }).catch((err) => {
console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`); console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
}); });
``` ```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: "markReach", frame: number, callback: Callback<number>): void on(type: "markReach", frame: number, callback: Callback&lt;number&gt;): void
Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
...@@ -5076,11 +5140,11 @@ Subscribes to mark reached events. When the number of frames captured reaches th ...@@ -5076,11 +5140,11 @@ Subscribes to mark reached events. When the number of frames captured reaches th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :---------------------- | :--- | :----------------------------------------- | | :------- | :--------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. | | type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback<number> | Yes | Callback invoked when the event is triggered.| | callback | Callback<number> | Yes | Callback invoked when the event is triggered. |
**Example** **Example**
...@@ -5090,6 +5154,7 @@ audioCapturer.on('markReach', 1000, (position) => { ...@@ -5090,6 +5154,7 @@ audioCapturer.on('markReach', 1000, (position) => {
console.info('ON Triggered successfully'); console.info('ON Triggered successfully');
} }
}); });
``` ```
### off('markReach')<sup>8+</sup> ### off('markReach')<sup>8+</sup>
...@@ -5102,19 +5167,20 @@ Unsubscribes from mark reached events. ...@@ -5102,19 +5167,20 @@ Unsubscribes from mark reached events.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :----- | :----- | :--- | :-------------------------------------------- | | :--- | :----- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.| | type | string | Yes | Event type. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
**Example** **Example**
```js ```js
audioCapturer.off('markReach'); audioCapturer.off('markReach');
``` ```
### on('periodReach')<sup>8+</sup> ### on('periodReach')<sup>8+</sup>
on(type: "periodReach", frame: number, callback: Callback<number>): void on(type: "periodReach", frame: number, callback: Callback&lt;number&gt;): void
Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked. Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
...@@ -5122,9 +5188,9 @@ Subscribes to mark reached events. When the period of frame capturing reaches th ...@@ -5122,9 +5188,9 @@ Subscribes to mark reached events. When the period of frame capturing reaches th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :----------------------- | :--- | :------------------------------------------ | | :------- | :--------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.| | type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | Callback<number> | Yes | Callback invoked when the event is triggered. | | callback | Callback<number> | Yes | Callback invoked when the event is triggered. |
...@@ -5136,6 +5202,7 @@ audioCapturer.on('periodReach', 1000, (position) => { ...@@ -5136,6 +5202,7 @@ audioCapturer.on('periodReach', 1000, (position) => {
console.info('ON Triggered successfully'); console.info('ON Triggered successfully');
} }
}); });
``` ```
### off('periodReach')<sup>8+</sup> ### off('periodReach')<sup>8+</sup>
...@@ -5148,14 +5215,15 @@ Unsubscribes from period reached events. ...@@ -5148,14 +5215,15 @@ Unsubscribes from period reached events.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :----- | :----- | :--- | :---------------------------------------------- | | :--- | :----- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.| | type | string | Yes | Event type. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter. |
**Example** **Example**
```js ```js
audioCapturer.off('periodReach') audioCapturer.off('periodReach')
``` ```
### on('stateChange')<sup>8+</sup> ### on('stateChange')<sup>8+</sup>
...@@ -5168,9 +5236,9 @@ Subscribes to state change events. ...@@ -5168,9 +5236,9 @@ Subscribes to state change events.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory | Description |
| :------- | :------------------------- | :--- | :------------------------------------------ | | :------- | :------------------------- | :-------- | :----------------------------------------------------------- |
| type | string | Yes | Event type. The value **stateChange** means the state change event.| | type | string | Yes | Event type. The value **stateChange** means the state change event. |
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example** **Example**
...@@ -5184,4 +5252,262 @@ audioCapturer.on('stateChange', (state) => { ...@@ -5184,4 +5252,262 @@ audioCapturer.on('stateChange', (state) => {
console.info('audio capturer state is: STATE_RUNNING'); console.info('audio capturer state is: STATE_RUNNING');
} }
}); });
```
## ToneType <sup>9+</sup>
Enumerates the tone types of the player.
**System capability**: SystemCapability.Multimedia.Audio.Tone
| Name | Default Value | Description |
| :----------------------------------------------- | :------------ | :------------------------------------------- |
| TONE_TYPE_DIAL_0 | 0 | DTMF tone of key 0. |
| TONE_TYPE_DIAL_1 | 1 | DTMF tone of key 1. |
| TONE_TYPE_DIAL_2 | 2 | DTMF tone of key 2. |
| TONE_TYPE_DIAL_3 | 3 | DTMF tone of key 3. |
| TONE_TYPE_DIAL_4 | 4 | DTMF tone of key 4. |
| TONE_TYPE_DIAL_5 | 5 | DTMF tone of key 5. |
| TONE_TYPE_DIAL_6 | 6 | DTMF tone of key 6. |
| TONE_TYPE_DIAL_7 | 7 | DTMF tone of key 7. |
| TONE_TYPE_DIAL_8 | 8 | DTMF tone of key 8. |
| TONE_TYPE_DIAL_9 | 9 | DTMF tone of key 9. |
| TONE_TYPE_DIAL_S | 10 | DTMF tone of the star key (*). |
| TONE_TYPE_DIAL_P | 11 | DTMF tone of the pound key (#). |
| TONE_TYPE_DIAL_A | 12 | DTMF tone of key A. |
| TONE_TYPE_DIAL_B | 13 | DTMF tone of key B. |
| TONE_TYPE_DIAL_C | 14 | DTMF tone of key C. |
| TONE_TYPE_DIAL_D | 15 | DTMF tone of key D. |
| TONE_TYPE_COMMON_SUPERVISORY_DIAL | 100 | Supervisory tone - dial tone. |
| TONE_TYPE_COMMON_SUPERVISORY_BUSY | 101 | Supervisory tone - busy. |
| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION | 102 | Supervisory tone - congestion. |
| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK | 103 | Supervisory tone - radio path acknowledgment |
| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104 | Supervisory tone - radio path not available |
| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING | 106 | Supervisory tone - call waiting tone |
| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE | 107 | Supervisory tone - ringing tone |
| TONE_TYPE_COMMON_PROPRIETARY_BEEP | 200 | Proprietary tone - beep tone. |
| TONE_TYPE_COMMON_PROPRIETARY_ACK | 201 | Proprietary tone - ACK. |
| TONE_TYPE_COMMON_PROPRIETARY_PROMPT | 203 | Proprietary tone - PROMPT. |
| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP | 204 | Proprietary tone - double beep tone. |
## TonePlayer<sup>9+</sup>
Provides APIs for playing and managing DTMF tones, such as dial tones, ringback tones, supervisory tones, and proprietary tones.
### load<sup>9+</sup>
load(type: ToneType, callback: AsyncCallback&lt;void&gt;): void
Loads the DTMF tone configuration. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :------------------- | :-------- | :---------------------------------- |
| type | ToneType(#tonetype9) | Yes | Tone type. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
if (err) {
console.error(`callback call load failed error: ${err.message}`);
return;
} else {
console.info('callback call load success');
}
});
```
### load<sup>9+</sup>
load(type: ToneType): Promise&lt;void&gt;
Loads the DTMF tone configuration. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory | Description |
| :--- | :------------------- | :-------- | ----------- |
| type | ToneType(#tonetype9) | Yes | Tone type. |
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
**Example**
```js
tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
console.info('promise call load ');
}).catch(() => {
console.error('promise call load fail');
});
```
### start<sup>9+</sup>
start(callback: AsyncCallback&lt;void&gt;): void
Starts DTMF tone playing. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
tonePlayer.start((err) => {
if (err) {
console.error(`callback call start failed error: ${err.message}`);
return;
} else {
console.info('callback call start success');
}
});
```
### start<sup>9+</sup>
start(): Promise&lt;void&gt;
Starts DTMF tone playing. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
**Example**
```js
tonePlayer.start().then(() => {
console.info('promise call start');
}).catch(() => {
console.error('promise call start fail');
});
```
### stop<sup>9+</sup>
stop(callback: AsyncCallback&lt;void&gt;): void
Stops the tone that is being played. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
tonePlayer.stop((err) => {
if (err) {
console.error(`callback call stop error: ${err.message}`);
return;
} else {
console.error('callback call stop success ');
}
});
```
### stop<sup>9+</sup>
stop(): Promise&lt;void&gt;
Stops the tone that is being played. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
**Example**
```js
tonePlayer.stop().then(() => {
console.info('promise call stop finish');
}).catch(() => {
console.error('promise call stop fail');
});
```
### release<sup>9+</sup>
release(callback: AsyncCallback&lt;void&gt;): void
Releases the resources associated with the **TonePlay** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Parameters**
| Name | Type | Mandatory | Description |
| :------- | :------------------- | :-------- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example**
```js
tonePlayer.release((err) => {
if (err) {
console.error(`callback call release failed error: ${err.message}`);
return;
} else {
console.info('callback call release success ');
}
});
```
### release<sup>9+</sup>
release(): Promise&lt;void&gt;
Releases the resources associated with the **TonePlay** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Tone
**Return value**
| Type | Description |
| :------------- | :--------------------------------- |
| Promise<void\> | Promise used to return the result. |
**Example**
```js
tonePlayer.release().then(() => {
console.info('promise call release');
}).catch(() => {
console.error('promise call release fail');
});
``` ```
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册