提交 1793f90f 编写于 作者: W wusongqing

update docs against 6668+7217+7211+7242+7299+7349+7425+7606+7595+7690+7669

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 749bca31
......@@ -37,6 +37,24 @@ Obtains an **AudioManager** instance.
var audioManager = audio.getAudioManager();
```
## audio.getStreamManager<sup>9+</sup>
getStreamManager(): AudioStreamManager
Obtains an **AudioStreamManager** instance.
**System capability**: SystemCapability.Multimedia.Audio.Core
**Return value**
| Type | Description |
| -------------------------------------------------| ------------------------------- |
| [AudioStreamManager](#audiostreammanager9) | **AudioStreamManager** instance. |
**Example**
```
var audioStreamManager = audio.getStreamManager();
```
## audio.createAudioRenderer<sup>8+</sup>
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
......@@ -66,7 +84,7 @@ var audioStreamInfo = {
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 1
rendererFlags: 0
}
var audioRendererOptions = {
......@@ -76,10 +94,9 @@ var audioRendererOptions = {
audio.createAudioRenderer(audioRendererOptions,(err, data) => {
if (err) {
console.error(`AudioRenderer Created : Error: ${err.message}`);
}
else {
console.info('AudioRenderer Created : Success : SUCCESS');
console.error(`AudioRenderer Created: Error: ${err.message}`);
} else {
console.info(`AudioRenderer Created: Success: SUCCESS`);
let audioRenderer = data;
}
});
......@@ -120,7 +137,7 @@ var audioStreamInfo = {
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 1
rendererFlags: 0
}
var audioRendererOptions = {
......@@ -131,9 +148,9 @@ var audioRendererOptions = {
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS');
console.info(`AudioFrameworkRenderLog: AudioRenderer Created : Success : Stream Type: SUCCESS`);
}).catch((err) => {
console.info('AudioFrameworkRenderLog: AudioRenderer Created : ERROR : '+err.message);
console.info(`AudioFrameworkRenderLog: AudioRenderer Created : ERROR :` + err.message);
});
```
......@@ -165,7 +182,7 @@ var audioStreamInfo = {
var audioCapturerInfo = {
source: audio.SourceType.SOURCE_TYPE_MIC,
capturerFlags: 1
capturerFlags: 0
}
var audioCapturerOptions = {
......@@ -173,12 +190,11 @@ var audioCapturerOptions = {
capturerInfo: audioCapturerInfo
}
audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
audio.createAudioCapturer(audioCapturerOptions, (err, data) => {
if (err) {
console.error(`AudioCapturer Created : Error: ${err.message}`);
}
else {
console.info('AudioCapturer Created : Success : SUCCESS');
} else {
console.info(`AudioCapturer Created : Success : SUCCESS`);
let audioCapturer = data;
}
});
......@@ -218,7 +234,7 @@ var audioStreamInfo = {
var audioCapturerInfo = {
source: audio.SourceType.SOURCE_TYPE_MIC,
capturerFlags: 1
capturerFlags: 0
}
var audioCapturerOptions = {
......@@ -229,9 +245,9 @@ var audioCapturerOptions = {
var audioCapturer;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
audioCapturer = data;
console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
console.info(`AudioCapturer Created : Success : Stream Type: SUCCESS`);
}).catch((err) => {
console.info('AudioCapturer Created : ERROR : '+err.message);
console.info(`AudioCapturer Created : ERROR : ` + err.message);
});
```
......@@ -253,7 +269,7 @@ Enumerates the audio stream types.
Enumerates the audio interruption modes.
**System capability**: SystemCapability.Multimedia.Audio.InterruptMode
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value| Description |
| ---------------------------- | ------ | ---------- |
......@@ -333,12 +349,13 @@ Enumerate the audio sample formats.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value| Description |
| --------------------- | ------ | -------------------------- |
| ---------------------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
| SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. |
| SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32-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.<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>
......@@ -410,6 +427,17 @@ Enumerates the audio stream usage.
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
## FocusType<sup>9+</sup>
Enumerates the focus types.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description |
| ---------------------------------- | ------ | ------------------------------- |
| FOCUS_TYPE_RECORDING | 0 | Other audios will be interrupted in recording scenarios. |
## AudioState<sup>8+</sup>
Enumerates the audio states.
......@@ -511,6 +539,17 @@ Describes audio renderer information.
| usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.|
| rendererFlags | number | Yes | Audio renderer flags.|
## AudioRendererFlag<sup>9+</sup>
Enumerates the audio renderer flags that determine the output policy.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description |
| ------------------| ------------ | ---------------------- |
| FLAG_NONE | 0 | There is no special policy. |
| FLAG_LOW_LATENCY | 1 | A low-latency process is used. |
## AudioRendererOptions<sup>8+</sup>
Describes audio renderer configurations.
......@@ -617,6 +656,17 @@ Describes audio capturer information.
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags.|
## AudioRendererDataInfo<sup>9+</sup>
Describes the information of the audio renderer.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description |
| ------- | ----------- | -------| ------------------------ |
| buffer | ArrayBuffer | Yes | Buffer to be filled in. |
| flags | number | Yes | Extension information of the buffer. |
## SourceType<sup>8+</sup><a name="sourcetype"></a>
Enumerates the audio source types.
......@@ -652,7 +702,7 @@ setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&l
Sets the volume for a stream. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
**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**.)
**System capability**: SystemCapability.Multimedia.Audio.Volume
......@@ -669,10 +719,10 @@ Sets the volume for a stream. This API uses an asynchronous callback to return t
```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
if (err) {
console.error('Failed to set the volume. ${err.message}');
console.error(`Failed to set the volume. ${err.message}`);
return;
}
console.log('Callback invoked to indicate a successful volume setting.');
console.log(`Callback invoked to indicate a successful volume setting.`);
});
```
......@@ -682,7 +732,7 @@ setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
Sets the volume for a stream. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
**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**.)
**System capability**: SystemCapability.Multimedia.Audio.Volume
......@@ -703,7 +753,7 @@ Sets the volume for a stream. This API uses a promise to return the result.
```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
console.log('Promise returned to indicate a successful volume setting.');
console.log(`Promise returned to indicate a successful volume setting.`);
});
```
......@@ -727,10 +777,10 @@ Obtains the volume of a stream. This API uses an asynchronous callback to return
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the volume. ${err.message}');
console.error(`Failed to obtain the volume. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the volume is obtained.');
console.log(`Callback invoked to indicate that the volume is obtained.`);
});
```
......@@ -758,7 +808,7 @@ Obtains the volume of a stream. This API uses a promise to return the result.
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
console.log('Promise returned to indicate that the volume is obtained.' + value);
console.log(`Promise returned to indicate that the volume is obtained.` + value);
});
```
......@@ -782,10 +832,10 @@ Obtains the minimum volume allowed for a stream. This API uses an asynchronous c
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the minimum volume. ${err.message}');
console.error(`Failed to obtain the minimum volume. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the minimum volume is obtained.' + value);
console.log(`Callback invoked to indicate that the minimum volume is obtained.` + value);
});
```
......@@ -813,7 +863,7 @@ Obtains the minimum volume allowed for a stream. This API uses a promise to retu
```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
console.log('Promised returned to indicate that the minimum volume is obtained.' + value);
console.log(`Promised returned to indicate that the minimum volume is obtained.` + value);
});
```
......@@ -837,10 +887,10 @@ Obtains the maximum volume allowed for a stream. This API uses an asynchronous c
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the maximum volume. ${err.message}');
console.error(`Failed to obtain the maximum volume. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the maximum volume is obtained.' + value);
console.log(`Callback invoked to indicate that the maximum volume is obtained.` + value);
});
```
......@@ -868,7 +918,7 @@ Obtains the maximum volume allowed for a stream. This API uses a promise to retu
```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
console.log('Promised returned to indicate that the maximum volume is obtained.');
console.log(`Promised returned to indicate that the maximum volume is obtained.`);
});
```
......@@ -878,6 +928,8 @@ mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void
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**.)
**System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
......@@ -893,10 +945,10 @@ Mutes or unmutes a stream. This API uses an asynchronous callback to return the
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
if (err) {
console.error('Failed to mute the stream. ${err.message}');
console.error(`Failed to mute the stream. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the stream is muted.');
console.log(`Callback invoked to indicate that the stream is muted.`);
});
```
......@@ -906,6 +958,8 @@ mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
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**.)
**System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
......@@ -926,7 +980,7 @@ Mutes or unmutes a stream. This API uses a promise to return the result.
```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
console.log('Promise returned to indicate that the stream is muted.');
console.log(`Promise returned to indicate that the stream is muted.`);
});
```
......@@ -951,10 +1005,10 @@ Checks whether a stream is muted. This API uses an asynchronous callback to retu
```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the mute status. ${err.message}');
console.error(`Failed to obtain the mute status. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the mute status of the stream is obtained.' + value);
console.log(`Callback invoked to indicate that the mute status of the stream is obtained.` + value);
});
```
......@@ -983,7 +1037,7 @@ Checks whether a stream is muted. This method uses a promise to return the resul
```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
console.log('Promise returned to indicate that the mute status of the stream is obtained.' + value);
console.log(`Promise returned to indicate that the mute status of the stream is obtained.` + value);
});
```
......@@ -1007,10 +1061,10 @@ Checks whether a stream is active. This API uses an asynchronous callback to ret
```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error('Failed to obtain the active status of the stream. ${err.message}');
console.error(`Failed to obtain the active status of the stream. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the active status of the stream is obtained.' + value);
console.log(`Callback invoked to indicate that the active status of the stream is obtained.` + value);
});
```
......@@ -1038,7 +1092,7 @@ Checks whether a stream is active. This method uses a promise to return the resu
```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
console.log('Promise returned to indicate that the active status of the stream is obtained.' + value);
console.log(`Promise returned to indicate that the active status of the stream is obtained.` + value);
});
```
......@@ -1048,7 +1102,7 @@ setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
Sets the ringer mode. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer.)
**System capability**: SystemCapability.Multimedia.Audio.Communication
......@@ -1064,10 +1118,10 @@ Sets the ringer mode. This API uses an asynchronous callback to return the resul
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
if (err) {
console.error('Failed to set the ringer mode.​ ${err.message}');
console.error(`Failed to set the ringer mode.​ ${err.message}`);
return;
}
console.log('Callback invoked to indicate a successful setting of the ringer mode.');
console.log(`Callback invoked to indicate a successful setting of the ringer mode.`);
});
```
......@@ -1077,7 +1131,7 @@ setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
Sets the ringer mode. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY
**Required permissions**: ohos.permission.ACCESS_NOTIFICATION_POLICY (This permission is required only for muting or unmuting the ringer.)
**System capability**: SystemCapability.Multimedia.Audio.Communication
......@@ -1097,7 +1151,7 @@ Sets the ringer mode. This API uses a promise to return the result.
```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
console.log('Promise returned to indicate a successful setting of the ringer mode.');
console.log(`Promise returned to indicate a successful setting of the ringer mode.`);
});
```
......@@ -1121,10 +1175,10 @@ Obtains the ringer mode. This API uses an asynchronous callback to return the re
```
audioManager.getRingerMode((err, value) => {
if (err) {
console.error('Failed to obtain the ringer mode.​ ${err.message}');
console.error(`Failed to obtain the ringer mode.​ ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the ringer mode is obtained.' + value);
console.log(`Callback invoked to indicate that the ringer mode is obtained.` + value);
});
```
......@@ -1147,7 +1201,7 @@ Obtains the ringer mode. This API uses a promise to return the result.
```
audioManager.getRingerMode().then((value) => {
console.log('Promise returned to indicate that the ringer mode is obtained.' + value);
console.log(`Promise returned to indicate that the ringer mode is obtained.` + value);
});
```
......@@ -1176,10 +1230,10 @@ This API is used to extend the audio configuration based on the hardware capabil
```
audioManager.setAudioParameter('key_example', 'value_example', (err) => {
if (err) {
console.error('Failed to set the audio parameter. ${err.message}');
console.error(`Failed to set the audio parameter. ${err.message}`);
return;
}
console.log('Callback invoked to indicate a successful setting of the audio parameter.');
console.log(`Callback invoked to indicate a successful setting of the audio parameter.`);
});
```
......@@ -1212,7 +1266,7 @@ This API is used to extend the audio configuration based on the hardware capabil
```
audioManager.setAudioParameter('key_example', 'value_example').then(() => {
console.log('Promise returned to indicate a successful setting of the audio parameter.');
console.log(`Promise returned to indicate a successful setting of the audio parameter.`);
});
```
......@@ -1238,10 +1292,10 @@ This API is used to extend the audio configuration based on the hardware capabil
```
audioManager.getAudioParameter('key_example', (err, value) => {
if (err) {
console.error('Failed to obtain the value of the audio parameter. ${err.message}');
console.error(`Failed to obtain the value of the audio parameter. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the value of the audio parameter is obtained.' + value);
console.log(`Callback invoked to indicate that the value of the audio parameter is obtained.` + value);
});
```
......@@ -1271,7 +1325,7 @@ This API is used to extend the audio configuration based on the hardware capabil
```
audioManager.getAudioParameter('key_example').then((value) => {
console.log('Promise returned to indicate that the value of the audio parameter is obtained.' + value);
console.log(`Promise returned to indicate that the value of the audio parameter is obtained.` + value);
});
```
......@@ -1294,10 +1348,10 @@ Obtains the audio devices with a specific flag. This API uses an asynchronous ca
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) {
console.error('Failed to obtain the device list. ${err.message}');
console.error(`Failed to obtain the device list. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the device list is obtained.');
console.log(`Callback invoked to indicate that the device list is obtained.`);
});
```
......@@ -1325,7 +1379,7 @@ Obtains the audio devices with a specific flag. This API uses a promise to retur
```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
console.log('Promise returned to indicate that the device list is obtained.');
console.log(`Promise returned to indicate that the device list is obtained.`);
});
```
......@@ -1350,10 +1404,10 @@ Sets a device to the active state. This API uses an asynchronous callback to ret
```
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
if (err) {
console.error('Failed to set the active status of the device. ${err.message}');
console.error(`Failed to set the active status of the device. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the device is set to the active status.');
console.log(`Callback invoked to indicate that the device is set to the active status.`);
});
```
......@@ -1383,7 +1437,7 @@ Sets a device to the active state. This API uses a promise to return the result.
```
audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
console.log('Promise returned to indicate that the device is set to the active status.');
console.log(`Promise returned to indicate that the device is set to the active status.`);
});
```
......@@ -1407,10 +1461,10 @@ Checks whether a device is active. This API uses an asynchronous callback to ret
```
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
if (err) {
console.error('Failed to obtain the active status of the device. ${err.message}');
console.error(`Failed to obtain the active status of the device. ${err.message}`);
return;
}
console.log('Callback invoked to indicate that the active status of the device is obtained.');
console.log(`Callback invoked to indicate that the active status of the device is obtained.`);
});
```
......@@ -1439,7 +1493,7 @@ Checks whether a device is active. This API uses a promise to return the result.
```
audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
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);
});
```
......@@ -1465,10 +1519,10 @@ Mutes or unmutes the microphone. This API uses an asynchronous callback to retur
```
audioManager.setMicrophoneMute(true, (err) => {
if (err) {
console.error('Failed to mute the microphone. ${err.message}');
console.error(`Failed to mute the microphone. ${err.message}`);
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 +1552,7 @@ Mutes or unmutes the microphone. This API uses a promise to return the result.
```
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.`);
});
```
......@@ -1523,10 +1577,10 @@ Checks whether the microphone is muted. This API uses an asynchronous callback t
```
audioManager.isMicrophoneMute((err, value) => {
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;
}
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 +1605,7 @@ Checks whether the microphone is muted. This API uses a promise to return the re
```
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 +1617,8 @@ Subscribes to system volume change events.
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.
**System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters**
......@@ -1576,9 +1632,9 @@ This is a system API and cannot be called by third-party applications.
```
audioManager.on('volumeChange', (volumeEvent) => {
console.log('VolumeType of stream: ' + volumeEvent.volumeType);
console.log('Volume level: ' + volumeEvent.volume);
console.log('Whether to updateUI: ' + volumeEvent.updateUi);
console.log(`VolumeType of stream: ` + volumeEvent.volumeType);
console.log(`Volume level: ` + volumeEvent.volume);
console.log(`Whether to updateUI: ` + volumeEvent.updateUi);
});
```
......@@ -1603,7 +1659,7 @@ This is a system API and cannot be called by third-party applications.
```
audioManager.on('ringerModeChange', (ringerMode) => {
console.log('Updated ringermode: ' + ringerMode);
console.log(`Updated ringermode: ` + ringerMode);
});
```
......@@ -1620,16 +1676,16 @@ Subscribes to device change events. When a device is connected or disconnected,
| 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.|
| 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. |
**Example**
```
audioManager.on('deviceChange', (deviceChanged) => {
console.info("device change type : " + deviceChanged.type);
console.info("device descriptor size : " + deviceChanged.deviceDescriptors.length);
console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceRole);
console.info("device change descriptor : " + deviceChanged.deviceDescriptors[0].deviceType);
console.info(`device change type : ` + deviceChanged.type);
console.info(`device descriptor size : ` + deviceChanged.deviceDescriptors.length);
console.info(`device change descriptor : ` + deviceChanged.deviceDescriptors[0].deviceRole);
console.info(`device change descriptor : ` + deviceChanged.deviceDescriptors[0].deviceType);
});
```
......@@ -1646,13 +1702,13 @@ Unsubscribes from device change events.
| 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.|
| 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**
```
audioManager.off('deviceChange', (deviceChanged) => {
console.log("Should be no callback.");
console.log(`Should be no callback.`);
});
```
......@@ -1682,12 +1738,12 @@ var interAudioInterrupt = {
};
audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) {
console.log("An event to gain the audio focus starts.");
console.log("Focus gain event:" + JSON.stringify(InterruptAction));
console.log(`An event to gain the audio focus starts.`);
console.log(`Focus gain event:` + JSON.stringify(InterruptAction));
}
if (InterruptAction.actionType === 1) {
console.log("An audio interruption event starts.");
console.log("Audio interruption event:" + JSON.stringify(InterruptAction));
console.log(`An audio interruption event starts.`);
console.log(`Audio interruption event:` + JSON.stringify(InterruptAction));
}
});
```
......@@ -1718,8 +1774,8 @@ var interAudioInterrupt = {
};
audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) {
console.log("An event to release the audio focus starts.");
console.log("Focus release event:" + JSON.stringify(InterruptAction));
console.log(`An event to release the audio focus starts.`);
console.log(`Focus release event:` + JSON.stringify(InterruptAction));
}
});
```
......@@ -1746,10 +1802,10 @@ This is a system API and cannot be called by third-party applications.
```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
if (err) {
console.error('Failed to set the audio scene mode.​ ${err.message}');
console.error(`Failed to set the audio scene mode.​ ${err.message}`);
return;
}
console.log('Callback invoked to indicate a successful setting of the audio scene mode.');
console.log(`Callback invoked to indicate a successful setting of the audio scene mode.`);
});
```
......@@ -1779,9 +1835,9 @@ This is a system API and cannot be called by third-party applications.
```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
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) => {
console.log('Failed to set the audio scene mode');
console.log(`Failed to set the audio scene mode`);
});
```
......@@ -1804,10 +1860,10 @@ Obtains the audio scene. This API uses an asynchronous callback to return the re
```
audioManager.getAudioScene((err, value) => {
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;
}
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 +1886,513 @@ Obtains the audio scene. This API uses a promise to return the result.
```
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) => {
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.
### getCurrentAudioRendererInfoArray<sup>9+</sup>
getCurrentAudioRendererInfoArray(callback: AsyncCallback&lt;AudioRendererChangeInfoArray&gt;): void
Obtains the information about the current audio renderers. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | -------- | --------------------------- |
| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes | Callback used to return the audio renderer information.|
**Example**
```
audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
console.info(`getCurrentAudioRendererInfoArray **** Get Callback Called ****`);
if (err) {
console.log(`getCurrentAudioRendererInfoArray :ERROR: `+ err.message);
resultFlag = false;
} else {
if (AudioRendererChangeInfoArray != null) {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
console.info(`StreamId for` + i + `is:` + AudioRendererChangeInfo.streamId);
console.info(`ClientUid for` + i + `is:` + AudioRendererChangeInfo.clientUid);
console.info(`Content` + i + `is:` + AudioRendererChangeInfo.rendererInfo.content);
console.info(`Stream`+ i + `is:` + AudioRendererChangeInfo.rendererInfo.usage);
console.info(`Flag`+ i + `is:` + AudioRendererChangeInfo.rendererInfo.rendererFlags);
console.info(`State for` + i + `is:` + AudioRendererChangeInfo.rendererState);
var devDescriptor = AudioRendererChangeInfo.deviceDescriptors;
for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].name);
console.info(`Address:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCount` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]);
console.info(`ChannelMask:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelMasks);
}
}
}
}
});
```
### getCurrentAudioRendererInfoArray<sup>9+</sup>
getCurrentAudioRendererInfoArray(): Promise&lt;AudioRendererChangeInfoArray&gt;
Obtains the information about the current audio renderers. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value**
| Type | Description |
| ---------------------------------------------------------------------------------| --------------------------------------- |
| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise used to return the audio renderer information. |
**Example**
```
await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
if (AudioRendererChangeInfoArray != null) {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
console.info(`StreamId for` + i + ` is:` + AudioRendererChangeInfo.streamId);
console.info(`ClientUid for` + i + ` is:` + AudioRendererChangeInfo.clientUid);
console.info(`Content` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.content);
console.info(`Stream` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.usage);
console.info(`Flag` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.rendererFlags);
console.info(`State for` + i + ` is:` + AudioRendererChangeInfo.rendererState);
var devDescriptor = AudioRendererChangeInfo.deviceDescriptors;
for (let j = 0; j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].name);
console.info(`Address:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCounts` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]);
console.info(`ChannnelMask:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelMasks);
}
}
}
}).catch((err) => {
console.log(`getCurrentAudioRendererInfoArray :ERROR: ` + err.message);
});
```
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
getCurrentAudioCapturerInfoArray(callback: AsyncCallback&lt;AudioCapturerChangeInfoArray&gt;): void
Obtains the information about the current audio capturers. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes | Callback used to return the audio capturer information.|
**Example**
```
audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
console.info(`getCurrentAudioCapturerInfoArray **** Get Callback Called ****`);
if (err) {
console.log(`getCurrentAudioCapturerInfoArray :ERROR: ` + err.message);
} else {
if (AudioCapturerChangeInfoArray != null) {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
console.info(`StreamId for ` + i + `is:` + AudioCapturerChangeInfoArray[i].streamId);
console.info(`ClientUid for ` + i + `is:` + AudioCapturerChangeInfoArray[i].clientUid);
console.info(`Source for `+ i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.source);
console.info(`Flag ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags);
console.info(`State for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerState);
var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name);
console.info(`Address:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCounts` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]);
console.info(`ChannelMask:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks);
}
}
}
}
});
```
### getCurrentAudioCapturerInfoArray<sup>9+</sup>
getCurrentAudioCapturerInfoArray(): Promise&lt;AudioCapturerChangeInfoArray&gt;
Obtains the information about the current audio capturers. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value**
| Type | Description |
| -----------------------------------------------------------------------------| ----------------------------------- |
| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise used to return the audio capturer information. |
**Example**
```
await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
console.info(`getCurrentAudioCapturerInfoArray **** Get Promise Called ****`);
if (AudioCapturerChangeInfoArray != null) {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
console.info(`StreamId for ` + i + `is:` + AudioCapturerChangeInfoArray[i].streamId);
console.info(`ClientUid for ` + i + `is:` + AudioCapturerChangeInfoArray[i].clientUid);
console.info(`Source for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.source);
console.info(`Flag ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags);
console.info(`State for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerState);
var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name)
console.info(`Address:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCounts` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]);
console.info(`ChannelMask:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks);
}
}
}
}).catch((err) => {
console.log(`getCurrentAudioCapturerInfoArray :ERROR: ` + err.message);
});
```
### on('audioRendererChange')<sup>9+</sup>
on(type: "audioRendererChange", callback: Callback&lt;AudioRendererChangeInfoArray&gt;): void
Subscribes to audio renderer change events.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
| type | string | Yes | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes. |
| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Yes | Callback used to return the result. |
**Example**
```
audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
console.info(`## RendererChange on is called for ` + i + ` ##`);
console.info(`StreamId for ` + i + ` is:` + AudioRendererChangeInfo.streamId);
console.info(`ClientUid for ` + i + ` is:` + AudioRendererChangeInfo.clientUid);
console.info(`Content for ` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.content);
console.info(`Stream for ` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.usage);
console.info(`Flag ` + i + ` is:` + AudioRendererChangeInfo.rendererInfo.rendererFlags);
console.info(`State for ` + i + ` is:` + AudioRendererChangeInfo.rendererState);
var devDescriptor = AudioRendererChangeInfo.deviceDescriptors;
for (let j = 0; j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].name);
console.info(`Address:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCounts` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]);
console.info(`ChannelMask:` + i + `:` + AudioRendererChangeInfo.deviceDescriptors[j].channelMasks);
}
}
});
```
### off('audioRendererChange')<sup>9+</sup>
off(type: "audioRendererChange");
Unsubscribes from audio renderer change events.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------- | ---- | ---------------- |
| type | string | Yes | Event type. The event `'audioRendererChange'` is triggered when the audio renderer changes.|
**Example**
```
audioStreamManager.off('audioRendererChange');
console.info(`######### RendererChange Off is called #########`);
```
### on('audioCapturerChange')<sup>9+</sup>
on(type: "audioCapturerChange", callback: Callback&lt;AudioCapturerChangeInfoArray&gt;): void
Subscribes to audio capturer change events.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------- | --------- | ------------------------------------------------------------------- ---- |
| type | string | Yes | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes. |
| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Yes | Callback used to return the result. |
**Example**
```
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
console.info(` ## CapChange on is called for element ' + i + ' ##');
console.info(`StreamId for ` + i + `is:` + AudioCapturerChangeInfoArray[i].streamId);
console.info(`ClientUid for ` + i + `is:` + AudioCapturerChangeInfoArray[i].clientUid);
console.info(`Source for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.source);
console.info(`Flag ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags);
console.info(`State for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerState);
for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
console.info(`Id:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id);
console.info(`Type:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType);
console.info(`Role:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole);
console.info(`Name:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name);
console.info(`Address:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address);
console.info(`SampleRates:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]);
console.info(`ChannelCounts` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]);
console.info(`ChannelMask:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks);
}
}
});
```
### off('audioCapturerChange')<sup>9+</sup>
off(type: "audioCapturerChange");
Unsubscribes from audio capturer change events.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------- | --- | ------------------------------------------------------------- |
| type | string |Yes | Event type. The event `'audioCapturerChange'` is triggered when the audio capturer changes.|
**Example**
```
audioStreamManager.off('audioCapturerChange');
console.info(`######### CapturerChange Off is called #########`);
```
### isAudioRendererLowLatencySupported<sup>9+</sup>
isAudioRendererLowLatencySupported(streaminfo: AudioStreamInfo, callback: Callback&lt;boolean&gt;): void;
Checks whether the system supports the low latency configuration in the audio renderer. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ----------------------- | -------- | --------------------------------------- |
| streaminfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information. |
| callback | Callback&lt;boolean&gt; | Yes | Callback used to return the result. If the system supports the low latency configuration, **true** is returned. Otherwise, **false** is returned.|
**Example**
```
var audioManager = audio.getAudioManager();
var AudioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioStreamManager = audioManager.getStreamManager();
audioStreamManager.isAudioRendererLowLatencySupported(AudioStreamInfo, (result) => {
console.info(`isAudioRendererLowLatencySupported success var = ` + result);
});
```
### isAudioRendererLowLatencySupported<sup>9+</sup>
isAudioRendererLowLatencySupported(streaminfo: AudioStreamInfo): Promise&lt;boolean&gt;
Checks whether the system supports the low latency configuration in the audio renderer.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------ | ---- | ------------|
| streaminfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information. |
**Return value**
| Type | Description |
| ------------------- | ---------------------------------------------------- |
| Promise&lt;void&gt; | Promise used to return the result. If the system supports the low latency configuration, **true** is returned. Otherwise, **false** is returned.|
**Example**
```
var audioManager = audio.getAudioManager();
var AudioStreamInfo = {
samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100,
channels: audio.AudioChannel.CHANNEL_1,
sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE,
encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW
}
var audioStreamManager = await audioManager.getStreamManager();
var result = audioStreamManager.isAudioRendererLowLatencySupported(AudioStreamInfo);
console.info(`isAudioRendererLowLatencySupported success var =` + result);
```
## AudioRendererChangeInfo<sup>9+</sup>
Describes the audio renderer change event.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Readable| Writable| Description |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
| 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.|
| 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.|
## AudioRendererChangeInfoArray<sup>9+</sup>
Describes the **AudioRenderChangeInfo** array, which is read-only.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Example**
```
import audio from '@ohos.multimedia.audio';
var audioStreamManager;
var audioStreamManagerCB;
var Tag = "AFCapLog : ";
var resultFlag = false;
await audioManager.getStreamManager().then(async function (data) {
audioStreamManager = data;
console.info(Tag + `Get AudioStream Manager : Success `);
}).catch((err) => {
console.info(Tag + `Get AudioStream Manager : ERROR : ` + err.message);
});
audioManager.getStreamManager((err, data) => {
if (err) {
console.error(Tag + `Get AudioStream Manager : ERROR : ` + err.message);
} else {
audioStreamManagerCB = data;
console.info(Tag + `Get AudioStream Manager : Success `);
}
});
audioStreamManagerCB.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
console.info(Tag + `## RendererChange on is called for ` + i + ` ##`);
console.info(Tag + `StreamId for ` + i + `is:` + AudioRendererChangeInfoArray[i].streamId);
console.info(Tag + `ClientUid for ` + i + `is:` + AudioRendererChangeInfoArray[i].clientUid);
console.info(Tag + `Content for ` + i + `is:` + AudioRendererChangeInfoArray[i].rendererInfo.content);
console.info(Tag + `Stream for ` + i + `is:` + AudioRendererChangeInfoArray[i].rendererInfo.usage);
console.info(Tag + `Flag ` + i + `is:` + AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags);
console.info(Tag + `State for ` + i + `is:` + AudioRendererChangeInfoArray[i].rendererState);
var devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
console.info(Tag + `Id:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].id);
console.info(Tag + `Type:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType);
console.info(Tag + `Role:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole);
console.info(Tag + `Name:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].name);
console.info(Tag + `Addr:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].address);
console.info(Tag + `SR:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]);
console.info(Tag + `C` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]);
console.info(Tag + `CM:` + i + `:` + AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks);
}
if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
resultFlag = true;
console.info(Tag + `ResultFlag for ` + i + ` is:` + resultFlag);
}
}
});
```
## AudioCapturerChangeInfo<sup>9+</sup>
Describes the audio capturer change event.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Type | Readable| Writable| Description |
| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
| 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.|
| 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.|
## AudioCapturerChangeInfoArray<sup>9+</sup>
Describes the **AudioCapturerChangeInfo** array, which is read-only.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**Example**
```
import audio from '@ohos.multimedia.audio';
const audioManager = audio.getAudioManager();
var Tag = "AFCapLog : ";
var resultFlag = false;
audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
console.info(Tag + ` ## CapChange on is called for element ' + i + ' ##');
console.info(Tag + `StrId for ` + i + `is:` + AudioCapturerChangeInfoArray[i].streamId);
console.info(Tag + `CUid for ` + i + `is:` + AudioCapturerChangeInfoArray[i].clientUid);
console.info(Tag + `Src for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.source);
console.info(Tag + `Flag ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags);
console.info(Tag + `State for ` + i + `is:` + AudioCapturerChangeInfoArray[i].capturerState);
var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
console.info(Tag + `Id:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id);
console.info(Tag + `Type:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType);
console.info(Tag + `Role:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole);
console.info(Tag + `Name:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name);
console.info(Tag + `Addr:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address);
console.info(Tag + `SR:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]);
console.info(Tag + `C` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]);
console.info(Tag + `CM:` + i + `:` + AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks);
}
if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
resultFlag = true;
console.info(Tag + `ResultFlag for element ` + i + ` is: ` + resultFlag);
}
}
});
```
......@@ -1843,9 +2403,15 @@ Describes an audio device.
**System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Readable| Writable| Description |
| ---------- | ------------------------- | ---- | ---- | ---------- |
| -------------------------- | -------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes | No | Device type.|
| id<sup>9+</sup> | number | Yes | No | Device ID. |
| name<sup>9+</sup> | string | Yes | No | Device name.|
| address<sup>9+</sup> | string | Yes | No | Device address.|
| 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.|
| channelMasks<sup>9+</sup> | Array&lt;number&gt; | Yes | No | Supported channel masks.|
## AudioDeviceDescriptors
......@@ -1859,20 +2425,18 @@ import audio from '@ohos.multimedia.audio';
function displayDeviceProp(value) {
deviceRoleValue = value.deviceRole;
deviceTypeValue = value.deviceType;
}
var deviceRoleValue = null;
var deviceTypeValue = null;
const promise = audio.getAudioManager().getDevices(1);
promise.then(function (value) {
console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
console.info(`AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG`);
value.forEach(displayDeviceProp);
if (deviceTypeValue != null && deviceRoleValue != null){
console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS');
}
else{
console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL');
console.info(`AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS`);
} else {
console.info(`AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL`);
}
});
```
......@@ -1913,10 +2477,10 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
```
audioRenderer.getRendererInfo((err, rendererInfo) => {
console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content);
console.log('Renderer usage:' + rendererInfo.usage);
console.log('Renderer flags:' + rendererInfo.rendererFlags);
console.log(`Renderer GetRendererInfo:`);
console.log(`Renderer content:` + rendererInfo.content);
console.log(`Renderer usage:` + rendererInfo.usage);
console.log(`Renderer flags:` + rendererInfo.rendererFlags);
});
```
......@@ -1939,12 +2503,12 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
```
var resultFlag = true;
audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content);
console.log('Renderer usage:' + rendererInfo.usage);
console.log('Renderer flags:' + rendererInfo.rendererFlags);
console.log(`Renderer GetRendererInfo:`);
console.log(`Renderer content:` + rendererInfo.content);
console.log(`Renderer usage:` + rendererInfo.usage);
console.log(`Renderer flags:` + rendererInfo.rendererFlags);
}).catch((err) => {
console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
console.log(`AudioFrameworkRenderLog: RendererInfo :ERROR: ` + err.message);
resultFlag = false;
});
```
......@@ -1967,11 +2531,11 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses
```
audioRenderer.getStreamInfo((err, streamInfo) => {
console.log('Renderer GetStreamInfo:');
console.log('Renderer sampling rate:' + streamInfo.samplingRate);
console.log('Renderer channel:' + streamInfo.channels);
console.log('Renderer format:' + streamInfo.sampleFormat);
console.log('Renderer encoding type:' + streamInfo.encodingType);
console.log(`Renderer GetStreamInfo:`);
console.log(`Renderer sampling rate:` + streamInfo.samplingRate);
console.log(`Renderer channel:` + streamInfo.channels);
console.log(`Renderer format:` + streamInfo.sampleFormat);
console.log(`Renderer encoding type:` + streamInfo.encodingType);
});
```
......@@ -1993,13 +2557,13 @@ Obtains the stream information of this **AudioRenderer** instance. This API uses
```
audioRenderer.getStreamInfo().then((streamInfo) => {
console.log('Renderer GetStreamInfo:');
console.log('Renderer sampling rate:' + streamInfo.samplingRate);
console.log('Renderer channel:' + streamInfo.channels);
console.log('Renderer format:' + streamInfo.sampleFormat);
console.log('Renderer encoding type:' + streamInfo.encodingType);
console.log(`Renderer GetStreamInfo:`);
console.log(`Renderer sampling rate:` + streamInfo.samplingRate);
console.log(`Renderer channel:` + streamInfo.channels);
console.log(`Renderer format:` + streamInfo.sampleFormat);
console.log(`Renderer encoding type:` + streamInfo.encodingType);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2022,9 +2586,9 @@ Starts the renderer. This API uses an asynchronous callback to return the result
```
audioRenderer.start((err) => {
if (err) {
console.error('Renderer start failed.');
console.error(`Renderer start failed.`);
} else {
console.info('Renderer start success.');
console.info(`Renderer start success.`);
}
});
```
......@@ -2047,9 +2611,9 @@ Starts the renderer. This API uses a promise to return the result.
```
audioRenderer.start().then(() => {
console.log('Renderer started');
console.log(`Renderer started`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2072,9 +2636,9 @@ Pauses rendering. This API uses an asynchronous callback to return the result.
```
audioRenderer.pause((err) => {
if (err) {
console.error('Renderer pause failed');
console.error(`Renderer pause failed`);
} else {
console.log('Renderer paused.');
console.log(`Renderer paused.`);
}
});
```
......@@ -2097,9 +2661,9 @@ Pauses rendering. This API uses a promise to return the result.
```
audioRenderer.pause().then(() => {
console.log('Renderer paused');
console.log(`Renderer paused`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2122,9 +2686,9 @@ Drains the playback buffer. This API uses an asynchronous callback to return the
```
audioRenderer.drain((err) => {
if (err) {
console.error('Renderer drain failed');
console.error(`Renderer drain failed`);
} else {
console.log('Renderer drained.');
console.log(`Renderer drained.`);
}
});
```
......@@ -2147,9 +2711,9 @@ Drains the playback buffer. This API uses a promise to return the result.
```
audioRenderer.drain().then(() => {
console.log('Renderer drained successfully');
console.log(`Renderer drained successfully`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2172,9 +2736,9 @@ Stops rendering. This API uses an asynchronous callback to return the result.
```
audioRenderer.stop((err) => {
if (err) {
console.error('Renderer stop failed');
console.error(`Renderer stop failed`);
} else {
console.log('Renderer stopped.');
console.log(`Renderer stopped.`);
}
});
```
......@@ -2197,9 +2761,9 @@ Stops rendering. This API uses a promise to return the result.
```
audioRenderer.stop().then(() => {
console.log('Renderer stopped successfully');
console.log(`Renderer stopped successfully`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2222,9 +2786,9 @@ Releases the renderer. This API uses an asynchronous callback to return the resu
```
audioRenderer.release((err) => {
if (err) {
console.error('Renderer release failed');
console.error(`Renderer release failed`);
} else {
console.log('Renderer released.');
console.log(`Renderer released.`);
}
});
```
......@@ -2247,9 +2811,9 @@ Releases the renderer. This API uses a promise to return the result.
```
audioRenderer.release().then(() => {
console.log('Renderer released successfully');
console.log(`Renderer released successfully`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2266,7 +2830,7 @@ Writes the buffer. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | --------------------------------------------------- |
| 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**
......@@ -2284,8 +2848,8 @@ var audioStreamInfo = {
var audioRendererInfo = {
content: audio.ContentType.CONTENT_TYPE_SPEECH,
usage: audio.streamUsage.STREAM_USAGE_VOICE_COMMUNICATION
rendererFlags: 1
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION
rendererFlags: 0
}
var audioRendererOptions = {
......@@ -2295,29 +2859,29 @@ var audioRendererOptions = {
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data)=> {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS`);
}).catch((err) => {
console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ` + err.message);
});
var bufferSize;
audioRenderer.getBufferSize().then((data)=> {
console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info.('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
console.info.(`AudioFrameworkRenderLog: getBufferSize: ERROR: ` + err.message);
});
console.info('Buffer size:'+bufferSize);
console.info(`Buffer size:` + bufferSize);
var context = featureAbility.getContext();
var 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 buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf, (err, writtenbytes) => {
if (writtenbytes < 0) {
console.error('write failed.');
console.error(`write failed.`);
} else {
console.log('Actual written bytes: ' + writtenbytes);
console.log(`Actual written bytes: ` + writtenbytes);
}
});
```
......@@ -2334,7 +2898,7 @@ Writes the buffer. This API uses a promise to return the result.
| Type | Description |
| ---------------- | ------------------------------------------------------------ |
| 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**
......@@ -2346,14 +2910,14 @@ 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
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: 1
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
......@@ -2363,18 +2927,18 @@ var audioRendererOptions = {
var audioRenderer;
audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS`);
}).catch((err) => {
console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
console.info(`AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ` + err.message);
});
var bufferSize;
audioRenderer.getBufferSize().then((data) => {
console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ` + err.message);
});
console.info('BufferSize: ' + bufferSize);
console.info(`BufferSize: ` + bufferSize);
var context = featureAbility.getContext();
var path = await context.getCacheDir();
var filePath = 'data/StarWars10s-2C-48000-4SW.wav';
......@@ -2383,12 +2947,12 @@ let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
audioRenderer.write(buf).then((writtenbytes) => {
if (writtenbytes < 0) {
console.error('write failed.');
console.error(`write failed.`);
} else {
console.log('Actual written bytes: ' + writtenbytes);
console.log(`Actual written bytes: ` + writtenbytes);
}
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2410,7 +2974,7 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
```
audioRenderer.getAudioTime((err, timestamp) => {
console.log('Current timestamp: ' + timestamp);
console.log(`Current timestamp: ` + timestamp);
});
```
......@@ -2432,9 +2996,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
```
audioRenderer.getAudioTime().then((timestamp) => {
console.log('Current timestamp: ' + timestamp);
console.log(`Current timestamp: ` + timestamp);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2457,7 +3021,7 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
```
var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
if (err) {
console.error('getBufferSize error');
console.error(`getBufferSize error`);
}
});
```
......@@ -2483,16 +3047,16 @@ 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
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: 1
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION,
rendererFlags: 0
}
var audioRendererOptions = {
......@@ -2504,14 +3068,14 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
audioRenderer = data;
console.info('AudioFrameworkRenderLog: AudioRenderer Created: SUCCESS');
}).catch((err) => {
console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: '+err.message);
console.info('AudioFrameworkRenderLog: AudioRenderer Created: ERROR: ' + err.message);
});
var bufferSize;
audioRenderer.getBufferSize().then((data) => {
console.info('AudioFrameworkRenderLog: getBufferSize: SUCCESS '+data);
bufferSize=data;
console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info('AudioFrameworkRenderLog: getBufferSize: ERROR: '+err.message);
console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ` + err.message);
});
```
......@@ -2535,9 +3099,9 @@ Sets the render rate. This API uses an asynchronous callback to return the resul
```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
if (err) {
console.error('Failed to set params');
console.error(`Failed to set params`);
} else {
console.log('Callback invoked to indicate a successful render rate setting.');
console.log(`Callback invoked to indicate a successful render rate setting.`);
}
});
```
......@@ -2566,9 +3130,9 @@ Sets the render rate. This API uses a promise to return the result.
```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
console.log('setRenderRate SUCCESS');
console.log(`setRenderRate SUCCESS`);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
......@@ -2590,7 +3154,7 @@ Obtains the current render rate. This API uses an asynchronous callback to retur
```
audioRenderer.getRenderRate((err, renderrate) => {
console.log('getRenderRate: ' + renderrate);
console.log(`getRenderRate: ` + renderrate);
});
```
......@@ -2612,14 +3176,14 @@ Obtains the current render rate. This API uses a promise to return the result.
```
audioRenderer.getRenderRate().then((renderRate) => {
console.log('getRenderRate: ' + renderRate);
console.log(`getRenderRate: ` + renderRate);
}).catch((err) => {
console.log('ERROR: '+err.message);
console.log(`ERROR: ` + err.message);
});
```
### setInterruptMode<sup>9+</sup>
setInterruptMode(interruptMode: InterruptMode): Promise&lt;void&gt;
setInterruptMode(mode: InterruptMode): Promise&lt;void&gt;
Sets the audio interruption mode for the application. This API uses a promise to return the result.
......@@ -2627,9 +3191,9 @@ Sets the audio interruption mode for the application. This API uses a promise to
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| interruptMode | [InterruptMode](#InterruptMode) | Yes | Audio interruption mode. |
| Name | Type | Mandatory | Description |
| ---------- | ---------------------------------- | ------ | ---------- |
| mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode. |
**Return value**
......@@ -2640,14 +3204,32 @@ Sets the audio interruption mode for the application. This API uses a promise to
**Example**
```
const audioManager = audio.getAudioManager();
audioManager.setInterruptMode(audio.InterruptMode.SHARE_MODE).then(() => {
console.log('Promise returned to indicate a successful volume setting.');
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;
audioRenderer.setInterruptMode(mode).then(data=>{
console.log(`setInterruptMode Success!`);
}).catch(err=>{
console.log(`setInterruptMode Fail:` + err.message);
});
```
### setInterruptMode<sup>9+</sup>
setInterruptMode(interruptMode: InterruptMode, callback: Callback\<void>): void
setInterruptMode(mode: InterruptMode, callback: Callback\<void>): void
Sets the audio interruption mode for the application. This API uses a callback to return the result.
......@@ -2655,17 +3237,36 @@ Sets the audio interruption mode for the application. This API uses a callback t
**Parameters**
| Name| Type| Mandatory| Description |
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
|interruptMode | [InterruptMode](#InterruptMode) | Yes | Audio interruption mode.|
| Name | Type | Mandatory | Description |
| ------- | ----------------------------------- | ------ | -------------- |
|mode | [InterruptMode](#interruptmode9) | Yes | Audio interruption mode.|
|callback | Callback\<void> | Yes |Callback used to return the result.|
**Example**
```
const audioManager = audio.getAudioManager();
audioManager.setInterruptMode(audio.InterruptMode.SHARE_MODE,()=>{
console.log('Callback returned to indicate a successful volume setting.');
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;
audioRenderer.setInterruptMode(mode, (err, data)=>{
if(err){
console.log(`setInterruptMode Fail:` + err.message);
}
console.log(`setInterruptMode Success!`);
});
```
### on('interrupt')<sup>9+</sup>
......@@ -2692,41 +3293,40 @@ audioRenderer.on('interrupt', async(interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Force paused. Stop writing');
console.log(`Force paused. Stop writing`);
isPlay = false;
break;
case audio.InterruptHint.INTERRUPT_HINT_STOP:
console.log('Force stopped. Stop writing');
console.log(`Force stopped. Stop writing`);
isPlay = false;
break;
}
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore');
console.log(`Resume force paused renderer or ignore`);
await audioRenderer.start().then(async function () {
console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
console.info(`AudioInterruptMusic: renderInstant started :SUCCESS `);
started = true;
}).catch((err) => {
console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
console.info(`AudioInterruptMusic: renderInstant start :ERROR : ` + err.message);
started = false;
});
if (started) {
isPlay = true;
console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
console.info(`AudioInterruptMusic Renderer started : isPlay : ` + isPlay);
} else {
console.error('AudioInterruptMusic Renderer start failed');
console.error(`AudioInterruptMusic Renderer start failed`);
}
break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore');
if (isPlay == true) {
isPlay == false;
console.info('AudioInterruptMusic: Media PAUSE : TRUE');
}
else {
console.info(`AudioInterruptMusic: Media PAUSE : TRUE`);
} else {
isPlay = true;
console.info('AudioInterruptMusic: Media PLAY : TRUE');
console.info(`AudioInterruptMusic: Media PLAY : TRUE`);
}
break;
}
......@@ -2755,7 +3355,7 @@ Subscribes to mark reached events. When the number of frames rendered reaches th
```
audioRenderer.on('markReach', 1000, (position) => {
if (position == 1000) {
console.log('ON Triggered successfully');
console.log(`ON Triggered successfully`);
}
});
```
......@@ -2802,7 +3402,7 @@ Subscribes to period reached events. When the period of frame rendering reaches
```
audioRenderer.on('periodReach', 1000, (position) => {
if (position == 1000) {
console.log('ON Triggered successfully');
console.log(`ON Triggered successfully`);
}
});
```
......@@ -2827,7 +3427,7 @@ Unsubscribes from period reached events.
audioRenderer.off('periodReach')
```
### on('stateChange') <sup>8+</sup>
### on('stateChange')<sup>8+</sup>
on(type: 'stateChange', callback: Callback<AudioState\>): void
......@@ -2847,14 +3447,43 @@ Subscribes to state change events.
```
audioRenderer.on('stateChange', (state) => {
if (state == 1) {
console.log("audio renderer state is: STATE_PREPARED");
console.log(`audio renderer state is: STATE_PREPARED`);
}
if (state == 2) {
console.log("audio renderer state is: STATE_RUNNING");
console.log(`audio renderer state is: STATE_RUNNING`);
}
});
```
### on('dataRequest') <sup>9+</sup>
on(type: "dataRequest", callback: Callback\<AudioRendererDataInfo>): void;
Subscribes to request events of audio data.
**System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------- | --------- | ------------------------------------------------------------------- |
| type | string | Yes | Event type. The value **dataRequest** indicates a data request event.|
| callback | [AudioRendererDataInfo](#audiorendererdatainfo9) | Yes | Callback used to return the audio renderer information.|
**Example**
```
const path = '/data/storage/el2/ba se/haps/entry/cache/PinkPanther60-44100-1c.wav';
let ss = fileio.createStreamSync(path, 'r');
let discardHeader = new ArrayBuffer(44);
ss.readSync(discardHeader);
let rlen = 0;
audioRenderer.on('dataRequest', (audioRendererDataInfo) => {
var viewObject = new DataView(audioRendererDataInfo.buffer);
rlen += ss.readSync(viewObject.buffer);
console.info(`AudioRenderLog: bytes read from file: ` + rlen);
})
```
## AudioCapturer<sup>8+</sup>
Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
......@@ -2892,11 +3521,11 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us
```
audioCapturer.getCapturerInfo((err, capturerInfo) => {
if (err) {
console.error('Failed to get capture info');
console.error(`Failed to get capture info`);
} else {
console.log('Capturer getCapturerInfo:');
console.log('Capturer source:' + capturerInfo.source);
console.log('Capturer flags:' + capturerInfo.capturerFlags);
console.log(`Capturer getCapturerInfo:`);
console.log(`Capturer source:` + capturerInfo.source);
console.log(`Capturer flags:` + capturerInfo.capturerFlags);
}
});
```
......@@ -2921,15 +3550,15 @@ Obtains the capturer information of this **AudioCapturer** instance. This API us
```
audioCapturer.getCapturerInfo().then((audioParamsGet) => {
if (audioParamsGet != undefined) {
console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
console.info('AudioFrameworkRecLog: Capturer SourceType:' + audioParamsGet.source);
console.info('AudioFrameworkRecLog: Capturer capturerFlags:' + audioParamsGet.capturerFlags);
}else {
console.info('AudioFrameworkRecLog: audioParamsGet is : '+audioParamsGet);
console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect: ');
console.info(`AudioFrameworkRecLog: Capturer CapturerInfo:`);
console.info(`AudioFrameworkRecLog: Capturer SourceType:` + audioParamsGet.source);
console.info(`AudioFrameworkRecLog: Capturer capturerFlags:` + audioParamsGet.capturerFlags);
} else {
console.info(`AudioFrameworkRecLog: audioParamsGet is : ` + audioParamsGet);
console.info(`AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect: `);
}
}).catch((err) => {
console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
console.log(`AudioFrameworkRecLog: CapturerInfo :ERROR: ` + err.message);
});
```
......@@ -2952,13 +3581,13 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses
```
audioCapturer.getStreamInfo((err, streamInfo) => {
if (err) {
console.error('Failed to get stream info');
console.error(`Failed to get stream info');
} else {
console.log('Capturer GetStreamInfo:');
console.log('Capturer sampling rate:' + streamInfo.samplingRate);
console.log('Capturer channel:' + streamInfo.channels);
console.log('Capturer format:' + streamInfo.sampleFormat);
console.log('Capturer encoding type:' + streamInfo.encodingType);
console.log(`Capturer GetStreamInfo:`);
console.log(`Capturer sampling rate:` + streamInfo.samplingRate);
console.log(`Capturer channel:` + streamInfo.channels);
console.log(`Capturer format:` + streamInfo.sampleFormat);
console.log(`Capturer encoding type:` + streamInfo.encodingType);
}
});
```
......@@ -2981,13 +3610,13 @@ Obtains the stream information of this **AudioCapturer** instance. This API uses
```
audioCapturer.getStreamInfo().then((audioParamsGet) => {
console.info('getStreamInfo:');
console.info('sampleFormat:' + audioParamsGet.sampleFormat);
console.info('samplingRate:' + audioParamsGet.samplingRate);
console.info('channels:' + audioParamsGet.channels);
console.info('encodingType:' + audioParamsGet.encodingType);
console.info(`getStreamInfo:`);
console.info(`sampleFormat:` + audioParamsGet.sampleFormat);
console.info(`samplingRate:` + audioParamsGet.samplingRate);
console.info(`channels:` + audioParamsGet.channels);
console.info(`encodingType:` + audioParamsGet.encodingType);
}).catch((err) => {
console.log('getStreamInfo :ERROR: ' + err.message);
console.log(`getStreamInfo :ERROR: ` + err.message);
});
```
......@@ -3010,9 +3639,9 @@ Starts capturing. This API uses an asynchronous callback to return the result.
```
audioCapturer.start((err) => {
if (err) {
console.error('Capturer start failed.');
console.error(`Capturer start failed.`);
} else {
console.info('Capturer start success.');
console.info(`Capturer start success.`);
}
});
```
......@@ -3047,27 +3676,28 @@ var audioStreamInfo = {
var audioCapturerInfo = {
source: audio.SourceType.SOURCE_TYPE_MIC,
capturerFlags = 1
capturerFlags: 0
}
var audioCapturer;
var stateFlag;
audio.createAudioCapturer(audioCapturerOptions).then((data) => {
audioCapturer = data;
console.info('AudioFrameworkRecLog: AudioCapturer Created: SUCCESS');
console.info(`AudioFrameworkRecLog: AudioCapturer Created: SUCCESS`);
}).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created: ERROR: '+err.message);
console.info(`AudioFrameworkRecLog: AudioCapturer Created: ERROR: ` + err.message);
});
audioCapturer.start().then(() => {
console.info('AudioFrameworkRecLog: ---------START---------');
console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
console.info('AudioFrameworkRecLog: AudioCapturer: STATE: '+audioCapturer.state);
console.info('AudioFrameworkRecLog: Capturer started: SUCCESS ');
console.info(`AudioFrameworkRecLog: ---------START---------`);
console.info(`AudioFrameworkRecLog: Capturer started: SUCCESS`);
console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ` + audioCapturer.state);
console.info(`AudioFrameworkRecLog: Capturer started: SUCCESS `);
if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
console.info(`AudioFrameworkRecLog: AudioCapturer is in Running State`);
}
}).catch((err) => {
console.info('AudioFrameworkRecLog: Capturer start :ERROR : '+err.message);
stateFlag=false;
console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ` + err.message);
stateFlag = false;
});
```
......@@ -3090,9 +3720,9 @@ Stops capturing. This API uses an asynchronous callback to return the result.
```
audioCapturer.stop((err) => {
if (err) {
console.error('Capturer stop failed');
console.error(`Capturer stop failed`);
} else {
console.log('Capturer stopped.');
console.log(`Capturer stopped.`);
}
});
```
......@@ -3116,13 +3746,13 @@ Stops capturing. This API uses a promise to return the result.
```
audioCapturer.stop().then(() => {
console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
console.info(`AudioFrameworkRecLog: ---------STOP RECORD---------`);
console.info(`AudioFrameworkRecLog: Capturer stopped: SUCCESS`);
if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
console.info('AudioFrameworkRecLog: State is Stopped': ');
console.info(`AudioFrameworkRecLog: State is Stopped: `);
}
}).catch((err) => {
console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ` + err.message);
});
```
......@@ -3145,9 +3775,9 @@ Releases this **AudioCapturer** instance. This API uses an asynchronous callback
```
audioCapturer.release((err) => {
if (err) {
console.error('capturer release failed');
console.error(`capturer release failed`);
} else {
console.log('capturer released.');
console.log(`capturer released.`);
}
});
```
......@@ -3170,13 +3800,14 @@ Releases this **AudioCapturer** instance. This API uses a promise to return the
**Example**
```
var stateFlag;
audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
console.info(`AudioFrameworkRecLog: ---------RELEASE RECORD---------`);
console.info(`AudioFrameworkRecLog: Capturer release : SUCCESS`);
console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ` + audioCapturer.state);
console.info(`AudioFrameworkRecLog: stateFlag : ` + stateFlag);
}).catch((err) => {
console.info('AudioFrameworkRecLog: Capturer stop: ERROR: '+err.message);
console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ` + err.message);
});
```
......@@ -3202,14 +3833,14 @@ Reads the buffer. This API uses an asynchronous callback to return the result.
```
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
console.info('AudioFrameworkRecLog: getBufferSize: SUCCESS '+data);
console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info('AudioFrameworkRecLog: getBufferSize: EROOR: '+err.message);
console.info(`AudioFrameworkRecLog: getBufferSize: EROOR: ` + err.message);
});
audioCapturer.read(bufferSize, true, async(err, buffer) => {
if (!err) {
console.log("Success in reading the buffer data");
console.log(`Success in reading the buffer data`);
}
});
```
......@@ -3234,23 +3865,23 @@ Reads the buffer. This API uses a promise to return the result.
| Type | Description |
| :-------------------- | :----------------------------------------------------- |
| 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.|
**Example**
```
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
console.info('AudioFrameworkRecLog: getBufferSize: SUCCESS '+data);
console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info('AudioFrameworkRecLog: getBufferSize: ERROR '+err.message);
console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ` + err.message);
});
console.info('Buffer size: ' + bufferSize);
console.info(`Buffer size: ` + bufferSize);
audioCapturer.read(bufferSize, true).then((buffer) => {
console.info('buffer read successfully');
console.info(`buffer read successfully`);
}).catch((err) => {
console.info('ERROR : '+err.message);
console.info(`ERROR : ` + err.message);
});
```
......@@ -3267,13 +3898,13 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
| 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**
```
audioCapturer.getAudioTime((err, timestamp) => {
console.log('Current timestamp: ' + timestamp);
console.log(`Current timestamp: ` + timestamp);
});
```
......@@ -3296,9 +3927,9 @@ Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970).
```
audioCapturer.getAudioTime().then((audioTime) => {
console.info('AudioFrameworkRecLog: AudioCapturer getAudioTime : Success' + audioTime );
console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success` + audioTime );
}).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ` + err.message);
});
```
......@@ -3322,11 +3953,11 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a
```
audioCapturer.getBufferSize((err, bufferSize) => {
if (!err) {
console.log('BufferSize : ' + bufferSize);
console.log(`BufferSize : ` + bufferSize);
audioCapturer.read(bufferSize, true).then((buffer) => {
console.info('Buffer read is ' + buffer );
console.info(`Buffer read is ` + buffer );
}).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ` + err.message);
});
}
});
......@@ -3352,10 +3983,10 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a
```
var bufferSize;
audioCapturer.getBufferSize().then((data) => {
console.info('AudioFrameworkRecLog: getBufferSize :SUCCESS '+ data);
console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ` + data);
bufferSize = data;
}).catch((err) => {
console.info('AudioFrameworkRecLog: getBufferSize :ERROR : '+ err.message);
console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ` + err.message);
});
```
......@@ -3381,7 +4012,7 @@ Subscribes to mark reached events. When the number of frames captured reaches th
```
audioCapturer.on('markReach', 1000, (position) => {
if (position == 1000) {
console.log('ON Triggered successfully');
console.log(`ON Triggered successfully`);
}
});
```
......@@ -3418,7 +4049,7 @@ Subscribes to mark reached events. When the period of frame capturing reaches th
| 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. |
| 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. |
......@@ -3427,7 +4058,7 @@ Subscribes to mark reached events. When the period of frame capturing reaches th
```
audioCapturer.on('periodReach', 1000, (position) => {
if (position == 1000) {
console.log('ON Triggered successfully');
console.log(`ON Triggered successfully`);
}
});
```
......@@ -3452,7 +4083,7 @@ Unsubscribes from period reached events.
audioCapturer.off('periodReach')
```
### on('stateChange') <sup>8+</sup>
### on('stateChange')<sup>8+</sup>
on(type: 'stateChange', callback: Callback<AudioState\>): void
......@@ -3472,10 +4103,10 @@ Subscribes to state change events.
```
audioCapturer.on('stateChange', (state) => {
if (state == 1) {
console.log("audio capturer state is: STATE_PREPARED");
console.log(`audio capturer state is: STATE_PREPARED`);
}
if (state == 2) {
console.log("audio capturer state is: STATE_RUNNING");
console.log(`audio capturer state is: STATE_RUNNING`);
}
});
```
......@@ -2103,7 +2103,7 @@ Creates a **PhotoOutput** instance. This API uses an asynchronous callback to re
| Name | Type | Mandatory| Description |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | Yes | Surface ID received from **ImageReceiver**. |
| surfaceId | string | Yes | Surface ID received from **[ImageReceiver](js-apis-image.md#imagereceiver9)**. |
| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | Yes | Callback used to return the **PhotoOutput** instance.|
**Example**
......@@ -2130,7 +2130,7 @@ Creates a **PhotoOutput** instance. This API uses a promise to return the instan
| Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | Yes | Surface ID received from **ImageReceiver**.|
| surfaceId | string | Yes | Surface ID received from **[ImageReceiver](js-apis-image.md#imagereceiver9)**. |
**Return value**
......
......@@ -15,6 +15,8 @@ getMediaLibrary(context: Context): MediaLibrary
Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.
This API can be used only in the stage model.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
**Parameters**
......@@ -49,6 +51,8 @@ getMediaLibrary(): MediaLibrary
Obtains a **MediaLibrary** instance, which is used to access and modify personal media data such as audios, videos, images, and documents.
This API can be used only in the FA model.
> **NOTE**
>
> This API is no longer maintained since API version 8. You are advised to use [mediaLibrary.getMediaLibrary<sup>8+</sup>](#medialibrarygetmedialibrary8) instead.
......@@ -256,17 +260,12 @@ Creates a media asset. This API uses a promise to return the result.
**Example**
```
async function example() {
// Create an image file in promise mode.
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
media.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) {
console.info("createAsset successfully:"+ JSON.stringify(asset));
}).catch(function(err){
console.info("createAsset failed with error:"+ err);
});
}
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA).then(function(dicResult){
console.info("getPublicDirectory successfully:"+ JSON.stringify(dicResult));
}).catch(function(err){
console.info("getPublicDirectory failed with error:"+ err);
});
```
### getPublicDirectory<sup>8+</sup>
......@@ -578,7 +577,7 @@ Starts image preview. This API can be used to preview local images whose URIs st
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **<Image\>** component can be used to render and display local images and network images.
> This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **\<Image>** component can be used to render and display local and online images.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -620,7 +619,7 @@ Starts image preview, with the first image to preview specified. This API can be
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **<Image\>** component can be used to render and display local images and network images.
> This API is deprecated since API version 9. You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **\<Image>** component can be used to render and display local and online images.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -1934,13 +1933,11 @@ async function example() {
extendArgs: "",
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(1, (err, fileAsset) => {
if (err) {
console.error('Failed ');
return;
}
console.log('fileAsset.displayName : ' + fileAsset.displayName);
})
fetchFileResult.getPositionObject(1) .then(function (fileAsset){
console.log('[Demo] fileAsset.displayName : ' + fileAsset.displayName);
}).catch(function (err) {
console.info("[Demo] getFileAssets failed with error:" + err);
});
}
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册