| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
| SAMPLE_FORMAT_F32LE<sup>9+</sup> | 4 | Signed 32-bit integer, little endian.<br>Due to system restrictions, only some devices support this sampling format.|
## AudioChannel<sup>8+</sup>
## AudioChannel<sup>8+</sup>
...
@@ -410,6 +427,17 @@ Enumerates the audio stream usage.
...
@@ -410,6 +427,17 @@ Enumerates the audio stream usage.
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.)
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.)
Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.)
Mutes or unmutes a stream. This API uses a promise to return the result.
Mutes or unmutes a stream. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer when **volumeType** is set to **AudioVolumeType.RINGTONE**.)
console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
console.log(`Promise returned to indicate that the active status of the device is obtained.` + value);
});
});
```
```
...
@@ -1464,11 +1496,11 @@ Mutes or unmutes the microphone. This API uses an asynchronous callback to retur
...
@@ -1464,11 +1496,11 @@ Mutes or unmutes the microphone. This API uses an asynchronous callback to retur
```
```
audioManager.setMicrophoneMute(true, (err) => {
audioManager.setMicrophoneMute(true, (err) => {
if (err) {
if (err) {
console.error('Failed to mute the microphone. ${err.message}');
console.error(`Failed to mute the microphone. ${err.message}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the microphone is muted.');
console.log(`Callback invoked to indicate that the microphone is muted.`);
});
});
```
```
...
@@ -1498,7 +1530,7 @@ Mutes or unmutes the microphone. This API uses a promise to return the result.
...
@@ -1498,7 +1530,7 @@ Mutes or unmutes the microphone. This API uses a promise to return the result.
```
```
audioManager.setMicrophoneMute(true).then(() => {
audioManager.setMicrophoneMute(true).then(() => {
console.log('Promise returned to indicate that the microphone is muted.');
console.log(`Promise returned to indicate that the microphone is muted.`);
});
});
```
```
...
@@ -1522,11 +1554,11 @@ Checks whether the microphone is muted. This API uses an asynchronous callback t
...
@@ -1522,11 +1554,11 @@ Checks whether the microphone is muted. This API uses an asynchronous callback t
```
```
audioManager.isMicrophoneMute((err, value) => {
audioManager.isMicrophoneMute((err, value) => {
if (err) {
if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}');
console.error(`Failed to obtain the mute status of the microphone. ${err.message}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the mute status of the microphone is obtained.' + value);
console.log(`Callback invoked to indicate that the mute status of the microphone is obtained.` + value);
});
});
```
```
...
@@ -1551,7 +1583,7 @@ Checks whether the microphone is muted. This API uses a promise to return the re
...
@@ -1551,7 +1583,7 @@ Checks whether the microphone is muted. This API uses a promise to return the re
```
```
audioManager.isMicrophoneMute().then((value) => {
audioManager.isMicrophoneMute().then((value) => {
console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
console.log(`Promise returned to indicate that the mute status of the microphone is obtained.`, + value);
});
});
```
```
...
@@ -1563,6 +1595,8 @@ Subscribes to system volume change events.
...
@@ -1563,6 +1595,8 @@ Subscribes to system volume change events.
This is a system API and cannot be called by third-party applications.
This is a system API and cannot be called by third-party applications.
Currently, when multiple **AudioManager** instances are used in a single process, only the subscription of the last instance takes effect, and the subscription of other instances is overwritten (even if the last instance does not initiate a subscription). Therefore, you are advised to use a single **AudioManager** instance.
| type | string | Yes | Event type. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| type | string | Yes | Event type. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the updated ringer mode. |
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the updated ringer mode. |
| 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.|
| callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes | Callback used to return the device update details. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | Yes | Callback used to return the device update details. |
| 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.|
| 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. |
console.log('Promise returned to indicate a successful setting of the audio scene mode.');
console.log(`Promise returned to indicate a successful setting of the audio scene mode.`);
}).catch ((err) => {
}).catch ((err) => {
console.log('Failed to set the audio scene mode');
console.log(`Failed to set the audio scene mode`);
});
});
```
```
...
@@ -1803,11 +1837,11 @@ Obtains the audio scene. This API uses an asynchronous callback to return the re
...
@@ -1803,11 +1837,11 @@ Obtains the audio scene. This API uses an asynchronous callback to return the re
```
```
audioManager.getAudioScene((err, value) => {
audioManager.getAudioScene((err, value) => {
if (err) {
if (err) {
console.error('Failed to obtain the audio scene mode. ${err.message}');
console.error(`Failed to obtain the audio scene mode. ${err.message}`);
return;
return;
}
}
console.log('Callback invoked to indicate that the audio scene mode is obtained.' + value);
console.log(`Callback invoked to indicate that the audio scene mode is obtained.` + value);
});
});
```
```
...
@@ -1830,9 +1864,443 @@ Obtains the audio scene. This API uses a promise to return the result.
...
@@ -1830,9 +1864,443 @@ Obtains the audio scene. This API uses a promise to return the result.
```
```
audioManager.getAudioScene().then((value) => {
audioManager.getAudioScene().then((value) => {
console.log('Promise returned to indicate that the audio scene mode is obtained.' + value);
console.log(`Promise returned to indicate that the audio scene mode is obtained.` + value);
}).catch ((err) => {
}).catch ((err) => {
console.log('Failed to obtain the audio scene mode');
console.log(`Failed to obtain the audio scene mode`);
});
```
## AudioStreamManager<sup>9+</sup>
Implements audio stream management. Before calling any API of **AudioStreamManager**, you must use **[getStreamManager](#audiogetstreammanager9)** to obtain an **AudioStreamManager** instance.
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes | Callback used to return the audio renderer information.|
| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes | Callback used to return the audio capturer information.|
| buffer | ArrayBuffer | Yes | Buffer to be written. |
| buffer | ArrayBuffer | Yes | Buffer to be written. |
| callback | AsyncCallback\<number> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
| 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**
...
@@ -2276,49 +2748,49 @@ import fileio from '@ohos.fileio';
...
@@ -2276,49 +2748,49 @@ import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility'
| Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
| 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**
...
@@ -2344,37 +2816,37 @@ import fileio from '@ohos.fileio';
...
@@ -2344,37 +2816,37 @@ import fileio from '@ohos.fileio';
import featureAbility from '@ohos.ability.featureAbility'
import featureAbility from '@ohos.ability.featureAbility'
| 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 | Period during which frame rendering is listened. The value must be greater than **0**. |
| frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
| 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.|
| 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.|
| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than **0**. |
| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |