diff --git a/en/application-dev/media/Readme-EN.md b/en/application-dev/media/Readme-EN.md index a9fe35694fd7458fe31cf6a5d2473f5d93757bd1..d4a62d39749fecdbab37c7646c3f11a35d0e4b45 100755 --- a/en/application-dev/media/Readme-EN.md +++ b/en/application-dev/media/Readme-EN.md @@ -12,6 +12,7 @@ - [Using TonePlayer for Audio Playback (for System Applications Only)](using-toneplayer-for-playback.md) - [Audio Playback Concurrency Policy](audio-playback-concurrency.md) - [Volume Management](volume-management.md) + - [Audio Effect Management](audio-effect-management.md) - [Audio Playback Stream Management](audio-playback-stream-management.md) - [Audio Output Device Management](audio-output-device-management.md) - [Distributed Audio Playback (for System Applications Only)](distributed-audio-playback.md) @@ -54,7 +55,8 @@ - [Image Overview](image-overview.md) - [Image Decoding](image-decoding.md) - Image Processing - - [Image Transformation](image-transformation.md) + - [Image Transformation (ArkTS)](image-transformation.md) + - [Image Transformation (Native)](image-transformation-native.md) - [Pixel Map Operation](image-pixelmap-operation.md) - [Image Encoding](image-encoding.md) - [Image Tool](image-tool.md) diff --git a/en/application-dev/media/audio-effect-management.md b/en/application-dev/media/audio-effect-management.md new file mode 100644 index 0000000000000000000000000000000000000000..7c838428c90a767c8ecc259a06eeec446f165eda --- /dev/null +++ b/en/application-dev/media/audio-effect-management.md @@ -0,0 +1,118 @@ +# Audio Effect Management + +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 + import audio from '@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. + + ```js + let audioStreamInfo = { + samplingRate: audio.AudioSamplingRate.SAMPLE_RATE_44100, + channels: audio.AudioChannel.CHANNEL_1, + sampleFormat: audio.AudioSampleFormat.SAMPLE_FORMAT_S16LE, + encodingType: audio.AudioEncodingType.ENCODING_TYPE_RAW + }; + + let audioRendererInfo = { + content: audio.ContentType.CONTENT_TYPE_SPEECH, + usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, + rendererFlags: 0 + }; + + let audioRendererOptions = { + streamInfo: audioStreamInfo, + rendererInfo: audioRendererInfo + }; + + audio.createAudioRenderer(audioRendererOptions, (err, data) => { + if (err) { + console.error(`Invoke createAudioRenderer failed, code is ${err.code}, message is ${err.message}`); + return; + } else { + console.info('Invoke createAudioRenderer succeeded.'); + let audioRenderer = data; + } + }); + ``` + +### Obtaining the Audio Effect Mode of the Playback Instance + + ```js + audioRenderer.getAudioEffectMode((err, effectmode) => { + if (err) { + console.error(`Failed to get params, code is ${err.code}, message is ${err.message}`); + return; + } else { + console.info(`getAudioEffectMode: ${effectmode}`); + } + }); + ``` + +### Setting an Audio Effect Mode for the Playback Instance + +Disable the system audio effect. + + ```js + audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_NONE, (err) => { + if (err) { + 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.'); + } + }); + ``` + +Enable the default system audio effect. + + ```js + audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err) => { + if (err) { + 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. + + ```js + import audio from '@ohos.multimedia.audio'; + let audioManager = audio.getAudioManager(); + let audioStreamManager = audioManager.getStreamManager(); + ``` + +### Querying the Audio Effect Mode of the Corresponding Scenario + + ```js + audioStreamManager.getAudioEffectInfoArray(audio.ContentType.CONTENT_TYPE_MUSIC, audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => { + if (err) { + console.error(`Failed to get effect info array`); + return; + } else { + console.info(`getAudioEffectInfoArray: ${audioEffectInfoArray}`); + } + }); + ``` diff --git a/en/application-dev/media/audio-output-device-management.md b/en/application-dev/media/audio-output-device-management.md index ad20276c60ce7e535f99778e18d04e4e50e29dc6..983a439c5796f30af220ea2b373c7f0b4856c2ea 100644 --- a/en/application-dev/media/audio-output-device-management.md +++ b/en/application-dev/media/audio-output-device-management.md @@ -45,16 +45,14 @@ Set a listener to listen for changes of the device connection state. When a devi ```ts // Listen for connection state changes of audio devices. audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => { - 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 descriptor size : ' + deviceChanged.deviceDescriptors.length); - console.info('device change descriptor: ' + deviceChanged.deviceDescriptors[0].deviceRole); // Device role. - console.info('device change descriptor: ' + deviceChanged.deviceDescriptors[0].deviceType); // Device type. + 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 descriptor size : ${deviceChanged.deviceDescriptors.length}`); + console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole}`); // Device role. + console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType}`); // Device type. }); // Cancel the listener for the connection state changes of audio devices. -audioRoutingManager.off('deviceChange', (deviceChanged) => { - console.info('Should be no callback.'); -}); +audioRoutingManager.off('deviceChange'); ``` ## Selecting an Audio Output Device (for System Applications only) @@ -88,3 +86,46 @@ async function selectOutputDevice(){ }); } ``` + +## Obtaining Information About the Output Device with the Highest Priority + +Call **getPreferOutputDeviceForRendererInfo()** to obtain the output device with the highest priority. + +> **NOTE** +> +> The output device with the highest priority is the device that will output audio. + +```ts +let rendererInfo = { + content : audio.ContentType.CONTENT_TYPE_MUSIC, + usage : audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags : 0, +} + +async function getPreferOutputDeviceForRendererInfo() { + audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc) => { + console.info(`device descriptor: ${desc}`); + }).catch((err) => { + console.error(`Result ERROR: ${err}`); + }) +} +``` + +## Listening for Changes of the Output Device with the Highest Priority + +```ts +let rendererInfo = { + content : audio.ContentType.CONTENT_TYPE_MUSIC, + usage : audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags : 0, +} + +// Listen for changes of the output device with the highest priority. +audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc) => { + console.info(`device change descriptor : ${desc.deviceDescriptors[0].deviceRole}`); // Device role. + console.info(`device change descriptor : ${desc.deviceDescriptors[0].deviceType}`); // Device type. +}); + +// Cancel the listening for changes of the output device with the highest priority. +audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo'); +``` diff --git a/en/application-dev/media/image-transformation-native.md b/en/application-dev/media/image-transformation-native.md new file mode 100644 index 0000000000000000000000000000000000000000..06d342d8092744d7c565d02d0e62c13b71cc12d2 --- /dev/null +++ b/en/application-dev/media/image-transformation-native.md @@ -0,0 +1,241 @@ +# Image Transformation (Native) + +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: + + ```c++ + EXTERN_C_START + static napi_value Init(napi_env env, napi_value exports) + { + napi_property_descriptor desc[] = { + { "createPixelMap", nullptr, CreatePixelMap, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "createAlphaPixelMap", nullptr, CreateAlphaPixelMap, nullptr, nullptr, nullptr, napi_default, nullptr }, + { "transform", nullptr, Transform, nullptr, nullptr, nullptr, napi_default, nullptr } + }; + + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; + } + EXTERN_C_END + ``` + + +**Calling the Native APIs** + +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. + + ```c++ + // Create a PixelMap object. + napi_value CreatePixelMap(napi_env env, napi_callback_info info) + { + napi_value udfVar = nullptr; + napi_value thisVar = nullptr; + napi_value argValue[2] = {0}; + size_t argCount = 2; + + void* buffer = nullptr; + size_t bufferSize = 0; + struct OhosPixelMapCreateOps createOps; + napi_value pixelmap = nullptr; + + napi_get_undefined(env, &udfVar); + napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr); + if (napi_get_arraybuffer_info(env, argValue[0], &buffer, &bufferSize) != napi_ok || + buffer == nullptr || bufferSize == 0) { + return udfVar; + } + + createOps.width = 4; + createOps.height = 6; + createOps.pixelFormat = 4; + createOps.alphaType = 0; + int32_t res = OH_PixelMap_CreatePixelMap(env, createOps, (uint8_t *)buffer, bufferSize, &pixelmap); + if (res != OHOS_IMAGE_RESULT_SUCCESS || pixelmap == nullptr) { + return udfVar; + } + return pixelmap; + } + + // Create a PixelMap object that contains only the alpha channel. + napi_value CreateAlphaPixelMap(napi_env env, napi_callback_info info) + { + napi_value udfVar = nullptr; + napi_value thisVar = nullptr; + napi_value argValue[1] = {0}; + size_t argCount = 1; + + napi_value alphaPixelmap = nullptr; + + napi_get_undefined(env, &udfVar); + + if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok || + argCount < 1 || argValue[0] == nullptr) { + return udfVar; + } + int32_t res = OH_PixelMap_CreateAlphaPixelMap(env, argValue[0], &alphaPixelmap); + if (res != OHOS_IMAGE_RESULT_SUCCESS || alphaPixelmap == nullptr) { + return udfVar; + } + return alphaPixelmap; + } + ``` + +2. Perform image transformation. For details about the operation, read the comments in the sample code below. + + ```c++ + napi_value Transform(napi_env env, napi_callback_info info) + { + napi_value thisVar = nullptr; + napi_value argValue[1] = {0}; + size_t argCount = 1; + + if (napi_get_cb_info(env, info, &argCount, argValue, &thisVar, nullptr) != napi_ok || + argCount < 1 || argValue[0] == nullptr) { + return nullptr; + } + napi_value result = nullptr; + napi_get_undefined(env, &result); + + NativePixelMap* native = OH_PixelMap_InitNativePixelMap(env, argValue[0]); + if (native == nullptr) { + return result; + } + + // Obtain image information. + struct OhosPixelMapInfo pixelmapInfo; + OH_PixelMap_GetImageInfo(native, &pixelmapInfo); + + // Obtain the number of bytes per row of the PixelMap object. + int32_t rowBytes; + OH_PixelMap_GetBytesNumberPerRow(native, &rowBytes); + + // Check whether the PixelMap object is editable. + int32_t editable = 0; + OH_PixelMap_GetIsEditable(native, &editable); + + // Check whether the PixelMap object supports alpha channels. + int32_t supportAlpha = 0; + OH_PixelMap_IsSupportAlpha(native, &supportAlpha); + + // Set an alpha channel for the PixelMap object. + int32_t alphaAble = 0; + OH_PixelMap_SetAlphaAble(native, alphaAble); + + // Obtain the pixel density of the PixelMap object. + int32_t densityG; + OH_PixelMap_GetDensity(native, &densityG); + + // Set the pixel density for the PixelMap object. + int32_t densityS = 100; + OH_PixelMap_SetDensity(native, densityS); + + // Set the opacity for the PixelMap object. + float opacity = 0.5; + OH_PixelMap_SetOpacity(native, opacity); + + // Scale the image. + // scaleX: The width of the image after scaling is 0.5 of the original width. + // scaleY: The height of the image after scaling is 0.5 of the original height. + float scaleX = 0.5; + float scaleY = 0.5; + OH_PixelMap_Scale(native, scaleX, scaleY); + + // Translate the image. + // translateX: Translate the image by 50 units downwards. + // translateY: Translate the image by 50 units rightwards. + float translateX = 50; + float translateY = 50; + OH_PixelMap_Translate(native, translateX, translateY); + + // Rate the image clockwise by 90°. + float angle = 90; + OH_PixelMap_Rotate(native, angle); + + // Flip the image. + // flipX: whether to flip the image horizontally. The value 1 means to flip the image and 0 means the opposite. + // flipY: whether to flip the image vertically. The value 1 means to flip the image and 0 means the opposite. + int32_t flipX = 0; + int32_t flipY = 1; + OH_PixelMap_Flip(native, flipX, flipY); + + // Crop the image. + // cropX: x-axis coordinate of the start point for cropping (0). + // cropY: y-axis coordinate of the start point for cropping (0). + // cropH: height after cropping (10), cropping from top to bottom. + // cropW: width after cropping (10), cropping from left to right. + int32_t cropX = 1; + int32_t cropY = 1; + int32_t cropW = 10; + int32_t cropH = 10; + OH_PixelMap_Crop(native, cropX, cropY, cropW, cropH); + + uint8_t* pixelAddr = nullptr; + // Obtain the memory address of the PixelMap object and lock the memory. + OH_PixelMap_AccessPixels(native, &pixelAddr); + // Unlock the memory of the PixelMap object. + OH_PixelMap_UnAccessPixels(native); + + return result; + } + ``` + +**Calling APIs on the JS Side** + +1. Open **src\main\ets\pages\index.ets**, and import **libentry.so**. + +2. Call the native APIs and pass in the JS resource object. The sample code is as follows: + + ```js + import testNapi from 'libentry.so' + import image from '@ohos.multimedia.image' + + @Entry + @Component + struct Index { + @State _pixelMap: image.PixelMap = undefined; + build() { + Row() { + Column() { + Button("PixelMap") + .width(100) + .height(100) + .onClick(() => { + const color = new ArrayBuffer(96); + var bufferArr = new Uint8Array(color); + for (var i = 0; i < bufferArr.length; i++) { + bufferArr[i] = 0x80; + } + + this._pixelMap = testNapi.createPixelMap(color); + testNapi.transform(this._pixelMap); + }) + + Image(this._pixelMap) + .width(500) + .height(500) + .objectFit(ImageFit.Cover) + } + .width('100%') + } + .height('100%') + } + } + ``` diff --git a/en/application-dev/media/image-transformation.md b/en/application-dev/media/image-transformation.md index 8965d409dda0fa9271feebb34b3b936c4b624bc6..c7bc907c7628ef85d45259742d2c9179e6c52dfc 100644 --- a/en/application-dev/media/image-transformation.md +++ b/en/application-dev/media/image-transformation.md @@ -1,4 +1,4 @@ -# Image Transformation +# Image Transformation (ArkTS) 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 ``` // Translate the image by 100 units downwards. - // Translate the image by 100 units to the right. + // Translate the image by 100 units rightwards. pixelMap.translate(100, 100); ``` diff --git a/en/application-dev/reference/apis/js-apis-audio.md b/en/application-dev/reference/apis/js-apis-audio.md index 4301f1019a2b6665a3ee039550146bee70e97be0..5fba4ed01ab7052e8a3ac220bad7d84fd4b5d9e5 100644 --- a/en/application-dev/reference/apis/js-apis-audio.md +++ b/en/application-dev/reference/apis/js-apis-audio.md @@ -486,8 +486,8 @@ Enumerates the audio channels. | Name | Value | Description | | --------- | -------- | -------- | -| CHANNEL_1 | 0x1 << 0 | Channel 1. | -| CHANNEL_2 | 0x1 << 1 | Channel 2. | +| CHANNEL_1 | 0x1 << 0 | Channel 1.| +| CHANNEL_2 | 0x1 << 1 | Channel 2.| ## AudioSamplingRate8+ @@ -545,7 +545,7 @@ Enumerates the audio stream usage. | ------------------------------------------| ------ | ---------- | | STREAM_USAGE_UNKNOWN | 0 | Unknown usage.| | STREAM_USAGE_MEDIA | 1 | Used for media. | -| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.| +| STREAM_USAGE_VOICE_COMMUNICATION | 2 | Used for voice communication.| | STREAM_USAGE_VOICE_ASSISTANT9+ | 3 | Used for voice assistant.| | STREAM_USAGE_ALARM10+ | 4 | Used for alarming. | | STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | Used for notification.| @@ -580,6 +580,17 @@ Enumerates the audio states. | STATE_RELEASED | 4 | Released. | | STATE_PAUSED | 5 | Paused. | +## AudioEffectMode10+ + +Enumerates the audio effect modes. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +| Name | Value | Description | +| ------------------ | ------ | ---------- | +| EFFECT_NONE | 0 | The audio effect is disabled.| +| EFFECT_DEFAULT | 1 | The default audio effect is used.| + ## AudioRendererRate8+ Enumerates the audio renderer rates. @@ -2023,7 +2034,7 @@ Currently, when multiple **AudioManager** instances are used in a single process | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | 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. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | 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. **Example** ```js -audioManager.off('deviceChange', (deviceChanged) => { - console.info('Should be no callback.'); -}); +audioManager.off('deviceChange'); ``` ### on('interrupt') @@ -2329,7 +2338,7 @@ Subscribes to system volume change events. This API uses an asynchronous callbac | Name | Type | Mandatory| Description | | -------- | -------------------------------------- | ---- | ------------------------------------------------------------ | | 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. | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | 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. | **Error codes** @@ -3397,6 +3406,68 @@ audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => { }); ``` +### getAudioEffectInfoArray10+ + +getAudioEffectInfoArray(content: ContentType, usage: StreamUsage, callback: AsyncCallback<AudioEffectInfoArray>): void + +Obtains information about the sound effect mode in use. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ----------------------------------- | -------- | --------------------------- | +| content | [ContentType](#contenttype) | Yes | Audio content type. | +| usage | [StreamUsage](#streamusage) | Yes | Audio stream usage. | +| callback | AsyncCallback<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Yes | Callback used to return the information obtained.| + +**Example** + +```js +audioStreamManager.getAudioEffectInfoArray(audio.ContentType.CONTENT_TYPE_MUSIC, audio.StreamUsage.STREAM_USAGE_MEDIA, async (err, audioEffectInfoArray) => { + console.info('getAudioEffectInfoArray **** Get Callback Called ****'); + if (err) { + console.error(`getAudioEffectInfoArray :ERROR: ${err}`); + return; + } else { + console.info(`The contentType of ${CONTENT_TYPE_MUSIC} and the streamUsage of ${STREAM_USAGE_MEDIA} 's effect modes are: ${audioEffectInfoArray}`); + } +}); +``` + +### getAudioEffectInfoArray10+ + +getAudioEffectInfoArray(content: ContentType, usage: StreamUsage): Promise<AudioEffectInfoArray> + +Obtains information about the sound effect mode in use. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ----------------------------------- | -------- | --------------------------- | +| content | [ContentType](#contenttype) | Yes | Audio content type. | +| usage | [StreamUsage](#streamusage) | Yes | Audio stream usage. | + +**Return value** + +| Type | Description | +| --------------------------------------------------------------------------| --------------------------------------- | +| Promise<[AudioEffectInfoArray](#audioeffectinfoarray10)> | Promise used to return the information obtained. | + +**Example** + +```js +audioStreamManager.getAudioEffectInfoArray().then((audioEffectInfoArray) => { + console.info(`getAudioEffectInfoArray ######### Get Promise is called ##########`); + console.info(`The contentType of ${CONTENT_TYPE_MUSIC} and the streamUsage of ${STREAM_USAGE_MEDIA} 's effect modes are: ${audioEffectInfoArray}`); +}).catch((err) => { + console.error(`getAudioEffectInfoArray :ERROR: ${err}`); +}); +``` + ## AudioRoutingManager9+ 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 **Example** ```js -audioRoutingManager.off('deviceChange', (deviceChanged) => { - console.info('Should be no callback.'); -}); +audioRoutingManager.off('deviceChange'); ``` ### selectInputDevice9+ @@ -4071,9 +4140,7 @@ For details about the error codes, see [Audio Error Codes](../errorcodes/errorco **Example** ```js -audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', () => { - console.info('Should be no callback.'); -}); +audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo'); ``` ## AudioRendererChangeInfoArray9+ @@ -4191,6 +4258,10 @@ audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => }); ``` +## AudioEffectInfoArray10+ + +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. @@ -4434,6 +4505,113 @@ audioRenderer.getAudioStreamId().then((streamid) => { }); ``` +### setAudioEffectMode10+ + +setAudioEffectMode(mode: AudioEffectMode, callback: AsyncCallback\): void + +Sets an audio effect mode. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ---------------------------------------- | ---- | ------------------------ | +| mode | [AudioEffectMode](#audioeffectmode10) | Yes | Audio effect mode to set. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Example** + +```js +audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT, (err) => { + if (err) { + console.error('Failed to set params'); + } else { + console.info('Callback invoked to indicate a successful audio effect mode setting.'); + } +}); +``` + +### setAudioEffectMode10+ + +setAudioEffectMode(mode: AudioEffectMode): Promise\ + +Sets an audio effect mode. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name| Type | Mandatory| Description | +| ------ | ---------------------------------------- | ---- | ------------ | +| mode | [AudioEffectMode](#audioeffectmode10) | Yes | Audio effect mode to set.| + +**Return value** + +| Type | Description | +| -------------- | ------------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +audioRenderer.setAudioEffectMode(audio.AudioEffectMode.EFFECT_DEFAULT).then(() => { + console.info('setAudioEffectMode SUCCESS'); +}).catch((err) => { + console.error(`ERROR: ${err}`); +}); +``` + +### getAudioEffectMode10+ + +getAudioEffectMode(callback: AsyncCallback\): void + +Obtains the audio effect mode in use. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | ------------------------------------------------------- | ---- | ------------------ | +| callback | AsyncCallback<[AudioEffectMode](#audioeffectmode10)> | Yes | Callback used to return the audio effect mode.| + +**Example** + +```js +audioRenderer.getAudioEffectMode((err, effectmode) => { + if (err) { + console.error('Failed to get params'); + } else { + console.info(`getAudioEffectMode: ${effectmode}`); + } +}); +``` + +### getAudioEffectMode10+ + +getAudioEffectMode(): Promise\ + +Obtains the audio effect mode in use. This API uses a promise to return the result. + +**System capability**: SystemCapability.Multimedia.Audio.Renderer + +**Return value** + +| Type | Description | +| ------------------------------------------------- | ------------------------- | +| Promise<[AudioEffectMode](#audioeffectmode10)> | Promise used to return the audio effect mode.| + +**Example** + +```js +audioRenderer.getAudioEffectMode().then((effectmode) => { + console.info(`getAudioEffectMode: ${effectmode}`); +}).catch((err) => { + console.error(`ERROR: ${err}`); +}); +``` + ### start8+ start(callback: AsyncCallback): void