You can manage the audio effect of a specific playback instance, for example, obtaining or setting the audio effect mode of the current audio playback stream. You can also obtain the global audio effect, that is, the audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**).
## Managing the Audio Effect of a Playback Instance
You can obtain and set the audio effect mode, which can be disabled (**EFFECT_NONE**) or default (**EFFECT_DEFAULT**), of the current audio playback stream. In default audio effect mode, the audio effect of the corresponding scenario is automatically loaded based on **ContentType** and **StreamUsage** of the audio stream.
### Creating a Playback Instance
Before obtaining or setting the audio effect mode, you must call **createAudioRenderer(options: AudioRendererOptions)** to create an **AudioRenderer** instance.
1. Import the audio module.
```js
importaudiofrom'@ohos.multimedia.audio';
```
2. Configure audio rendering parameters and create an **AudioRenderer** instance. For details about the audio rendering parameters, see [AudioRendererOptions](../reference/apis/js-apis-audio.md#audiorendereroptions8). For the **AudioRenderer** instance, the audio effect mode **EFFECT_DEFAULT** is used by default.
console.error(`Failed to set params, code is ${err.code}, message is ${err.message}`);
return;
}else{
console.info('Callback invoked to indicate a successful audio effect mode setting.');
}
});
```
## Obtaining the Global Audio Effect Mode
You can obtain the global audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**).
For an audio playback application, pay attention to the audio effect mode used by the audio stream of the application and perform corresponding operations. For example, for a music application, select the audio effect mode for the music scenario. Before obtaining the global audio effect mode, call **getStreamManager()** to create an **AudioStreamManager** instance.
### Creating an AudioStreamManager Instance
Create an **AudioStreamManager** instance. Before using **AudioStreamManager** APIs, you must use **getStreamManager()** to create an **AudioStreamManager** instance.
console.info('device change type: '+deviceChanged.type);// Device connection state change. The value 0 means that the device is connected and 1 means that the device is disconnected.
console.info(`device change type : ${deviceChanged.type}`);// Device connection state change. The value 0 means that the device is connected and 1 means that the device is disconnected.
You will learn how to use native image APIs to process images, including cropping, rotating, scaling, flipping, translating, and opacity setting.
## How to Develop
**Adding Dependencies**
Open the **src/main/cpp/CMakeLists.txt** file of the native project, add **libpixelmap_ndk.z.so** of the image and **libhilog_ndk.z.so** of the log to the **target_link_libraries** dependency.
```txt
target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libpixelmap_ndk.z.so)
```
**Adding API Mappings**
Open the **src/main/cpp/hello.cpp** file and add the following API mappings to the **Init** function:
For details about the APIs, see [Image API Reference](../reference/native-apis/image.md).
Obtain the JS resource object from the **hello.cpp** file and convert it to a native resource object. Then you can call native APIs. The sample code is as follows:
1. Create a **PixelMap** object based on a pixel array.
Image processing refers to a series of operations performed on the pixel map, such as obtaining image information, cropping, scaling, translating, rotating, flipping, setting opacity, and reading and writing pixel data. These operations can be classified into image transformation and [pixel map operation](image-pixelmap-operation.md). This topic describes the image transformation operations that you can perform.
...
...
@@ -51,7 +51,7 @@ Read [Image](../reference/apis/js-apis-image.md#pixelmap7) for APIs related to i
| type | string | Yes | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when a system volume change is detected.|
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes | Callback used to return the system volume change event. |
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes | Callback used to return the result. |
**Example**
...
...
@@ -2054,7 +2065,7 @@ Subscribes to ringer mode change events.
| type | string | Yes | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the ringer mode change event. |
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the result. |
**Example**
...
...
@@ -2116,9 +2127,7 @@ Unsubscribes from device change events.
| type | string | Yes | Event type. The value **'volumeChange'** means the system volume change event, which is triggered when the system volume changes.|
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes | Callback used to return the system volume change event. |
| callback | Callback<[VolumeEvent](#volumeevent9)> | Yes | Callback used to return the result. |
**Error codes**
...
...
@@ -2839,7 +2848,7 @@ Subscribes to ringer mode change events.
| type | string | Yes | Event type. The value **'ringerModeChange'** means the ringer mode change event, which is triggered when a ringer mode change is detected.|
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the system volume change event. |
| callback | Callback<[AudioRingMode](#audioringmode)> | Yes | Callback used to return the result. |
Implements audio routing management. Before calling any API in **AudioRoutingManager**, you must use [getRoutingManager](#getroutingmanager9) to obtain an **AudioRoutingManager** instance.
...
...
@@ -3517,9 +3588,7 @@ For details about the error codes, see [Audio Error Codes](../errorcodes/errorco
Defines an array that contains the audio effect mode corresponding to a specific audio content type (specified by **ContentType**) and audio stream usage (specified by **StreamUsage**). The [AudioEffectMode](#audioeffectmode10) array is read-only.
## AudioDeviceDescriptors
Defines an [AudioDeviceDescriptor](#audiodevicedescriptor) array, which is read-only.