提交 383d7017 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 fa1d4442
# Audio Management # Audio Management
> **NOTE** > **NOTE**<br/>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides the following common audio-related functions: This module provides the following common audio-related functions:
- [AudioManager](#audiomanager): Audio management. - [AudioManager](#audiomanager): audio management.
- [AudioRenderer](#audiorenderer8): Audio rendering, used to play Pulse Code Modulation (PCM) audio data. - [AudioRenderer](#audiorenderer8): audio rendering, used to play Pulse Code Modulation (PCM) audio data.
- [AudioCapturer](#audiocapturer8): Audio capture, used to record PCM audio data. - [AudioCapturer](#audiocapturer8): audio capture, used to record PCM audio data.
## Modules to Import ## Modules to Import
...@@ -15,22 +15,21 @@ This module provides the following common audio-related functions: ...@@ -15,22 +15,21 @@ This module provides the following common audio-related functions:
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
``` ```
## audio.getAudioManager ## audio.getAudioManager
getAudioManager(): AudioManager getAudioManager(): AudioManager
Obtains an **AudioManager** instance. Obtains an **AudioManager** instance.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Return value:**
**Return value**
| Type | Description | | Type | Description |
| ----------------------------- | -------------------- | | ----------------------------- | ------------ |
| [AudioManager](#audiomanager) | AudioManager object. | | [AudioManager](#audiomanager) | **AudioManager** instance.|
**Example:**
**Example**
``` ```
var audioManager = audio.getAudioManager(); var audioManager = audio.getAudioManager();
``` ```
...@@ -39,17 +38,18 @@ var audioManager = audio.getAudioManager(); ...@@ -39,17 +38,18 @@ var audioManager = audio.getAudioManager();
createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void createAudioRenderer(options: AudioRendererOptions, callback: AsyncCallback\<AudioRenderer>): void
Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the renderer instance. Obtains an **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ---------------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. | | options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
| callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the audio renderer instance. | | callback | AsyncCallback<[AudioRenderer](#audiorenderer8)> | Yes | Callback used to return the **AudioRenderer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -81,26 +81,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => { ...@@ -81,26 +81,28 @@ audio.createAudioRenderer(audioRendererOptions,(err, data) => {
} }
}); });
``` ```
## audio.createAudioRenderer<sup>8+</sup> ## audio.createAudioRenderer<sup>8+</sup>
createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer> createAudioRenderer(options: AudioRendererOptions): Promise<AudioRenderer\>
Obtains an **AudioRenderer** instance. This API uses a promise to return the renderer instance. Obtains an **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description |
| :--------- | :--------------------------------------------- | :-------- | :---------------------------|
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations. |
**Return value:** | Name | Type | Mandatory| Description |
| :------ | :--------------------------------------------- | :--- | :----------- |
| options | [AudioRendererOptions](#audiorendereroptions8) | Yes | Renderer configurations.|
**Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | ---------------- |
| Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the audio renderer instance. | | Promise<[AudioRenderer](#audiorenderer8)> | Promise used to return the **AudioRenderer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -136,17 +138,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => { ...@@ -136,17 +138,18 @@ audio.createAudioRenderer(audioRendererOptions).then((data) => {
createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void createAudioCapturer(options: AudioCapturerOptions, callback: AsyncCallback<AudioCapturer\>): void
Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------- | :---------------------------------------------- | :--- | :--------------- |
| :--------- | :---------------------------------------------- | :-------- | :--------------------------------------------------- | | options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. | | callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the **AudioCapturer** instance.|
| callback | AsyncCallback<[AudioCapturer](#audiocapturer8)> | Yes | Callback used to return the audio capturer instance. |
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -182,22 +185,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => { ...@@ -182,22 +185,23 @@ audio.createAudioCapturer(audioCapturerOptions,(err, data) => {
createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\> createAudioCapturer(options: AudioCapturerOptions): Promise<AudioCapturer\>
Obtains an **AudioCapturer** instance. This API uses a promise to return the capturer instance. Obtains an **AudioCapturer** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Audio.Capturer
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| Name | Type | Mandatory | Description | | :------ | :--------------------------------------------- | :--- | :--------------- |
| :--------- | :-------------------------------------------- | :-------- | :-------------------------- | | options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations.|
| options | [AudioCapturerOptions](#audiocaptureroptions8) | Yes | Capturer configurations. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | --------------------------------------------------- | | ----------------------------------------- | -------------- |
| Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the audio capturer instance. | | Promise<[AudioCapturer](#audiocapturer8)> | Promise used to return the **AudioCapturer** instance.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -230,56 +234,58 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => { ...@@ -230,56 +234,58 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
## AudioVolumeType ## AudioVolumeType
Enumerates audio stream types. Enumerates the audio stream types.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Default Value | Description | | Name | Default Value| Description |
| ---------------------------- | -------------- | --------------------------------- | | ---------------------------- | ------ | ---------- |
| VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls. | | VOICE_CALL<sup>8+</sup> | 0 | Audio stream for voice calls.|
| RINGTONE | 2 | Audio stream for ringtones. | | RINGTONE | 2 | Audio stream for ringtones. |
| MEDIA | 3 | Audio stream for media purpose. | | MEDIA | 3 | Audio stream for media purpose. |
| VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant. | | VOICE_ASSISTANT<sup>8+</sup> | 9 | Audio stream for voice assistant.|
## DeviceFlag ## DeviceFlag
Enumerates audio device flags. Enumerates the audio device flags.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | -------------- | | ------------------- | ------ | ---------- |
| OUTPUT_DEVICES_FLAG | 1 | Output device. | | OUTPUT_DEVICES_FLAG | 1 | Output device.|
| INPUT_DEVICES_FLAG | 2 | Input device. | | INPUT_DEVICES_FLAG | 2 | Input device.|
| ALL_DEVICES_FLAG | 3 | All devices. | | ALL_DEVICES_FLAG | 3 | All devices.|
## DeviceRole ## DeviceRole
Enumerates audio device roles. Enumerates the audio device roles.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value| Description |
| ------------- | ------ | -------------- |
| INPUT_DEVICE | 1 | Input role.|
| OUTPUT_DEVICE | 2 | Output role.|
| Name | Default Value | Description |
| ------------- | ------------- | ------------ |
| INPUT_DEVICE | 1 | Input role. |
| OUTPUT_DEVICE | 2 | Output role. |
## DeviceType ## DeviceType
Enumerates audio device types. Enumerates the audio device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ---------------- | ------------- | ------------------------------------------------------------------------ | | ---------------- | ------ | --------------------------------------------------------- |
| INVALID | 0 | Invalid device. | | INVALID | 0 | Invalid device. |
| EARPIECE | 1 | Earpiece. | | EARPIECE | 1 | Earpiece. |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| WIRED_HEADSET | 3 | Wired headset. | | WIRED_HEADSET | 3 | Wired headset with a microphone. |
| WIRED_HEADPHONES | 4 | Wired headset without microphone. | | WIRED_HEADPHONES | 4 | Wired headset without microphone. |
| BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. | | BLUETOOTH_SCO | 7 | Bluetooth device using Synchronous Connection Oriented (SCO) links. |
| BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links. | | BLUETOOTH_A2DP | 8 | Bluetooth device using Advanced Audio Distribution Profile (A2DP) links.|
| MIC | 15 | Microphone. | | MIC | 15 | Microphone. |
| USB_HEADSET | 22 | USB Type-C headset. | | USB_HEADSET | 22 | USB Type-C headset. |
...@@ -287,203 +293,195 @@ Enumerates audio device types. ...@@ -287,203 +293,195 @@ Enumerates audio device types.
Enumerates the active device types. Enumerates the active device types.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------- | ------------- | ---------------------------------------------------------------------- | | ------------- | ------ | ---------------------------------------------------- |
| SPEAKER | 2 | Speaker. | | SPEAKER | 2 | Speaker. |
| BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links. | | BLUETOOTH_SCO | 7 | Bluetooth device using the SCO links.|
## AudioRingMode ## AudioRingMode
Enumerates ringer modes. Enumerates the ringer modes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| ------------------- | ------------- | ---------------- | | ------------------- | ------ | ---------- |
| RINGER_MODE_SILENT | 0 | Silent mode. | | RINGER_MODE_SILENT | 0 | Silent mode.|
| RINGER_MODE_VIBRATE | 1 | Vibration mode. | | RINGER_MODE_VIBRATE | 1 | Vibration mode.|
| RINGER_MODE_NORMAL | 2 | Normal mode. | | RINGER_MODE_NORMAL | 2 | Normal mode.|
## AudioSampleFormat<sup>8+</sup> ## AudioSampleFormat<sup>8+</sup>
Enumerates the audio sample formats. Enumerate the audio sample formats.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------------- | :------------ | :------------------------------------ | | --------------------- | ------ | -------------------------- |
| SAMPLE_FORMAT_INVALID | -1 | Invalid format. | | SAMPLE_FORMAT_INVALID | -1 | Invalid format. |
| SAMPLE_FORMAT_U8 | 0 | Unsigned 8 bit integer. | | SAMPLE_FORMAT_U8 | 0 | Unsigned 8-bit integer. |
| SAMPLE_FORMAT_S16LE | 1 | Signed 16 bit integer, little endian. | | SAMPLE_FORMAT_S16LE | 1 | Signed 16-bit integer, little endian.|
| SAMPLE_FORMAT_S24LE | 2 | Signed 24 bit integer, little endian. | | SAMPLE_FORMAT_S24LE | 2 | Signed 24-bit integer, little endian.|
| SAMPLE_FORMAT_S32LE | 3 | Signed 32 bit integer, little endian. | | SAMPLE_FORMAT_S32LE | 3 | Signed 32-bit integer, little endian.|
## AudioChannel<sup>8+</sup> ## AudioChannel<sup>8+</sup>
Enumerates the audio channels. Enumerates the audio channels.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value | Description |
| :-------- | :------------ | :--------------- | | --------- | -------- | -------- |
| CHANNEL_1 | 0x1 << 0 | Channel count 1. | | CHANNEL_1 | 0x1 << 0 | Mono.|
| CHANNEL_2 | 0x1 << 1 | Channel count 2. | | CHANNEL_2 | 0x1 << 1 | Dual-channel.|
## AudioSamplingRate<sup>8+</sup> ## AudioSamplingRate<sup>8+</sup>
Enumerates the audio sampling rates. Enumerates the audio sampling rates.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :---------------- | :------------ | :------------------- | | ----------------- | ------ | --------------- |
| SAMPLE_RATE_8000 | 8000 | Sampling rate 8000. | | SAMPLE_RATE_8000 | 8000 | The sampling rate is 8000. |
| SAMPLE_RATE_11025 | 11025 | Sampling rate 11025. | | SAMPLE_RATE_11025 | 11025 | The sampling rate is 11025.|
| SAMPLE_RATE_12000 | 12000 | Sampling rate 12000. | | SAMPLE_RATE_12000 | 12000 | The sampling rate is 12000.|
| SAMPLE_RATE_16000 | 16000 | Sampling rate 16000. | | SAMPLE_RATE_16000 | 16000 | The sampling rate is 16000.|
| SAMPLE_RATE_22050 | 22050 | Sampling rate 22050. | | SAMPLE_RATE_22050 | 22050 | The sampling rate is 22050.|
| SAMPLE_RATE_24000 | 24000 | Sampling rate 24000. | | SAMPLE_RATE_24000 | 24000 | The sampling rate is 24000.|
| SAMPLE_RATE_32000 | 32000 | Sampling rate 32000. | | SAMPLE_RATE_32000 | 32000 | The sampling rate is 32000.|
| SAMPLE_RATE_44100 | 44100 | Sampling rate 44100. | | SAMPLE_RATE_44100 | 44100 | The sampling rate is 44100.|
| SAMPLE_RATE_48000 | 48000 | Sampling rate 48000. | | SAMPLE_RATE_48000 | 48000 | The sampling rate is 48000.|
| SAMPLE_RATE_64000 | 64000 | Sampling rate 64000. | | SAMPLE_RATE_64000 | 64000 | The sampling rate is 64000.|
| SAMPLE_RATE_96000 | 96000 | Sampling rate 96000. | | SAMPLE_RATE_96000 | 96000 | The sampling rate is 96000.|
## AudioEncodingType<sup>8+</sup> ## AudioEncodingType<sup>8+</sup>
Enumerates the audio encoding types. Enumerates the audio encoding types.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------------- | :------------- | :---------------- | | --------------------- | ------ | --------- |
| ENCODING_TYPE_INVALID | -1 | Invalid. | | ENCODING_TYPE_INVALID | -1 | Invalid. |
| ENCODING_TYPE_RAW | 0 | PCM encoding. | | ENCODING_TYPE_RAW | 0 | PCM encoding.|
## ContentType ## ContentType
Enumerates the content types. Enumerates the audio content types.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description |
| :----------------------------------| :------------ | :---------------------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content. |
| CONTENT_TYPE_SPEECH | 1 | Speech content. |
| CONTENT_TYPE_MUSIC | 2 | Music content. |
| CONTENT_TYPE_MOVIE | 3 | Movie content. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content. |
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone content. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| CONTENT_TYPE_UNKNOWN | 0 | Unknown content.|
| CONTENT_TYPE_SPEECH | 1 | Speech. |
| CONTENT_TYPE_MUSIC | 2 | Music. |
| CONTENT_TYPE_MOVIE | 3 | Movie. |
| CONTENT_TYPE_SONIFICATION | 4 | Sonification content.|
| CONTENT_TYPE_RINGTONE<sup>8+</sup> | 5 | Ringtone. |
## StreamUsage ## StreamUsage
Enumerates the stream usage. Enumerates the audio stream usage.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Core
| :--------------------------------- | :------------ | :-------------------------------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage. |
| STREAM_USAGE_MEDIA | 1 | Media usage. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Voice communication usage. |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Notification or ringtone usage. |
| Name | Default Value| Description |
| ---------------------------------- | ------ | ---------- |
| STREAM_USAGE_UNKNOWN | 0 | Unknown usage.|
| STREAM_USAGE_MEDIA | 1 | Used for media. |
| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.|
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.|
## AudioState<sup>8+</sup> ## AudioState<sup>8+</sup>
Enumerates the audio states. Enumerates the audio states.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------- | :------------ | :--------------------------- | | -------------- | ------ | ---------------- |
| STATE_INVALID | -1 | Invalid state. | | STATE_INVALID | -1 | Invalid state. |
| STATE_NEW | 0 | Creating new instance state. | | STATE_NEW | 0 | Creating instance state.|
| STATE_PREPARED | 1 | Prepared state. | | STATE_PREPARED | 1 | Prepared. |
| STATE_RUNNING | 2 | Running state. | | STATE_RUNNING | 2 | Running. |
| STATE_STOPPED | 3 | Stopped state. | | STATE_STOPPED | 3 | Stopped. |
| STATE_RELEASED | 4 | Released state. | | STATE_RELEASED | 4 | Released. |
| STATE_PAUSED | 5 | Paused state. | | STATE_PAUSED | 5 | Paused. |
## AudioRendererRate<sup>8+</sup> ## AudioRendererRate<sup>8+</sup>
Enumerates the audio renderer rates. Enumerates the audio renderer rates.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :----------------- | :------------ | :------------ | | ------------------ | ------ | ---------- |
| RENDER_RATE_NORMAL | 0 | Normal rate. | | RENDER_RATE_NORMAL | 0 | Normal rate.|
| RENDER_RATE_DOUBLE | 1 | Double rate. | | RENDER_RATE_DOUBLE | 1 | Double rate. |
| RENDER_RATE_HALF | 2 | Half rate. | | RENDER_RATE_HALF | 2 | Half rate. |
## InterruptType ## InterruptType
Enumerates the interrupt types. Enumerates the audio interruption types.
**System capability:** SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | **System capability**: SystemCapability.Multimedia.Audio.Renderer
| :------------------- | :------------ | :----------------------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio playback interruption started. |
| INTERRUPT_TYPE_END | 2 | Audio playback interruption ended. |
| Name | Default Value| Description |
| -------------------- | ------ | ---------------------- |
| INTERRUPT_TYPE_BEGIN | 1 | Audio interruption started.|
| INTERRUPT_TYPE_END | 2 | Audio interruption ended.|
## InterruptForceType<sup>9+</sup> ## InterruptForceType<sup>9+</sup>
Enumerates the interrupt force types. Enumerates the types of force that causes audio interruption.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :-------------- | :------------ | :----------------------------------------- | | --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0 | Forced action taken by system. | | INTERRUPT_FORCE | 0 | Forced action taken by the system. |
| INTERRUPT_SHARE | 1 | App can choose to take action or ignore. | | INTERRUPT_SHARE | 1 | The application can choose to take action or ignore.|
## InterruptHint ## InterruptHint
Enumerates the interrupt hints. Enumerates the hints provided along with audio interruption.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------------------- | :------------ | :--------------------------- | | ---------------------------------- | ------ | -------------------------------------------- |
| INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. | | INTERRUPT_HINT_NONE<sup>8+</sup> | 0 | None. |
| INTERRUPT_HINT_RESUME | 1 | Resume the playback. | | INTERRUPT_HINT_RESUME | 1 | Resume the playback. |
| INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. | | INTERRUPT_HINT_PAUSE | 2 | Paused/Pause the playback. |
| INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. | | INTERRUPT_HINT_STOP | 3 | Stopped/Stop the playback. |
| INTERRUPT_HINT_DUCK | 4 | Ducked the playback. | | INTERRUPT_HINT_DUCK | 4 | Ducked the playback. (In ducking, the audio volume is reduced, but not silenced.)|
| INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. | | INTERRUPT_HINT_UNDUCK<sup>8+</sup> | 5 | Unducked the playback. |
## InterruptActionType ## InterruptActionType
Enumerates the interrupt event return types. Enumerates the returned event types for audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer | Name | Default Value| Description |
| -------------- | ------ | ------------------ |
| Name | Default Value | Description | | TYPE_ACTIVATED | 0 | Focus gain event.|
| :------------- | :------------ | :---------------------------------------- | | TYPE_INTERRUPT | 1 | Audio interruption event.|
| TYPE_ACTIVATED | 0 | Audio interrupt activated. |
| TYPE_INTERRUPT | 1 | Audio interrupted. |
## AudioStreamInfo<sup>8+</sup> ## AudioStreamInfo<sup>8+</sup>
Describes audio stream information. Describes audio stream information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :---------------------------------------- | :-------- | :-------------------- | | ------------ | ---------------------------------------- | ---- | ------------------ |
| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Sampling rate. | | samplingRate | [AudioSamplingRate](#audiosamplingrate8) | Yes | Audio sampling rate.|
| channels | [AudioChannel](#audiochannel8) | Yes | Audio channels. | | channels | [AudioChannel](#audiochannel8) | Yes | Number of audio channels.|
| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. | | sampleFormat | [AudioSampleFormat](#audiosampleformat8) | Yes | Audio sample format. |
| encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. | | encodingType | [AudioEncodingType](#audioencodingtype8) | Yes | Audio encoding type. |
...@@ -491,171 +489,166 @@ Describes audio stream information. ...@@ -491,171 +489,166 @@ Describes audio stream information.
Describes audio renderer information. Describes audio renderer information.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------ | :-------------------------- | :-------- | :-------------------- | | ------------- | --------------------------- | ---- | ---------------- |
| contentType | [ContentType](#contenttype) | Yes | Content type. | | content | [ContentType](#contenttype) | Yes | Audio content type. |
| usage | [StreamUsage](#streamusage) | Yes | Stream usage. | | usage | [StreamUsage](#streamusage) | Yes | Audio stream usage.|
| rendererFlags | number | Yes | Audio renderer flags. | | rendererFlags | number | Yes | Audio renderer flags.|
## AudioRendererOptions<sup>8+</sup> ## AudioRendererOptions<sup>8+</sup>
Describes audio renderer configuration options. Describes audio renderer configurations.
**System capability:** SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description |
| :------------ | :-----------------------------------------| :-------- | :-------------------- |
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Renderer information. |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability:** SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory | Description |
| :---------------| :------------------------- | :-------- | :-------------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags. |
## AudioCapturerOptions<sup>8+</sup>
Describes audio capturer configuration options. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Capturer | Name | Type | Mandatory| Description |
| ------------ | ---------------------------------------- | ---- | ---------------- |
| Name | Type | Mandatory | Description | | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| :------------ | :-----------------------------------------| :-------- | :-------------------- | | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | Yes | Audio renderer information.|
| streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Stream information. |
| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | Yes | Capturer information. |
## InterruptEvent<sup>9+</sup> ## InterruptEvent<sup>9+</sup>
Describes the interrupt event received by the app when playback is interrupted. Describes the interruption event received by the application when playback is interrupted.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :-------- | :-------------------------------------------- | :-------- | :---------------------------------------------------------------- | | --------- | ------------------------------------------ | ---- | ------------------------------------ |
| eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or finished. | | eventType | [InterruptType](#interrupttype) | Yes | Whether the interruption has started or ended. |
| forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the action is taken by system or to be taken by the app. | | forceType | [InterruptForceType](#interruptforcetype9) | Yes | Whether the interruption is taken by the system or to be taken by the application.|
| hintType | [InterruptHint](#interrupthint) | Yes | Type of action. | | hintType | [InterruptHint](#interrupthint) | Yes | Hint provided along the interruption. |
## AudioInterrupt ## AudioInterrupt
The parameters passed in by the audio listener event. Describes input parameters of audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------------- | --------------------------- | ---- | ------------------------------------------------------------ | | --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
| streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage type. | | streamUsage | [StreamUsage](#streamusage) | Yes | Audio stream usage. |
| contentType | [ContentType](#contenttype) | Yes | Audio interrupt media type. | | contentType | [ContentType](#contenttype) | Yes | Audio content type. |
| pauseWhenDucked | boolean | Yes | Whether audio playback can be paused when audio is interrupted (true means audio playback can be paused during audio interruptions and false means the opposite). | | pauseWhenDucked | boolean | Yes | Whether audio playback can be paused during audio interruption. The value **true** means that audio playback can be paused during audio interruption, and **false** means the opposite.|
## InterruptAction ## InterruptAction
Callback method for the audio interrupt or audio interrupt activated event. Describes the callback invoked for audio interruption or focus gain events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| actionType | [InterruptActionType](#interruptactiontype) | Yes | Event return type. TYPE_ACTIVATED is the audio interrupt activated event, and TYPE_INTERRUPT is the audio interrupt event. | | actionType | [InterruptActionType](#interruptactiontype) | Yes | Returned event type. The value **TYPE_ACTIVATED** means the focus gain event, and **TYPE_INTERRUPT** means the audio interruption event.|
| type | [InterruptType](#interrupttype) | No | Interrupt event type. | | type | [InterruptType](#interrupttype) | No | Type of the audio interruption event. |
| hint | [InterruptHint](#interrupthint) | No | Interrupt event prompts. | | hint | [InterruptHint](interrupthint) | No | Hint provided along with the audio interruption event. |
| activated | boolean | No | Acquire/release focus. true indicates that the focus acquisition/release is successful, and false indicates that the focus acquisition/release fails. | | activated | boolean | No | Whether the focus is gained or released. The value **true** means that the focus is gained or released, and **false** means that the focus fails to be gained or released.|
## VolumeEvent<sup>8+</sup> ## VolumeEvent<sup>8+</sup>
Describes the volume event received by the app when the volume is changed.
Describes the event received by the application when the volume is changed.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :--------- | :---------------------------------- | :-------- | :--------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume type of the current stream. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume level. | | volume | number | Yes | Volume level. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| updateUi | boolean | Yes | Whether to show the volume change in UI. | | updateUi | boolean | Yes | Whether to show the volume change in UI. |
## DeviceChangeAction ## DeviceChangeAction
Describes the device change type and device information. Describes the device connection status and device information.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Mandatory | Description |
| :------------------ | :------------------------------------------------ | :-------- | :------------------ |
| type | [DeviceChangeType](#devicechangetype) | Yes | Device change type. |
| deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. |
| Name | Type | Mandatory| Description |
| :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. |
## DeviceChangeType ## DeviceChangeType
Enumerates device change types. Enumerates the device connection statuses.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Default Value | Description | | Name | Default Value| Description |
| :--------------------- | :------------ | :-------------------- | | :--------- | :----- | :------------- |
| CONNECT | 0 | Device connection. | | CONNECT | 0 | Connected. |
| DISCONNECT | 1 | Device disconnection. | | DISCONNECT | 1 | Disconnected.|
## SourceType<sup>8+</sup><a name="sourcetype"></a> ## AudioCapturerOptions<sup>8+</sup>
Enumerates source types. Describes audio capturer configurations.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Capturer
| Name | Default Value | Description | | Name | Type | Mandatory| Description |
| :----------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | :------------------------------- | | ------------ | --------------------------------------- | ---- | ---------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid source type. | | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | Yes | Audio stream information.|
| SOURCE_TYPE_MIC | 0 | Mic source type. | | capturerInfo | [AudioCapturerInfo](#audiocapturerinfo) | Yes | Audio capturer information.|
| SOURCE_TYPE_VOICE_COMMUNICATION(This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR) | 7 | Voice communication source type. |
## AudioCapturerInfo<sup>8+</sup><a name="audiocapturerinfo"></a>
Describes audio capturer information.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Type | Mandatory| Description |
| :------------ | :------------------------ | :--- | :--------------- |
| source | [SourceType](#sourcetype) | Yes | Audio source type. |
| capturerFlags | number | Yes | Audio capturer flags.|
## SourceType<sup>8+</sup><a name="sourcetype"></a>
Enumerates the audio source types.
**System capability**: SystemCapability.Multimedia.Audio.Core
| Name | Default Value| Description |
| :------------------------------ | :----- | :--------------------- |
| SOURCE_TYPE_INVALID | -1 | Invalid audio source. |
| SOURCE_TYPE_MIC | 0 | Mic source. |
| SOURCE_TYPE_VOICE_COMMUNICATION | 7 | Voice communication source.|
## AudioScene<sup>8+</sup><a name="audioscene"></a> ## AudioScene<sup>8+</sup><a name="audioscene"></a>
Enumerates audio scenes. Enumerates the audio scenes.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
| Name | Default Value | Description | | Name | Default Value| Description |
| :------------------------------------------------------------------------------------ | :------------ | :---------------------- | | :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT | 0 | Default audio scene. | | AUDIO_SCENE_DEFAULT | 0 | Default audio scene. |
| AUDIO_SCENE_RINGING(system API, not supported by third-party applications) | 1 | Ringing audio scene. | | AUDIO_SCENE_RINGING | 1 | Ringing audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_PHONE_CALL(system API, not supported by third-party applications) | 2 | Phone call audio scene. | | AUDIO_SCENE_PHONE_CALL | 2 | Phone call audio scene.<br>This is a system API and cannot be called by third-party applications.|
| AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. | | AUDIO_SCENE_VOICE_CHAT | 3 | Voice chat audio scene. |
## AudioManager ## AudioManager
Implements audio volume and audio device management. Before calling the interface of AudioManager, you need to create an instance through [getAudioManager](#audiogetaudiomanager). Implements audio volume and audio device management. Before calling any API in **AudioManager**, you must use [getAudioManager](#audiogetaudiomanager) to create an **AudioManager** instance.
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void\>\): void setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback&lt;void&gt;): void
Sets the volume for a stream. This API uses an asynchronous callback to return the result. Sets the volume for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
...@@ -666,28 +659,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => { ...@@ -666,28 +659,29 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
console.log('Callback invoked to indicate a successful volume setting.'); console.log('Callback invoked to indicate a successful volume setting.');
}); });
``` ```
### setVolume ### setVolume
setVolume\(volumeType: AudioVolumeType, volume: number\): Promise<void\> setVolume(volumeType: AudioVolumeType, volume: number): Promise&lt;void&gt;
Sets the volume for a stream. This API uses a promise to return the result. Sets the volume for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ---------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Volume stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling getMinVolume and getMaxVolume. | | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ----------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
...@@ -697,20 +691,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => { ...@@ -697,20 +691,20 @@ audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the volume of a stream. This API uses an asynchronous callback to return the query result. Obtains the volume of a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -722,28 +716,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -722,28 +716,27 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getVolume ### getVolume
getVolume\(volumeType: AudioVolumeType\): Promise<number\> getVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the volume of a stream. This API uses a promise to return the query result. Obtains the volume of a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the volume.|
**Example:** **Example**
``` ```
audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -753,20 +746,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -753,20 +746,20 @@ audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the minimum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -778,28 +771,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -778,28 +771,27 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMinVolume ### getMinVolume
getMinVolume\(volumeType: AudioVolumeType\): Promise<number\><a name="section41556389511"></a> getMinVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the minimum volume allowed for a stream. This API uses a promise to return the query result. Obtains the minimum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the minimum volume.|
**Example:** **Example**
``` ```
audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -809,20 +801,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -809,20 +801,20 @@ audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType, callback: AsyncCallback<number\>\): void getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void
Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the query result. Obtains the maximum volume allowed for a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ---------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -834,28 +826,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -834,28 +826,27 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### getMaxVolume ### getMaxVolume
getMaxVolume\(volumeType: AudioVolumeType\): Promise<number\> getMaxVolume(volumeType: AudioVolumeType): Promise&lt;number&gt;
Obtains the maximum volume allowed for a stream. This API uses a promise to return the query result. Obtains the maximum volume allowed for a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------- |
| Promise<number> | Promise used to return the result. | | Promise&lt;number&gt; | Promise used to return the maximum volume.|
**Example:** **Example**
``` ```
audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
...@@ -865,21 +856,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => { ...@@ -865,21 +856,21 @@ audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void\>\): void mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes a stream. This API uses an asynchronous callback to return the result. Mutes or unmutes a stream. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
| callback | AsyncCallback<number> | Yes | Callback used to return the volume. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
...@@ -891,29 +882,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => { ...@@ -891,29 +882,29 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
}); });
``` ```
### mute ### mute
mute\(volumeType: AudioVolumeType, mute: boolean\): Promise<void\> mute(volumeType: AudioVolumeType, mute: boolean): Promise&lt;void&gt;
Mutes a stream. This API uses a promise to return the result. Mutes or unmutes a stream. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------ | | ---------- | ----------------------------------- | ---- | ------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| mute | boolean | Yes | Mute status to set. The value true means to mute the stream, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the stream, and **false** means the opposite.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ----------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
...@@ -924,20 +915,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => { ...@@ -924,20 +915,20 @@ audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\): void isMute(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is muted. This API uses an asynchronous callback to return the query result. Checks whether a stream is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -952,25 +943,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -952,25 +943,25 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
### isMute ### isMute
isMute\(volumeType: AudioVolumeType\): Promise<boolean\> isMute(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is muted. This API uses a promise to return the result. Checks whether a stream is muted. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------- | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | ------------------------------------------------------ |
| Promise<boolean> | Promise used to return the mute status of the stream. The value true means that the stream is muted, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the mute status of the stream. The value **true** means that the stream is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -980,20 +971,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -980,20 +971,20 @@ audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
### isActive ### isActive
isActive\(volumeType: AudioVolumeType, callback: AsyncCallback<boolean\>\) isActive(volumeType: AudioVolumeType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a stream is active. This API uses an asynchronous callback to return the query result. Checks whether a stream is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the stream. The value true means that the stream is active, and false means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
...@@ -1005,28 +996,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => { ...@@ -1005,28 +996,27 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
}); });
``` ```
### isActive ### isActive
isActive\(volumeType: AudioVolumeType\): Promise<boolean\> isActive(volumeType: AudioVolumeType): Promise&lt;boolean&gt;
Checks whether a stream is active. This API uses a promise to return the query result. Checks whether a stream is active. This method uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ------------------ | | ---------- | ----------------------------------- | ---- | ------------ |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | | ---------------------- | -------------------------------------------------------- |
| Promise<boolean> | Promise used to return the active status of the stream. The value true means that the stream is active, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the active status of the stream. The value **true** means that the stream is active, and **false** means the opposite.|
**Example:** **Example**
``` ```
audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
...@@ -1034,23 +1024,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { ...@@ -1034,23 +1024,22 @@ audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode, callback: AsyncCallback<void\>\): void setRingerMode(mode: AudioRingMode, callback: AsyncCallback&lt;void&gt;): void
Sets the ringer mode. This API uses an asynchronous callback to return the result. Sets the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | -------- | ------------------------------- | ---- | ------------------------ |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
...@@ -1062,28 +1051,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => { ...@@ -1062,28 +1051,27 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
}); });
``` ```
### setRingerMode ### setRingerMode
setRingerMode\(mode: AudioRingMode\): Promise<void\> setRingerMode(mode: AudioRingMode): Promise&lt;void&gt;
Sets the ringer mode. This API uses a promise to return the result. Sets the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| ---------- | ----------------------------------- | --------- | ----------------------------------- | | ------ | ------------------------------- | ---- | -------------- |
| mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode. | | mode | [AudioRingMode](#audioringmode) | Yes | Ringer mode.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
...@@ -1094,19 +1082,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => { ...@@ -1094,19 +1082,19 @@ audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
### getRingerMode ### getRingerMode
getRingerMode\(callback: AsyncCallback<AudioRingMode\>\): void getRingerMode(callback: AsyncCallback&lt;AudioRingMode&gt;): void
Obtains the ringer mode. This API uses an asynchronous callback to return the query result. Obtains the ringer mode. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ---------- | ----------------------------------------------- | --------- | ---------------------------------------- | | -------- | ---------------------------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode. | | callback | AsyncCallback&lt;[AudioRingMode](#audioringmode)&gt; | Yes | Callback used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode((err, value) => { audioManager.getRingerMode((err, value) => {
...@@ -1121,19 +1109,19 @@ audioManager.getRingerMode((err, value) => { ...@@ -1121,19 +1109,19 @@ audioManager.getRingerMode((err, value) => {
### getRingerMode ### getRingerMode
getRingerMode\(\): Promise<AudioRingMode\> getRingerMode(): Promise&lt;AudioRingMode&gt;
Obtains the ringer mode. This API uses a promise to return the query result. Obtains the ringer mode. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------------------- | --------------------------------------- | | ---------------------------------------------- | ------------------------------- |
| Promise<[AudioRingMode](#audioringmode)> | Promise used to return the ringer mode. | | Promise&lt;[AudioRingMode](#audioringmode)&gt; | Promise used to return the ringer mode.|
**Example:** **Example**
``` ```
audioManager.getRingerMode().then((value) => { audioManager.getRingerMode().then((value) => {
...@@ -1141,24 +1129,23 @@ audioManager.getRingerMode().then((value) => { ...@@ -1141,24 +1129,23 @@ audioManager.getRingerMode().then((value) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string, callback: AsyncCallback<void\>\): void setAudioParameter(key: string, value: string, callback: AsyncCallback&lt;void&gt;): void
Sets an audio parameter. This API uses an asynchronous callback to return the result. Sets an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | -------- | ------------------------- | ---- | ------------------------ |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set. |
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
...@@ -1170,29 +1157,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => { ...@@ -1170,29 +1157,28 @@ audioManager.setAudioParameter('PBits per sample', '8 bit', (err) => {
}); });
``` ```
### setAudioParameter ### setAudioParameter
setAudioParameter\(key: string, value: string\): Promise<void\> setAudioParameter(key: string, value: string): Promise&lt;void&gt;
Sets an audio parameter. This API uses a promise to return the result. Sets an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter to set. | | key | string | Yes | Key of the audio parameter to set.|
| value | string | Yes | Value of the audio parameter to set. | | value | string | Yes | Value of the audio parameter to set.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
...@@ -1200,23 +1186,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => { ...@@ -1200,23 +1186,22 @@ audioManager.setAudioParameter('PBits per sample', '8 bit').then(() => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string, callback: AsyncCallback<string\>\) getAudioParameter(key: string, callback: AsyncCallback&lt;string&gt;): void
Obtains the value of an audio parameter. This API uses an asynchronous callback to return the query result. Obtains the value of an audio parameter. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ----------------------| --------- | ---------------------------------------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained. |
| callback | AsyncCallback<string> | Yes | Callback used to return the value of the audio parameter. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample', (err, value) => { audioManager.getAudioParameter('PBits per sample', (err, value) => {
...@@ -1228,28 +1213,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => { ...@@ -1228,28 +1213,27 @@ audioManager.getAudioParameter('PBits per sample', (err, value) => {
}); });
``` ```
### getAudioParameter ### getAudioParameter
getAudioParameter\(key: string\): Promise<string\> getAudioParameter(key: string): Promise&lt;string&gt;
Obtains the value of an audio parameter. This API uses a promise to return the query result. Obtains the value of an audio parameter. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Core **System capability**: SystemCapability.Multimedia.Audio.Core
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | ----------------------| --------- | ----------------------------------------------------------- | | ------ | ------ | ---- | ---------------------- |
| key | string | Yes | Key of the audio parameter whose value is to be obtained. | | key | string | Yes | Key of the audio parameter whose value is to be obtained.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | --------------------- | ----------------------------------- |
| Promise<string> | Promise used to return the value of the audio parameter. | | Promise&lt;string&gt; | Promise used to return the value of the audio parameter.|
**Example:** **Example**
``` ```
audioManager.getAudioParameter('PBits per sample').then((value) => { audioManager.getAudioParameter('PBits per sample').then((value) => {
...@@ -1257,24 +1241,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => { ...@@ -1257,24 +1241,22 @@ audioManager.getAudioParameter('PBits per sample').then((value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors\>\): void getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void
Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the query result. Obtains the audio devices with a specific flag. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------------------------------- | --------- | ----------------------------------------- | | ---------- | ------------------------------------------------------------ | ---- | -------------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | | deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. |
| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Yes | Callback used to return the device list. | | callback | AsyncCallback&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Yes | Callback used to return the device list.|
**Example:**
**Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
if (err) { if (err) {
...@@ -1285,29 +1267,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => { ...@@ -1285,29 +1267,27 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
}); });
``` ```
### getDevices ### getDevices
getDevices\(deviceFlag: DeviceFlag\): Promise<AudioDeviceDescriptors\> getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;
Obtains the audio devices with a specific flag. This API uses a promise to return the query result. Obtains the audio devices with a specific flag. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------- | --------- | ------------------- | | ---------- | ------------------------- | ---- | ---------------- |
| deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag. | | deviceFlag | [DeviceFlag](#deviceflag) | Yes | Audio device flag.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------------------------- | ---------------------------------------- | | ------------------------------------------------------------ | ------------------------- |
| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise used to return the device list. | | Promise&lt;[AudioDeviceDescriptors](#audiodevicedescriptors)&gt; | Promise used to return the device list.|
**Example:** **Example**
``` ```
audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
...@@ -1317,21 +1297,21 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { ...@@ -1317,21 +1297,21 @@ audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean, callback: AsyncCallback<void\>\): void setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void
Sets a device to the active state. This API uses an asynchronous callback to return the result. Sets a device to the active state. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
...@@ -1343,31 +1323,29 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { ...@@ -1343,31 +1323,29 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => {
}); });
``` ```
### setDeviceActive ### setDeviceActive
setDeviceActive\(deviceType: DeviceType, active: boolean\): Promise<void\> setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;
Sets a device to the active state. This API uses a promise to return the result. Sets a device to the active state. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ---------------------------------------------------------------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
| active | boolean | Yes | Active status to set. The value true means to set the device to the active status, and false means the opposite. | | active | boolean | Yes | Active state to set. The value **true** means to set the device to the active state, and **false** means the opposite. |
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
...@@ -1375,23 +1353,22 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { ...@@ -1375,23 +1353,22 @@ audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => {
}); });
``` ```
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType, callback: AsyncCallback<boolean\>\): void isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a device is active. This API uses an asynchronous callback to return the query result. Checks whether a device is active. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | -------------------------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the active status of the device. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
...@@ -1406,25 +1383,25 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { ...@@ -1406,25 +1383,25 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => {
### isDeviceActive ### isDeviceActive
isDeviceActive\(deviceType: DeviceType\): Promise<boolean\> isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;
Checks whether a device is active. This API uses a promise to return the query result. Checks whether a device is active. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | ---------------------------------------| --------- | ----------------------------------------- | | ---------- | ------------------------------------- | ---- | ------------------ |
| deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type. | | deviceType | [ActiveDeviceType](#activedevicetype) | Yes | Audio device type.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ---------------------- | ------------------------------- |
| Promise<boolean> | Promise used to return the active status of the device. | | Promise&lt;boolean&gt; | Promise used to return the active state of the device.|
**Example:** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
...@@ -1432,23 +1409,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { ...@@ -1432,23 +1409,22 @@ audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => {
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean, callback: AsyncCallback<void\>\): void setMicrophoneMute(mute: boolean, callback: AsyncCallback&lt;void&gt;): void
Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result. Mutes or unmutes the microphone. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | | -------- | ------------------------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
| callback | AsyncCallback<void> | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioManager.setMicrophoneMute(true, (err) => { audioManager.setMicrophoneMute(true, (err) => {
...@@ -1460,30 +1436,27 @@ audioManager.setMicrophoneMute(true, (err) => { ...@@ -1460,30 +1436,27 @@ audioManager.setMicrophoneMute(true, (err) => {
}); });
``` ```
### setMicrophoneMute ### setMicrophoneMute
setMicrophoneMute\(mute: boolean\): Promise<void\> setMicrophoneMute(mute: boolean): Promise&lt;void&gt;
Mutes or unmutes the microphone. This API uses a promise to return the result. Mutes or unmutes the microphone. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| --------- | -------------------- | --------- | ---------------------------------------------------------------------------------------------- | | ------ | ------- | ---- | --------------------------------------------- |
| mute | boolean | Yes | Mute status to set. The value true means to mute the microphone, and false means the opposite. | | mute | boolean | Yes | Mute status to set. The value **true** means to mute the microphone, and **false** means the opposite.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ----------------------------------- | | ------------------- | ------------------------------- |
| Promise<void> | Promise used to return the result. | | Promise&lt;void&gt; | Promise used to return the result.|
</table> **Example**
**Example:**
``` ```
audioManager.setMicrophoneMute(true).then(() => { audioManager.setMicrophoneMute(true).then(() => {
...@@ -1491,25 +1464,23 @@ audioManager.setMicrophoneMute(true).then(() => { ...@@ -1491,25 +1464,23 @@ audioManager.setMicrophoneMute(true).then(() => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(callback: AsyncCallback<boolean\>\): void isMicrophoneMute(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the microphone is muted. This API uses an asynchronous callback to return the query result. Checks whether the microphone is muted. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | -------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
**Example:** **Example**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute((err, value) => { audioManager.isMicrophoneMute((err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the mute status of the microphone. ${err.message}'); console.error('Failed to obtain the mute status of the microphone. ${err.message}');
...@@ -1519,25 +1490,24 @@ audioManager.isMicrophoneMute((err, value) => { ...@@ -1519,25 +1490,24 @@ audioManager.isMicrophoneMute((err, value) => {
}); });
``` ```
### isMicrophoneMute ### isMicrophoneMute
isMicrophoneMute\(\): Promise<boolean\> isMicrophoneMute(): Promise&lt;boolean&gt;
Checks whether the microphone is muted. This API uses a promise to return the query result. Checks whether the microphone is muted. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Return value:** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | ---------------------- | ------------------------------------------------------------ |
| Promise<boolean> | Promise used to return the mute status of the microphone. The value true means that the microphone is muted, and false means the opposite. | | Promise&lt;boolean&gt; | Promise used to return the mute status of the microphone. The value **true** means that the microphone is muted, and **false** means the opposite.|
**Example**
**Example:**
``` ```
var audioManager = audio.getAudioManager();
audioManager.isMicrophoneMute().then((value) => { audioManager.isMicrophoneMute().then((value) => {
console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value); console.log('Promise returned to indicate that the mute status of the microphone is obtained.', + value);
}); });
...@@ -1547,20 +1517,20 @@ audioManager.isMicrophoneMute().then((value) => { ...@@ -1547,20 +1517,20 @@ audioManager.isMicrophoneMute().then((value) => {
on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void on(type: 'volumeChange', callback: Callback\<VolumeEvent>): void
Subscribes to system volume change events. This API uses a callback to get volume change events. Subscribes to system volume change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Volume **System capability**: SystemCapability.Multimedia.Audio.Volume
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------------------------| :-------------| :------------------------------------------------------------------------------------------------------------------------------------------------------------ | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'volumeChange' means the system volume change event, which is triggered when a system volume change is detected. | | type | string | Yes | Type of event to subscribe to. The value **volumeChange** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to get the system volume change event. | | callback | Callback<[VolumeEvent](#volumeevent8)> | Yes | Callback used to return the system volume change event. |
**Example:** **Example**
``` ```
audioManager.on('volumeChange', (volumeEvent) => { audioManager.on('volumeChange', (volumeEvent) => {
...@@ -1570,25 +1540,24 @@ audioManager.on('volumeChange', (volumeEvent) => { ...@@ -1570,25 +1540,24 @@ audioManager.on('volumeChange', (volumeEvent) => {
}); });
``` ```
### on('ringerModeChange')<sup>8+</sup> ### on('ringerModeChange')<sup>8+</sup>
on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void on(type: 'ringerModeChange', callback: Callback\<AudioRingMode>): void
Subscribes to ringer mode change events. This API uses a callback to get ringer mode changes. Subscribes to ringer mode change events.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------- | :-------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------- | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'ringerModeChange' means the ringer mode change event, which is triggered when a ringer mode change is detected. | | type | string | Yes | Type of event to subscribe to. The value **ringerModeChange** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to get the updated ringer mode. | | callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the updated ringer mode. |
**Example:** **Example**
``` ```
audioManager.on('ringerModeChange', (ringerMode) => { audioManager.on('ringerModeChange', (ringerMode) => {
...@@ -1600,18 +1569,18 @@ audioManager.on('ringerModeChange', (ringerMode) => { ...@@ -1600,18 +1569,18 @@ audioManager.on('ringerModeChange', (ringerMode) => {
on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void on(type: 'deviceChange', callback: Callback<DeviceChangeAction\>): void
Subscribes to device change events. When a device is connected/disconnected, registered clients will receive the callback. Subscribes to device change events. When a device is connected or disconnected, registered clients will receive the callback.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :---------| :---------------------------------------------------------------------------------------------------------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to. The value 'deviceChange' means the device change event, which is triggered when a device change is detected. | | type | string | Yes | Type of event to subscribe to. 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 obtain the device update details. | | callback | Callback<[DeviceChangeAction](#DeviceChangeAction)\> | Yes | Callback used to return the device update details. |
**Example:** **Example**
``` ```
audioManager.on('deviceChange', (deviceChanged) => { audioManager.on('deviceChange', (deviceChanged) => {
...@@ -1626,20 +1595,18 @@ audioManager.on('deviceChange', (deviceChanged) => { ...@@ -1626,20 +1595,18 @@ audioManager.on('deviceChange', (deviceChanged) => {
off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
Unsubscribes from audio device connection change events. Unsubscribes from device change events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Device
**System capability:** SystemCapability.Multimedia.Audio.Device **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Type of event to unsubscribe from. 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. |
| Name | Type | Mandatory | Description | **Example**
| :------- | :-------------------------------------------------- | :---------| :-------------------------------------------------- |
| type | string | Yes | Type of the event to unsubscribe from. |
| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | No | Callback used to obtain the device update details. |
**Example:**
``` ```
audioManager.off('deviceChange', (deviceChanged) => { audioManager.off('deviceChange', (deviceChanged) => {
...@@ -1647,26 +1614,23 @@ audioManager.off('deviceChange', (deviceChanged) => { ...@@ -1647,26 +1614,23 @@ audioManager.off('deviceChange', (deviceChanged) => {
}); });
``` ```
### on('interrupt') ### on('interrupt')
on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\<InterruptAction>): void
Subscribes to audio interrupt events. When the application's audio is interrupted by another playback event, the application will receive the callback. Subscribes to audio interruption events. When the application's audio is interrupted by another playback event, the application will receive the callback.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to subscribe to. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application.| | type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt | Yes | Audio interrupt event type. | | interrupt | AudioInterrupt | Yes | Audio interruption event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | Yes | Audio interrupt event callback method. | | callback | Callback<[InterruptAction](#interruptaction)> | Yes | Callback invoked for the audio interruption event. |
**Example:** **Example**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1690,21 +1654,19 @@ this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1690,21 +1654,19 @@ this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\<InterruptAction>): void
Unsubscribes from audio interrupt events. Unsubscribes from audio interruption events.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. **System capability**: SystemCapability.Multimedia.Audio.Renderer
**System capability:** SystemCapability.Multimedia.Audio.Renderer **Parameters**
**Parameters:** | Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of event to unsubscribe from. The value **interrupt** means the audio interruption event, which is triggered when the audio playback of the current application is interrupted by another application.|
| interrupt | AudioInterrupt | Yes | Audio interruption event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | No | Callback invoked for the audio interruption event. |
| Name | Type | Mandatory | Description | **Example**
| --------- | --------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| type | string | Yes | Type of event to unsubscribe from. The value 'interrupt' means the audio interrupt event, which is triggered when the audio playback of the current application is interrupted by another application. |
| interrupt | AudioInterrupt | Yes | Audio interrupt event type. |
| callback | Callback<[InterruptAction](#interruptaction)> | No | Audio interrupt event callback method. |
**Example:**
``` ```
var interAudioInterrupt = { var interAudioInterrupt = {
...@@ -1720,25 +1682,24 @@ this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { ...@@ -1720,25 +1682,24 @@ this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void setAudioScene\(scene: AudioScene, callback: AsyncCallback<void\>\): void
Sets the audio scene mode to change audio strategies. This API uses an asynchronous callback to return the result. Sets an audio scene. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------ | :-------- | :---------------------------------- | | :------- | :----------------------------------- | :--- | :------------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. | | scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
...@@ -1750,32 +1711,29 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => { ...@@ -1750,32 +1711,29 @@ audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
}); });
``` ```
### setAudioScene<sup>8+</sup> ### setAudioScene<sup>8+</sup>
setAudioScene\(scene: AudioScene\): Promise<void\> setAudioScene\(scene: AudioScene\): Promise<void\>
Sets the audio scene mode to change audio strategies. This API uses a promise to return the result. Sets an audio scene. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications. This is a system API and cannot be called by third-party applications.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:**
| Name | Type | Mandatory | Description | **Parameters**
| :------- | :-------------------------------------- | :-------- | :---------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene mode. |
| Name| Type | Mandatory| Description |
| :----- | :----------------------------------- | :--- | :------------- |
| scene | <a href="#audioscene">AudioScene</a> | Yes | Audio scene to set.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :---------------------------------- | | :------------- | :------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example**
**Example:**
``` ```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => {
...@@ -1785,22 +1743,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() ...@@ -1785,22 +1743,21 @@ audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(()
}); });
``` ```
### getAudioScene<sup>8+</sup> ### getAudioScene<sup>8+</sup>
getAudioScene\(callback: AsyncCallback<AudioScene\>\): void getAudioScene\(callback: AsyncCallback<AudioScene\>\): void
Obtains the audio scene mode. This API uses an asynchronous callback to return the query result. Obtains the audio scene. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------------- | :-------- | :-------------------------------------------- | | :------- | :-------------------------------------------------- | :--- | :--------------------------- |
| callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene mode. | | callback | AsyncCallback<<a href="#audioscene">AudioScene</a>> | Yes | Callback used to return the audio scene.|
**Example:** **Example**
``` ```
audioManager.getAudioScene((err, value) => { audioManager.getAudioScene((err, value) => {
...@@ -1817,18 +1774,17 @@ audioManager.getAudioScene((err, value) => { ...@@ -1817,18 +1774,17 @@ audioManager.getAudioScene((err, value) => {
getAudioScene\(\): Promise<AudioScene\> getAudioScene\(\): Promise<AudioScene\>
Obtains the audio scene mode. This API uses a promise to return the query result. Obtains the audio scene. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Communication **System capability**: SystemCapability.Multimedia.Audio.Communication
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------- | :------------------------------------------- | | :-------------------------------------------- | :--------------------------- |
| Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene mode. | | Promise<<a href="#audioscene">AudioScene</a>> | Promise used to return the audio scene.|
**Example**
**Example:**
``` ```
audioManager.getAudioScene().then((value) => { audioManager.getAudioScene().then((value) => {
...@@ -1842,20 +1798,18 @@ audioManager.getAudioScene().then((value) => { ...@@ -1842,20 +1798,18 @@ audioManager.getAudioScene().then((value) => {
Describes an audio device. Describes an audio device.
**System capability:** SystemCapability.Multimedia.Audio.Device **System capability**: SystemCapability.Multimedia.Audio.Device
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| ---------- | ------------------------- | -------- | -------- | ------------------ | | ---------- | ------------------------- | ---- | ---- | ---------- |
| deviceRole | [DeviceRole](#devicerole) | Yes | No | Audio device role. | | deviceRole | [DeviceRole](#devicerole) | Yes | No | Device role.|
| deviceType | [DeviceType](#devicetype) | Yes | No | Audio device type. | | deviceType | [DeviceType](#devicetype) | Yes | No | Device type.|
## AudioDeviceDescriptors ## AudioDeviceDescriptors
Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only. Array of [AudioDeviceDescriptor](#audiodevicedescriptor), which is read-only.
**System capability:** SystemCapability.Multimedia.Audio.Device **Example**
**Example:**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -1880,45 +1834,40 @@ promise.then(function (value) { ...@@ -1880,45 +1834,40 @@ promise.then(function (value) {
} }
}); });
``` ```
## AudioRenderer<sup>8+</sup>
Provides related APIs for audio rendering. Before calling the AudioRenderer API, you need to create an instance through [createAudioRenderer](#audiocreateaudiorenderer8). ## AudioRenderer<sup>8+</sup>
**System capability:** SystemCapability.Multimedia.Audio.Renderer
### state<sup>8+</sup>
readonly state: AudioState Provides APIs for audio rendering. Before calling any API in **AudioRenderer**, you must use [createAudioRenderer](#audiocreateaudiorenderer8) to create an **AudioRenderer** instance.
Defines the current render state. ### Attributes
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
| Name | Type | Readable | Writable | Description | | Name | Type | Readable| Writable| Description |
| :---- | :-------------------------- | :------- | :------- | :------------------ | | ----- | -------------------------- | ---- | ---- | ------------------ |
| state | [AudioState](#audiostate8) | Yes | No | Audio render state. | | state<sup>8+</sup> | [AudioState](#audiostate8) | Yes | No | Audio renderer state.|
**Example:** **Example**
``` ```
var state = audioRenderer.state; var state = audioRenderer.state;
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void getRendererInfo(callback: AsyncCallback<AudioRendererInfo\>): void
Obtains the renderer information provided while creating a renderer instance. This API uses an asynchronous callback to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :------------------------------------------------------- | :--- | :--------------------- |
| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)> | Yes | Callback used to return the renderer information. | | callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | Yes | Callback used to return the renderer information.|
**Example:** **Example**
``` ```
audioRenderer.getRendererInfo((err, rendererInfo) => { audioRenderer.getRendererInfo((err, rendererInfo) => {
...@@ -1929,22 +1878,21 @@ audioRenderer.getRendererInfo((err, rendererInfo) => { ...@@ -1929,22 +1878,21 @@ audioRenderer.getRendererInfo((err, rendererInfo) => {
}); });
``` ```
### getRendererInfo<sup>8+</sup> ### getRendererInfo<sup>8+</sup>
getRendererInfo(): Promise<AudioRendererInfo\> getRendererInfo(): Promise<AudioRendererInfo\>
Obtains the renderer information provided while creating a renderer instance. This API uses a promise to return the result. Obtains the renderer information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | -------------------------------------------------- | ------------------------------- |
| Promise<[AudioRendererInfo](#audiorendererinfo8)> | Promise used to return the renderer information. | | Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise used to return the renderer information.|
**Example:** **Example**
``` ```
audioRenderer.getRendererInfo().then((rendererInfo) => { audioRenderer.getRendererInfo().then((rendererInfo) => {
...@@ -1956,24 +1904,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => { ...@@ -1956,24 +1904,23 @@ audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message); console.log('AudioFrameworkRenderLog: RendererInfo :ERROR: '+err.message);
resultFlag = false; resultFlag = false;
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the renderer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------ | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo((err, streamInfo) => { audioRenderer.getStreamInfo((err, streamInfo) => {
...@@ -1989,17 +1936,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => { ...@@ -1989,17 +1936,17 @@ audioRenderer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the renderer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioRenderer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------------------------------------------- | :--------------------------------------------- | | :--------------------------------------------- | :--------------------- |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioRenderer.getStreamInfo().then((streamInfo) => { audioRenderer.getStreamInfo().then((streamInfo) => {
...@@ -2011,7 +1958,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => { ...@@ -2011,7 +1958,6 @@ audioRenderer.getStreamInfo().then((streamInfo) => {
}).catch((err) => { }).catch((err) => {
console.log('ERROR: '+err.message); console.log('ERROR: '+err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2020,16 +1966,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2020,16 +1966,15 @@ start(callback: AsyncCallback<void\>): void
Starts the renderer. This API uses an asynchronous callback to return the result. Starts the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.start((err) => { audioRenderer.start((err) => {
...@@ -2047,15 +1992,15 @@ start(): Promise<void\> ...@@ -2047,15 +1992,15 @@ start(): Promise<void\>
Starts the renderer. This API uses a promise to return the result. Starts the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.start().then(() => { audioRenderer.start().then(() => {
...@@ -2065,23 +2010,21 @@ audioRenderer.start().then(() => { ...@@ -2065,23 +2010,21 @@ audioRenderer.start().then(() => {
}); });
``` ```
### pause<sup>8+</sup> ### pause<sup>8+</sup>
pause(callback: AsyncCallback\<void>): void pause(callback: AsyncCallback\<void>): void
Pauses rendering. This API uses an asynchronous callback to return the result. Pauses rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------ | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.pause((err) => { audioRenderer.pause((err) => {
...@@ -2099,15 +2042,15 @@ pause(): Promise\<void> ...@@ -2099,15 +2042,15 @@ pause(): Promise\<void>
Pauses rendering. This API uses a promise to return the result. Pauses rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.pause().then(() => { audioRenderer.pause().then(() => {
...@@ -2123,16 +2066,15 @@ drain(callback: AsyncCallback\<void>): void ...@@ -2123,16 +2066,15 @@ drain(callback: AsyncCallback\<void>): void
Drains the playback buffer. This API uses an asynchronous callback to return the result. Drains the playback buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :---------------------------------------| | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
| | | | |
**Example:** **Example**
``` ```
audioRenderer.drain((err) => { audioRenderer.drain((err) => {
...@@ -2150,15 +2092,15 @@ drain(): Promise\<void> ...@@ -2150,15 +2092,15 @@ drain(): Promise\<void>
Drains the playback buffer. This API uses a promise to return the result. Drains the playback buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.drain().then(() => { audioRenderer.drain().then(() => {
...@@ -2168,22 +2110,21 @@ audioRenderer.drain().then(() => { ...@@ -2168,22 +2110,21 @@ audioRenderer.drain().then(() => {
}); });
``` ```
### stop<sup>8+</sup> ### stop<sup>8+</sup>
stop(callback: AsyncCallback\<void>): void stop(callback: AsyncCallback\<void>): void
Stops rendering. This API uses an asynchronous callback to return the result. Stops rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop((err) => { audioRenderer.stop((err) => {
...@@ -2201,15 +2142,15 @@ stop(): Promise\<void> ...@@ -2201,15 +2142,15 @@ stop(): Promise\<void>
Stops rendering. This API uses a promise to return the result. Stops rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.stop().then(() => { audioRenderer.stop().then(() => {
...@@ -2219,22 +2160,21 @@ audioRenderer.stop().then(() => { ...@@ -2219,22 +2160,21 @@ audioRenderer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback\<void>): void release(callback: AsyncCallback\<void>): void
Releases the renderer. This API uses an asynchronous callback to return the result. Releases the renderer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | -------- | -------------------- | ---- | ---------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release((err) => { audioRenderer.release((err) => {
...@@ -2252,15 +2192,15 @@ release(): Promise\<void> ...@@ -2252,15 +2192,15 @@ release(): Promise\<void>
Releases the renderer. This API uses a promise to return the result. Releases the renderer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.release().then(() => { audioRenderer.release().then(() => {
...@@ -2276,16 +2216,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void ...@@ -2276,16 +2216,16 @@ write(buffer: ArrayBuffer, callback: AsyncCallback\<number>): void
Writes the buffer. This API uses an asynchronous callback to return the result. Writes the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :--------------------------------------------------------------------------------------------------- | | -------- | ---------------------- | ---- | --------------------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer to be written. | | buffer | ArrayBuffer | Yes | Buffer to be written. |
| callback | AsyncCallback<boolean\> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | callback | AsyncCallback\<number> | Yes | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2303,22 +2243,21 @@ audioRenderer.write(buf, (err, writtenbytes) => { ...@@ -2303,22 +2243,21 @@ audioRenderer.write(buf, (err, writtenbytes) => {
}); });
``` ```
### write<sup>8+</sup> ### write<sup>8+</sup>
write(buffer: ArrayBuffer): Promise\<number> write(buffer: ArrayBuffer): Promise\<number>
Writes the buffer. This API uses a promise to return the result. Writes the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :--------------------------------------------------------------------------------------------------- | | ---------------- | ------------------------------------------------------------ |
| Promise<number\> | Returns the number of bytes written if the operation is successful; returns an error code otherwise. | | Promise\<number> | Returns the number of bytes written if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
import audio from '@ohos.multimedia.audio'; import audio from '@ohos.multimedia.audio';
...@@ -2343,17 +2282,17 @@ audioRenderer.write(buf).then((writtenbytes) => { ...@@ -2343,17 +2282,17 @@ audioRenderer.write(buf).then((writtenbytes) => {
getAudioTime(callback: AsyncCallback\<number>): void getAudioTime(callback: AsyncCallback\<number>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback\<number> | Yes | Callback used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime((err, timestamp) => { audioRenderer.getAudioTime((err, timestamp) => {
...@@ -2361,22 +2300,21 @@ audioRenderer.getAudioTime((err, timestamp) => { ...@@ -2361,22 +2300,21 @@ audioRenderer.getAudioTime((err, timestamp) => {
}); });
``` ```
### getAudioTime<sup>8+</sup> ### getAudioTime<sup>8+</sup>
getAudioTime(): Promise\<number> getAudioTime(): Promise\<number>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | ---------------- | ----------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise\<number> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioRenderer.getAudioTime().then((timestamp) => { audioRenderer.getAudioTime().then((timestamp) => {
...@@ -2386,22 +2324,21 @@ audioRenderer.getAudioTime().then((timestamp) => { ...@@ -2386,22 +2324,21 @@ audioRenderer.getAudioTime().then((timestamp) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(callback: AsyncCallback\<number>): void getBufferSize(callback: AsyncCallback\<number>): void
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback\<number> | Yes | Callback used to return the buffer size.|
**Example:** **Example**
``` ```
audioRenderer.getBufferSize((err, bufferSize) => { audioRenderer.getBufferSize((err, bufferSize) => {
...@@ -2413,22 +2350,21 @@ let buf = new ArrayBuffer(bufferSize); ...@@ -2413,22 +2350,21 @@ let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf); ss.readSync(buf);
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise\<number> getBufferSize(): Promise\<number>
Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | ---------------- | --------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise\<number> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
audioRenderer.getBufferSize().then((bufferSize) => { audioRenderer.getBufferSize().then((bufferSize) => {
...@@ -2445,16 +2381,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void ...@@ -2445,16 +2381,16 @@ setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\<void>): void
Sets the render rate. This API uses an asynchronous callback to return the result. Sets the render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------ | :-------- | :---------------------------------- | | -------- | ---------------------------------------- | ---- | ------------------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
...@@ -2466,28 +2402,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => ...@@ -2466,28 +2402,27 @@ audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) =>
}); });
``` ```
### setRenderRate<sup>8+</sup> ### setRenderRate<sup>8+</sup>
setRenderRate(rate: AudioRendererRate): Promise\<void> setRenderRate(rate: AudioRendererRate): Promise\<void>
Sets the render rate. This API uses a promise to return the result. Sets the render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :--- | :--------------------------------------- | :-------- | :----------------- | | ------ | ---------------------------------------- | ---- | ------------ |
| rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate. | | rate | [AudioRendererRate](#audiorendererrate8) | Yes | Audio render rate.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | -------------- | ------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise\<void> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => { audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
...@@ -2503,15 +2438,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void ...@@ -2503,15 +2438,15 @@ getRenderRate(callback: AsyncCallback\<AudioRendererRate>): void
Obtains the current render rate. This API uses an asynchronous callback to return the result. Obtains the current render rate. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :--------------------------------------------- | | -------- | ------------------------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)\> | Yes | Callback used to return the audio render rate. | | callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | Yes | Callback used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate((err, renderrate) => { audioRenderer.getRenderRate((err, renderrate) => {
...@@ -2519,22 +2454,21 @@ audioRenderer.getRenderRate((err, renderrate) => { ...@@ -2519,22 +2454,21 @@ audioRenderer.getRenderRate((err, renderrate) => {
}); });
``` ```
### getRenderRate<sup>8+</sup> ### getRenderRate<sup>8+</sup>
getRenderRate(): Promise\<AudioRendererRate> getRenderRate(): Promise\<AudioRendererRate>
Obtains the current render rate. This API uses a promise to return the result. Obtains the current render rate. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :-------------------------------------------- | | ------------------------------------------------- | ------------------------- |
| Promise<<[AudioRendererRate](#audiorendererrate8)\> | Promise used to return the audio render rate. | | Promise<[AudioRendererRate](#audiorendererrate8)> | Promise used to return the audio render rate.|
**Example:** **Example**
``` ```
audioRenderer.getRenderRate().then((renderRate) => { audioRenderer.getRenderRate().then((renderRate) => {
...@@ -2544,23 +2478,22 @@ audioRenderer.getRenderRate().then((renderRate) => { ...@@ -2544,23 +2478,22 @@ audioRenderer.getRenderRate().then((renderRate) => {
}); });
``` ```
### on('interrupt')<sup>9+</sup> ### on('interrupt')<sup>9+</sup>
on(type: 'interrupt', callback: Callback\<InterruptEvent>): void on(type: 'interrupt', callback: Callback\<InterruptEvent>): void
Subscribes to audio interrupt events. This API uses a callback to get interrupt events. The interrupt event is triggered when audio rendering is interrupted. Subscribes to audio interruption events. This API uses a callback to get interrupt events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :-------------------------------------------- | :-------- | :---------------------------------------------- | | -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | Yes | Type of the playback event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **interrupt** means the audio interruption event, which is triggered when audio playback is interrupted.|
| callback | Callback<[InterruptEvent](#interruptevent9)\> | Yes | Callback used to listen for interrupt callback. | | callback | Callback<[InterruptEvent](#interruptevent9)> | Yes | Callback used to return the audio interruption event. |
**Example:** **Example**
``` ```
audioRenderer.on('interrupt', (interruptEvent) => { audioRenderer.on('interrupt', (interruptEvent) => {
...@@ -2594,19 +2527,19 @@ audioRenderer.on('interrupt', (interruptEvent) => { ...@@ -2594,19 +2527,19 @@ audioRenderer.on('interrupt', (interruptEvent) => {
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames rendered reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames rendered reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :---------------------------------------- |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('markReach', 1000, (position) => { audioRenderer.on('markReach', 1000, (position) => {
...@@ -2623,15 +2556,15 @@ off(type: 'markReach'): void ...@@ -2623,15 +2556,15 @@ off(type: 'markReach'): void
Unsubscribes from mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :------------------------------------------------ |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **markReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('markReach'); audioRenderer.off('markReach');
...@@ -2641,19 +2574,19 @@ audioRenderer.off('markReach'); ...@@ -2641,19 +2574,19 @@ audioRenderer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame rendering reaches the value of frame parameter, the callback is invoked. Subscribes to period reached events. When the period of frame rendering reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the renderer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame rendering reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame rendering is listened. The value must be greater than 0. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioRenderer.on('periodReach', 1000, (position) => { audioRenderer.on('periodReach', 1000, (position) => {
...@@ -2669,15 +2602,15 @@ off(type: 'periodReach'): void ...@@ -2669,15 +2602,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------------- |
| type | string | Yes | Type of the renderer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value is fixed at **periodReach**.|
**Example:** **Example**
``` ```
audioRenderer.off('periodReach') audioRenderer.off('periodReach')
...@@ -2689,16 +2622,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -2689,16 +2622,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Renderer **System capability**: SystemCapability.Multimedia.Audio.Renderer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioRenderer.on('stateChange', (state) => { audioRenderer.on('stateChange', (state) => {
...@@ -2713,42 +2646,37 @@ audioRenderer.on('stateChange', (state) => { ...@@ -2713,42 +2646,37 @@ audioRenderer.on('stateChange', (state) => {
## AudioCapturer<sup>8+</sup> ## AudioCapturer<sup>8+</sup>
Provides related APIs for audio capture. Before calling the API of AudioCapturer, you need to create an instance through [createAudioCapturer](#audiocreateaudiocapturer8). Provides APIs for audio capture. Before calling any API in **AudioCapturer**, you must use [createAudioCapturer](#audiocreateaudiocapturer8) to create an **AudioCapturer** instance.
### state<sup>8+</sup> ### Attributes
readonly state: AudioState **System capability**: SystemCapability.Multimedia.Audio.Capturer
Defines the current capture state. | Name | Type | Readable| Writable| Description |
| :---- | :------------------------- | :--- | :--- | :--------------- |
| state<sup>8+</sup> | [AudioState](#audiostate8) | Yes| No | Audio capturer state.|
**System capability:** SystemCapability.Multimedia.Audio.Capturer **Example**
| Name | Type | Readable | Writable | Description |
| :---- | :------------------------- | :------- | :------- | :------------------- |
| state | [AudioState](#audiostate8) | Yes | No | Audio capture state. |
**Example:**
``` ```
var state = audioCapturer.state; var state = audioCapturer.state;
``` ```
### getCapturerInfo<sup>8+</sup> ### getCapturerInfo<sup>8+</sup>
getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void getCapturerInfo(callback: AsyncCallback<AudioCapturerInfo\>): void
Obtains the capturer information provided while creating a capturer instance. This API uses an asynchronous callback to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------------------------------------- | :-------- | :------------------------------------------------ | | :------- | :-------------------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<[AudioCapturerInfo](#audiocapturerinfo)\> | Yes | Callback used to return the capturer information. | | callback | AsyncCallback<AudioCapturerInfo\> | Yes | Callback used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo((err, capturerInfo) => { audioCapturer.getCapturerInfo((err, capturerInfo) => {
...@@ -2767,17 +2695,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => { ...@@ -2767,17 +2695,17 @@ audioCapturer.getCapturerInfo((err, capturerInfo) => {
getCapturerInfo(): Promise<AudioCapturerInfo\> getCapturerInfo(): Promise<AudioCapturerInfo\>
Obtains the capturer information provided while creating a capturer instance. This API uses a promise to return the result. Obtains the capturer information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------------------------------------- | :----------------------------------------------- | | :------------------------------------------------ | :---------------------------------- |
| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information. | | Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | Promise used to return the capturer information.|
**Example:** **Example**
``` ```
audioCapturer.getCapturerInfo().then((audioParamsGet) => { audioCapturer.getCapturerInfo().then((audioParamsGet) => {
...@@ -2792,24 +2720,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => { ...@@ -2792,24 +2720,23 @@ audioCapturer.getCapturerInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message); console.log('AudioFrameworkRecLog: CapturerInfo :ERROR: '+err.message);
}); });
``` ```
### getStreamInfo<sup>8+</sup> ### getStreamInfo<sup>8+</sup>
getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void getStreamInfo(callback: AsyncCallback<AudioStreamInfo\>): void
Obtains the capturer stream information. This API uses an asynchronous callback to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------------------------------------------- | :-------- | :---------------------------------------------- | | :------- | :--------------------------------------------------- | :--- | :------------------------------- |
| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information. | | callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | Yes | Callback used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo((err, streamInfo) => { audioCapturer.getStreamInfo((err, streamInfo) => {
...@@ -2829,17 +2756,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => { ...@@ -2829,17 +2756,17 @@ audioCapturer.getStreamInfo((err, streamInfo) => {
getStreamInfo(): Promise<AudioStreamInfo\> getStreamInfo(): Promise<AudioStreamInfo\>
Obtains the capturer stream information. This API uses a promise to return the result. Obtains the stream information of this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :---------------------------------------------------- | :----------------------------------------------- | | :--------------------------------------------- | :------------------------------ |
| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information. | | Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise used to return the stream information.|
**Example:** **Example**
``` ```
audioCapturer.getStreamInfo().then((audioParamsGet) => { audioCapturer.getStreamInfo().then((audioParamsGet) => {
...@@ -2851,7 +2778,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => { ...@@ -2851,7 +2778,6 @@ audioCapturer.getStreamInfo().then((audioParamsGet) => {
}).catch((err) => { }).catch((err) => {
console.log('getStreamInfo :ERROR: ' + err.message); console.log('getStreamInfo :ERROR: ' + err.message);
}); });
``` ```
### start<sup>8+</sup> ### start<sup>8+</sup>
...@@ -2860,15 +2786,15 @@ start(callback: AsyncCallback<void\>): void ...@@ -2860,15 +2786,15 @@ start(callback: AsyncCallback<void\>): void
Starts capturing. This API uses an asynchronous callback to return the result. Starts capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :-------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start((err) => { audioCapturer.start((err) => {
...@@ -2887,15 +2813,15 @@ start(): Promise<void\> ...@@ -2887,15 +2813,15 @@ start(): Promise<void\>
Starts capturing. This API uses a promise to return the result. Starts capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.start().then(() => { audioCapturer.start().then(() => {
...@@ -2918,15 +2844,15 @@ stop(callback: AsyncCallback<void\>): void ...@@ -2918,15 +2844,15 @@ stop(callback: AsyncCallback<void\>): void
Stops capturing. This API uses an asynchronous callback to return the result. Stops capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop((err) => { audioCapturer.stop((err) => {
...@@ -2945,15 +2871,15 @@ stop(): Promise<void\> ...@@ -2945,15 +2871,15 @@ stop(): Promise<void\>
Stops capturing. This API uses a promise to return the result. Stops capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.stop().then(() => { audioCapturer.stop().then(() => {
...@@ -2969,22 +2895,21 @@ audioCapturer.stop().then(() => { ...@@ -2969,22 +2895,21 @@ audioCapturer.stop().then(() => {
}); });
``` ```
### release<sup>8+</sup> ### release<sup>8+</sup>
release(callback: AsyncCallback<void\>): void release(callback: AsyncCallback<void\>): void
Releases the capturer. This API uses an asynchronous callback to return the result. Releases this **AudioCapturer** instance. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :---------------------- | :-------- | :------------------------------------- | | :------- | :------------------- | :--- | :---------------------------------- |
| callback | AsyncCallback<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback<void\> | Yes | Callback used to return the result. |
**Example:** **Example**
``` ```
audioCapturer.release((err) => { audioCapturer.release((err) => {
...@@ -3001,20 +2926,19 @@ audioCapturer.release((err) => { ...@@ -3001,20 +2926,19 @@ audioCapturer.release((err) => {
release(): Promise<void\> release(): Promise<void\>
Releases the capturer. This API uses a promise to return the result. Releases this **AudioCapturer** instance. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :------------- | :--------------------------------- | | :------------- | :---------------------------- |
| Promise<void\> | Promise used to return the result. | | Promise<void\> | Promise used to return the result.|
**Example:** **Example**
``` ```
audioCapturer.release().then(() => { audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer release : SUCCESS'); console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
...@@ -3027,7 +2951,6 @@ audioCapturer.release().then(() => { ...@@ -3027,7 +2951,6 @@ audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
stateFlag=false stateFlag=false
}); });
``` ```
...@@ -3035,19 +2958,19 @@ audioCapturer.release().then(() => { ...@@ -3035,19 +2958,19 @@ audioCapturer.release().then(() => {
read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void read(size: number, isBlockingRead: boolean, callback: AsyncCallback<ArrayBuffer\>): void
Reads the buffer from the audio capturer. This API uses an asynchronous callback to return the result. Reads the buffer. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :-------------------------- | :-------- | :-------------------------------------------- | | :------------- | :-------------------------- | :--- | :------------------------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation. |
| callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer. | | callback | AsyncCallback<ArrayBuffer\> | Yes | Callback used to return the buffer.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true, async(err, buffer) => { audioCapturer.read(bufferSize, true, async(err, buffer) => {
...@@ -3062,24 +2985,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => { ...@@ -3062,24 +2985,24 @@ audioCapturer.read(bufferSize, true, async(err, buffer) => {
read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\> read(size: number, isBlockingRead: boolean): Promise<ArrayBuffer\>
Reads the buffer from the audio capturer. This API uses a promise to return the result. Reads the buffer. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------------- | :--------- | :-------- | :-------------------------------------------- | | :------------- | :------ | :--- | :--------------- |
| size | number | Yes | Number of bytes to read. | | size | number | Yes | Number of bytes to read. |
| isBlockingRead | boolean | Yes | Whether the read operation should be blocked. | | isBlockingRead | boolean | Yes | Whether to block the read operation.|
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :-------------------- | :----------------------------------------------------------------------------------------------- | | :-------------------- | :----------------------------------------------------- |
| Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise. | | Promise<ArrayBuffer\> | Returns the buffer data read if the operation is successful; returns an error code otherwise.|
**Example:** **Example**
``` ```
audioCapturer.read(bufferSize, true).then((buffer) => { audioCapturer.read(bufferSize, true).then((buffer) => {
...@@ -3094,18 +3017,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => { ...@@ -3094,18 +3017,17 @@ audioCapturer.read(bufferSize, true).then((buffer) => {
getAudioTime(callback: AsyncCallback<number\>): void getAudioTime(callback: AsyncCallback<number\>): void
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses an asynchronous callback to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp. | | callback | AsyncCallback<number\> | Yes | Callback used to return the timestamp.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getAudioTime((err, timestamp) => { audioCapturer.getAudioTime((err, timestamp) => {
...@@ -3118,17 +3040,17 @@ audioCapturer.getAudioTime((err, timestamp) => { ...@@ -3118,17 +3040,17 @@ audioCapturer.getAudioTime((err, timestamp) => {
getAudioTime(): Promise<number\> getAudioTime(): Promise<number\>
Obtains the timestamp in Unix epoch time (starts from January 1, 1970), in nanoseconds. This API uses a promise to return the result. Obtains the number of nanoseconds elapsed from the Unix epoch (January 1, 1970). This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :------------------------------------ | | :--------------- | :---------------------------- |
| Promise<number\> | Promise used to return the timestamp. | | Promise<number\> | Promise used to return the timestamp.|
**Example:** **Example**
``` ```
audioCapturer.getAudioTime().then((audioTime) => { audioCapturer.getAudioTime().then((audioTime) => {
...@@ -3136,7 +3058,6 @@ audioCapturer.getAudioTime().then((audioTime) => { ...@@ -3136,7 +3058,6 @@ audioCapturer.getAudioTime().then((audioTime) => {
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message); console.info('AudioFrameworkRecLog: AudioCapturer Created : ERROR : '+err.message);
}); });
``` ```
...@@ -3146,16 +3067,15 @@ getBufferSize(callback: AsyncCallback<number\>): void ...@@ -3146,16 +3067,15 @@ getBufferSize(callback: AsyncCallback<number\>): void
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :--------------------- | :-------- | :--------------------------------------- | | :------- | :--------------------- | :--- | :----------------------------------- |
| callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size. | | callback | AsyncCallback<number\> | Yes | Callback used to return the buffer size.|
| | | | |
**Example:** **Example**
``` ```
audioCapturer.getBufferSize((err, bufferSize) => { audioCapturer.getBufferSize((err, bufferSize) => {
...@@ -3170,21 +3090,22 @@ audioCapturer.getBufferSize((err, bufferSize) => { ...@@ -3170,21 +3090,22 @@ audioCapturer.getBufferSize((err, bufferSize) => {
}); });
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
getBufferSize(): Promise<number\> getBufferSize(): Promise<number\>
Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result. Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a promise to return the result.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Return value:** **Return value**
| Type | Description | | Type | Description |
| :--------------- | :-------------------------------------- | | :--------------- | :---------------------------------- |
| Promise<number\> | Promise used to return the buffer size. | | Promise<number\> | Promise used to return the buffer size.|
**Example:** **Example**
``` ```
audioCapturer.getBufferSize().then((bufferSize) => { audioCapturer.getBufferSize().then((bufferSize) => {
...@@ -3199,23 +3120,24 @@ audioCapturer.getBufferSize().then((bufferSize) => { ...@@ -3199,23 +3120,24 @@ audioCapturer.getBufferSize().then((bufferSize) => {
}); });
``` ```
### on('markReach')<sup>8+</sup> ### on('markReach')<sup>8+</sup>
on(type: 'markReach', frame: number, callback: (position: number) => {}): void on(type: 'markReach', frame: number, callback: (position: number) => {}): void
Subscribes to mark reached events. When the number of frames captured reaches the value of the frame parameter, the callback is invoked. Subscribes to mark reached events. When the number of frames captured reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :----------------------------------------------------------------------- | | :------- | :---------------------- | :--- | :----------------------------------------- |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter. |
| frame | number | Yes | Number of frames to trigger the event. The value must be greater than 0. | | frame | number | Yes | Number of frames to trigger the event. The value must be greater than **0**. |
| callback | position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | position: number) => {} | Yes | Callback invoked when the event is triggered.|
**Example:** **Example**
``` ```
audioCapturer.on('markReach', 1000, (position) => { audioCapturer.on('markReach', 1000, (position) => {
...@@ -3225,22 +3147,21 @@ audioCapturer.on('markReach', 1000, (position) => { ...@@ -3225,22 +3147,21 @@ audioCapturer.on('markReach', 1000, (position) => {
}); });
``` ```
### off('markReach')<sup>8+</sup> ### off('markReach')<sup>8+</sup>
off(type: 'markReach'): void off(type: 'markReach'): void
Unsubscribes from the mark reached events. Unsubscribes from mark reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :-------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **markReach** means the mark reached event, which is triggered when the number of frames captured reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('markReach'); audioCapturer.off('markReach');
...@@ -3250,19 +3171,19 @@ audioCapturer.off('markReach'); ...@@ -3250,19 +3171,19 @@ audioCapturer.off('markReach');
on(type: "periodReach", frame: number, callback: (position: number) => {}): void on(type: "periodReach", frame: number, callback: (position: number) => {}): void
Subscribes to period reached events. When the period of frame capturing reaches the value of frame parameter, the callback is invoked. Subscribes to mark reached events. When the period of frame capturing reaches the value of the **frame** parameter, the callback is invoked.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :--------------------------------------------------------------------------------- | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the capturer event to subscribe to. | | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame capturing is listened. The value must be greater than 0. | | frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example:** **Example**
``` ```
audioCapturer.on('periodReach', 1000, (position) => { audioCapturer.on('periodReach', 1000, (position) => {
...@@ -3278,15 +3199,15 @@ off(type: 'periodReach'): void ...@@ -3278,15 +3199,15 @@ off(type: 'periodReach'): void
Unsubscribes from period reached events. Unsubscribes from period reached events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name| Type | Mandatory| Description |
| :------- | :------------------------ | :-------- | :---------------------------------------------- | | :----- | :----- | :--- | :---------------------------------------------- |
| type | string | Yes | Type of the capturer event to unsubscribe from. | | type | string | Yes | Type of event to unsubscribe from. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
**Example:** **Example**
``` ```
audioCapturer.off('periodReach') audioCapturer.off('periodReach')
...@@ -3298,16 +3219,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void ...@@ -3298,16 +3219,16 @@ on(type: 'stateChange', callback: Callback<AudioState\>): void
Subscribes to state change events. Subscribes to state change events.
**System capability:** SystemCapability.Multimedia.Audio.Capturer **System capability**: SystemCapability.Multimedia.Audio.Capturer
**Parameters:** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| :------- | :------------------------- | :-------- | :--------------------------------------------------------------------------------------- | | :------- | :------------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of the event to subscribe to. The value 'stateChange' means the state change event. | | type | string | Yes | Type of event to subscribe to. The value **stateChange** means the state change event.|
| callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. | | callback | [AudioState](#audiostate8) | Yes | Callback used to return the state change. |
**Example:** **Example**
``` ```
audioCapturer.on('stateChange', (state) => { audioCapturer.on('stateChange', (state) => {
......
# Image Processing # Image Processing
> **NOTE** > **NOTE**<br/>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
``` ```js
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
createPixelMap(colors: ArrayBuffer, options: InitializetionOptions): Promise\<PixelMap> createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<PixelMap>
Creates a **PixelMap** object. This API uses a promise to return the result. Creates a **PixelMap** object. This API uses a promise to return the result.
...@@ -21,7 +21,7 @@ Creates a **PixelMap** object. This API uses a promise to return the result. ...@@ -21,7 +21,7 @@ Creates a **PixelMap** object. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors | ArrayBuffer | Yes | Color array. | | colors | ArrayBuffer | Yes | Color array. |
| options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.| | options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties, including the alpha type, size, scale mode, pixel format, and editable.|
**Return value** **Return value**
...@@ -39,7 +39,7 @@ image.createPixelMap(Color, opts) ...@@ -39,7 +39,7 @@ image.createPixelMap(Color, opts)
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
createPixelMap(colors: ArrayBuffer, options: InitializetionOptions, callback: AsyncCallback\<PixelMap>): void createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: AsyncCallback\<PixelMap>): void
Creates a **PixelMap** object. This API uses an asynchronous callback to return the result. Creates a **PixelMap** object. This API uses an asynchronous callback to return the result.
...@@ -50,7 +50,7 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return ...@@ -50,7 +50,7 @@ Creates a **PixelMap** object. This API uses an asynchronous callback to return
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | -------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors | ArrayBuffer | Yes | Color array. | | colors | ArrayBuffer | Yes | Color array. |
| options | [InitializetionOptions](#initializationoptions8) | Yes | Pixel properties. | | options | [InitializationOptions](#initializationoptions8) | Yes | Pixel properties. |
| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.| | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | Yes | Callback used to return the **PixelMap** object.|
**Example** **Example**
...@@ -66,9 +66,11 @@ Provides APIs to read or write image pixel map data and obtain image pixel map i ...@@ -66,9 +66,11 @@ Provides APIs to read or write image pixel map data and obtain image pixel map i
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ | | ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | Yes | No | Whether the image pixel map is editable.<br>**System capability**: SystemCapability.Multimedia.Image| | isEditable<sup>7+</sup> | boolean | Yes | No | Whether the image pixel map is editable.|
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -468,7 +470,7 @@ Creates an **ImageSource** instance based on the URI. ...@@ -468,7 +470,7 @@ Creates an **ImageSource** instance based on the URI.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------- | | ------ | ------ | ---- | ---------------------------------- |
| uri | string | Yes | Image source URI. Currently, only the local absolute path is supported.| | uri | string | Yes | Image path. Currently, only the application sandbox path is supported.|
**Return value** **Return value**
...@@ -479,7 +481,8 @@ Creates an **ImageSource** instance based on the URI. ...@@ -479,7 +481,8 @@ Creates an **ImageSource** instance based on the URI.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource('/data/local/tmp/test.jpg') let path = this.context.getApplicationContext().fileDirs + "test.jpg";
const imageSourceApi = image.createImageSource(path);
``` ```
## image.createImageSource<sup>7+</sup> ## image.createImageSource<sup>7+</sup>
...@@ -514,9 +517,11 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour ...@@ -514,9 +517,11 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.<br>**System capability**: SystemCapability.Multimedia.Image| | supportedFormats | Array\<string> | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.|
### getImageInfo ### getImageInfo
...@@ -793,13 +798,15 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must ...@@ -793,13 +798,15 @@ Provide APIs to pack images. Before calling any API in **ImagePacker**, you must
### Attributes ### Attributes
**System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | Yes | No | Supported image format, which can be jpeg.<br>**System capability**: SystemCapability.Multimedia.Image| | supportedFormats | Array\<string> | Yes | No | Supported image format, which can be jpeg.|
### packing ### packing
packing(source: ImageSource, option: PackingOption, callback: AsyncCallback<Array\<ArrayBuffer>>): void packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
Packs an image. This API uses an asynchronous callback to return the result. Packs an image. This API uses an asynchronous callback to return the result.
...@@ -811,7 +818,7 @@ Packs an image. This API uses an asynchronous callback to return the result. ...@@ -811,7 +818,7 @@ Packs an image. This API uses an asynchronous callback to return the result.
| -------- | ---------------------------------- | ---- | ---------------------------------- | | -------- | ---------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | Yes | Image to pack. | | source | [ImageSource](#imagesource) | Yes | Image to pack. |
| option | [PackingOption](#packingoption) | Yes | Option for image packing. | | option | [PackingOption](#packingoption) | Yes | Option for image packing. |
| callback | AsyncCallback<Array\<ArrayBuffer>> | Yes | Callback used to return the packed data.| | callback | AsyncCallback\<ArrayBuffer> | Yes | Callback used to return the packed data.|
**Example** **Example**
...@@ -822,7 +829,7 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => {}) ...@@ -822,7 +829,7 @@ imagePackerApi.packing(imageSourceApi, packOpts, data => {})
### packing ### packing
packing(source: ImageSource, option: PackingOption): Promise<Array\<ArrayBuffer>> packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
Packs an image. This API uses a promise to return the result. Packs an image. This API uses a promise to return the result.
...@@ -839,7 +846,7 @@ Packs an image. This API uses a promise to return the result. ...@@ -839,7 +846,7 @@ Packs an image. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| :--------------------------- | :-------------------------------------------- | | :--------------------------- | :-------------------------------------------- |
| Promise<Array\<ArrayBuffer>> | Promise used to return the packed data.| | Promise\<ArrayBuffer> | Promise used to return the packed data.|
**Example** **Example**
...@@ -850,7 +857,7 @@ imagePackerApi.packing(imageSourceApi, packOpts) ...@@ -850,7 +857,7 @@ imagePackerApi.packing(imageSourceApi, packOpts)
.catch(error => {}) .catch(error => {})
``` ```
### packing ### packing<sup>8+</sup>
packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayBuffer>): void
...@@ -873,9 +880,9 @@ let packOpts = { format:["image/jpeg"], quality:98 } ...@@ -873,9 +880,9 @@ let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts, data => {}) imagePackerApi.packing(pixelMapApi, packOpts, data => {})
``` ```
### packing ### packing<sup>8+</sup>
packing(source: PixelMap, option: PackingOption): Promise<Array\<ArrayBuffer>> packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
Packs an image. This API uses a promise to return the result. Packs an image. This API uses a promise to return the result.
...@@ -884,15 +891,15 @@ Packs an image. This API uses a promise to return the result. ...@@ -884,15 +891,15 @@ Packs an image. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------------------------------- | ---- | -------------- | | ------ | ------------------------------- | ---- | ------------------ |
| source | [PixelMap](#pixelmap) | Yes | **PixelMap** object to pack.| | source | [PixelMap](#pixelmap) | Yes | **PixelMap** object to pack.|
| option | [PackingOption](#packingoption) | Yes | Option for image packing.| | option | [PackingOption](#packingoption) | Yes | Option for image packing. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| :--------------------------- | :-------------------------------------------- | | :--------------------------- | :-------------------------------------------- |
| Promise<Array\<ArrayBuffer>> | Promise used to return the packed data.| | Promise\<ArrayBuffer> | Promise used to return the packed data.|
**Example** **Example**
...@@ -944,6 +951,345 @@ Releases this **ImagePacker** instance. This API uses a promise to return the re ...@@ -944,6 +951,345 @@ Releases this **ImagePacker** instance. This API uses a promise to return the re
}).catch((error)=>{}) }).catch((error)=>{})
``` ```
## image.createImageReceiver<sup>9+</sup>
createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
Create an **ImageReceiver** instance by specifying the image width, height, format, and capacity.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------ | ---- | ---------------------- |
| width | number | Yes | Default image width. |
| height | number | Yes | Default image height. |
| format | number | Yes | Image format. |
| capacity | number | Yes | Maximum number of images that can be accessed at the same time.|
**Return value**
| Type | Description |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | Returns an **ImageReceiver** instance if the operation is successful.|
**Example**
```js
var receiver = image.createImageReceiver(8192, 8, 4, 8)
```
## ImageReceiver<sup>9+</sup>
Provides APIs to obtain the surface ID of a component, read the latest image, read the next image, and release the **ImageReceiver** instance.
Before calling any APIs in **ImageReceiver**, you must create an **ImageReceiver** instance.
### Attributes
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
| Name | Type | Readable| Writable| Description |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup> | [Size](#size) | Yes | No | Image size. |
| capacity<sup>9+</sup> | number | Yes | No | Maximum number of images that can be accessed at the same time.|
| format<sup>9+</sup> | [ImageFormat](#imageformat9) | Yes | No | Image format. |
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(callback: AsyncCallback\<string>): void
Obtains a surface ID for the camera or other components. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | Yes | Callback used to return the surface ID.|
**Example**
```js
receiver.getReceivingSurfaceId((err, id) => {});
```
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(): Promise\<string>
Obtains a surface ID for the camera or other components. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Return value**
| Type | Description |
| ---------------- | -------------------- |
| Promise\<string> | Promise used to return the surface ID.|
**Example**
```js
receiver.getReceivingSurfaceId().then( id => {
}).catch(error => {
})
```
### readLatestImage<sup>9+</sup>
readLatestImage(callback: AsyncCallback\<Image>): void
Reads the latest image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the latest image.|
**Example**
```js
receiver.readLatestImage((err, img) => { });
```
### readLatestImage<sup>9+</sup>
readLatestImage(): Promise\<Image>
Reads the latest image from the **ImageReceiver** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Return value**
| Type | Description |
| ------------------------- | ------------------ |
| Promise<[Image](#image8)> | Promise used to return the latest image.|
**Example**
```js
receiver.readLatestImage().then(img => {})
.catch(error => {})
```
### readNextImage<sup>9+</sup>
readNextImage(callback: AsyncCallback\<Image>): void
Reads the next image from the **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | Yes | Callback used to return the next image.|
**Example**
```js
receiver.readNextImage((err, img) => {});
```
### readNextImage<sup>9+</sup>
readNextImage(): Promise\<Image>
Reads the next image from the **ImageReceiver** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Return value**
| Type | Description |
| ------------------------- | -------------------- |
| Promise<[Image](#image9)> | Promise used to return the next image.|
**Example**
```js
receiver.readNextImage().then(img => {
}).catch(error => {
})
```
### on('imageArrival')<sup>9+</sup>
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
Listens for image arrival events.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| type | string | Yes | Type of event to listen for. The value is fixed at **imageArrival**, which is triggered when an image is received.|
| callback | AsyncCallback\<void> | Yes | Callback invoked for the event. |
**Example**
```js
receiver.on('imageArrival', () => {})
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
Releases this **ImageReceiver** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
receiver.release(() => {})
```
### release<sup>9+</sup>
release(): Promise\<void>
Releases this **ImageReceiver** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
**Return value**
| Type | Description |
| -------------- | ------------------ |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
receiver.release().then(() => {})
.catch(error => {})
```
## Image<sup>9+</sup>
Provides APIs for basic image operations, including obtaining image information and reading and writing image data. An **Image** instance is returned when [readNextImage](#readnextimage9) and [readLatestImage](#readlatestimage9) are called.
### Attributes
**System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect<sup>9+</sup> | [Region](#region7) | Yes | Yes | Image area to be cropped. |
| size<sup>9+</sup> | [Size](#size) | Yes | No | Image size. |
| format<sup>9+</sup> | number | Yes | No | Image format. For details, see [PixelMapFormat](#pixelmapformat7).|
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
Obtains the component buffer from the **Image** instance based on the color component type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | --------------------------------------- | ---- | -------------------- |
| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image. |
| callback | AsyncCallback<[Component](#component9)> | Yes | Callback used to return the component buffer.|
**Example**
```js
img.getComponent(4, (err, component) => {})
```
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType): Promise\<Component>
Obtains the component buffer from the **Image** instance based on the color component type. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------------- | -------------------------------- | ---- | ---------------- |
| componentType | [ComponentType](#componenttype9) | Yes | Color component type of the image.|
**Return value**
| Type | Description |
| --------------------------------- | --------------------------------- |
| Promise<[Component](#component9)> | Promise used to return the component buffer.|
**Example**
```js
img.getComponent(4).then(component => { })
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
Releases this **Image** instance. This API uses an asynchronous callback to return the result.
The corresponding resources must be released before another image arrives.
**System capability**: SystemCapability.Multimedia.Image.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**Example**
```js
img.release(() =>{ })
```
### release<sup>9+</sup>
release(): Promise\<void>
Releases this **Image** instance. This API uses a promise to return the result.
The corresponding resources must be released before another image arrives.
**System capability**: SystemCapability.Multimedia.Image.Core
**Return value**
| Type | Description |
| -------------- | --------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
img.release().then(() =>{
}).catch(error => {
})
```
## PositionArea<sup>7+</sup> ## PositionArea<sup>7+</sup>
Describes area information in an image. Describes area information in an image.
...@@ -955,7 +1301,7 @@ Describes area information in an image. ...@@ -955,7 +1301,7 @@ Describes area information in an image.
| pixels | ArrayBuffer | Yes | No | Pixels of the image. | | pixels | ArrayBuffer | Yes | No | Pixels of the image. |
| offset | number | Yes | No | Offset for data reading. | | offset | number | Yes | No | Offset for data reading. |
| stride | number | Yes | No | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4. | | stride | number | Yes | No | Number of bytes from one row of pixels in memory to the next row of pixels in memory. The value of **stride** must be greater than or equal to the value of **region.size.width** multiplied by 4. |
| region | [Region](#region8) | Yes | No | Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.| | region | [Region](#region7) | Yes | No | Region to read or write. The width of the region to write plus the X coordinate cannot be greater than the width of the original image. The height of the region to write plus the Y coordinate cannot be greater than the height of the original image.|
## ImageInfo ## ImageInfo
...@@ -980,7 +1326,7 @@ Describes the size of an image. ...@@ -980,7 +1326,7 @@ Describes the size of an image.
## PixelMapFormat<sup>7+</sup> ## PixelMapFormat<sup>7+</sup>
Enumerates pixel map formats. Enumerates the pixel formats of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
...@@ -992,7 +1338,7 @@ Enumerates pixel map formats. ...@@ -992,7 +1338,7 @@ Enumerates pixel map formats.
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
Enumerates alpha types. Enumerates the alpha types of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
...@@ -1005,7 +1351,7 @@ Enumerates alpha types. ...@@ -1005,7 +1351,7 @@ Enumerates alpha types.
## ScaleMode<sup>9+</sup> ## ScaleMode<sup>9+</sup>
Enumerates scale modes. Enumerates the scale modes of images.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
...@@ -1016,10 +1362,12 @@ Enumerates scale modes. ...@@ -1016,10 +1362,12 @@ Enumerates scale modes.
## InitializationOptions<sup>8+</sup> ## InitializationOptions<sup>8+</sup>
Defines pixel map initialization options.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ----------- | ---------------------------------- | ---- | ---- | -------------- | | ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. | | alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | Yes | Yes | Alpha type. |
| editable | boolean | Yes | Yes | Whether the image is editable. | | editable | boolean | Yes | Yes | Whether the image is editable. |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | Yes | Yes | Pixel map format. |
...@@ -1028,7 +1376,7 @@ Enumerates scale modes. ...@@ -1028,7 +1376,7 @@ Enumerates scale modes.
## DecodingOptions<sup>7+</sup> ## DecodingOptions<sup>7+</sup>
Describes the decoding options. Defines image decoding options.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
...@@ -1056,7 +1404,7 @@ Describes region information. ...@@ -1056,7 +1404,7 @@ Describes region information.
## PackingOption ## PackingOption
Describes the option for image packing. Defines the option for image packing.
**System capability**: SystemCapability.Multimedia.Image **System capability**: SystemCapability.Multimedia.Image
...@@ -1092,3 +1440,40 @@ Describes the exchangeable image file format (Exif) information of an image. ...@@ -1092,3 +1440,40 @@ Describes the exchangeable image file format (Exif) information of an image.
| GPS_LONGITUDE | "GPSLongitude" | Image longitude. | | GPS_LONGITUDE | "GPSLongitude" | Image longitude. |
| GPS_LATITUDE_REF | "GPSLatitudeRef" | Latitude reference, for example, N or S.| | GPS_LATITUDE_REF | "GPSLatitudeRef" | Latitude reference, for example, N or S.|
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E.| | GPS_LONGITUDE_REF | "GPSLongitudeRef" | Longitude reference, for example, W or E.|
## ImageFormat<sup>9+</sup>
Enumerates the image formats.
**System capability**: SystemCapability.Multimedia.Image.Core
| Name | Default Value| Description |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000 | YCBCR422 semi-planar format.|
| JPEG | 2000 | JPEG encoding format. |
## ComponentType<sup>9+</sup>
Enumerates the color component types of images.
**System capability**: SystemCapability.Multimedia.Image.ImageReceiver
| Name | Default Value| Description |
| ----- | ------ | ----------- |
| YUV_Y | 1 | Luminance component. |
| YUV_U | 2 | Chrominance component. |
| YUV_V | 3 | Chrominance component. |
| JPEG | 4 | JPEG type.|
## Component<sup>9+</sup>
Describes the color components of an image.
**System capability**: SystemCapability.Multimedia.Image.Core
| Name | Type | Readable| Writable| Description |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
| componentType | [ComponentType](#componenttype9) | Yes | No | Color component type. |
| rowStride | number | Yes | No | Row stride. |
| pixelStride | number | Yes | No | Pixel stride. |
| byteBuffer | ArrayBuffer | Yes | No | Component buffer.|
...@@ -28,7 +28,13 @@ Obtains a **MediaLibrary** instance, which is used to access and modify personal ...@@ -28,7 +28,13 @@ Obtains a **MediaLibrary** instance, which is used to access and modify personal
| ----------------------------- | :---- | | ----------------------------- | :---- |
| [MediaLibrary](#medialibrary) | **MediaLibrary** instance.| | [MediaLibrary](#medialibrary) | **MediaLibrary** instance.|
**Example** **Example (from API version 9)**
```
var media = mediaLibrary.getMediaLibrary(this.context);
```
**Example (API version 8)**
``` ```
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
...@@ -246,7 +252,7 @@ Creates a media asset. This API uses a promise to return the result. ...@@ -246,7 +252,7 @@ Creates a media asset. This API uses a promise to return the result.
``` ```
async function example() { async function example() {
// Create an image file in promise mode // Create an image file in promise mode.
let mediaType = mediaLibrary.MediaType.IMAGE; let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE); const path = await media.getPublicDirectory(DIR_IMAGE);
...@@ -437,13 +443,13 @@ var media = mediaLibrary.getMediaLibrary(context); ...@@ -437,13 +443,13 @@ var media = mediaLibrary.getMediaLibrary(context);
media.release() media.release()
``` ```
### storeMediaAsset ### storeMediaAsset<sup>(deprecated)</sup>
storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void
Stores a media asset. This API uses an asynchronous callback to return the URI that stores the media asset. Stores a media asset. This API uses an asynchronous callback to return the URI that stores the media asset.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -467,19 +473,19 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => { ...@@ -467,19 +473,19 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => {
console.log("An error occurred when storing the media asset."); console.log("An error occurred when storing the media asset.");
return; return;
} }
console.log("Media asset stored. "); console.log("Media asset stored.");
// Obtain the URI that stores the media asset. // Obtain the URI that stores the media asset.
}); });
``` ```
### storeMediaAsset ### storeMediaAsset<sup>(deprecated)</sup>
storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt; storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt;
Stores a media asset. This API uses a promise to return the URI that stores the media asset. Stores a media asset. This API uses a promise to return the URI that stores the media asset.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -512,13 +518,13 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => { ...@@ -512,13 +518,13 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
``` ```
### startImagePreview ### startImagePreview<sup>(deprecated)</sup>
startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result. Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -526,7 +532,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a ...@@ -526,7 +532,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **https://** or **dataability://**.| | images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **dataability://** or **https://**.|
| index | number | Yes | Index of the first image to preview. | | index | number | Yes | Index of the first image to preview. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
...@@ -537,7 +543,7 @@ let images = [ ...@@ -537,7 +543,7 @@ let images = [
"dataability:///media/xxxx/2", "dataability:///media/xxxx/2",
"dataability:///media/xxxx/3" "dataability:///media/xxxx/3"
]; ];
/* Online image usage mode /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image1.jpg",
"https://media.xxxx.com/image2.jpg" "https://media.xxxx.com/image2.jpg"
...@@ -554,13 +560,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => { ...@@ -554,13 +560,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => {
``` ```
### startImagePreview ### startImagePreview<sup>(deprecated)</sup>
startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
Starts image preview. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result. Starts image preview. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -578,7 +584,7 @@ let images = [ ...@@ -578,7 +584,7 @@ let images = [
"dataability:///media/xxxx/2", "dataability:///media/xxxx/2",
"dataability:///media/xxxx/3" "dataability:///media/xxxx/3"
]; ];
/* Online image usage mode /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image1.jpg",
"https://media.xxxx.com/image2.jpg" "https://media.xxxx.com/image2.jpg"
...@@ -594,13 +600,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => { ...@@ -594,13 +600,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => {
``` ```
### startImagePreview ### startImagePreview<sup>(deprecated)</sup>
startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt; startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt;
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with dataability:// or online images whose URIs start with https://. It uses a promise to return the execution result. Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with dataability:// or online images whose URIs start with https://. It uses a promise to return the execution result.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -608,7 +614,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a ...@@ -608,7 +614,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------------------- | ---- | ---------------------------------------- | | ------ | ------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **https://** or **dataability://**.| | images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **dataability://** or **https://**.|
| index | number | No | Index of the first image to preview. If this parameter is not specified, the default value **0** is used. | | index | number | No | Index of the first image to preview. If this parameter is not specified, the default value **0** is used. |
**Return value** **Return value**
...@@ -624,7 +630,7 @@ let images = [ ...@@ -624,7 +630,7 @@ let images = [
"dataability:///media/xxxx/2", "dataability:///media/xxxx/2",
"dataability:///media/xxxx/3" "dataability:///media/xxxx/3"
]; ];
/* Online image usage mode /* Preview online images.
let images = [ let images = [
"https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image1.jpg",
"https://media.xxxx.com/image2.jpg" "https://media.xxxx.com/image2.jpg"
...@@ -639,13 +645,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => { ...@@ -639,13 +645,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
``` ```
### startMediaSelect ### startMediaSelect<sup>(deprecated)</sup>
startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Starts media selection. This API uses an asynchronous callback to return the list of URIs that store the selected media assets. Starts media selection. This API uses an asynchronous callback to return the list of URIs that store the selected media assets.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -674,13 +680,13 @@ mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => { ...@@ -674,13 +680,13 @@ mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => {
``` ```
### startMediaSelect ### startMediaSelect<sup>(deprecated)</sup>
startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt; startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt;
Starts media selection. This API uses a promise to return the list of URIs that store the selected media assets. Starts media selection. This API uses a promise to return the list of URIs that store the selected media assets.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -723,7 +729,7 @@ Provides APIs for encapsulating file asset attributes. ...@@ -723,7 +729,7 @@ Provides APIs for encapsulating file asset attributes.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | | ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
| id | number | Yes | No | File asset ID. | | id | number | Yes | No | File asset ID. |
| uri | string | Yes | No | File asset URI, for example, dataability:///media/image/2. | | uri | string | Yes | No | File asset URI, for example, **dataability:///media/image/2**. |
| mimeType | string | Yes | No | Extended file attributes. | | mimeType | string | Yes | No | Extended file attributes. |
| mediaType<sup>8+</sup> | [MediaType](#mediatype8) | Yes | No | Media type. | | mediaType<sup>8+</sup> | [MediaType](#mediatype8) | Yes | No | Media type. |
| displayName | string | Yes | Yes | Display file name, including the file name extension. | | displayName | string | Yes | Yes | Display file name, including the file name extension. |
...@@ -821,7 +827,7 @@ async function example() { ...@@ -821,7 +827,7 @@ async function example() {
commitModify(callback: AsyncCallback&lt;void&gt;): void commitModify(callback: AsyncCallback&lt;void&gt;): void
Commits the modification of this file asset to the database. This API uses an asynchronous callback to return the result. Commits the modification in this file asset to the database. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
...@@ -857,7 +863,7 @@ async function example() { ...@@ -857,7 +863,7 @@ async function example() {
commitModify(): Promise&lt;void&gt; commitModify(): Promise&lt;void&gt;
Commits the modification of this file asset to the database. This API uses a promise to return the result. Commits the modification in this file asset to the database. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
...@@ -893,6 +899,8 @@ open(mode: string, callback: AsyncCallback&lt;number&gt;): void ...@@ -893,6 +899,8 @@ open(mode: string, callback: AsyncCallback&lt;number&gt;): void
Opens this file asset. This API uses an asynchronous callback to return the result. Opens this file asset. This API uses an asynchronous callback to return the result.
Note: Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**)
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -901,7 +909,7 @@ Opens this file asset. This API uses an asynchronous callback to return the resu ...@@ -901,7 +909,7 @@ Opens this file asset. This API uses an asynchronous callback to return the resu
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ----------------------------------- | | -------- | --------------------------- | ---- | ----------------------------------- |
| mode | string | Yes | Mode of opening the file, for example, **r** (read-only), **w** (write-only), and **rw** (read-write).| | mode | string | Yes | Mode of opening the file, for example, **'r'** (read-only), **'w'** (write-only), and **'rw'** (read-write).|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the file handle. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the file handle. |
**Example** **Example**
...@@ -928,6 +936,8 @@ open(mode: string): Promise&lt;number&gt; ...@@ -928,6 +936,8 @@ open(mode: string): Promise&lt;number&gt;
Opens this file asset. This API uses a promise to return the result. Opens this file asset. This API uses a promise to return the result.
Note: Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource.
**Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**)
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -1009,7 +1019,7 @@ close(fd: number): Promise&lt;void&gt; ...@@ -1009,7 +1019,7 @@ close(fd: number): Promise&lt;void&gt;
Closes this file asset. This API uses a promise to return the result. Closes this file asset. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **'r'**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **'w'**)
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -1531,7 +1541,7 @@ Checks whether the cursor is in the last row of the result set. ...@@ -1531,7 +1541,7 @@ Checks whether the cursor is in the last row of the result set.
| Type | Description | | Type | Description |
| ------- | ---------------------------------- | | ------- | ---------------------------------- |
| boolean | Returns **true** if the cursor is in the last row of the result set; returns *false** otherwise.| | boolean | Returns **true** if the cursor is in the last row of the result set; returns *false* otherwise.|
**Example** **Example**
...@@ -1566,7 +1576,7 @@ async function example() { ...@@ -1566,7 +1576,7 @@ async function example() {
close(): void close(): void
Releases and invalidates this **FetchFileResult** instance. Other APIs cannot be invoked after the instance is released. Releases and invalidates this **FetchFileResult** instance. Other APIs in this instance cannot be invoked after it is released.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
...@@ -1965,7 +1975,7 @@ Provides APIs to implement a physical album. ...@@ -1965,7 +1975,7 @@ Provides APIs to implement a physical album.
commitModify(callback: AsyncCallback&lt;void&gt;): void commitModify(callback: AsyncCallback&lt;void&gt;): void
Commits the modification of the album attributes to the database. This API uses an asynchronous callback to return the result. Commits the modification in the album attributes to the database. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
...@@ -2002,7 +2012,7 @@ async function example() { ...@@ -2002,7 +2012,7 @@ async function example() {
commitModify(): Promise&lt;void&gt; commitModify(): Promise&lt;void&gt;
Commits the modification of the album attributes to the database. This API uses a promise to return the result. Commits the modification in the album attributes to the database. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
...@@ -2204,7 +2214,7 @@ Describes options for fetching media files. ...@@ -2204,7 +2214,7 @@ Describes options for fetching media files.
| ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ | | ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ |
| selections | string | Yes | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?',| | selections | string | Yes | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?',|
| selectionArgs | Array&lt;string&gt; | Yes | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], | | selectionArgs | Array&lt;string&gt; | Yes | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
| order<sup>8+</sup> | string | Yes | Yes | No | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " AESC"<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + " DESC"| | order | string | Yes | Yes | No | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " AESC"<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + " DESC"|
| uri<sup>8+</sup> | string | Yes | Yes | No | File URI. | | uri<sup>8+</sup> | string | Yes | Yes | No | File URI. |
| networkId<sup>8+</sup> | string | Yes | Yes | No | Network ID of the registered device. | | networkId<sup>8+</sup> | string | Yes | Yes | No | Network ID of the registered device. |
| extendArgs<sup>8+</sup> | string | Yes | Yes | No | Extended parameters for fetching the files. Currently, no extended parameters are available. | | extendArgs<sup>8+</sup> | string | Yes | Yes | No | Extended parameters for fetching the files. Currently, no extended parameters are available. |
...@@ -2218,30 +2228,30 @@ Describes the image size. ...@@ -2218,30 +2228,30 @@ Describes the image size.
| width | number | Yes | Yes | Image width, in pixels.| | width | number | Yes | Yes | Image width, in pixels.|
| height | number | Yes | Yes | Image height, in pixels.| | height | number | Yes | Yes | Image height, in pixels.|
## MediaAssetOption ## MediaAssetOption<sup>(deprecated)</sup>
Implements the media asset option. Implements the media asset option.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory| Description |
| ------------ | ------ | ---- | ---------------------------------------- | | ------------ | ------ | ---- | ------------------------------------------------------------ |
| src | string | Yes | Absolute path of the local file of the application. | | src | string | Yes | Application sandbox oath of the local file. |
| mimeType | string | Yes | Multipurpose Internet Mail Extensions (MIME) type of the media.<br>The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.| | mimeType | string | Yes | Multipurpose Internet Mail Extensions (MIME) type of the media.<br>The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.|
| relativePath | string | No | Custom path for storing media assets, for example, 'Pictures/'. If this parameter is unspecified, media assets are stored in the default path.<br> Default path of images: 'Pictures/'<br> Default path of videos: 'Videos/'<br> Default path of audios: 'Audios/'<br> Default path of files: 'Documents/'| | relativePath | string | No | Custom path for storing media assets, for example, 'Pictures/'. If this parameter is unspecified, media assets are stored in the default path.<br> Default path of images: 'Pictures/'<br> Default path of videos: 'Videos/'<br> Default path of audios: 'Audios/'<br> Default path of files: 'Documents/'|
## MediaSelectOption ## MediaSelectOption<sup>(deprecated)</sup>
Describes media selection option. Describes media selection option.
This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. > **NOTE**<br>This API is deprecated since API version 9.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core **System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ----- | ------ | ---- | -------------------- | | ----- | ------ | ---- | -------------------- |
| type | string | Yes | Media type, which can be **image**, **media**, or **video**. Currently, only **media** is supported.| | type | string | Yes | Media type, which can be **image**, **media**, or **video**. Currently, only **media** is supported.|
| count | number | Yes | Number of media assets selected. If **count** is set to **1**, one media asset can be selected. If **count** is greater than **1**, multiple media assets can be selected. | | count | number | Yes | Number of media assets selected. The value starts from 1, which indicates that one media asset can be selected. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册