diff --git a/README_zh.md b/README_zh.md
index ebf1bc8d7557d35f99eaacf8fd1427972d61d3b0..386fa1d7449553f92f399839d947a0dacd4e18b8 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -18,15 +18,15 @@
- master:最新开发版本。
- - OpenHarmony 3.2 Beta2版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.2-beta2.md)了解版本详情。
+ - OpenHarmony 3.2 Beta3版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.2-beta3.md)了解版本详情。
- OpenHarmony 3.1 Release版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.1-release.md)了解版本详情。
- 该已更新至OpenHarmony 3.1.1 Release,点击[此处](zh-cn/release-notes/OpenHarmony-v3.1.1-release.md)了解版本详情。
+ 该版本已更新至OpenHarmony 3.1.3 Release,点击[此处](zh-cn/release-notes/OpenHarmony-v3.1.3-release.md)了解版本详情。
- OpenHarmony 3.0 LTS版本:点击[此处](zh-cn/release-notes/OpenHarmony-v3.0-LTS.md)了解版本详情。
- 该版本已更新至OpenHarmony 3.0.5 LTS,点击[此处](zh-cn/release-notes/OpenHarmony-v3.0.5-LTS.md)了解版本详情。
+ 该版本已更新至OpenHarmony 3.0.6 LTS,点击[此处](zh-cn/release-notes/OpenHarmony-v3.0.6-LTS.md)了解版本详情。
- OpenHarmony 2.2 Beta2版本:点击[此处](zh-cn/release-notes/OpenHarmony-v2.2-beta2.md)了解版本详情。
@@ -34,7 +34,7 @@
### 历史稳定版本
-OpenHarmony_v1.x_release:OpenHarmony 1.1.4 LTS稳定版本,点击[此处](zh-cn/release-notes/OpenHarmony-v1-1-4-LTS.md)了解版本详情。
+OpenHarmony_v1.x_release:OpenHarmony 1.1.5 LTS稳定版本,点击[此处](zh-cn/release-notes/OpenHarmony-v1.1.5-LTS.md)了解版本详情。
如需了解更多版本详情,点击[此处](zh-cn/release-notes/)。
diff --git a/en/application-dev/reference/arkui-ts/ts-appendix-enums.md b/en/application-dev/reference/arkui-ts/ts-appendix-enums.md
index f1bce5a8cc619c0e72e1bff539b311d355c23755..d7b27a661400b2557de5cf6c710f26b0d00e05a5 100644
--- a/en/application-dev/reference/arkui-ts/ts-appendix-enums.md
+++ b/en/application-dev/reference/arkui-ts/ts-appendix-enums.md
@@ -137,9 +137,9 @@
| Name | Description |
| -------- | ---------------------- |
| Top | Top edge in the vertical direction. |
-| Center(deprecated) | Center position in the vertical direction.
This API is deprecated since API version 9. |
+| Center(deprecated) | Center position in the vertical direction.
This API is deprecated since API version 9. |
| Bottom | Bottom edge in the vertical direction. |
-| Baseline(deprecated) | Text baseline position in the cross axis direction.
This API is deprecated since API version 9.|
+| Baseline(deprecated) | Text baseline position in the cross axis direction.
This API is deprecated since API version 9. |
| Start | Start position in the horizontal direction. |
| Middle(deprecated) | Center position in the horizontal direction.
This API is deprecated since API version 9. |
| End | End position in the horizontal direction. |
@@ -249,7 +249,7 @@
| End | The child components are aligned with the end edge of the main axis. The last component is aligned with the main-end, and other components are aligned with the next one.|
| SpaceBetween | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The first component is aligned with the main-start, the last component is aligned with the main-end, and the remaining components are distributed so that the space between any two adjacent components is the same.|
| SpaceAround | The child components are evenly distributed along the main axis. The space between any two adjacent components is the same. The space between the first component and main-start, and that between the last component and cross-main are both half the size of the space between two adjacent components.|
-| SpaceEvenly | The child components are equally distributed along the main axis. The space between the first component and main-start, the space between the last component and main-end, and the space between two adjacent components are the same.|
+| SpaceEvenly | The child components are evenly distributed along the main axis. The space between the first component and main-start, the space between the last component and main-end, and the space between any two adjacent components are the same. |
## ItemAlign
@@ -355,9 +355,9 @@
| Name | Description |
| -------- | -------------------------------------- |
-| Clip | Extra-long text is truncated. |
+| Clip | Extra-long text is clipped. |
| Ellipsis | An ellipsis (...) is used to represent clipped text.|
-| None | No truncation or ellipsis is used for extra-long text. |
+| None | No clipping or ellipsis is used for extra-long text. |
## TextDecorationType
@@ -413,9 +413,9 @@
| Name | Description |
| ----------- | -------------------- |
-| None | Copy and paste is not allowed. |
-| InApp | Intra-application copy and paste is allowed.|
-| LocalDevice | Intra-device copy and paste is allowed.|
+| None | Copy is not allowed. |
+| InApp | Intra-application copy is allowed.|
+| LocalDevice | Intra-device copy is allowed.|
## HitTestMode9+
diff --git a/en/contribute/introducing-third-party-open-source-software.md b/en/contribute/introducing-third-party-open-source-software.md
index a0b35543246aff22d2d6ad693f1553add5932457..9d035a952d283b41604c492639eb2f0f52c37a88 100644
--- a/en/contribute/introducing-third-party-open-source-software.md
+++ b/en/contribute/introducing-third-party-open-source-software.md
@@ -12,7 +12,7 @@ This guide applies to all third-party open-source software to be introduced to t
## Improvements and Revisions
1. This document is drafted and maintained by the OpenHarmony SIG QA. What you are reading now is the latest version of this document.
-
+
2. Any addition, modification, or deletion of the principles mentioned in this document can be traced in the tracing system.
3. The PMC reviews and finalizes the principles after thorough discussion in the community.
@@ -40,6 +40,22 @@ For easier maintenance and evolution, comply with the following principles when
12. When software introduction depends on other dependency software, it is not allowed to nest the dependency software in the subdirectory of the software introduction, and all dependency softwares must be placed in separate repository, and name it in the format of **third_party_*****softwareName***, because nested placement of dependency software may lead to multiple versions of the same software, old versions of security vulnerabilities cannot be fixed in a timely, and will risk the opensource compliance issues.
- Dependency software are named in the compiled BUILD.gn with part name by prefixing the newly software introduction name, e.g. part_name = "software_introduction_name_dependency software_name".
- The inter-component dependencies between software introduction and dependency software are resolved via external_deps.
+13. OpenHarmony's archiving directory requirements for third-party software introduction.
+ - If you don't have a really good reason to store it elsewhere and under one of the permitted licenses belongs in third_party.
+ - For the dedicated third-party software introduction which belongs to the specail devboard, and is is not suitable introduced into the OpenHarmony platform, you could apply to store it in the following locations, Naming it in the format of **softwareName**, where **softwareName** must be an official name, and create README.OpenSource description file in the corresponding directory; Creating BUILD.gn to build it independently to support the automatic collection of open source obligation declaration.
+
+ ```
+ device/soc/$(SOC_COMPANY)/third_party
+ device/board/$(BOARD_COMPANY)/third_party
+ vendor/$(PRODUCT_COMPANY)/third_party
+ ```
+
+14. Precompiled binary or toolchain used in the OpenHarmony, the following information needs to be provided.
+ - The source code corresponding to the pre-compiled binary or toolchain, which needs to store the corresponding source code in the OpenHarmony community, and provide the corresponding build guide, and provide open source obligation statement guide;
+ - Third-party software introduction for precompiled binary or toolchain, need to meet the principles 1 ~ 13;
+ - The [prebuilt toolchain's description documentation](./prebuilts-readme-template.md): including source code acquisition address, build instructions, update methods, archived in the toolchain root directory with the toolchain build;
+ - The root directory corresponding to the pre-compiled binary or toolchain needs to provide notice file of the full open source obligation statement;
+ - If the precompiled binary files come from upstream service platform (e.g. npm packages, etc.). We need to provide the following information in the place where the binary is archived, first we need to provide a general description with the name **README**, include the following information: background description of the introduction and official website; next we need to provide a opensource obligation statement file with the name **NOTICE**, include the following information: software name, version, copyrights, and license information of every third-party open-source software.
### Software Introduction Process
@@ -64,10 +80,10 @@ Follow the process described in the [SIG Management Regulations](https://gitee.c
| Check Item| Description| Self-Check Result Example|
| :----- | :----- | :----- |
| Software name| Provide the official name of the software and the repository name to which the software is introduced. The repository name is in the format of **third_party**_**softwareName**.| third_party_**softwareName**|
-| Official website| Provide the official website link of the software.| https://softwaresite |
+| Official website| Provide the official website link of the software.| |
| Software version| Provide the version number of the software to be introduced. The version number must be an official version number released by the community. Do not modify the version number or introduce a version that is not officially released.| 1.0.0 |
| Software version release date| Provide the official release date of the software version.| 2021.01.01 |
-| Software version address| Provide the official download URL of the version. Note that the URL must be able to locate the release package of the specific version.| https://gitee.com/softwarecodesite/v1.0.0.zip |
+| Software version address| Provide the official download URL of the version. Note that the URL must be able to locate the release package of the specific version.| |
| Software license| Provide the official license name of the version and the relative path of the license file. If there are multiple licenses, list them all and describe their relationship, for example, And, Or, or different licenses for different directories.| Apache-2.0 |
| Software lifecycle| Describe whether the software has an LTS version, how frequent a version is released, code submitted to the community in the last year, issue resolution status, and whether end of maintenance or evolution is notified.| No LTS version; one version released every six months; 10 code submissions in the last six months|
| Security vulnerabilities| List disclosed security vulnerabilities in the software, including the vulnerability number, severity, link, and whether patches or solutions are available.| No disclosed vulnerabilities.|
@@ -121,9 +137,9 @@ Confirm the issues found by the OAT tool and configure the **OAT.xml** file. For
]
```
-#### PMC Review
+#### Open source software introduction Review
-Refer to the [SIG Management Regulations](https://gitee.com/openharmony/community/tree/master/sig). The PMC will arrange the SIG request review and repository construction based on the received PR.
+Refer to the [SIG-Architecture](https://gitee.com/openharmony/community/blob/master/sig/sig-architecture/sig-architecture_cn.md). The SIG-Architecture will arrange the review of the applying of creating new repository.
### License Requirements for Third-Party Open-Source Software
@@ -131,66 +147,66 @@ Refer to the [SIG Management Regulations](https://gitee.com/openharmony/communit
2. The software license must be compatible with the license for the code repository.
3. The following licenses for third-party open-source software are recommended in the OpenHarmony project:
-* Apache License 2.0
-* Mulan Permissive Software License, Version 2
-* BSD 2-clause
-* BSD 3-clause
-* DOM4J License
-* PostgreSQL License
-* Eclipse Distribution License 1.0
-* MIT
-* ISC
-* ICU
-* University of Illinois/NCSA
-* W3C Software License
-* zlib/libpng
-* Academic Free License 3.0
-* Python Software Foundation License
-* Python Imaging Library Software License
-* Boost Software License Version 1.0
-* WTF Public License
-* UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
-* Zope Public License 2.0
+- Apache License 2.0
+- Mulan Permissive Software License, Version 2
+- BSD 2-clause
+- BSD 3-clause
+- DOM4J License
+- PostgreSQL License
+- Eclipse Distribution License 1.0
+- MIT
+- ISC
+- ICU
+- University of Illinois/NCSA
+- W3C Software License
+- zlib/libpng
+- Academic Free License 3.0
+- Python Software Foundation License
+- Python Imaging Library Software License
+- Boost Software License Version 1.0
+- WTF Public License
+- UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE
+- Zope Public License 2.0
4. The following licenses for third-party open-source software are not recommended in the OpenHarmony project:
-* GNU GPL 1, 2, 3
-* GNU Affero GPL 3
-* GNU LGPL 2, 2.1, 3
-* QPL
-* Sleepycat License
-* Server Side Public License (SSPL) version 1
-* Code Project Open License (CPOL)
-* BSD-4-Clause/BSD-4-Clause (University of California-Specific)
-* Facebook BSD+Patents license
-* NPL 1.0/NPL 1.1
-* The Solipsistic Eclipse Public License
-* The "Don't Be A Dick" Public License
-* JSON License
-* Binary Code License (BCL)
-* Intel Simplified Software License
-* JSR-275 License
-* Microsoft Limited Public License
-* Amazon Software License (ASL)
-* Java SDK for Satori RTM license
-* Redis Source Available License (RSAL)
-* Booz Allen Public License
-* Creative Commons Non-Commercial
-* Sun Community Source License 3.0
-* Common Development and Distribution Licenses: CDDL 1.0 and CDDL 1.1
-* Common Public License: CPL 1.0
-* Eclipse Public License: EPL 1.0
-* IBM Public License: IPL 1.0
-* Mozilla Public Licenses: MPL 1.0, MPL 1.1, and MPL 2.0
-* Sun Public License: SPL 1.0
-* Open Software License 3.0
-* Erlang Public License
-* UnRAR License
-* SIL Open Font License
-* Ubuntu Font License Version 1.0
-* IPA Font License Agreement v1.0
-* Ruby License
-* Eclipse Public License 2.0: EPL 2.0
+- GNU GPL 1, 2, 3
+- GNU Affero GPL 3
+- GNU LGPL 2, 2.1, 3
+- QPL
+- Sleepycat License
+- Server Side Public License (SSPL) version 1
+- Code Project Open License (CPOL)
+- BSD-4-Clause/BSD-4-Clause (University of California-Specific)
+- Facebook BSD+Patents license
+- NPL 1.0/NPL 1.1
+- The Solipsistic Eclipse Public License
+- The "Don't Be A Dick" Public License
+- JSON License
+- Binary Code License (BCL)
+- Intel Simplified Software License
+- JSR-275 License
+- Microsoft Limited Public License
+- Amazon Software License (ASL)
+- Java SDK for Satori RTM license
+- Redis Source Available License (RSAL)
+- Booz Allen Public License
+- Creative Commons Non-Commercial
+- Sun Community Source License 3.0
+- Common Development and Distribution Licenses: CDDL 1.0 and CDDL 1.1
+- Common Public License: CPL 1.0
+- Eclipse Public License: EPL 1.0
+- IBM Public License: IPL 1.0
+- Mozilla Public Licenses: MPL 1.0, MPL 1.1, and MPL 2.0
+- Sun Public License: SPL 1.0
+- Open Software License 3.0
+- Erlang Public License
+- UnRAR License
+- SIL Open Font License
+- Ubuntu Font License Version 1.0
+- IPA Font License Agreement v1.0
+- Ruby License
+- Eclipse Public License 2.0: EPL 2.0
If you want to introduce the software that complies with the unrecommended licenses listed in **4** or other licenses that are not mentioned, send an email to oh-legal@openatom.io.
diff --git a/en/contribute/prebuilts-readme-template.md b/en/contribute/prebuilts-readme-template.md
new file mode 100644
index 0000000000000000000000000000000000000000..d106f08a850bc065e5be5d2c597058d82996fc22
--- /dev/null
+++ b/en/contribute/prebuilts-readme-template.md
@@ -0,0 +1,28 @@
+Prebuilts for Clang/LLVM-based tools used in OpenHarmony
+====================================================
+
+1. For the latest version of this doc, please make sure to visit:
+[OpenHarmony Clang/LLVM-based Tools Readme Doc](https://gitee.com/openharmony/third_party_llvm-project/blob/master/llvm-build/README.md)
+
+2. Build Instructions
+------------------
+
+```
+# Get source code
+repo init -u https://gitee.com/openharmony/manifest.git -b llvm_toolchain-dev
+repo sync -c
+repo forall -c 'git lfs pull'
+cp -r toolchain/llvm-project/llvm-build toolchain
+
+# Build Clang/LLVM-based prebuilts tool
+./toolchain/llvm-project/llvm-build/env_prepare.sh
+python3 ./toolchain/llvm-build/build.py
+```
+
+3. Update Prebuilts
+----------------
+From an OpenHarmony project run:
+
+```
+$ ./build/prebuilts_download.sh
+```
diff --git a/zh-cn/application-dev/media/camera.md b/zh-cn/application-dev/media/camera.md
index 60f0348ee1442aba10a477226a3effd969151c98..617c4107faa983dc2231c80578405be95cf93e1c 100644
--- a/zh-cn/application-dev/media/camera.md
+++ b/zh-cn/application-dev/media/camera.md
@@ -59,7 +59,8 @@ import image from '@ohos.multimedia.image'
import media from '@ohos.multimedia.media'
// 创建CameraManager对象
-let cameraManager = await camera.getCameraManager(null)
+context: any = getContext(this)
+let cameraManager = await camera.getCameraManager(this.context)
if (!cameraManager) {
console.error('Failed to get the CameraManager instance');
}
@@ -78,14 +79,10 @@ for (let index = 0; index < cameraArray.length; index++) {
}
// 创建相机输入流
-let cameraInput
-await cameraManager.createCameraInput(cameraArray[0].cameraId).then((input) => {
- console.log('Promise returned with the CameraInput instance');
- cameraInput = input
-})
+let cameraInput = await cameraManager.createCameraInput(cameraArray[0])
// 获取相机设备支持的输出流能力
-let cameraOutputCap = await camera.getSupportedOutputCapability(cameraInput);
+let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
if (!cameraOutputCap) {
console.error("outputCapability outputCapability == null || undefined")
} else {
@@ -112,8 +109,8 @@ if (!metadataObjectTypesArray) {
console.error("createOutput metadataObjectTypesArray == null || undefined")
}
-// 创建预览输出流
-let previewOutput = await camera.createPreviewOutput(previewProfilesArray[0], surfaceId)
+// 创建预览输出流,其中参数 surfaceId 参考下面 XComponent 组件,预览流为XComponent组件提供的surface
+let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
if (!previewOutput) {
console.error("Failed to create the PreviewOutput instance.")
}
@@ -123,7 +120,7 @@ let imageReceiver = await image.createImageReceiver(1920, 1080, 4, 8)
// 获取照片显示SurfaceId
let photoSurfaceId = await imageReceiver.getReceivingSurfaceId()
// 创建拍照输出流
-let photoOutput = await this.camera.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
+let photoOutput = await cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
if (!photoOutput) {
console.error('Failed to create the PhotoOutput instance.');
return;
@@ -155,20 +152,21 @@ let videoConfig = {
// 创建录像输出流
let videoRecorder
-await media.createVideoRecorder().then((recorder) => {
+media.createVideoRecorder().then((recorder) => {
console.log('createVideoRecorder called')
videoRecorder = recorder
})
// 设置视频录制的参数
-await videoRecorder.prepare(videoConfig)
+videoRecorder.prepare(videoConfig)
//获取录像SurfaceId
-await videoRecorder.getInputSurface().then((id) => {
+let videoSurfaceId
+videoRecorder.getInputSurface().then((id) => {
console.log('getInputSurface called')
videoSurfaceId = id
})
// 创建VideoOutput对象
-let videoOutput = camera.createVideoOutput(videoProfilesArray[0], videoSurfaceId)
+let videoOutput = await cameraManager.createVideoOutput(videoProfilesArray[0], videoSurfaceId)
if (!videoOutput) {
console.error('Failed to create the videoOutput instance.');
return;
@@ -205,11 +203,11 @@ build() {
```typescript
function getImageReceiverSurfaceId() {
- var receiver = image.createImageReceiver(640, 480, 4, 8)
+ let receiver = image.createImageReceiver(640, 480, 4, 8)
console.log(TAG + 'before ImageReceiver check')
if (receiver !== undefined) {
console.log('ImageReceiver is ok')
- surfaceId1 = await receiver.getReceivingSurfaceId()
+ surfaceId1 = receiver.getReceivingSurfaceId()
console.log('ImageReceived id: ' + JSON.stringify(surfaceId1))
} else {
console.log('ImageReceiver is not ok')
@@ -399,17 +397,17 @@ videoOutput.start(async (err) => {
});
// 开始录像
-await videoRecorder.start().then(() => {
+videoRecorder.start().then(() => {
console.info('videoRecorder start success');
}
// 停止录像
-await videoRecorder.stop().then(() => {
+videoRecorder.stop().then(() => {
console.info('stop success');
}
// 停止录像输出流
-await videoOutput.stop((err) => {
+videoOutput.stop((err) => {
if (err) {
console.error('Failed to stop the video output ${err.message}');
return;
@@ -424,22 +422,22 @@ await videoOutput.stop((err) => {
```typescript
// 停止当前会话
-await captureSession.stop()
+captureSession.stop()
// 释放相机输入流
-await cameraInput.release()
+cameraInput.release()
// 释放预览输出流
-await previewOutput.release()
+previewOutput.release()
// 释放拍照输出流
-await photoOutput.release()
+photoOutput.release()
// 释放录像输出流
-await videoOutput.release()
+videoOutput.release()
// 释放会话
-await captureSession.release()
+captureSession.release()
// 会话置空
captureSession = null
diff --git a/zh-cn/application-dev/quick-start/arkts-state-mgmt-page-level.md b/zh-cn/application-dev/quick-start/arkts-state-mgmt-page-level.md
index 959f924a34bbe7fd48ded0a20c3b38178b323035..a140452948660edabecc87e7b98706b91c51a268 100644
--- a/zh-cn/application-dev/quick-start/arkts-state-mgmt-page-level.md
+++ b/zh-cn/application-dev/quick-start/arkts-state-mgmt-page-level.md
@@ -1,6 +1,6 @@
# 页面级变量的状态管理
-@State、@Prop、@Link、@Provide、Consume、@ObjectLink、@Observed和@Watch用于管理页面级变量的状态。
+@State、@Prop、@Link、@Provide、@Consume、@ObjectLink、@Observed和@Watch用于管理页面级变量的状态。
请参考[状态变量多种数据类型声明的使用限制](./arkts-restrictions-and-extensions.md)了解@State、@Provide、 @Link和@Consume四种状态变量的约束条件。
diff --git a/zh-cn/application-dev/quick-start/package-structure.md b/zh-cn/application-dev/quick-start/package-structure.md
index 462dc9120fb3f296677c5cac7d2390078f41fe67..c51e7a2855d52515c947406c6c1cbe0d178f938b 100755
--- a/zh-cn/application-dev/quick-start/package-structure.md
+++ b/zh-cn/application-dev/quick-start/package-structure.md
@@ -92,9 +92,6 @@ app对象包含应用全局配置信息,内部结构说明参见表2。
| vendor | 标识对应用开发厂商的描述。字符串长度不超过255字节。 | 字符串 | 可缺省,缺省值为空 |
| version | 标识应用的版本信息。参考表3。 | 对象 | 否 |
| apiVersion | 标识应用程序所依赖的OpenHarmony API版本。参考表4。 | 对象 | 可缺省,缺省值为空 |
-| singleton | 标识应用是否开启单例模式,仅支持系统应用,三方应用配置不生效。如果配置为true,在多用户场景下,该应用仍然单实例运行,不会随用户切换而变动,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为false |
-| removable | 标识应用是否可卸载,仅支持系统应用,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true |
-| userDataClearable | 标识是否允许应用清除用户数据,仅支持系统应用,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true |
表3 version内部结构说明
diff --git a/zh-cn/application-dev/quick-start/stage-structure.md b/zh-cn/application-dev/quick-start/stage-structure.md
index dbdb68f9ae500bd586ec8fc85f20159cf1bcf8b6..fe72991043a1e313e677f968c8240d6b96bec2fa 100755
--- a/zh-cn/application-dev/quick-start/stage-structure.md
+++ b/zh-cn/application-dev/quick-start/stage-structure.md
@@ -2,7 +2,7 @@
# 应用包结构配置文件的说明
-在开发FA模型下的应用程序时,需要在config.json文件中对应用的包结构进行申明;同样的,在开发stage模型下的应用程序时,需要在module.json5和app.json配置文件中对应用的包结构进行声明。
+在开发stage模型的应用程序时,需要在app.json5和module.json5配置文件中对应用的包结构进行声明。
## 配置文件内部结构
@@ -12,18 +12,41 @@
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | ---------- |
-| app | 标识应用的全局配置信息。参考[app对象内部结构](#app对象内部结构)。 | 对象 | 否 |
-| module | 标识HAP包的配置信息。该标签下的配置只对当前HAP包生效。参考[module对象内部结构](#module对象内部结构)。 | 对象 | 否 |
+| app | 标识应用的全局配置信息。参考[app对象内部结构](#app对象内部结构)。 | 对象 | 不可缺省。 |
+| module | 标识HAP包的配置信息。该标签下的配置只对当前HAP包生效。参考[module对象内部结构](#module对象内部结构)。 | 对象 | 不可缺省。 |
### app对象内部结构
-app.json示例:
+该标签为整个应用的属性,影响应用中所有HAP及组件。该标签的内部结构参见表2。
+
+表2 app对象的内部结构说明
+
+| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
+| ------------------------------ | ------------------------------------------------------------ | -------- | ------------------------------------------- |
+| bundleName | 该标签标识应用的包名,用于标识应用的唯一性。标签的值命名规则 :
1)字符串以字母、数字、下划线和符号”.”组成;
2)以字母开头;
3)最小长度7字节,最大长度127个字节。
推荐采用反域名形式命名(如 :com.example.xxx,建议第一级为域名后缀com,第二级为厂商/个人名,第三级为应用名,也可以多级)。 | 字符串 | 不可缺省。 |
+| debug | 该标签标识应用是否可调试。该标签由IDE编译构建时产生。 | 布尔值 | 可缺省,缺省值为false。 |
+| icon | 该标签标识应用的图标,标签值为图标资源文件的索引。 | 字符串 | 不可缺省。 |
+| label | 该标签标识应用的名称,标签值为字符串资源的索引。 | 字符串 | 不可缺省。 |
+| description | 该标签标识App的描述信息,标签值是是字符串类型或对描述内容的字符串资源索引。 | 字符串 | 可缺省,缺省值为空。 |
+| vendor | 该标签是对应用开发厂商的描述。最大长度255字节。 | 字符串 | 可缺省,缺省值为空。 |
+| versionCode | 该标签标识应用的版本号,该标签值为32位非负整数。此数字仅用于确定某个版本是否比另一个版本更新,数值越大表示版本越高。开发者可以将该值设置为任何正整数,但是必须确保应用的新版本都使用比旧版本更大的值。versionCode 值应小于2的31次方。 | 数值 | 不可缺省。 |
+| versionName | 该标签标识版本号的文字描述,用于向用户展示。
该标签仅由数字和点构成,推荐采用“A.B.C.D”四段式的形式。四段式推荐的含义如下所示。
第一段 :主版本号/Major,范围0-99,重大修改的版本,如实现新的大功能或重大变化。
第二段 :次版本号/Minor,范围0-99,表示实现较突出的特点,如新功能添加和大问题修复。
第三段 :特性版本号/Feature,范围0-99,标识规划的新版本特性。
第四段 :修订版本号/Patch,范围0-999,表示维护版本,修复bug。 | 字符串 | 不可缺省。 |
+| minCompatibleVersionCode | 该标签标识该app能够兼容的最低历史版本号,用于跨设备兼容性判断。 | 数值 | 可缺省。缺省值等于versionCode标签值。|
+| minAPIVersion | 该标签标识应用运行需要的SDK的API最小版本。 | 数值 | 可缺省,缺省值为bundle-profile.json5中的compatibleSdkVersion。|
+| targetAPIVersion | 该标签标识应用运行需要的API目标版本。 | 数值 | 可缺省,缺省值为bundle-profile.json5中的compileSdkVersion。|
+| apiReleaseType | 该标签标识应用运行需要的API目标版本的类型,采用字符串类型表示。取值为“CanaryN”、“BetaN”或者“Release”,其中,N代表大于零的整数。
Canary :受限发布的版本。
Beta :公开发布的Beta版本。
Release :公开发布的正式版本。
该字段由IDE读取当前使用的SDK的stage来生成。 | 字符串 | 可缺省,由IDE生成并覆盖。 |
+| distributedNotificationEnabled | 该标签标记该应用是否开启分布式通知。 | 布尔值 | 可缺省,缺省值为true。 |
+| entityType | 该标签标记该应用的类别,具体有 :游戏类(game),影音类(media)、社交通信类(communication)、新闻类(news)、出行类(travel)、工具类(utility)、购物类(shopping)、教育类(education)、少儿类(kids)、商务类(business)、拍摄类(photography)。 | 字符串 | 可缺省,缺省值为"unspecified"。 |
+| multiProjects | 标识当前工程是否支持多工程。 | 布尔值 | 可缺省,缺省值为false。 |
+| 设备类型 | 该标签可以配置多个,表示具体设备上的特殊配置信息,具体的设备类型有:"tablet"、"tv"、"wearable"、"car"、"default",可包含的字段有:minAPIVersion、distributedNotificationEnabled。 | 对象 | 可缺省,缺省值使用app下面相关的字段。 |
+
+app.json示例 :
```json
{
"app": {
- "bundleName": "com.application.music",
- "vendor": "application",
+ "bundleName": "bundleName",
+ "vendor": "vendorName",
"versionCode": 1,
"versionName": "1.0",
"minCompatibleVersionCode": 1,
@@ -32,76 +55,73 @@ app.json示例:
"apiReleaseType": "Release",
"debug": false,
"icon": "$media:app_icon",
- "label": "$string:app_name",
- "description": "$string:description_application",
+ "label": "$string:app_label",
+ "description": "$string:app_description",
"distributedNotificationEnabled": true,
"entityType": "game",
"car": {
- "apiCompatibleVersion": 8
+ "minAPIVersion": 8
}
}
}
```
-该标签为整个应用的属性,影响应用中所有hap及组件。该标签的内部结构参见表2。
+### module对象内部结构
-表2 app对象的内部结构说明
+HAP包的配置信息,该标签下的配置只对当前HAP包生效。
-| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
-| ------------------------------ | ------------------------------------------------------------ | -------- | ------------------------------------------- |
-| bundleName | 该标签标识应用的包名,用于标识应用的唯一性。该标签不可缺省。标签的值命名规则 :
1)字符串以字母、数字、下划线和符号”.”组成;
2)以字母开头;
3)最小长度7个字节,最大长度127个字节。
推荐采用反域名形式命名(如 :com.example.xxx,建议第一级为域名后缀com,第二级为厂商/个人名,第三级为应用名,也可以多级)。
其中,随系统源码编译的应用需命名为”com.ohos.xxx”形式, ohos标识OpenHarmony系统应用。 | 字符串 | 否 |
-| debug | 该标签标识应用是否可调试。 | 布尔值 | 该标签可以缺省,缺省为false。 |
-| icon | 该标签标识应用的图标,标签值为资源文件的索引。 | 字符串 | 该标签不可缺省。 |
-| label | 该标签标识应用的的名称,标签值为资源文件的索引,以支持多语言。 | 字符串 | 该标签不可缺省。 |
-| description | 该标签标识App的描述信息,标签值是是字符串类型或对描述内容的资源索引,以支持多语言。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| vendor | 该标签是对应用开发厂商的描述。该标签的值是字符串类型(最大255个字节)。 | 字符串 | 该标签可以缺省,缺省为空。 |
-| versionCode | 该标签标识应用的版本号,该标签值为32位非负整数。此数字仅用于确定某个版本是否比另一个版本更新,数值越大表示版本越高。开发者可以将该值设置为任何正整数,但是必须确保应用的新版本都使用比旧版本更大的值。该标签不可缺省,versionCode 值应小于2的31方。 | 数值 | 该标签不可缺省 |
-| versionName | 该标签标识版本号的文字描述,用于向用户展示。
该标签仅由数字和点构成,推荐采用“A.B.C.D”四段式的形式。四段式推荐的含义如下所示。
第一段 :主版本号/Major,范围0-99,重大修改的版本,如实现新的大功能或重大变化。
第二段 :次版本号/Minor,范围0-99,表示实现较突出的特点,如新功能添加和大问题修复。
第三段 :特性版本号/Feature,范围0-99,标识规划的新版本特性。
第四段 :修订版本号/Patch,范围0-999,表示维护版本,修复bug。 | 字符串 | 该标签不可缺省 |
-| minCompatibleVersionCode | 该标签标识该app能够兼容的最低历史版本号,用于跨设备兼容性判断。 | 数值 | 该标签可缺省。缺省值等于versionCode标签值。|
-| minAPIVersion | 该标签标识应用运行需要的API最小版本。 | 整形 | 该标签可缺省,缺省值为bundle-profile.json5中的compatibleSdkVersion。|
-| targetAPIVersion | 该标签标识应用运行需要的API目标版本。 | 整形 | 该标签可缺省,缺省值为bundle-profile.json5中的compileSdkVersion。|
-| apiReleaseType | 该标签标识应用运行需要的API目标版本的类型,采用字符串类型表示。取值为“CanaryN”、“BetaN”或者“Release”,其中,N代表大于零的整数。
Canary :受限发布的版本。
Beta :公开发布的Beta版本。
Release :公开发布的正式版本。 | 字符串 | 该标签可缺省,缺省为“Release”。 |
-| distributedNotificationEnabled | 该标签标记该应用是否开启分布式通知。 | 布尔值 | 该标签可缺省,缺省值为true。 |
-| entityType | 该标签标记该应用的类别,具体有 :游戏类(game),影音类(media)、社交通信类(communication)、新闻类(news)、出行类(travel)、工具类(utility)、购物类(shopping)、教育类(education)、少儿类(kids)、商务类(business)、拍摄类(photography)。 | 字符串 | 该标签可以缺省,缺省为unspecified。 |
-| singleton | 标识该应用开启单例模式,仅支持系统应用配置,三方应用配置不生效。配置为true时,在多用户场景下,该应用仍然单实例运行,不会随用户切换而变动。采用布尔类型,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为false。 |
-| removable | 标识应用是否可卸载,仅支持系统应用配置,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true。 |
-| keepAlive | 标识应用是否始终保持运行状态,仅支持系统应用配置,三方应用配置不生效。标签值为布尔类型,如果为true,应用将始终保持为运行状态,并且在系统启动的时候会被系统启动起来,应用进程退出后,系统也会重新启动该应用进程。 | 布尔值 | 可缺省,缺省值为false。 |
-| userDataClearable | 标识是否允许应用清除用户数据,仅支持系统应用配置,三方应用配置不生效,该字段从API8开始支持。 | 布尔值 | 可缺省,缺省值为true。 |
-| accessible | 标识应用的安装目录是否是可访问的,仅支持系统应用配置,三方应用配置不生效。配置为true表示安装目录可以被三方应用访问,false表示不能被三方应用访问。 | 布尔值 | 可缺省,缺省值为false。 |
-| multiProjects | 标识当前工程是否支持多工程。 | 布尔值 | 可缺省,缺省值为false。 |
-| 设备类型 | 该标签可以配置多个,表示具体设备上的特殊配置信息,具体的设备类型有:"tablet"、"tv"、"wearable"、"car",可能包含的字段有:minAPIVersion、distributedNotificationEnabled、keepAlive、removable。 | 对象 | 该标签可缺省,缺省值使用app下面相关的字段。 |
+表3 module对象内部结构说明
+
+| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
+| -------------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
+| name | 该标签标识当前module的名字。module打包成HAP后,表示HAP的名称,标签值采用字符串表示(最大长度31字节),该名称在整个应用要唯一。 | 字符串 | 不可缺省。 |
+| type | 该标签标识当前module的类型。类型有两种,分别是entry、feature。 | 字符串 | 不可缺省。 |
+| srcEntrance | 该标签标识HAP所对应的入口js代码路径,标签值为字符串(最大长度127字节)。 | 字符串 | 可缺省,缺省值为空。 |
+| description | 该标签标识HAP包的描述信息,标签值是是字符串类型或对描述内容的字符串资源索引。 | 字符串 | 可缺省,缺省值为空。 |
+| process | 该标签标识HAP的进程名,标签值为字符串类型(最大长度31字节)。如果在HAP标签下配置了process,该应用的所有ability都运行在该进程中。该标签只支持系统应用配置。 | 字符串 | 可缺省,缺省值为app标签下的bundleName。 |
+| mainElement | 该标签标识HAP的入口Ability名称或者Extension名称。只有配置为mainElement的Ability或者Extension才允许在服务中心露出。 | 字符串 | 创建OpenHarmony原子化服务时,不可缺省。OpenHarmony应用下,可缺省,缺省值为空。 |
+| deviceTypes | 该标签标识HAP可以运行在哪类设备上,标签值采用字符串数组的表示,系统预定义的设备类型见表4。 | 字符串数组 | 不可缺省。 |
+| deliveryWithInstall | 该标签标识当前HAP是否在用户主动安装的时候安装,true表示主动安装时安装,false表示主动安装时不安装。 | 布尔值 | 不可缺省。 |
+| installationFree | 标识当前HAP是否支持免安装特性。所有Hap包都需要配置不可缺省。
true :表示支持免安装特性,且符合免安装约束。
false :表示不支持免安装特性。
当entry.hap该字段配置为true时,与该entry.hap相关的所有feature.hap该字段也需要配置为true。
当entry.hap该字段配置为false时,与该entry.hap相关的各feature.hap该字段可按业务需求配置true或false。 | 布尔值 | 不可缺省。 |
+| virtualMachine | 该标签用于标识当前HAP运行的目标虚拟机类型,供云端分发使用,如应用市场和分发中心。
该标签值为字符串。如果目标虚拟机类型为方舟虚拟机,则其值为"ark + 版本号"。 该标签由IDE构建HAP的时候自动插入。 | 字符串 | 该标签由IDE构建HAP的时候自动插入。 |
+| uiSyntax(deprecated) | syntax定义该JS Component的语法类型。
hml标识该JS Component使用hml/css/js进行开发;
ets标识该JS Component使用ets声明式语法进行开发。 | 字符串 | 可缺省,缺省值为hml,该字段从API9开始废弃。 |
+| pages | 该标签是一个profile资源,用于列举JS Component中每个页面信息。可以配置window标签定义与显示窗口相关的配置。window参考[window对象内部结构](#window对象内部结构)。 | 字符串 | 在有ability的场景下,不可缺省。 |
+| metadata | 该标签标识Hap的自定义元信息。参考[metadata对象内部结构](#metadata对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| abilities | 描述元能力的配置信息,该标签下的配置只对当前ability生效。参考[abilities对象内部结构](#abilities对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| extensionAbilities | 描述extensionAbilities的配置信息,该标签下的配置只对当前extensionAbility生效。参考[extensionAbilities对象内部结构](#extensionabilities对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| definePermissions | 标识HAP定义的权限,仅支持系统应用配置,三方应用配置不生效。参考[definePermissions对象内部结构](#definepermissions对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| requestPermissions | 该标签标识应用运行时需向系统申请的权限集合。参考[requestPermissions对象内部结构](#requestpermissions对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| testRunner | 该标签用于支持对测试框架的配置,参考[testRunner对象内部结构说明](#testrunner对象内部结构)。 | 对象 | 可缺省,缺省值为空。 |
-### module对象内部结构
module.json5示例:
```json
{
"module": {
- "name": "myHapName",
- "type": "entry|feature|har",
- "srcEntrance" : "./MyAbilityStage.js",
+ "name": "moduleName",
+ "type": "entry",
+ "srcEntrance" : "./abilityStage.js",
"description" : "$string:description_application",
"mainElement": "MainAbility",
+ "pages": "$profile:pages_config",
"deviceTypes": [
"tablet",
"tv",
"wearable",
- "car",
- "router"
+ "car"
],
"deliveryWithInstall": true,
"installationFree": false,
- "virtualMachine": "ark | default",
"metadata": [
{
- "name": "string",
- "value": "string",
+ "name": "name1",
+ "value": "value1",
"resource": "$profile:config_file1"
},
{
- "name": "string",
- "value": "string",
+ "name": "name2",
+ "value": "value2",
"resource": "$profile:config_file2"
}
],
@@ -111,7 +131,7 @@ module.json5示例:
"srcEntrance" : "./login/MyMainAbility.ts",
"description": "$string:description_main_ability",
"icon": "$media:icon",
- "label": "HiMusic",
+ "label": "$string:label",
"visible": true,
"skills": [
{
@@ -121,7 +141,7 @@ module.json5示例:
"entities": [
"entity.system.home"
],
- "uris": [ ]
+ "uris": []
}
],
"backgroundModes": [
@@ -143,7 +163,7 @@ module.json5示例:
"srcEntrance" : "./login/sampleAbility.ts",
"description": "$string:description_sample_ability",
"icon": "$media:icon",
- "label": "HiMusic",
+ "label": "$string:label",
"visible": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:red"
@@ -151,7 +171,7 @@ module.json5示例:
],
"requestPermissions": [
{
- "name": "ohos.abilitydemo.permission.PROVIDER",
+ "name": "permissionName",
"reason": "$string:reason",
"usedScene": {
"abilities": [
@@ -165,80 +185,76 @@ module.json5示例:
}
```
-hap包的配置信息,该标签下的配置只对当前hap包生效。
+pages示例 :
-表3 module对象内部结构
+1.在开发视图的resources/base/profile下面定义配置文件pages_config.json(文件名称可由开发者定义):
-| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
-| -------------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
-| name | 该标签标识当前module的名字,module打包成hap后,表示hap的名称,标签值采用字符串表示(最大长度31个字节),该名称在整个应用要唯一。 | 字符串 | 该标签不可缺省。 |
-| type | 该标签标识当前hap的类型。类型有三种,分别是entry、feature和har。 | 字符串 | 该标签不可缺省。 |
-| srcEntrance | 该标签标识hap所对应的入口js代码路径,标签值为字符串(最长为127字节)。 | 字符串 | 该标签可缺省。 |
-| description | 该标签标识hap包的描述信息,标签值是是字符串类型或对描述内容的资源索引,以支持多语言。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| process | 该标签标识hap的进程名,标签值为字符串类型(最长为31个字节)。如果在hap标签下配置了process,该应用的所有ability都运行在该进程中。该标签只支持系统应用配置。 | 字符串 | 可缺省,缺省为app标签下的bundleName。 |
-| mainElement | 该标签标识hap的入口ability名称或者extension名称。只有配置为mainElement的ability或者extension才允许在服务中心露出。创建OpenHarmony原子化服务时,该标签不可缺省。 | 字符串 | OpenHarmony应用下,该标签可缺省。 |
-| deviceTypes | 该标签标识hap可以运行在哪类设备上,标签值采用字符串数组的表示,系统预定义的设备类型见表4。
与syscap不同的是,deviceTypes是以设备类型为粒度,而syscap是以设备能力(例如蓝牙、wifi)为粒度。 | 字符串数组 | 该标签不可缺省,可以为空值。 |
-| deliveryWithInstall | 该标签标识当前hap是否在用户主动安装的时候安装,true表示主动安装时安装,false表示主动安装时不安装。 | 布尔值 | 该标签不可缺省。 |
-| installationFree | 标识当前HAP是否支持免安装特性。所有Hap包都需要配置不可缺省。
true :表示支持免安装特性,且符合免安装约束。
false :表示不支持免安装特性。
当entry.hap该字段配置为true时,与该entry.hap相关的所有feature.hap该字段也需要配置为true。
当entry.hap该字段配置为false时,与该entry.hap相关的各feature.hap该字段可按业务需求配置true或false。 | 布尔值 | 该标签不可缺省。 |
-| virtualMachine | 该标签用于标识当前hap运行的目标虚拟机类型,供云端分发使用,如应用市场和分发中心。
该标签值为字符串。如果目标虚拟机类型为方舟虚拟机,则其值为”ark”; 如果目标虚拟机类型不是方舟虚拟机,则其值为”default”。该标签由IDE构建hap的时候自动插入。解包工具解析时,如果hap包没有该标签,设置该标签值为”default”。 | 字符串 | 该标签可缺省,缺省值为“default”。 |
-| uiSyntax(deprecated) | syntax定义该JS Component的语法类型。
hml标识该JS Component使用hml/css/js进行开发;
ets标识该JS Component使用ets声明式语法进行开发。 | 字符串 | 该标签可缺省,默认值为hml,该字段从API9开始废弃。 |
-| pages | 该标签是一个profile资源,用于列举JS Component中每个页面信息。pages使用参考pages示例。 | 对象 | 在有ability的场景下,该标签不可缺省。 |
-| metadata | 该标签标识Hap的自定义元信息,标签值为数组类型,该标签下的配置只对当前module、或者ability、或者extensionAbility生效。metadata参考[metadata对象内部结构](#metadata对象内部结构)。 | 数组 | 该标签可缺省,缺省值为空。 |
-| abilities | 描述元能力的配置信息,标签值为数组类型,该标签下的配置只对当前ability生效。abilities参考[abilities对象内部结构](#abilities对象内部结构)。 | 对象 | 该标签可缺省,缺省值为空。 |
-| extensionAbilities | 描述extensionAbilities的配置信息,标签值为数组类型,该标签下的配置只对当前extensionAbility生效。extensionAbilities参考[extensionAbility对象的内部结构说明](#extensionability对象的内部结构说明)。 | 对象 | 该标签可缺省,缺省值为空。 |
-| definePermissions | 标识hap定义的权限,仅支持系统应用配置,三方应用配置不生效。该应用的调用者必须申请这些权限才能正常调用该应用。definePermissions参考[definePermissions对象内部结构](#definepermissions对象内部结构) | 对象 | 该标签可缺省,缺省值为空,表示调用者无需任何权限即可调用该应用。 |
-| requestPermissions | 该标签标识应用运行时需向系统申请的权限集合,标签值为数组类型。requestPermissions参考[requestPermissions对象内部结构](#requestpermissions对象内部结构)。 | 对象 | 该标签可缺省,缺省值为空。 |
-| testRunner | 此标签用于支持对测试框架的配置,参考[testRunner对象内部结构说明](#testrunner对象内部结构)说明。 | 对象 | 可缺省,缺省值为空 |
-
-表4 deviceTypes对象的系统预定义设备
-
-| 中文 | 英文 | 枚举值 | 设备类型 |
-| -------- | ----------- | -------- | -------------------------------------------------------- |
-| 平板 | tablet | tablet | 平板,带屏音箱 |
-| 智慧屏 | smart TV | tv | 智慧屏 |
-| 智能手表 | smart watch | wearable | 智能手表,儿童手表,特指资源较丰富的的手表,具备电话功能 |
-| 车机 | head unit | car | 车机 |
-| 路由器 | router | router | 路由器 |
+```json
+{
+ "src": [
+ "pages/index/index",
+ "pages/second/second",
+ "pages/third/third",
+ "pages/four/four"
+ ],
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
+}
+```
-deviceTypes示例 :
+2.在module.json5的module标签下定义pages信息 :
```json
{
"module": {
- "name": "myHapName",
- "type": "har",
- "deviceTypes" : [
- "wearable"
- ]
+ "pages": "$profile:pages_config"
}
}
```
-pages示例 :
+表4 deviceTypes对象的系统预定义设备
+
+| 设备类型 | 枚举值 | 说明 |
+| -------- | ----------- | -------- |
+| 平板 | tablet | - |
+| 智慧屏 | tv | - |
+| 智能手表 | wearable | 系统能力较丰富的手表,具备电话功能。 |
+| 车机 | car | - |
+| 默认设备 | default | 能够使用全部系统能力的OpenHarmony设备。 |
+
+deviceTypes示例 :
```json
{
"module": {
- "name": "myHapName",
- "type": "har",
"deviceTypes" : [
"wearable"
- ],
- "pages": "$profile:pages_config"
+ ]
}
}
```
-pages_config配置文件
+#### window对象内部结构
+
+定义与显示窗口相关的配置。
+
+表5 window对象内部结构说明
+
+| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
+| -------- | ------------------------------------------------------------ | -------- | -------------------------- |
+| designWidth | 定义页面设计基准宽度,根据实际设备宽度来缩放元素大小。 | 数值 | 可缺省,缺省值为750。 |
+| autoDesignWidth | 定义页面设计基准宽度是否自动计算,当设置为true时,designWidth将被忽略,设计基准宽度由设备宽度与屏幕密度计算得出。 | 布尔值 | 可缺省,缺省值为false。 |
+
+window示例 :
```json
{
- "src": [
- "pages/index/index",
- "pages/second/second",
- "pages/third/third",
- "pages/four/four"
- ]
+ "window": {
+ "designWidth": 720,
+ "autoDesignWidth": false
+ }
}
```
@@ -248,112 +264,32 @@ pages_config配置文件
描述的module、ability、extensionAbility配置信息,标签值为数组类型,该标签下的配置只对当前module、或者ability、或者extensionAbility生效。
-表5 metadata对象内部结构说明
+表6 metadata对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------------- |
-| name | 该标签标识数据项的键名称,字符串类型(最大长度255字节)。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| value | 该标签标识数据项的值,标签值为字符串(最大长度255字节)。 | 字符串 | 可缺省,缺省为空。 |
-| resource | 该标签标识定义用户自定义数据格式,标签值为标识该数据的资源的索引值。 | 字符串 | 可缺省,缺省为空。 |
+| name | 该标签标识数据项的键名称,最大长度255字节。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 该标签标识数据项的值,最大长度255字节。 | 字符串 | 可缺省,缺省值为空。 |
+| resource | 该标签标识定义用户自定义数据格式,标签值为标识该数据的资源的索引值。 | 字符串 | 可缺省,缺省值为空。 |
-metadata示例 :
+metadata示例 :
```json
-{
+{
"module": {
"metadata": [
{
- "name": "string",
- "value": "string",
- "resource": "$profile:config_file"
+ "name": "name1",
+ "value": "value1",
+ "resource": "$profile:config_file1"
},
{
- "name": "string",
- "value": "string",
- "resource": "$profile:config_file"
+ "name": "name2",
+ "value": "value2",
+ "resource": "$profile:config_file2"
}
- ]
- }
-}
-```
-
-#### abilities对象内部结构
-
-abilities描述ability的配置信息,标签值为数组类型。
-
-表6 abilities对象内部结构说明
-
-| 属性 | 含义 | 数据类型 | 是否可缺省 |
-| --------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
-| name | 该标签标识当前ability的逻辑名,该名称在整个应用要唯一,标签值采用字符串表示(最大长度127个字节)。 | 字符串 | 该标签不可缺省。 |
-| srcEntrance | 该标签标识ability所对应的js代码路径,标签值为字符串(最长为127字节)。。 | 字符串 | 该标签不可缺省。 |
-| launchType | 该标签标示ability的启动模式,标签值可选“standard”、“singleton”、“specified”。该标签缺省为"singleton"。standard表示普通多实例,specified表示指定实例,运行时由ability内部业务决定是否创建多实例,singleton表示单实例。 | 字符串 | 可缺省,该标签缺省为"singleton" |
-| description | 该标签标识ability的描述,标签值是是字符串类型或对描述内容的资源索引,要求采用用资源索引方式,以支持多语言。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| icon | 该标签标识ability图标,标签值为资源文件的索引。该标签可缺省,缺省值为空。
如果ability被配置为MainElement,该标签必须配置。 | 字符串 | 该标签可缺省,缺省值为空。
如果ability被配置为MainElement,该标签必须配置。 |
-| permissions | 该标签标识被其它应用的ability调用时需要申请的权限的集合,一个数组元素为一个权限名称。通常采用反向域名格式(最大255字节),取值为系统预定义的权限。 | 字符串数组 | 该标签可缺省,缺省值为空。 |
-| metadata | 该标签标识ability的元信息。metadata参考[metadata对象内部结构](#metadata对象内部结构)。 | 数组 | 该标签可缺省,缺省值为空。 |
-| visible | 该标签标识ability是否可以被其它应用调用,为布尔类型,true表示可以被其它应用调用, false表示不可以被其它应用调用。 | 布尔值 | 该标签可缺省,缺省值为false。 |
-| continuable | 该标签标识ability是否可以迁移,为布尔类型,true表示可以被迁移, false表示不可以被迁移。 | 布尔值 | 该标签可缺省,缺省值为false。 |
-| skills | 该标签标识ability能够接收的意图的特征集,为数组格式。
配置规则 : entry包可以配置多个具有入口能力的skills标签(配置了action.system.home和entity.system.home)的ability,其中第一个配置了skills标签的ability中的label和icon作为OpenHarmony服务或应用的label和icon。
OpenHarmony服务的Feature包不能配置具有入口能力的skills标签。
OpenHarmony应用的Feature包可以配置具有入口能力的skills标签。
skills内部结构参考[skills对象内部结构](#skills对象内部结构)。 | 数组 | 该标签可缺省,缺省值为空。 |
-| backgroundModes | 该标签标识ability长时任务集合。指定用于满足特定类型的长时任务。
长时任务类型有如下 :
dataTransfer :通过网络/对端设备进行数据下载、备份、分享、传输等业务。
audioPlayback :音频输出业务。
audioRecording :音频输入业务。
location :定位、导航业务。
bluetoothInteraction :蓝牙扫描、连接、传输业务(穿戴)。
multiDeviceConnection :多设备互联业务。
wifiInteraction :Wifi扫描、连接、传输业务(克隆 多屏)。
voip :音视频电话,VOIP业务。
taskKeeping :计算业务。
| 字符串 | 可缺省,缺省为空。 |
-| startWindowIcon | 标识该Ability启动页面图标资源文件的索引。取值示例:$media:icon。 | 字符串 | 不可缺省。|
-| startWindowBackground | 标识该Ability启动页面背景颜色资源文件的索引。取值示例:$color:red。 | 字符串 | 不可缺省。|
-| removeMissionAfterTerminate | 该标签标识ability销毁后是否从任务列表中移除任务。为布尔类型,true表示销毁后移除任务, false表示销毁后不移除任务。 | 布尔值 | 该标签可缺省,缺省值为false。|
-| orientation | 标识该ability启动时的方向。该方向的取值范围包括:
unspecified: 未指定方向,由系统自动判断显示方向,
landscape:横屏,
portrait:竖屏,
landscape_inverted: 反向横屏,
portrait_inverted: 反向竖屏,
auto_rotation: 随传感器旋转,
auto_rotation_landscape: 传感器横屏旋转,包括了横屏和反向横屏,
auto_rotation_portrait: 传感器竖屏旋转,包括了竖屏和反向竖屏,
auto_rotation_restricted: 传感器开关打开,方向可随传感器旋转,
auto_rotation_landscape_restricted: 传感器开关打开,方向可随传感器旋转为横屏, 包括了横屏和反向横屏,
auto_rotation_portrait_restricted: 传感器开关打开,方向随可传感器旋转为竖屏, 包括了横屏和反向横屏,
locked: 传感器开关关闭,方向锁定。 | 字符串 | 该标签可缺省,缺省值为unspecified。|
-|supportWindowMode|标识该ability所支持的窗口模式,包含:
fullscreen: 全屏模式,
split: 分屏模式,
floating: 悬浮窗模式。 |数组 | 该标签可缺省,缺省值为
["fullscreen", "split", "floating"]。|
-|priority|标识ability的优先级,仅支持系统应用配置,三方应用配置不生效。隐式查询时,优先级越高,ability在返回列表越靠前。该标签取值为integer类型,取值范围0-10。数值越大,优先级越高。 |数值 | 该标签可缺省,缺省值为0。 |
-|maxWindowRatio|标识该ability支持的最大的宽高比。| 数值 |该标签可缺省,缺省值为平台支持的最大的宽高比。|
-|minWindowRatio|标识该ability支持的最小的宽高比。| 数值 |该标签可缺省,缺省值为平台支持的最小的宽高比。|
-|maxWindowWidth|标识该ability支持的最大的窗口宽度,宽度单位为vp。| 数值 |该标签可缺省,缺省值为平台支持的最大的窗口宽度。|
-|minWindowWidth|标识该ability支持的最小的窗口宽度, 宽度单位为vp。| 数值 |该标签可缺省,缺省值为平台支持的最小的窗口宽度。|
-|maxWindowHeight|标识该ability支持的最大的窗口高度, 高度单位为vp。| 数值 |该标签可缺省,缺省值为平台支持的最大的窗口高度。|
-|minWindowHeight|标识该ability支持的最小的窗口高度, 高度单位为vp。| 数值 |该标签可缺省,缺省值为平台支持的最小的窗口高度。|
-| excludeFromMissions | 该标签标识ability是否在最近任务列表中显示,仅支持系统应用配置,三方应用配置不生效。为布尔类型,true表示不在任务列表中显示,false表示在任务列表中显示。 | 布尔值 | 该标签可缺省,缺省值为false。|
-
-abilities示例
-
-```json
-{
- "abilities": [{
- "name": "MainAbility",
- "srcEntrance": "./ets/login/MyLoginAbility.ts",
- "launchType":"standard",
- "description": "$string:description_main_ability",
- "icon": "$media:icon",
- "label": "Login",
- "permissions": [],
- "metadata": [],
- "visible": true,
- "continuable": true,
- "skills": [{
- "actions": ["action.system.home"],
- "entities": ["entity.system.home"],
- "uris": []
- }],
- "backgroundModes": [
- "dataTransfer",
- "audioPlayback",
- "audioRecording",
- "location",
- "bluetoothInteraction",
- "multiDeviceConnection",
- "wifiInteraction",
- "voip",
- "taskKeeping"
],
- "startWindowIcon": "$media:icon",
- "startWindowBackground": "$color:red",
- "removeMissionAfterTerminate": true,
- "orientation": " ",
- "supportWindowMode": ["fullscreen", "split", "floating"],
- "maxWindowRatio": 3.5,
- "minWindowRatio": 0.5,
- "maxWindowWidth": 2560,
- "minWindowWidth": 1400,
- "maxWindowHeight": 300,
- "minWindowHeight": 200,
- "excludeFromMissions": false
- }]
+ }
}
```
@@ -361,231 +297,374 @@ abilities示例
该标签标识ability或者extension能够接收的意图的特征。
-表7 skills内部结构示例
+表7 skill对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | ---------- | -------------------- |
| actions | 该标签标识能够接收的意图的action值的集合,取值通常为系统预定义的action值,也允许自定义。 | 字符串数组 | 可缺省,缺省值为空。 |
| entities | 该标签标识能够接收Want的元能力的类别集合,取值通常为系统预定义的类别,也允许自定义。 | 字符串数组 | 可缺省,缺省值为空。 |
-| uris | 该标签标识向 want过滤器添加数据规范集合。该规范可以是只有数据类型(mimeType 属性),可以是只有 URI,也可以是既有数据类型又有 URI。uris内部结构参考表8。 | 对象数组 | 可缺省,缺省值为空。 |
+| uris | 该标签标识与意图中URI(Uniform Resource Identifier)相匹配的集合。uris内部结构参考表8。 | 对象数组 | 可缺省,缺省值为空。 |
-表8 uris对象的内部结构说明
+表8 uris对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------- | -------- | -------------------- |
-| scheme | 标识uri的scheme值。 | 字符串 | 不可缺省。 |
-| host | 标识uri的host值。 | 字符串 | 可缺省,缺省值为空。 |
-| port | 标识uri的port值。 | 字符串 | 可缺省,缺省值为空。 |
-| path | 标识uri的path值。 | 字符串 | 可缺省,缺省值为空。 |
-| type | 标识uri的type值。 | 字符串 | 可缺省,缺省值为空。 |
+| scheme | 标识URI的协议名部分,常见的有http、https、file、ftp等。 | 字符串 | 当配置type时可缺省,缺省值为空。没有配置type时不可缺省。 |
+| host | 标识URI的主机地址部分,常见的有域名的方式,如example.com,ip地址的方式,如192.0.0.1。该字段要在scheme存在时才有意义。 | 字符串 | 可缺省,缺省值为空。 |
+| port | 标识URI的端口部分。如http默认端口为80,https默认端口是443,ftp默认端口是21。该字段要在scheme和host都存在时才有意义。| 字符串 | 可缺省,缺省值为空。 |
+| path \| pathStartWith \| pathRegex | 标识URI的路径部分,path、pathStartWith和pathRegex配置时三选一。path标识URI与want中的路径部分全匹配,pathStartWith标识URI与want中的路径部分允许前缀匹配,pathRegex标识URI与want中的路径部分允许正则匹配。该字段要在scheme和host都存在时才有意义。| 字符串 | 可缺省,缺省值为空。 |
+| type | 标识数据类型,使用MIME(Multipurpose Internet Mail Extensions)类型规范。可与scheme同时配置,也可以单独配置。| 字符串 | 可缺省,缺省值为空。 |
-skills示例
+skills示例 :
```json
{
- "abilities": [
- {
- "skills": [
- {
- "actions": [
- "action.system.home"
- ],
- "entities": [
- "entity.system.home"
- ],
- "uris": [
- {
- "scheme":"uri2",
- "host":"host2",
- "port":"port2",
- "pathStartWith":"path2",
- "pathRegex":"/query/.*",
- "path":"path",
- "type": "text/*"
- }
- ]
- }
- ]
- }
- ],
- "extensionAbilities": [
- {
- "skills": [
- {
- "actions": [
- ],
- "entities": [
- ],
- "uris": [
- {
- "scheme":"uri2",
- "host":"host2",
- "port":"port2",
- "pathStartWith":"path2",
- "pathRegex":"/query/.*",
- "path":"path",
- "type": "text/*"
- }
- ]
- }
- ]
- }
- ]
+ "module": {
+ "abilities": [
+ {
+ "skills": [
+ {
+ "actions": [
+ "action.system.home"
+ ],
+ "entities": [
+ "entity.system.home"
+ ],
+ "uris": [
+ {
+ "scheme":"https",
+ "host":"www.example.com",
+ "port":"8080",
+ "path":"query/student/name",
+ "pathStartWith":"query/student",
+ "pathRegex":"query/.*/name",
+ "type": "text/*"
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "extensionAbilities": [
+ {
+ "skills": [
+ {
+ "actions": [
+ "actionName"
+ ],
+ "entities": [
+ "entityName"
+ ],
+ "uris": [
+ {
+ "scheme":"https",
+ "host":"www.example.com",
+ "port":"8080",
+ "path":"query/student/name",
+ "pathStartWith":"query/student",
+ "pathRegex":"query/.*/name",
+ "type": "text/*"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+}
+```
+
+#### abilities对象内部结构
+
+abilities描述Ability组件的配置信息,标签值为数组类型。
+
+表9 ability对象内部结构说明
+
+| 属性 | 含义 | 数据类型 | 是否可缺省 |
+| --------------- | ------------------------------------------------------------ | ---------- | ------------------------------------------------------------ |
+| name | 该标签标识当前Ability组件的逻辑名,该名称在整个应用要唯一,标签值采用字符串表示(最大长度127字节)。 | 字符串 | 不可缺省。 |
+| srcEntrance | 该标签标识Ability组件所对应的js代码路径,标签值为字符串(最大长度127字节)。 | 字符串 | 不可缺省。 |
+| launchType | 该标签标识Ability组件的启动模式,可选标签值:
"standard":多实例,每次启动创建一个新的实例。
"singleton":单实例,仅第一次启动创建新实例。
"specified":运行时由开发者决定是否创建新实例。 | 字符串 | 可缺省,缺省值为"singleton" |
+| description | 该标签标识Ability组件的描述信息,标签值是是字符串类型或对描述内容的资源索引,要求采用资源索引方式,以支持多语言。 | 字符串 | 可缺省,缺省值为空。 |
+| icon | 该标签标识Ability组件的图标,标签值为图标资源文件的索引。 | 字符串 | 可缺省,缺省值为空。
如果Ability组件被配置为MainElement,该标签必须配置。 |
+| permissions | 该标签标识被其它应用的Ability组件调用时需要申请的权限的集合,一个数组元素为一个权限名称。通常采用反向域名格式(最大长度255字节),取值为系统预定义的权限。 | 字符串数组 | 可缺省,缺省值为空。 |
+| metadata | 该标签标识Ability组件的元信息。参考[metadata对象内部结构](#metadata对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| visible | 该标签标识Ability组件是否可以被其它应用调用,true表示可以被其它应用调用, false表示不可以被其它应用调用。 | 布尔值 | 可缺省,缺省值为false。 |
+| continuable | 该标签标识Ability组件是否可以迁移,true表示可以被迁移, false表示不可以被迁移。 | 布尔值 | 可缺省,缺省值为false。 |
+| skills | 该标签标识Ability组件能够接收的意图的特征集。
配置规则 : entry包可以配置多个具有入口能力的skills标签(配置了action.system.home和entity.system.home)的Ability组件,其中第一个配置了skills标签的Ability组件中的label和icon作为OpenHarmony服务或应用的label和icon。
OpenHarmony服务的Feature包不能配置具有入口能力的skills标签。
OpenHarmony应用的Feature包可以配置具有入口能力的skills标签。
参考[skills对象内部结构](#skills对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| backgroundModes | 该标签标识Ability组件的长时任务集合。指定用于满足特定类型的长时任务。
长时任务类型有如下 :
dataTransfer :通过网络/对端设备进行数据下载、备份、分享、传输等业务。
audioPlayback :音频输出业务。
audioRecording :音频输入业务。
location :定位、导航业务。
bluetoothInteraction :蓝牙扫描、连接、传输业务(穿戴)。
multiDeviceConnection :多设备互联业务。
wifiInteraction :Wifi扫描、连接、传输业务(克隆 多屏)。
voip :音视频电话,VOIP业务。
taskKeeping :计算业务。
| 字符串 | 可缺省,缺省值为空。 |
+| startWindowIcon | 标识该Ability组件启动页面图标资源文件的索引。取值示例:$media:icon。 | 字符串 | 不可缺省。|
+| startWindowBackground | 标识该Ability组件启动页面背景颜色资源文件的索引。取值示例:$color:red。 | 字符串 | 不可缺省。|
+| removeMissionAfterTerminate | 该标签标识Ability组件销毁后是否从任务列表中移除任务。true表示销毁后移除任务, false表示销毁后不移除任务。 | 布尔值 | 可缺省,缺省值为false。|
+| orientation | 标识该Ability组件启动时的方向。取值范围包括:
unspecified: 未指定方向,由系统自动判断显示方向,
landscape:横屏,
portrait:竖屏,
landscape_inverted: 反向横屏,
portrait_inverted: 反向竖屏,
auto_rotation: 随传感器旋转,
auto_rotation_landscape: 传感器横屏旋转,包括了横屏和反向横屏,
auto_rotation_portrait: 传感器竖屏旋转,包括了竖屏和反向竖屏,
auto_rotation_restricted: 传感器开关打开,方向可随传感器旋转,
auto_rotation_landscape_restricted: 传感器开关打开,方向可随传感器旋转为横屏, 包括了横屏和反向横屏,
auto_rotation_portrait_restricted: 传感器开关打开,方向随可传感器旋转为竖屏, 包括了横屏和反向横屏,
locked: 传感器开关关闭,方向锁定。 | 字符串 | 可缺省,缺省值为"unspecified"。|
+|supportWindowMode|标识该Ability组件所支持的窗口模式,取值范围包括:
fullscreen: 全屏模式,
split: 分屏模式,
floating: 悬浮窗模式。 |字符串数组 | 可缺省,缺省值为
["fullscreen", "split", "floating"]。|
+|maxWindowRatio|标识该Ability组件支持的最大的宽高比。| 数值 |可缺省,缺省值为平台支持的最大的宽高比。|
+|minWindowRatio|标识该Ability组件支持的最小的宽高比。| 数值 |可缺省,缺省值为平台支持的最小的宽高比。|
+|maxWindowWidth|标识该Ability组件支持的最大的窗口宽度,宽度单位为vp。| 数值 |可缺省,缺省值为平台支持的最大的窗口宽度。|
+|minWindowWidth|标识该Ability组件支持的最小的窗口宽度, 宽度单位为vp。| 数值 |可缺省,缺省值为平台支持的最小的窗口宽度。|
+|maxWindowHeight|标识该Ability组件支持的最大的窗口高度, 高度单位为vp。| 数值 |可缺省,缺省值为平台支持的最大的窗口高度。|
+|minWindowHeight|标识该Ability组件支持的最小的窗口高度, 高度单位为vp。| 数值 |可缺省,缺省值为平台支持的最小的窗口高度。|
+
+abilities示例 :
+
+```json
+{
+ "module": {
+ "abilities": [
+ {
+ "name": "MainAbility",
+ "srcEntrance": "./ets/login/LoginAbility.ts",
+ "launchType":"standard",
+ "description": "$string:description",
+ "icon": "$media:icon",
+ "label": "$string:label",
+ "permissions": [],
+ "metadata": [],
+ "visible": true,
+ "continuable": true,
+ "skills": [
+ {
+ "actions": ["action.system.home"],
+ "entities": ["entity.system.home"],
+ "uris": []
+ }
+ ],
+ "backgroundModes": [
+ "dataTransfer",
+ "audioPlayback",
+ "audioRecording",
+ "location",
+ "bluetoothInteraction",
+ "multiDeviceConnection",
+ "wifiInteraction",
+ "voip",
+ "taskKeeping"
+ ],
+ "startWindowIcon": "$media:icon",
+ "startWindowBackground": "$color:red",
+ "removeMissionAfterTerminate": true,
+ "orientation": "landscape",
+ "supportWindowMode": ["fullscreen", "split", "floating"],
+ "maxWindowRatio": 3.5,
+ "minWindowRatio": 0.5,
+ "maxWindowWidth": 2560,
+ "minWindowWidth": 1400,
+ "maxWindowHeight": 300,
+ "minWindowHeight": 200
+ }
+ ]
+ }
}
```
-#### extensionAbility对象的内部结构说明
-描述extensionAbility的配置信息,标签值为数组类型,该标签下的配置只对当前extensionAbility生效。
+#### extensionAbilities对象内部结构
+
+extensionAbilities描述extensionAbility的配置信息,标签值为数组类型。
-表9 extensionAbility对象内部结构说明
+表10 extensionAbility对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ----------- | ------------------------------------------------------------ | ---------- | ----------------------------- |
-| name | 该标签标识当前extensionAbility的逻辑名,标签值采用字符串表示(最大长度127个字节),该名称在整个应用要唯一。 | 字符串 | 该标签不可缺省。 |
-| srcEntrance | 该标签标识extensionAbility所对应的js代码路径,标签值为字符串(最长为127字节)。 | 字符串 | 该标签不可缺省。 |
-| description | 该标签标识extensionAbility的描述,标签值是是字符串类型或对描述内容的资源索引,以支持多语言。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| icon | 该标签标识extensionAbility图标,标签值为资源文件的索引。如果extensionAbility被配置为MainElement,该标签必须配置。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| label | 该标签标识extensionAbility对用户显示的名称,标签值配置为该名称的资源索引以支持多语言。
如果extensionAbility被配置为MainElement,该标签必须配置,且应用内唯一。 | 字符串 | 该标签不可缺省。 |
-| type | 该标签标识extensionAbility的类型,取值为form、workScheduler、inputMethod、service、accessibility、dataShare、fileShare、staticSubscriber、wallpaper、backup、window、enterpriseAdmin、thumbnail、preview其中之一。 | 字符串 | 该标签不可缺省。 |
-| permissions | 该标签标识被其它应用的ability调用时需要申请的权限的集合,字符串数组类型,每个数组元素为一个权限名称,通常采用反向域名方式表示(最大255字节),可以是系统预定义的权限,也可以是该应用自定义的权限。如果是后者,需与defPermissions标签中定义的某个权限的name标签值一致。 | 字符串数组 | 该标签可缺省,缺省值为空。 |
-| uri | 该标签标识ability提供的数据uri,为字符数组类型(最大长度255),用反向域名的格式表示。该标签在type为dataShare类型的extensionAbility时,不可缺省。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| skills | 该标签标识ability能够接收的意图的特征集,为数组格式。
配置规则 : entry包可以配置多个具有入口能力的skills标签(配置了action.system.home和entity.system.home)的ability,其中第一个配置了skills标签的ability中的label和icon作为OpenHarmony服务或应用的label和icon。
OpenHarmony服务的Feature包不能配置具有入口能力的skills标签。
OpenHarmony应用的Feature包可以配置具有入口能力的skills标签。
skills内部结构参考[skills对象内部结构](#skills对象内部结构)。 | 数组 | 该标签可缺省,缺省值为空。 |
-| metadata | 该标签标识extensionAbility的元信息。metadata内部结构参考[metadata对象内部结构](#metadata对象内部结构)。 | 对象 | 该标签可缺省,缺省值为空。 |
-| visible | 该标签标识extensionAbility是否可以被其它应用调用,为布尔类型。true表示可以被其它应用调用, false表示不可以被其它应用调用。 | 布尔值 | 该标签可缺省,缺省值为false。 |
-
-extensionAbility示例 :
+| name | 该标签标识当前ExtensionAbility组件的逻辑名,标签值采用字符串表示(最大长度127字节),该名称在整个应用要唯一。 | 字符串 | 不可缺省。 |
+| srcEntrance | 该标签标识ExtensionAbility组件所对应的js代码路径,标签值为字符串(最大长度127字节)。 | 字符串 | 不可缺省。 |
+| description | 该标签标识ExtensionAbility组件的描述,标签值是是字符串类型或对描述内容的资源索引,以支持多语言。 | 字符串 | 可缺省,缺省值为空。 |
+| icon | 该标签标识ExtensionAbility组件图标,标签值为资源文件的索引。 | 字符串 | 可缺省,缺省值为空。如果ExtensionAbility组件被配置为MainElement,不可缺省。 |
+| label | 该标签标识ExtensionAbility组件对用户显示的名称,标签值配置为该名称的资源索引以支持多语言。 | 字符串 | 可缺省,缺省值为空。如果ExtensionAbility组件被配置为MainElement,该标签必须配置,且应用内唯一。 |
+| type | 该标签标识ExtensionAbility组件的类型,取值为form、workScheduler、inputMethod、service、accessibility、dataShare、fileShare、staticSubscriber、wallpaper、backup、window、enterpriseAdmin、thumbnail、preview其中之一。 | 字符串 | 不可缺省。 |
+| permissions | 该标签标识被其它应用的ability调用时需要申请的权限的集合,字符串数组类型,每个数组元素为一个权限名称,通常采用反向域名方式表示(最大长度255字节),取值为系统预定义权限或者应用自定义权限,如果是后者,需与defPermissions标签中定义的某个权限的name标签值一致。 | 字符串数组 | 可缺省,缺省值为空。 |
+| uri | 该标签标识ability提供的数据URI,为字符数组类型(最大长度255字节),用反向域名的格式表示。 | 字符串 | 可缺省,缺省值为空。该标签在type为dataShare类型的ExtensionAbility组件时,不可缺省。 |
+| skills | 该标签标识ability能够接收的意图的特征集,为数组格式。
配置规则 : entry包可以配置多个具有入口能力的skills标签(配置了action.system.home和entity.system.home)的ability,其中第一个配置了skills标签的ability中的label和icon作为OpenHarmony服务或应用的label和icon。
OpenHarmony服务的Feature包不能配置具有入口能力的skills标签。
OpenHarmony应用的Feature包可以配置具有入口能力的skills标签。
参考[skills对象内部结构](#skills对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| metadata | 该标签标识ExtensionAbility组件的元信息。参考[metadata对象内部结构](#metadata对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| visible | 该标签标识ExtensionAbility组件是否可以被其它应用调用。true表示可以被其它应用调用, false表示不可以被其它应用调用。 | 布尔值 | 可缺省,缺省值为false。 |
+| readPermission | 该标签标识读取ExtensionAbility组件的数据所需的权限。最大长度255字节。type为dataShare类型的ExtensionAbility组件支持该配置。该标签只对系统应用生效。 | 字符串 | 可缺省,缺省值为空。 |
+| writePermission | 该标签标识向ExtensionAbility组件写数据所需的权限。最大长度255字节。type为dataShare类型的ExtensionAbility组件支持该配置。该标签只对系统应用生效。 | 字符串 | 可缺省,缺省值为空。 |
+
+extensionAbilities示例 :
```json
{
- "extensionAbilities": [
- {
- "name": "FormName",
- "srcEntrance": "./form/MyForm.ts",
- "icon": "$media:icon",
- "label" : "$string:extension_name",
- "description": "$string:form_description",
- "type": "form",
- "permissions": ["ohos.abilitydemo.permission.PROVIDER"],
- "readPermission": "",
- "writePermission": "",
- "visible": true,
- "uri":"scheme://authority/path/query"
- "skills": [{
- "actions": [],
- "entities": [],
- "uris": []
- }],
- "metadata": [
- {
- "name": "ohos.extability.form",
- "resource": "$profile:form_config",
- }
- ]
- }
- ]
+ "module": {
+ "extensionAbilities": [
+ {
+ "name": "extensionName",
+ "srcEntrance": "./extension/FormExtension.ts",
+ "icon": "$media:icon",
+ "label" : "$string:label",
+ "description": "$string:description",
+ "type": "form",
+ "permissions": ["permissionName"],
+ "readPermission": "",
+ "writePermission": "",
+ "visible": true,
+ "uri":"scheme://authority/path/query"
+ "skills": [
+ {
+ "actions": [],
+ "entities": [],
+ "uris": []
+ }
+ ],
+ "metadata": [
+ {
+ "name": "ohos.extability.form",
+ "resource": "$profile:form_config",
+ }
+ ]
+ }
+ ]
+ }
}
```
#### definePermissions对象内部结构
-该标签标识hap定义的权限。
+该标签标识HAP定义的权限。该标签只支持系统应用配置。
-表10 definePermissions定义权限字段说明
+表11 definePermission对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ---------------------- | ------------------------------------------------------------ | -------- | ------------------------------ |
-| name | 标识权限的名称。 | 字符串 | 不可缺省 |
-| grantMode | 标识权限的授予方式,授予模式如下:
system_grant:安装后系统自动授予该权限。
user_grant:使用动态申请,用户授权后才可使用 | 字符串 | 可缺省,缺省值为system_grant。 |
-| availableLevel | 标识权限限制门限,可选值为"system_core"、"system_basic"、"normal"。该标签有缺省值,缺省值为normal。权限范围如下:
system_core:系统核心权限。
system_basic:系统基础权限。
normal:普通权限。所有应用允许申请的权限。 | 字符串 | 可缺省,缺省值为"normal" |
-| provisionEnable | 标识权限是否支持证书方式申请权限,包括高级别的权限,true标识需要开发者可以通过provision证书acls方式申请权限。 | 布尔值 | 可缺省,缺省值为true |
-| distributedSceneEnable | 标识权限是否支持分布式场景下使用该权限。 | 布尔值 | 可缺省,缺省值为false |
-| label | 标识权限的简短描述,配置为对描述内容的资源索引。 | 字符串 | 可缺省,缺省值为空 |
-| description | 标识权限的详细描述,可以是表示描述内容的字符串,也可以是对描述内容的资源索引。 | 字符串 | 可缺省,缺省值为空 |
+| name | 标识权限的名称。 | 字符串 | 不可缺省。 |
+| grantMode | 标识权限的授予方式,授予模式如下:
system_grant:安装后系统自动授予该权限。
user_grant:应用动态申请,用户授权后才可使用 | 字符串 | 可缺省,缺省值为"system_grant"。 |
+| availableLevel | 标识权限限制门限,可选值为system_core、system_basic、normal。
system_core:系统核心权限。
system_basic:系统基础权限。
normal:普通权限。所有应用允许申请的权限。 | 字符串 | 可缺省,缺省值为"normal"。 |
+| provisionEnable | 标识权限是否支持证书方式申请权限,包括高级别的权限,true标识需要开发者可以通过provision证书acls方式申请权限。 | 布尔值 | 可缺省,缺省值为true。 |
+| distributedSceneEnable | 标识权限是否支持分布式场景下使用该权限。 | 布尔值 | 可缺省,缺省值为false。 |
+| label | 标识权限的简短描述,配置为对描述内容的资源索引。 | 字符串 | 可缺省,缺省值为空。 |
+| description | 标识权限的详细描述,可以是表示描述内容的字符串,也可以是对描述内容的资源索引。 | 字符串 | 可缺省,缺省值为空。 |
+
+definePermissions示例 :
+
+```json
+{
+ "module": {
+ "definePermissions": [
+ {
+ "name": "permissionName",
+ "grantMode": "user_grant",
+ "availableLevel": "system_basic",
+ "provisionEnable": false,
+ "distributedSceneEnable": true,
+ "label" : "$string:label",
+ "description": "$string:description"
+ }
+ ]
+ }
+}
+
+```
#### requestPermissions对象内部结构
该标签标识应用运行时需向系统申请的权限集合。
-表11 requestPermissions权限申请字段说明
+表12 requestPermission对象内部结构说明
-| 属性名称 | 含义 | **类型** | **取值范围** | **默认值** | **规则约束** |
-| --------- | ------------------------------------------------------------ | ---------------------------------------- | ------------------------------------------------------------ | -------------------- | ------------------------------------------------------------ |
-| name | 必须,填写需要使用的权限名称。 | 字符串 | 自定义 | 无 | 未填写时,解析失败。 |
-| reason | 可选,当申请的权限为user_grant权限时此字段必填。描述申请权限的原因。 | 字符串 | 使用string类资源引用。格式为`$string: ***`。 | 空 | user_grant权限必填,否则不允许在应用市场上架。需做多语种适配。 |
-| usedScene | 可选,当申请的权限为user_grant权限时此字段必填。描述权限使用的场景和时机。场景类型有 :ability、when(调用时机)。可配置多个ability。 | abilities:ability字符串数组,when:字符串 | abilities:ability的名称,when:inuse(使用时)、always(始终) | abilities:空 when:空 | user_grant权限必填abilities,可选填when。 |
+| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
+| ------| ------| -------- | ------------------------------ |
+| name | 需要申请的权限名称。| 字符串 | 不可缺省。 |
+| reason | 申请权限的原因。配置为描述内容的资源索引,以支持多语言。 | 字符串 | 可缺省,缺省值为空。当申请权限的grantMode为user_grant时不可缺省。 |
+| usedScene | 权限使用的场景和时机。参考[usedScene对象内部结构](#usedscene对象内部结构)。| 对象 | 可缺省,缺省值为空。当申请权限的grantMode为user_grant时不可缺省。 |
-requestPermissions示例 :
+requestPermissions示例 :
```json
{
- "name": "ohos.abilitydemo.permission.PROVIDER",
- "reason": "$string:reason",
- "usedScene": {
- "abilities": [
- "AudioAbility",
- "VideoAbility",
- ],
- "when": "inuse"
- }
+ "module": {
+ "requestPermissions": [
+ {
+ "name": "permissionName",
+ "reason": "$string:reason",
+ "usedScene": {
+ "abilities": [
+ "AudioAbility",
+ "VideoAbility"
+ ],
+ "when": "inuse"
+ }
+ }
+ ]
+ }
}
```
+
权限访问的更多说明,可参考[访问控制开发指导](../security/accesstoken-guidelines.md)
-#### form对象内部结构
+#### usedScene对象内部结构
+
+该标签标识权限使用的场景和时机。
+
+表13 usedScene对象内部结构说明
+
+| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
+| ------- | --------------------| -------- | ------ |
+| abilities | 标识需要使用到该权限的ability。| 字符串数组 | 不可缺省。 |
+| when | 标识使用该权限的时机,可选值为inuse和always。inuse表示仅前台使用,always表示前后台都可使用 | 字符串 | 可缺省,缺省值为空。 |
-forms标签标识卡片的配置,form卡片是可以嵌入桌面上并接收定期更新的应用简要视图。在以下场景中可以包含form标签。
-1. extensions中指定type为form。
+usedScene示例 :
+
+```json
+{
+ "module": {
+ "requestPermissions": [
+ {
+ "usedScene": {
+ "abilities": [
+ "AudioAbility",
+ "VideoAbility"
+ ],
+ "when": "inuse"
+ }
+ }
+ ]
+ }
+}
+```
+
+#### forms对象内部结构
-2. metadata中指定form信息,其中 :
- name :指定form的名称。使用ohos.extability.form作为form信息的标识。
- resource :指定form信息的资源位置。
+forms标签标识卡片的配置,form卡片是可以嵌入桌面上并接收定期更新的应用简要视图。
+配置方式如下:
+extensionAbility标签配置type为form,并配置metadata信息:name :"ohos.extability.form"。resource :指定form信息的资源位置。
-表12 forms对象的内部结构说明
+表14 form对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ------------------- | ------------------------------------------------------------ | ---------- | ----------------------------- |
-| name | 标识卡片的类名。字符串最大长度为127字节。 | 字符串 | 否 |
-| description | 标识卡片的描述。取值可以是描述性内容,也可以是对描述性内容的资源索引,以支持多语言。字符串最大长度为255字节。 | 字符串 | 可缺省,缺省为空。 |
-| src | 该标签标识JS卡片对应的UI代码。建议开发者通过自适应布局显示不同规格卡片,如果不同规格卡片布局相差较大,建议通过不同卡片来区分。 | 字符串 | 可缺省,缺省为空。 |
-| window | 该标签标识JS卡片的自适应能力。window结构参考表12。 | 对象 | 可缺省,缺省为空。 |
-| isDefault | 标识该卡片是否为默认卡片,每个Ability有且只有一个默认卡片。 true :默认卡片。 false :非默认卡片。 | 布尔值 | 否 |
-| colorMode | 标识卡片的主题样式,取值范围如下 : auto :自适应。 dark :深色主题。 light :浅色主题。 | 字符串 | 可缺省,缺省值为“auto”。 |
-| supportDimensions | 标识卡片支持的外观规格,取值范围 : 1 * 2 :表示1行2列的二宫格。 2 * 1 :表示2行1列的二宫格。 2 * 2 :表示2行2列的四宫格。 2 * 4 :表示2行4列的八宫格。 4 * 4 :表示4行4列的十六宫格。 | 字符串数组 | 否 |
-| defaultDimension | 标识卡片的默认外观规格,取值必须在该卡片supportDimensions配置的列表中。 | 字符串 | 否 |
-| updateEnabled | 该标签标识该卡片是否支持实时刷新,true标识卡片支持实时刷新,false标识不支持。 | 布尔值 | 否 |
-| scheduledUpdateTime | 该标签标识卡片定点刷新的时间,采用24小时计数,精确到分钟。 | 字符串 | 是 |
-| updateDuration | 该标签标识卡片定时刷新的更新频率,单位为30分钟,取值为30的倍数值。卡片的最高频率为每30分钟刷新一次,和定点刷新二选一,二者都配置的情况下,定时优先。 | 数值 | 可缺省,缺省为空。 |
-| metadata | 该标签标识卡片的自定义信息。metadata内部结构参考表5。 | 对象 | 可缺省,缺省为空。 |
-| formConfigAbility | 该标签标识卡片调整的Ability名称。标签值为字符串类型(最长127字符)。该标签值必须满足下面的格式 :
ability://单个ability名字
单个ability名字必须为本应用的ability。 | 字符串 | 可缺省,缺省为空。 |
-| formVisibleNotify | 该标签标识卡片是否被允许使用卡片可见性通知。标签值为true或false | 布尔值 | 该标签可缺省,默认值为false。 |
-
-表13 window内部结构说明
-
-| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
-| --------------- | ------------------------------------------------------------ | -------- | -------------------- |
-| designWidth | 指示页面设计的基线宽度,以像素为单位。 元素的大小由实际设备宽度缩放。 这个标签是一个整数。 | 数值 | 可缺省,缺省值为空。 |
-| autoDesignWidth | 指定是否自动计算页面设计的基线宽度。 如果设置为true,则designWidth属性无效。基线宽度根据设备宽度和屏幕密度计算。 | 布尔值 | 可缺省,缺省值为空。 |
+| name | 标识卡片的名称。最大长度为127字节。 | 字符串 | 不可缺省。 |
+| description | 标识卡片的描述。取值可以是描述性内容,也可以是对描述性内容的资源索引,以支持多语言。最大长度为255字节。 | 字符串 | 可缺省,缺省值为空。 |
+| src | 该标签标识JS卡片对应的UI代码。建议开发者通过自适应布局显示不同规格卡片,如果不同规格卡片布局相差较大,建议通过不同卡片来区分。 | 字符串 | 可缺省,缺省值为空。 |
+| window | 该标签标识JS卡片的自适应能力。参考[window对象内部结构](#window对象内部结构)。 | 对象 | 可缺省,缺省值为空。 |
+| isDefault | 标识该卡片是否为默认卡片,每个Ability有且只有一个默认卡片。 true :默认卡片。 false :非默认卡片。 | 布尔值 | 不可缺省。 |
+| colorMode | 标识卡片的主题样式,取值范围如下 :
auto :自适应。
dark :深色主题。
light :浅色主题。
| 字符串 | 可缺省,缺省值为“auto”。 |
+| supportDimensions | 标识卡片支持的外观规格,取值范围 :
1 * 2 :表示1行2列的二宫格。
2 * 1 :表示2行1列的二宫格。
2 * 2 :表示2行2列的四宫格。
2 * 4 :表示2行4列的八宫格。
4 * 4 :表示4行4列的十六宫格。 | 字符串数组 | 不可缺省。 |
+| defaultDimension | 标识卡片的默认外观规格,取值必须在该卡片supportDimensions配置的列表中。 | 字符串 | 不可缺省。 |
+| updateEnabled | 该标签标识该卡片是否支持实时刷新,true标识卡片支持实时刷新,false表示不支持。 | 布尔值 | 不可缺省。 |
+| scheduledUpdateTime | 该标签标识卡片定点刷新的时间,采用24小时计数,精确到分钟。 | 字符串 | 可缺省,缺省值为空。 |
+| updateDuration | 该标签标识卡片定时刷新的更新频率,单位为30分钟,取值为30的倍数。卡片的最高频率为每30分钟刷新一次,和定点刷新二选一,二者都配置的情况下,定时优先。 | 数值 | 可缺省,缺省值为空。 |
+| metadata | 该标签标识卡片的元信息。参考[metadata对象内部结构](#metadata对象内部结构)。 | 对象数组 | 可缺省,缺省值为空。 |
+| formConfigAbility | 该标签标识卡片调整的Ability名称。最大长度127字节。该标签值必须满足下面的格式 :
ability://单个ability名字
单个ability名字必须为本应用的ability。 | 字符串 | 可缺省,缺省值为空。 |
+| formVisibleNotify | 该标签标识卡片是否被允许使用卡片可见性通知。 | 布尔值 | 可缺省,缺省值为false。 |
form示例 :
-在开发视图的resources/base/profile下面定义配置文件form_config.json(文件名称可由开发者定义)
+1.在开发视图的resources/base/profile下面定义配置文件form_config.json(文件名称可由开发者定义):
```json
{
"forms": [
{
"name": "Form_Js",
- "description": "$string:form_description",
+ "description": "$string:description",
"src": "./js/pages/card/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
- "formConfigAbility": "ability://xxxxx",
+ "formConfigAbility": "ability://xxx",
"formVisibleNotify": false,
"isDefault": true,
"updateEnabled": true,
@@ -593,200 +672,221 @@ form示例 :
"updateDuration": 1,
"defaultDimension": "2*2",
"updateEnabled": true,
- "scheduledUpdateTime": "21:33",
"supportDimensions": [
"2*2"
],
"metadata": [
- {
- "name": "string",
- "value": "string",
- "resource": "$profile:config_file"
- }
+ {
+ "name": "name",
+ "value": "value",
+ "resource": "$profile:resource"
+ }
]
}
]
}
```
-在module.json5的extension组件下面定义metadata信息
+2.在module.json5的extensionAbilities标签下定义metadata信息 :
```json
{
- "extensionAbilities": [{
- "name": "MyForm",
- "type": "form",
- "metadata": [{
- "name": "ohos.extability.form",
- "resource": "$profile:form_config"
- }]
- }]
+ "module": {
+ "extensionAbilities": [
+ {
+ "type": "form",
+ "metadata": [
+ {
+ "name": "ohos.extability.form",
+ "resource": "$profile:form_config"
+ }
+ ]
+ }
+ ]
+ }
}
```
#### shortcuts对象内部结构
-标识应用的快捷方式信息。标签值为数组,最多可以配置四个快捷方式。其包含四个子标签shortcutId、label、icon、wants。
-
-metadata中指定shortcut信息,其中 :
-1)name :指定shortcuts的名称。使用ohos.ability.shortcuts作为shortcuts信息的标识。
-2)resource :指定shortcuts信息的资源位置。
+标识应用的快捷方式信息。最多可以配置四个快捷方式。
+配置方式如下:
+ability标签配置metadata信息。name :"ohos.ability.shortcuts"。resource :指定shortcuts信息的资源位置。
-表14 shortcuts对象的内部结构说明
+表15 shortcut对象内部结构说明
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ---------- | ------------------------------------------------------------ | -------- | -------------------------- |
-| shortcutId | 标识快捷方式的ID。字符串的最大长度为63字节。 | 字符串 | 否 |
-| label | 标识快捷方式的标签信息,即快捷方式对外显示的文字描述信息。取值可以是描述性内容,也可以是标识label的资源索引。字符串最大长度为63字节。 | 字符串 | 可缺省,缺省为空。 |
-| icon | 该标签标识shortcut的图标,标签值为资源文件的索引。 | 字符串 | 该标签可缺省,缺省值为空。 |
-| wants | 该标签标识快捷方式内定义的目标wants信息集合,每个want可配置两个子标签,bundleName,abilityName。
bundleName :快捷方式目标包名,字符串类型。
abilityName :快捷方式的目标组件名,字符串类型。 | 对象 | 该标签可缺省,缺省为空。 |
+| shortcutId | 标识快捷方式的ID。最大长度为63字节。 | 字符串 | 不可缺省。 |
+| label | 标识快捷方式的标签信息,即快捷方式对外显示的文字描述信息。取值可以是描述性内容,也可以是标识label的资源索引。字符串最大长度为63字节。 | 字符串 | 可缺省,缺省值为空。 |
+| icon | 该标签标识shortcut的图标,标签值为资源文件的索引。 | 字符串 | 可缺省,缺省值为空。 |
+| wants | 该标签标识快捷方式内定义的目标wants信息集合,每个want可配置两个子标签,bundleName,abilityName。
bundleName :快捷方式目标包名,字符串类型。
abilityName :快捷方式的目标组件名,字符串类型。 | 对象数组 | 可缺省,缺省值为空。 |
-在开发视图的resources/base/profile下面定义配置文件shortcut_config.json(文件名称可由开发者定义)。
+shortcuts示例 :
+
+1.在开发视图的resources/base/profile下面定义配置文件shortcuts_config.json(文件名称可由开发者定义):
```json
{
- "shortcuts": [{
- "shortcutId": "id_test1",
- "label": "$string:shortcut",
- "icon": "$media:aa_icon",
- "wants": [{
- "bundleName": "com.ohos.hello",
- "abilityName": "MainAbility"
- }]
- }]
+ "shortcuts": [
+ {
+ "shortcutId": "shortcut_id",
+ "label": "$string:label",
+ "icon": "$media:icon",
+ "wants": [
+ {
+ "bundleName": "bundleName",
+ "abilityName": "abilityName"
+ }
+ ]
+ }
+ ]
}
```
-在module.json5的module下面定义metadata信息,如下 :
+2.在module.json5的abilities标签下定义metadata信息 :
```json
{
"module": {
- "name": "MyAbilityStage",
- "abilities": [{
- "name": "MyAbility",
- "srcEntrance": "./abilities/MyAbility.ts",
- "skills": [{
- "actions": ["action.system.home"],
- "entities": ["entity.system.home"],
- "uris": []
- }],
- "metadata": [{
- "name": "ohos.ability.shortcuts",
- "resource": "$profile:shortcuts_config"
- }]
- }]
+ "abilities": [
+ {
+ "name": "MainAbility",
+ "srcEntrance": "./abilities/MainAbility.ts",
+ "skills": [
+ {
+ "actions": ["action.system.home"],
+ "entities": ["entity.system.home"]
+ }
+ ],
+ "metadata": [
+ {
+ "name": "ohos.ability.shortcuts",
+ "resource": "$profile:shortcuts_config"
+ }
+ ]
+ }
+ ]
}
}
```
#### commonEvents对象内部结构
-commonEvents标签标识注册静态公共事件信息。标签值为数组。
-metadata中指定commonEvent信息,其中 :
-
-1. name :指定commonEvent的名称。使用ohos.extability.staticSubscriber作为commonEvent信息的标识。
+commonEvents标签标识注册静态公共事件信息。
+配置方式如下:
+extensionAbility标签配置type为staticSubscriber,并配置metadata信息:name :"ohos.extability.staticSubscriber"。resource :指定commonEvents信息的资源位置。
-2. resource :指定commonEvent信息的资源位置。
-
-表15 commonEvents对象内部结构
+表16 commonEvent对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ---------- | ------------------------------------------------------------ | ---------- | -------------------------- |
-| name | 该标签指明当前静态公共事件对应的ability名,该类需要在ability中标明。 | 字符串 | 该标签不可缺省。 |
+| name | 该标签指明当前静态公共事件对应的ability名,该类需要在ability中标明。 | 字符串 | 不可缺省。 |
| permission | 该标签标识实现该静态公共事件需要申请的权限,以字符串类型表示一个权限名称,通常采用反向域名方式表示(最大255字节)。 | 字符串 | 可缺省,缺省值为空。 |
-| types | 该标签配置当前静态公共事件的类别数组,字符串数组类型,每个数组元素为一个类别名称。 | 字符串数组 | 该标签可缺省,缺省值为空。 |
-| events | 该标签标识能够接收的意图的event值的集合,取值通常为系统预定义的event值,也允许自定义。 | 字符串数组 | 该标签不可缺省。 |
+| types | 该标签配置当前静态公共事件的类别数组,字符串数组类型,每个数组元素为一个类别名称。 | 字符串数组 | 可缺省,缺省值为空。 |
+| events | 该标签标识能够接收的意图的event值的集合,取值通常为系统预定义的event值,也允许自定义。 | 字符串数组 | 不可缺省。 |
+
+commonEvents示例 :
-在开发视图的resources/base/profile下面定义配置文件common_event_config.json(文件名称可由开发者定义)。
+1.在开发视图的resources/base/profile下面定义配置文件common_event_config.json(文件名称可由开发者定义):
```json
{
- "commonEvents": [{
- "name": "abilityName",
- "permission": "string",
- "types": [
- "string",
- "string"
- ],
- "events": [
- "string",
- "string"
- ]
- }]
+ "commonEvents": [
+ {
+ "name": "abilityName",
+ "permission": "permissionName",
+ "types": [
+ "type1",
+ "type2"
+ ],
+ "events": [
+ "event1",
+ "event2"
+ ]
+ }
+ ]
}
```
-在module.json5的extension组件下面定义metadata信息,如下 :
+2.在module.json5的extensionAbilities标签下定义metadata信息 :
```json
-"extensionAbilities": [
- {
- "name": "mySubscriber",
- "srcEntrance": "./extension/my_subscriber.js",
- "type": "staticSubscriber",
- "metadata": [{
- "name": "ohos.extability.staticSubscriber",
- "resource": "$profile:common_event_config",
- }],
+{
+ "module": {
+ "extensionAbilities": [
+ {
+ "name": "subscriber",
+ "srcEntrance": "./extension/subscriber.js",
+ "type": "staticSubscriber",
+ "metadata": [
+ {
+ "name": "ohos.extability.staticSubscriber",
+ "resource": "$profile:common_event_config"
+ }
+ ]
+ }
+ ]
}
-]
+}
```
#### distroFilter对象内部结构
标识应用的分发规则。
-该标签用于定义HAP包对应的细分设备规格的分发策略,以便在应用市场进行云端分发应用包时做精准匹配。该标签可配置的分发策略维度包括API Version、屏幕形状、屏幕分辨率。在进行分发时,通过deviceType与这三个属性的匹配关系,唯一确定一个用于分发到设备的HAP。
+该标签用于定义HAP包对应的细分设备规格的分发策略,以便在应用市场进行云端分发应用包时做精准匹配。该标签可配置的分发策略维度包括API Version、屏幕形状、窗口分辨率、屏幕分辨率、国家码。在进行分发时,通过deviceType与这五个属性的匹配关系,唯一确定一个用于分发到设备的HAP。
+配置方式如下:
+module标签配置metadata信息。name :"ohos.module.distro"。resource :指定distroFilter信息的资源位置。
-表16 distroFilter对象内部结构
+表17 distroFilter对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| ------------- | ------------------------------------------------------------ | -------- | -------------------------- |
-| apiVersion | 标识支持的apiVersion范围。参考表16。 | 对象数组 | 该标签可缺省,缺省值为空。 |
-| screenShape | 标识屏幕形状的支持策略。 | 对象数组 | 该标签可缺省,缺省值为空。 |
-| screenWindow | 标识应用运行时窗口的分辨率支持策略。该字段仅支持对轻量级智能穿戴设备进行配置。 | 对象数组 | 该标签可缺省,缺省值为空。 |
-| screenDensity | 该标签标识屏幕的像素密度(dpi :Dot Per Inch)。该字段可选,如果配置了该字段,取值必须合法。该标签为字符串数组,字符串范围如下。
sdpi :表示小规模的屏幕密度(Small-scale Dots per Inch),适用于dpi取值为(0,120]的设备。
mdpi :表示中规模的屏幕密度(Medium-scale Dots Per Inch),适用于dpi取值为(120,160]的设备。
ldpi :表示大规模的屏幕密度(Large-scale Dots Per Inch),适用于dpi取值为(160,240]的设备。
xldpi :表示大规模的屏幕密度(Extra Large-scale Dots Per Inch),适用于dpi取值为(240,320]的设备。
xxldpi :表示大规模的屏幕密度(Extra Extra Large-scale Dots Per Inch),适用于dpi取值为(320,480]的设备。
xxxldpi :表示大规模的屏幕密度(Extra Extra Extra Large-scale Dots Per Inch),适用于dpi取值为(480, 640]的设备。 | 对象数组 | 该标签可缺省,缺省值为空。 |
-| countryCode | 该标签标识应用需要分发的国家地区码,具体值以ISO-3166-1标准为准。支持多个国家和地区枚举定义。该字段可选,如果配置了该字段,取值必须合法。标签值字符串数组,子串表示所支持的国家或地区,由两个大写字母组成。 | 对象数组 | 该标签可缺省,缺省值为空。 |
+| apiVersion | 标识支持的apiVersion。 | 对象 | 可缺省,缺省值为空。 |
+| screenShape | 标识屏幕形状的支持策略。仅支持liteWearable设备配置。 | 对象 | 可缺省,缺省值为空。 |
+| screenWindow | 标识应用运行时窗口的分辨率支持策略。仅支持liteWearable设备配置。 | 对象 | 可缺省,缺省值为空。 |
+| screenDensity | 标识屏幕的像素密度(dpi : Dot Per Inch)。 | 对象 | 可缺省,缺省值为空。 |
+| countryCode | 标识应用需要分发的国家地区码。具体值以ISO-3166-1标准为准。 | 对象 | 可缺省,缺省值为空。 |
-表17 apiVersion对象的内部结构说明
+表18 apiVersion对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------- |
-| policy | 标识该子属性取值的黑白名单规则。配置为“exclude”或“include”。“include”表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
-| value | 支持的取值为API Version存在的整数值,例如4、5、6。场景示例 :某应用,针对相同设备型号,同时在网的为使用API 5和API 6开发的两个软件版本,则允许上架2个entry类型的安装包,分别支持到对应设备侧软件版本的分发。 | 数组 | 可缺省,缺省值为空。 |
+| policy | 标识该子属性取值的黑白名单规则。配置为"exclude"或"include"。"include"表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 支持的取值为API Version存在的整数值,例如4、5、6,最小取值为3。场景示例 :某应用,针对相同设备型号,同时在网的为使用API 5和API 6开发的两个软件版本,则允许上架2个entry类型的安装包,分别支持到对应设备侧软件版本的分发。 | 数值数组 | 可缺省,缺省值为空。 |
-表18 screenShape对象的内部结构说明
+表19 screenShape对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------- |
-| policy | 标识该子属性取值的黑白名单规则。配置为“exclude”或“include”。“include”表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
-| value | 支持的取值为circle(圆形)、rect(矩形)。场景示例 :针对智能穿戴设备,可为圆形表盘和矩形表盘分别提供不同的HAP。 | 数组 | 可缺省,缺省值为空。 |
+| policy | 标识该子属性取值的黑白名单规则。配置为"exclude"或"include"。"include"表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 支持的取值为circle(圆形屏幕)、rect(矩形屏幕)。场景示例:针对智能穿戴设备,可为圆形表盘和矩形表盘分别提供不同的HAP。 | 字符串数组 | 可缺省,缺省值为空。 |
-表19 screenWindow对象的内部结构说明
+表20 screenWindow对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------- |
-| policy | 标识该子属性取值的黑白名单规则。配置为“exclude”或“include”。“include”表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
-| value | 单个字符串的取值格式为 :“宽 * 高”,取值为整数像素值,例如“454 * 454”。 | 数组 | 可缺省,缺省值为空。 |
+| policy | 标识该子属性取值的黑白名单规则。配置为"include"。"include"表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 单个字符串的取值格式为 :“宽 * 高”,取值为整数像素值,例如“454 * 454”。 | 字符串数组 | 可缺省,缺省值为空。 |
-表20 screenDensity对象的内部结构说明
+表21 screenDensity对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------- |
-| policy | 标识该子属性取值的黑白名单规则。配置为“exclude”或“include”。“include”表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
-| value | 该标签标识屏幕的像素密度(dpi :Dot Per Inch)。 | 数组 | 可缺省,缺省值为空。 |
+| policy | 标识该子属性取值的黑白名单规则。配置为"exclude"或"include"。"include"表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 字符串范围如下:
sdpi :表示小规模的屏幕密度(Small-scale Dots per Inch),适用于dpi取值为(0,120]的设备。
mdpi :表示中规模的屏幕密度(Medium-scale Dots Per Inch),适用于dpi取值为(120,160]的设备。
ldpi :表示大规模的屏幕密度(Large-scale Dots Per Inch),适用于dpi取值为(160,240]的设备。
xldpi :表示大规模的屏幕密度(Extra Large-scale Dots Per Inch),适用于dpi取值为(240,320]的设备。
xxldpi :表示大规模的屏幕密度(Extra Extra Large-scale Dots Per Inch),适用于dpi取值为(320,480]的设备。
xxxldpi :表示大规模的屏幕密度(Extra Extra Extra Large-scale Dots Per Inch),适用于dpi取值为(480, 640]的设备。 | 字符串数组 | 可缺省,缺省值为空。 |
-表21 countryCode对象的内部结构说明
+表22 countryCode对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ------------------------------------------------------------ | -------- | -------------------- |
-| policy | 标识该子属性取值的黑白名单规则。配置为“exclude”或“include”。“include”表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
-| value | 该标签标识应用需要分发的国家地区码。 | 数组 | 可缺省,缺省值为空。 |
+| policy | 标识该子属性取值的黑白名单规则。配置为"exclude"或"include"。"include"表示该字段取值为白名单,满足value枚举值匹配规则的表示匹配该属性。 | 字符串 | 可缺省,缺省值为空。 |
+| value | 支持多个国家和地区枚举定义。字符串表示所支持的国家或地区,由两个大写字母组成。 | 字符串数组 | 可缺省,缺省值为空。 |
distroFilter示例 :
-在开发视图的resources/base/profile下面定义配置文件distroFilter_config.json(文件名称可由开发者定义)。
+1.在开发视图的resources/base/profile下面定义配置文件distro_filter_config.json(文件名称可由开发者定义):
```json
"distroFilter": [
@@ -802,39 +902,50 @@ distroFilter示例 :
"screenWindow": {
"policy": "include",
"value": ["454*454", "466*466"]
+ },
+ "screenDensity": {
+ "policy": "exclude",
+ "value": ["ldpi", "xldpi"]
+ },
+ "countryCode": {
+ "policy": "include",
+ "value": ["CN", "HK"]
}
}
]
```
-在module.json5的extensionAbilities组件下面定义metadata信息,如下 :
+2.在module.json5的module标签下定义metadata信息 :
```json
-"extensionAbilities": [
- {
- "name": "mySubscriber",
- "srcEntrance": "./extension/my_subscriber.js",
- "type": "staticSubscriber",
- "metadata": [{
- "name": "ohos.extability.staticSubscriber",
- "resource": "$profile:distroFilter_config",
- }],
+{
+ "module":{
+ "metadata": [
+ {
+ "name": "ohos.module.distro",
+ "resource": "$profile:distro_filter_config"
+ }
+ ]
}
-]
+}
```
#### testRunner对象内部结构
-表22 testRunner对象内部结构说明
+该标签用于支持对测试框架的配置
+
+表23 testRunner对象内部结构
| 属性名称 | 含义 | 数据类型 | 是否可缺省 |
| -------- | ---------------------- | -------- | ---------- |
| name | 标识测试框架对象名称。 | 字符串 | 不可缺省。 |
| srcPath | 标识测试框架代码路径。 | 字符串 | 不可缺省。 |
+testRunner示例 :
+
```
"testRunner": {
- "name": "myTestRUnnerName",
+ "name": "testRunnerName",
"srcPath": "etc/test/TestRunner.ts"
}
```
diff --git a/zh-cn/application-dev/reference/apis/Readme-CN.md b/zh-cn/application-dev/reference/apis/Readme-CN.md
index c5d34d86f5b43fa4406c9ac48dc9cce6628edaf9..fa059f26d31f655d191450b8b6562bf0f2680903 100755
--- a/zh-cn/application-dev/reference/apis/Readme-CN.md
+++ b/zh-cn/application-dev/reference/apis/Readme-CN.md
@@ -221,7 +221,7 @@
- [@ohos.multimodalInput.inputDevice (输入设备)](js-apis-inputdevice.md)
- [@ohos.multimodalInput.inputDeviceCooperate (键鼠穿越管理)](js-apis-cooperate.md)
- [@ohos.multimodalInput.inputEvent (输入事件)](js-apis-inputevent.md)
- - [@ohos.multimodalInput.inputEventClient (注入按键)](js-apis-inputeventclient.md)
+ - [@ohos.multimodalInput.inputEventClient (按键注入)](js-apis-inputeventclient.md)
- [@ohos.multimodalInput.inputMonitor (输入监听)](js-apis-inputmonitor.md)
- [@ohos.multimodalInput.keyCode (键值)](js-apis-keycode.md)
- [@ohos.multimodalInput.keyEvent (按键输入事件)](js-apis-keyevent.md)
diff --git a/zh-cn/application-dev/reference/apis/js-apis-animator.md b/zh-cn/application-dev/reference/apis/js-apis-animator.md
index 6689361e739a8a6746f1a6fe98b7f19b70977cbb..5a8dad19cbdb6903b750f7ab7ed19aca7acea863 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-animator.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-animator.md
@@ -34,7 +34,7 @@ create(options: AnimatorOptions): AnimatorResult
**示例:**
```js
- var options = {
+ let options = {
duration: 1500,
easing: 'friction',
delay: 0,
@@ -79,7 +79,7 @@ reset(options: AnimatorOptions): void
**示例:**
```js
-var options = {
+let options = {
duration: 1500,
easing: 'friction',
delay: 0,
@@ -266,7 +266,7 @@ export default {
animator: null
},
onInit() {
- var options = {
+ let options = {
duration: 1500,
easing: 'friction',
delay: 0,
@@ -279,7 +279,7 @@ export default {
this.animator = animator.create(options);
},
Show() {
- var options1 = {
+ let options1 = {
duration: 1500,
easing: 'friction',
delay: 0,
@@ -294,7 +294,7 @@ export default {
} catch(error) {
console.error(`Animator reset failed, error code: ${error.code}, message: ${error.message}.`);
}
- var _this = this;
+ let _this = this;
this.animator.onframe = function(value) {
_this.divWidth = value;
_this.divHeight = value;
@@ -353,7 +353,7 @@ createAnimator(options: AnimatorOptions): AnimatorResult
**示例:**
```js
-var options = {
+let options = {
duration: 1500,
easing: 'friction',
delay: 0,
diff --git a/zh-cn/application-dev/reference/apis/js-apis-application-Want.md b/zh-cn/application-dev/reference/apis/js-apis-application-Want.md
index be3a1a0272edf7872b269db394cf6e77c87614f0..73c71a6204d6bbd3bccb0e644bb47e204d401a8b 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-application-Want.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-application-Want.md
@@ -24,9 +24,9 @@ import Want from '@ohos.application.Want';
| uri | 只读 | string | 否 | 表示Uri描述。如果在Want中指定了Uri,则Want将匹配指定的Uri信息,包括scheme, schemeSpecificPart, authority和path信息。 |
| type | 只读 | string | 否 | 表示MIME type类型描述,打开文件的类型,主要用于文管打开文件。比如:"text/xml" 、 "image/*"等,MIME定义参考:https://www.iana.org/assignments/media-types/media-types.xhtml?utm_source=ld246.com。 |
| flags | 只读 | number | 否 | 表示处理Want的方式。默认传数字,具体参考:[flags说明](js-apis-featureAbility.md#flags说明)。 |
-| action | 只读 | string | 否 | 表示action选项描述。 |
-| parameters | 只读 | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:
ohos.aafwk.callerPid 表示拉起方的pid。
ohos.aafwk.param.callerToken 表示拉起方的token。
ohos.aafwk.param.callerUid 表示发起方的uid。[Bundle](js-apis-Bundle.md)模块中userId参数,可用于获取应用信息、包信息等,具体参考:[Bundle](js-apis-Bundle.md)。 |
-| entities | 只读 | Array\ | 否 | 表示entities相关描述。 |
+| action | 只读 | string | 否 | 表示要执行的通用操作(如:查看、分享、应用详情)。在隐式Want中,您可以定义该字段,配合uri或parameters来表示对数据要执行的操作。 |
+| parameters | 只读 | {[key: string]: any} | 否 | 表示WantParams描述,由开发者自行决定传入的键值对。默认会携带以下key值:
ohos.aafwk.callerPid 表示拉起方的pid。
ohos.aafwk.param.callerToken 表示拉起方的token。
ohos.aafwk.param.callerUid 表示[bundleInfo](js-apis-bundle-BundleInfo.md#bundleinfo-1)中的uid,应用包里应用程序的uid。 |
+| entities | 只读 | Array\ | 否 | 表示目标Ability额外的类别信息(如:浏览器、视频播放器),在隐式Want中是对action字段的补充。在隐式Want中,您可以定义该字段,来过滤匹配Ability类型。 |
| moduleName9+ | 只读 | string | 否 | 表示待启动的Ability所属的模块(module)。 |
**示例:**
diff --git a/zh-cn/application-dev/reference/apis/js-apis-application-shellCmdResult.md b/zh-cn/application-dev/reference/apis/js-apis-application-shellCmdResult.md
index 7fb56e487ec5d78cd1f6ae87edbc645faee0a5bc..978d61fb22593e3bd13d26f1cec086de57720e5d 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-application-shellCmdResult.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-application-shellCmdResult.md
@@ -8,17 +8,17 @@
## 使用说明
-通过abilityDelegator中的executeShellCommand方法来获取。
+通过abilityDelegator中的[executeShellCommand](js-apis-application-abilityDelegator.md#executeshellcommand)方法来获取。
```js
-import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
-var abilityDelegator;
-var cmd = "cmd";
-var timeout = 100;
+import AbilityDelegatorRegistry from "@ohos.application.abilityDelegatorRegistry";
+let abilityDelegator;
+let cmd = "cmd";
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
-abilityDelegator.executeShellCommand(cmd, timeout).then((data : any) => {
- console.info("executeShellCommand promise");
+abilityDelegator.executeShellCommand(cmd, (err: any, data: any) => {
+ console.info("executeShellCommand callback, failed: ", err);
+ console.info("executeShellCommand callback, success: ", data);
});
```
@@ -30,5 +30,5 @@ Shell命令执行结果
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------- | ------ | ---- | ---- | ------------------------------------------------------------ |
-| stdResult | string | 是 | 是 | 标准输出内容 |
-| exitCode | number | 是 | 是 | 结果码 |
+| stdResult | string | 是 | 是 | 标准输出内容。 |
+| exitCode | number | 是 | 是 | 结果码。 |
diff --git a/zh-cn/application-dev/reference/apis/js-apis-audio.md b/zh-cn/application-dev/reference/apis/js-apis-audio.md
index 0fddf9e9588d7165b64047f31cc65001127b671b..83ee7b3ef188b7aab26be93dbdce6cec416d79ed 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-audio.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md
@@ -20,13 +20,11 @@ import audio from '@ohos.multimedia.audio';
## 常量
-**系统接口:** 该接口为系统接口
-
-**系统能力:** SystemCapability.Multimedia.Audio.Device
-
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| ----- | -------------------------- | ---- | ---- | ------------------ |
-| LOCAL_NETWORK_ID9+ | string | 是 | 否 | 本地设备网络id。 |
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| --------------------------------------- | ----------| ---- | ---- | ------------------ |
+| LOCAL_NETWORK_ID9+ | string | 是 | 否 | 本地设备网络id。
此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.Audio.Device |
+| DEFAULT_VOLUME_GROUP_ID9+ | number | 是 | 否 | 默认音量组id。
**系统能力:** SystemCapability.Multimedia.Audio.Volume |
+| DEFAULT_INTERRUPT_GROUP_ID9+ | number | 是 | 否 | 默认音频中断组id。
**系统能力:** SystemCapability.Multimedia.Audio.Interrupt |
**示例:**
@@ -34,6 +32,8 @@ import audio from '@ohos.multimedia.audio';
import audio from '@ohos.multimedia.audio';
const localNetworkId = audio.LOCAL_NETWORK_ID;
+const defaultVolumeGroupId = audio.DEFAULT_VOLUME_GROUP_ID;
+const defaultInterruptGroupId = audio.DEFAULT_INTERRUPT_GROUP_ID;
```
## audio.getAudioManager
@@ -263,6 +263,8 @@ createTonePlayer(options: AudioRendererInfo, callback: AsyncCallback<TonePlay
**系统能力:** SystemCapability.Multimedia.Audio.Tone
+**系统接口:** 该接口为系统接口
+
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
@@ -281,6 +283,7 @@ let audioRendererInfo = {
"rendererFlags": 0
}
let tonePlayer;
+
audio.createTonePlayer(audioRendererInfo, (err, data) => {
console.info(`callback call createTonePlayer: audioRendererInfo: ${audioRendererInfo}`);
if (err) {
@@ -300,6 +303,8 @@ createTonePlayer(options: AudioRendererInfo): Promise<TonePlayer>
**系统能力:** SystemCapability.Multimedia.Audio.Tone
+**系统接口:** 该接口为系统接口
+
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
@@ -338,18 +343,31 @@ async function createTonePlayer(){
| RINGTONE | 2 | 铃声。 |
| MEDIA | 3 | 媒体。 |
| VOICE_ASSISTANT8+ | 9 | 语音助手。 |
-| ALL9+ | 100 | 所有公共音频流。
此接口为系统接口,三方应用不支持调用。|
+| ALL9+ | 100 | 所有公共音频流。
此接口为系统接口。|
+
+## InterruptRequestResultType9+
+
+枚举,音频中断请求结果类型。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
+
+**系统接口:** 该接口为系统接口
+
+| 名称 | 默认值 | 描述 |
+| ---------------------------- | ------ | ---------- |
+| INTERRUPT_REQUEST_GRANT | 0 | 请求音频中断成功。 |
+| INTERRUPT_REQUEST_REJECT | 1 | 请求音频中断失败,可能具有较高优先级类型。 |
## InterruptMode9+
枚举,焦点模型。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
| 名称 | 默认值 | 描述 |
| ---------------------------- | ------ | ---------- |
-| SHARE_MODE | 0 | 共享焦点模式。 |
-| INDEPENDENT_MODE| 1 | 独立焦点模式。 |
+| SHARE_MODE | 0 | 共享焦点模式。 |
+| INDEPENDENT_MODE | 1 | 独立焦点模式。 |
## DeviceFlag
@@ -359,14 +377,13 @@ async function createTonePlayer(){
| 名称 | 默认值 | 描述 |
| ------------------------------- | ------ | ------------------------------------------------- |
-| NONE_DEVICES_FLAG9+ | 0 | 无
此接口为系统接口,三方应用不支持调用。 |
+| NONE_DEVICES_FLAG9+ | 0 | 无
此接口为系统接口。 |
| OUTPUT_DEVICES_FLAG | 1 | 输出设备。 |
| INPUT_DEVICES_FLAG | 2 | 输入设备。 |
| ALL_DEVICES_FLAG | 3 | 所有设备。 |
-| DISTRIBUTED_OUTPUT_DEVICES_FLAG9+ | 4 | 分布式输出设备。
此接口为系统接口,三方应用不支持调用。 |
-| DISTRIBUTED_INPUT_DEVICES_FLAG9+ | 8 | 分布式输入设备。
此接口为系统接口,三方应用不支持调用。 |
-| ALL_DISTRIBUTED_DEVICES_FLAG9+ | 12 | 分布式输入和输出设备。
此接口为系统接口,三方应用不支持调用。 |
-
+| DISTRIBUTED_OUTPUT_DEVICES_FLAG9+ | 4 | 分布式输出设备。
此接口为系统接口。 |
+| DISTRIBUTED_INPUT_DEVICES_FLAG9+ | 8 | 分布式输入设备。
此接口为系统接口。 |
+| ALL_DISTRIBUTED_DEVICES_FLAG9+ | 12 | 分布式输入和输出设备。
此接口为系统接口。 |
## DeviceRole
@@ -379,7 +396,6 @@ async function createTonePlayer(){
| INPUT_DEVICE | 1 | 输入设备角色。 |
| OUTPUT_DEVICE | 2 | 输出设备角色。 |
-
## DeviceType
枚举,设备类型。
@@ -399,16 +415,15 @@ async function createTonePlayer(){
| USB_HEADSET | 22 | USB耳机,带麦克风。 |
| DEFAULT9+ | 1000 | 默认设备类型。 |
-## ActiveDeviceType
+## CommunicationDeviceType9+
-枚举,活跃设备类型。
+枚举,用于通信的可用设备类型。
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Communication
-| 名称 | 默认值 | 描述 |
-| ------------- | ------ | ---------------------------------------------------- |
-| SPEAKER | 2 | 扬声器。 |
-| BLUETOOTH_SCO | 7 | 蓝牙设备SCO(Synchronous Connection Oriented)连接。 |
+| 名称 | 默认值 | 描述 |
+| ------------- | ------ | -------------|
+| SPEAKER | 2 | 扬声器。 |
## AudioRingMode
@@ -437,6 +452,22 @@ async function createTonePlayer(){
| SAMPLE_FORMAT_S32LE | 3 | 带符号的32位整数,小尾数。
由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
| SAMPLE_FORMAT_F32LE9+ | 4 | 带符号的32位整数,小尾数。
由于系统限制,该采样格式仅部分设备支持,请根据实际情况使用。|
+## AudioErrors9+
+
+枚举,音频错误码。
+
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core
+
+| 错误信息 | 错误码 | 错误描述 |
+| ---------------------| --------| ----------------- |
+| ERROR_INVALID_PARAM | 6800101 | 无效入参。 |
+| ERROR_NO_MEMORY | 6800102 | 分配内存失败。 |
+| ERROR_ILLEGAL_STATE | 6800103 | 状态不支持。 |
+| ERROR_UNSUPPORTED | 6800104 | 参数选项不支持。 |
+| ERROR_TIMEOUT | 6800105 | 处理超时。 |
+| ERROR_STREAM_LIMIT | 6800201 | 音频流数量达到限制。|
+| ERROR_SYSTEM | 6800301 | 系统处理异常。 |
+
## AudioChannel8+
枚举, 音频声道。
@@ -508,18 +539,17 @@ async function createTonePlayer(){
| STREAM_USAGE_VOICE_ASSISTANT9+ | 3 | 语音播报。 |
| STREAM_USAGE_NOTIFICATION_RINGTONE | 6 | 通知铃声。 |
-## FocusType9+
+## InterruptRequestType9+
-表示焦点类型的枚举。
+枚举,音频中断请求类型。
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Core
-
-| 名称 | 默认值 | 描述 |
-| ---------------------------------- | ------ | ------------------------------- |
-| FOCUS_TYPE_RECORDING | 0 | 在录制场景使用,可打断其他音频。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
+| 名称 | 默认值 | 描述 |
+| ---------------------------------- | ------ | ------------------------- |
+| INTERRUPT_REQUEST_TYPE_DEFAULT | 0 | 默认类型,可中断音频请求。 |
## AudioState8+
@@ -586,29 +616,18 @@ async function createTonePlayer(){
| INTERRUPT_HINT_DUCK | 4 | 提示音频躲避。(躲避:音量减弱,而不会停止) |
| INTERRUPT_HINT_UNDUCK8+ | 5 | 提示音量恢复。 |
-## InterruptActionType
-
-枚举,中断事件返回类型。
-
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-
-| 名称 | 默认值 | 描述 |
-| -------------- | ------ | ------------------ |
-| TYPE_ACTIVATED | 0 | 表示触发焦点事件。 |
-| TYPE_INTERRUPT | 1 | 表示音频打断事件。 |
-
## AudioStreamInfo8+
音频流信息。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Core
-| 名称 | 类型 | 必填 | 说明 |
-| ------------ | ---------------------------------------- | ---- | ------------------ |
-| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | 是 | 音频文件的采样率。 |
-| channels | [AudioChannel](#audiochannel8) | 是 | 音频文件的通道数。 |
-| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | 是 | 音频采样格式。 |
-| encodingType | [AudioEncodingType](#audioencodingtype8) | 是 | 音频编码格式。 |
+| 名称 | 类型 | 必填 | 说明 |
+| ------------ | ------------------------------------------------- | ---- | ------------------ |
+| samplingRate | [AudioSamplingRate](#audiosamplingrate8) | 是 | 音频文件的采样率。 |
+| channels | [AudioChannel](#audiochannel8) | 是 | 音频文件的通道数。 |
+| sampleFormat | [AudioSampleFormat](#audiosampleformat8) | 是 | 音频采样格式。 |
+| encodingType | [AudioEncodingType](#audioencodingtype8) | 是 | 音频编码格式。 |
## AudioRendererInfo8+
@@ -622,6 +641,19 @@ async function createTonePlayer(){
| usage | [StreamUsage](#streamusage) | 是 | 音频流使用类型。 |
| rendererFlags | number | 是 | 音频渲染器标志。 |
+## InterruptResult9+
+
+音频中断结果。
+
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Interrupt
+
+**系统接口:** 该接口为系统接口
+
+| 名称 | 类型 | 必填 | 说明 |
+| --------------| -------------------------------------------------------------- | ---- | ---------------- |
+| requestResult | [InterruptRequestResultType](#interruptrequestresulttype9) | 是 | 表示音频请求中断类型。 |
+| interruptNode | number | 是 | 音频请求中断的节点。 |
+
## AudioRendererOptions8+
音频渲染器选项信息。
@@ -645,31 +677,6 @@ async function createTonePlayer(){
| forceType | [InterruptForceType](#interruptforcetype9) | 是 | 操作是由系统执行或是由应用程序执行。 |
| hintType | [InterruptHint](#interrupthint) | 是 | 中断提示。 |
-## AudioInterrupt
-
-音频监听事件传入的参数。
-
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-
-| 名称 | 类型 | 必填 | 说明 |
-| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
-| streamUsage | [StreamUsage](#streamusage) | 是 | 音频流使用类型。 |
-| contentType | [ContentType](#contenttype) | 是 | 音频打断媒体类型。 |
-| pauseWhenDucked | boolean | 是 | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
-
-## InterruptAction
-
-音频打断/获取焦点事件的回调方法。
-
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-
-| 名称 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
-| actionType | [InterruptActionType](#interruptactiontype) | 是 | 事件返回类型。TYPE_ACTIVATED为焦点触发事件,TYPE_INTERRUPT为音频打断事件。 |
-| type | [InterruptType](#interrupttype) | 否 | 打断事件类型。 |
-| hint | [InterruptHint](#interrupthint) | 否 | 打断事件提示。 |
-| activated | boolean | 否 | 获得/释放焦点。true表示焦点获取/释放成功,false表示焦点获得/释放失败。 |
-
## VolumeEvent8+
音量改变时,应用接收的事件。
@@ -702,7 +709,7 @@ async function createTonePlayer(){
**系统接口:** 该接口为系统接口
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Volume
| 名称 | 默认值 | 描述 |
| :------------------------------ | :----- | :--------------------- |
@@ -739,7 +746,7 @@ async function createTonePlayer(){
import audio from '@ohos.multimedia.audio';
async function getVolumeGroupInfos(){
- let volumegroupinfos = await audio.getAudioManager().getVolumeGroups(audio.LOCAL_NETWORK_ID);
+ let volumegroupinfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
}
getVolumeGroupInfos();
@@ -811,889 +818,968 @@ getVolumeGroupInfos();
| 名称 | 默认值 | 描述 |
| :--------------------- | :----- | :-------------------------------------------- |
| AUDIO_SCENE_DEFAULT | 0 | 默认音频场景。 |
-| AUDIO_SCENE_RINGING | 1 | 响铃模式。
此接口为系统接口,三方应用不支持调用。 |
-| AUDIO_SCENE_PHONE_CALL | 2 | 电话模式。
此接口为系统接口,三方应用不支持调用。 |
+| AUDIO_SCENE_RINGING | 1 | 响铃模式。
此接口为系统接口。 |
+| AUDIO_SCENE_PHONE_CALL | 2 | 电话模式。
此接口为系统接口。 |
| AUDIO_SCENE_VOICE_CHAT | 3 | 语音聊天模式。 |
## AudioManager
管理音频音量和音频设备。在调用AudioManager的接口前,需要先通过[getAudioManager](#audiogetaudiomanager)创建实例。
-### getRoutingManager9+
+### setAudioParameter
+
+setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void
-getRoutingManager(callback: AsyncCallback<AudioRoutingManager>): void
+音频参数设置,使用callback方式异步返回结果。
-获取AudioRoutingManager对象,使用callback方式异步返回结果。
+本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
+
+**系统能力:** SystemCapability.Multimedia.Audio.Core
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ---------------------------------------------------------------- | ---- | --------------------------------- |
-| callback | AsyncCallback<[AudioRoutingManager](#audioroutingmanager9)> | 是 | 回调,返回AudioRoutingManager对象。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------------- | ---- | ------------------------ |
+| key | string | 是 | 被设置的音频参数的键。 |
+| value | string | 是 | 被设置的音频参数的值。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
+
```js
-audioManager.getRoutingManager((err, callback) => {
+audioManager.setAudioParameter('key_example', 'value_example', (err) => {
if (err) {
- console.error(`Result ERROR: ${err}`);
+ console.error(`Failed to set the audio parameter. ${err}`);
+ return;
}
- console.info('getRoutingManager Callback SUCCESS.');
- let audioRoutingManager;
- audioRoutingManager = callback;
+ console.info('Callback invoked to indicate a successful setting of the audio parameter.');
});
```
-### getRoutingManager9+
+### setAudioParameter
-getRoutingManager(): Promise<AudioRoutingManager>
+setAudioParameter(key: string, value: string): Promise<void>
-获取AudioRoutingManager对象,使用Promise方式异步返回结果。
+音频参数设置,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
+
+**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
+
+**系统能力:** SystemCapability.Multimedia.Audio.Core
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ------ | ---- | ---------------------- |
+| key | string | 是 | 被设置的音频参数的键。 |
+| value | string | 是 | 被设置的音频参数的值。 |
**返回值:**
-| 类型 | 说明 |
-| ----------------------------------------------------------- | --------------------------------------- |
-| Promise<[AudioRoutingManager](#audioroutingmanager9)> | Promise回调返回AudioRoutingManager对象。 |
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
**示例:**
+
```js
-let audioManager = audio.getAudioManager();
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- let routingManager = value;
- console.info('getRoutingManager Promise SUCCESS.');
- }).catch((err) => {
- console.error(`Result ERROR: ${err}`);
- });
-}
+audioManager.setAudioParameter('key_example', 'value_example').then(() => {
+ console.info('Promise returned to indicate a successful setting of the audio parameter.');
+});
```
-### setVolume
-
-setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void
+### getAudioParameter
-设置指定流的音量,使用callback方式异步返回结果。
+getAudioParameter(key: string, callback: AsyncCallback<string>): void
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+获取指定音频参数值,使用callback方式异步返回结果。
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Core
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
-| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | --------------------------- | ---- | ---------------------------- |
+| key | string | 是 | 待获取的音频参数的键。 |
+| callback | AsyncCallback<string> | 是 | 回调返回获取的音频参数的值。 |
**示例:**
```js
-audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
+audioManager.getAudioParameter('key_example', (err, value) => {
if (err) {
- console.error(`Failed to set the volume. ${err}`);
+ console.error(`Failed to obtain the value of the audio parameter. ${err}`);
return;
}
- console.info('Callback invoked to indicate a successful volume setting.');
+ console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
});
```
-### setVolume
-
-setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
+### getAudioParameter
-设置指定流的音量,使用Promise方式异步返回结果。
+getAudioParameter(key: string): Promise<string>
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+获取指定音频参数值,使用Promise方式异步返回结果。
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Core
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ------ | ---- | ---------------------- |
+| key | string | 是 | 待获取的音频参数的键。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise<void> | Promise回调表示成功还是失败。 |
+| 类型 | 说明 |
+| --------------------- | ----------------------------------- |
+| Promise<string> | Promise回调返回获取的音频参数的值。 |
**示例:**
```js
-audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
- console.info('Promise returned to indicate a successful volume setting.');
+audioManager.getAudioParameter('key_example').then((value) => {
+ console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
});
```
-### getVolume
+### setAudioScene8+
-getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+setAudioScene\(scene: AudioScene, callback: AsyncCallback\): void
-获取指定流的音量,使用callback方式异步返回结果。
+设置音频场景模式,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回音量大小。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :----------------------------------- | :--- | :------------------- |
+| scene | AudioScene | 是 | 音频场景模式。 |
+| callback | AsyncCallback | 是 | 用于返回结果的回调。 |
**示例:**
```js
-audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
+let audioManager = audio.getAudioManager();
+audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
if (err) {
- console.error(`Failed to obtain the volume. ${err}`);
+ console.error(`Failed to set the audio scene mode. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the volume is obtained.');
+ console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
});
```
-### getVolume
+### setAudioScene8+
-getVolume(volumeType: AudioVolumeType): Promise<number>
+setAudioScene\(scene: AudioScene\): Promise
-获取指定流的音量,使用Promise方式异步返回结果。
+设置音频场景模式,使用Promise方式返回异步结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :----- | :----------------------------------- | :--- | :------------- |
+| scene | AudioScene | 是 | 音频场景模式。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------- | ------------------------- |
-| Promise<number> | Promise回调返回音量大小。 |
+| 类型 | 说明 |
+| :------------- | :------------------- |
+| Promise | 用于返回结果的回调。 |
**示例:**
```js
-audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
+let audioManager = audio.getAudioManager();
+audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
+ console.info('Promise returned to indicate a successful setting of the audio scene mode.');
+}).catch ((err) => {
+ console.error(`Failed to set the audio scene mode ${err}`);
});
```
-### getMinVolume
+### getAudioScene8+
-getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+getAudioScene\(callback: AsyncCallback\): void
-获取指定流的最小音量,使用callback方式异步返回结果。
+获取音频场景模式,使用callback方式返回异步结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回最小音量。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
+| callback | AsyncCallback<AudioScene> | 是 | 用于返回音频场景模式的回调。 |
**示例:**
```js
-audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
+let audioManager = audio.getAudioManager();
+audioManager.getAudioScene((err, value) => {
if (err) {
- console.error(`Failed to obtain the minimum volume. ${err}`);
+ console.error(`Failed to obtain the audio scene mode. ${err}`);
return;
}
- console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
+ console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
});
```
-### getMinVolume
+### getAudioScene8+
-getMinVolume(volumeType: AudioVolumeType): Promise<number>
-
-获取指定流的最小音量,使用Promise方式异步返回结果。
-
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+getAudioScene\(\): Promise
-**参数:**
+获取音频场景模式,使用Promise方式返回异步结果。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**返回值:**
-| 类型 | 说明 |
-| --------------------- | ------------------------- |
-| Promise<number> | Promise回调返回最小音量。 |
+| 类型 | 说明 |
+| :-------------------------------------------- | :--------------------------- |
+| Promise<AudioScene> | 用于返回音频场景模式的回调。 |
**示例:**
```js
-audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
+let audioManager = audio.getAudioManager();
+audioManager.getAudioScene().then((value) => {
+ console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
+}).catch ((err) => {
+ console.error(`Failed to obtain the audio scene mode ${err}`);
});
```
-### getMaxVolume
+### getVolumeManager9+
-getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+getVolumeManager(): AudioVolumeManager
-获取指定流的最大音量,使用callback方式异步返回结果。
+获取音频音量管理器。
**系统能力:** SystemCapability.Multimedia.Audio.Volume
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ---------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回最大音量大小。 |
-
**示例:**
```js
-audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the maximum volume. ${err}`);
- return;
- }
- console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
-});
+let audioVolumeManager = audioManager.getVolumeManager();
```
-### getMaxVolume
+### getStreamManager9+
-getMaxVolume(volumeType: AudioVolumeType): Promise<number>
+getStreamManager(): AudioStreamManager
-获取指定流的最大音量,使用Promise方式异步返回结果。
+获取音频流管理器。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Core
-**参数:**
+**示例:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+```js
+let audioStreamManager = audioManager.getStreamManager();
+```
-**返回值:**
+### getRoutingManager9+
-| 类型 | 说明 |
-| --------------------- | ----------------------------- |
-| Promise<number> | Promise回调返回最大音量大小。 |
+getRoutingManager(): AudioRoutingManager
+
+获取音频路由设备管理器。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**示例:**
```js
-audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
- console.info('Promised returned to indicate that the maximum volume is obtained.');
-});
+let audioRoutingManager = audioManager.getRoutingManager();
```
-### mute
+## AudioVolumeManager9+
-mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void
+音量管理。在使用AudioVolumeManager的接口前,需要使用[getVolumeManager](#getvolumemanager9)获取AudioVolumeManager实例。
-设置指定音量流静音,使用callback方式异步返回结果。
+### getVolumeGroupInfos9+
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+getVolumeGroupInfos(networkId: string, callback: AsyncCallback\): void
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+获取音量组信息列表,使用callback方式异步返回结果。
+
+**系统接口:** 该接口为系统接口
**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
-| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
+| networkId | string | 是 | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID。 |
+| callback | AsyncCallback<[VolumeGroupInfos](#volumegroupinfos9)> | 是 | 回调,返回音量组信息列表。 |
**示例:**
-
```js
-audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
+audioVolumeManager.getVolumeGroupInfos(audio.LOCAL_NETWORK_ID, (err, value) => {
if (err) {
- console.error(`Failed to mute the stream. ${err}`);
+ console.error(`Failed to obtain the volume group infos list. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the stream is muted.');
+ console.info('Callback invoked to indicate that the volume group infos list is obtained.');
});
```
-### mute
+### getVolumeGroupInfos9+
-mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
-
-设置指定音量流静音,使用Promise方式异步返回结果。
+getVolumeGroupInfos(networkId: string\): Promise
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+获取音量组信息列表,使用promise方式异步返回结果。
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+**系统接口:** 该接口为系统接口
**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------| ---- | -------------------- |
+| networkId | string | 是 | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------- | ----------------------------- |
-| Promise<void> | Promise回调表示成功还是失败。 |
+| Promise<[VolumeGroupInfos](#volumegroupinfos9)> | 音量组信息列表。 |
**示例:**
-
```js
-audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
- console.info('Promise returned to indicate that the stream is muted.');
-});
+async function getVolumeGroupInfos(){
+ let volumegroupinfos = await audio.getAudioManager().getVolumeManager().getVolumeGroupInfos(audio.LOCAL_NETWORK_ID);
+ console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
+}
```
+### getVolumeGroupManager9+
-### isMute
+getVolumeGroupManager(groupId: number, callback: AsyncCallback\): void
-isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
-
-获取指定音量流是否被静音,使用callback方式异步返回结果。
+获取音频组管理器,使用callback方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调返回流静音状态,true为静音,false为非静音。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
+| groupId | number | 是 | 音量组id。 |
+| callback | AsyncCallback< [AudioVolumeGroupManager](#audiovolumegroupmanager9) > | 是 | 回调,返回一个音量组实例。 |
**示例:**
```js
-audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
+let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
+audioVolumeManager.getVolumeGroupManager(groupid, (err, value) => {
if (err) {
- console.error(`Failed to obtain the mute status. ${err}`);
+ console.error(`Failed to obtain the volume group infos list. ${err}`);
return;
}
- console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
+ console.info('Callback invoked to indicate that the volume group infos list is obtained.');
});
-```
+```
-### isMute
+### getVolumeGroupManager9+
-isMute(volumeType: AudioVolumeType): Promise<boolean>
+getVolumeGroupManager(groupId: number\): Promise
-获取指定音量流是否被静音,使用Promise方式异步返回结果。
+获取音频组管理器,使用promise方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ---------------------------------------- | ---- | ---------------- |
+| groupId | number | 是 | 音量组id。 |
**返回值:**
-| 类型 | 说明 |
-| ---------------------- | ------------------------------------------------------ |
-| Promise<boolean> | Promise回调返回流静音状态,true为静音,false为非静音。 |
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise< [AudioVolumeGroupManager](#audiovolumegroupmanager9) > | 音量组实例。 |
**示例:**
```js
-audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
-});
+let groupid = audio.DEFAULT_VOLUME_GROUP_ID;
+let audioVolumeGroupManager = await audioVolumeManager.getVolumeGroupManager(groupid);
+console.info('Callback invoked to indicate that the volume group infos list is obtained.');
```
-### isActive
+### on('volumeChange')9+
-isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
+on(type: 'volumeChange', callback: Callback\): void
-获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
+监听系统音量变化事件,使用callback方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调返回流的活跃状态,true为活跃,false为不活跃。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'volumeChange'。 |
+| callback | Callback<[VolumeEvent](#volumeevent8)> | 是 | 回调方法。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the active status of the stream. ${err}`);
- return;
- }
- console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
+audioVolumeManager.on('volumeChange', (volumeEvent) => {
+ console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
+ console.info(`Volume level: ${volumeEvent.volume} `);
+ console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
});
```
-### isActive
+## AudioVolumeGroupManager9+
-isActive(volumeType: AudioVolumeType): Promise<boolean>
+管理音频组音量。在调用AudioVolumeGroupManager的接口前,需要先通过 [getVolumeGroupManager](#getvolumegroupmanager9) 创建实例。
-获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
+**系统接口:** 该接口为系统接口
**系统能力:** SystemCapability.Multimedia.Audio.Volume
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-
-**返回值:**
-
-| 类型 | 说明 |
-| ---------------------- | -------------------------------------------------------- |
-| Promise<boolean> | Promise回调返回流的活跃状态,true为活跃,false为不活跃。 |
-
-**示例:**
-
-```js
-audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
-});
-```
-
-### setRingerMode
+### setVolume9+
-setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
+setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void
-设置铃声模式,使用callback方式异步返回结果。
+设置指定流的音量,使用callback方式异步返回结果。
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-仅在静音和非静音状态切换时需要该权限。
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ------------------------------- | ---- | ------------------------ |
-| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
-| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
+| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
**示例:**
```js
-audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
+audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
if (err) {
- console.error(`Failed to set the ringer mode. ${err}`);
+ console.error(`Failed to set the volume. ${err}`);
return;
}
- console.info('Callback invoked to indicate a successful setting of the ringer mode.');
+ console.info('Callback invoked to indicate a successful volume setting.');
});
```
-### setRingerMode
+### setVolume9+
-setRingerMode(mode: AudioRingMode): Promise<void>
+setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
-设置铃声模式,使用Promise方式异步返回结果。
+设置指定流的音量,使用Promise方式异步返回结果。
**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-仅在静音和非静音状态切换时需要该权限。
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ------------------------------- | ---- | -------------- |
-| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ------------------------------- |
-| Promise<void> | Promise回调返回设置成功或失败。 |
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise回调表示成功还是失败。 |
**示例:**
```js
-audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
- console.info('Promise returned to indicate a successful setting of the ringer mode.');
+audioVolumeGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
+ console.info('Promise returned to indicate a successful volume setting.');
});
```
+### getVolume9+
-### getRingerMode
-
-getRingerMode(callback: AsyncCallback<AudioRingMode>): void
+getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-获取铃声模式,使用callback方式异步返回结果。
+获取指定流的音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------------------- | ---- | ------------------------ |
-| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | 是 | 回调返回系统的铃声模式。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回音量大小。 |
**示例:**
```js
-audioManager.getRingerMode((err, value) => {
+audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error(`Failed to obtain the ringer mode. ${err}`);
+ console.error(`Failed to obtain the volume. ${err}`);
return;
}
- console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
+ console.info('Callback invoked to indicate that the volume is obtained.');
});
```
+### getVolume9+
-### getRingerMode
+getVolume(volumeType: AudioVolumeType): Promise<number>
-getRingerMode(): Promise<AudioRingMode>
+获取指定流的音量,使用Promise方式异步返回结果。
-获取铃声模式,使用Promise方式异步返回结果。
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| ---------------------------------------------- | ------------------------------- |
-| Promise<[AudioRingMode](#audioringmode)> | Promise回调返回系统的铃声模式。 |
+| 类型 | 说明 |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise回调返回音量大小。 |
**示例:**
```js
-audioManager.getRingerMode().then((value) => {
- console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
+audioVolumeGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
});
```
-### setAudioParameter
-
-setAudioParameter(key: string, value: string, callback: AsyncCallback<void>): void
-
-音频参数设置,使用callback方式异步返回结果。
+### getMinVolume9+
-本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
+getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
+获取指定流的最小音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ------------------------- | ---- | ------------------------ |
-| key | string | 是 | 被设置的音频参数的键。 |
-| value | string | 是 | 被设置的音频参数的值。 |
-| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回最小音量。 |
**示例:**
```js
-audioManager.setAudioParameter('key_example', 'value_example', (err) => {
+audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error(`Failed to set the audio parameter. ${err}`);
+ console.error(`Failed to obtain the minimum volume. ${err}`);
return;
}
- console.info('Callback invoked to indicate a successful setting of the audio parameter.');
+ console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
});
```
-### setAudioParameter
-
-setAudioParameter(key: string, value: string): Promise<void>
-
-音频参数设置,使用Promise方式异步返回结果。
+### getMinVolume9+
-本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
+getMinVolume(volumeType: AudioVolumeType): Promise<number>
-**需要权限:** ohos.permission.MODIFY_AUDIO_SETTINGS
+获取指定流的最小音量,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ------ | ---- | ---------------------- |
-| key | string | 是 | 被设置的音频参数的键。 |
-| value | string | 是 | 被设置的音频参数的值。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ------------------------------- |
-| Promise<void> | Promise回调返回设置成功或失败。 |
+| 类型 | 说明 |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise回调返回最小音量。 |
**示例:**
```js
-audioManager.setAudioParameter('key_example', 'value_example').then(() => {
- console.info('Promise returned to indicate a successful setting of the audio parameter.');
+audioVolumeGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
});
```
-### getAudioParameter
-
-getAudioParameter(key: string, callback: AsyncCallback<string>): void
+### getMaxVolume9+
-获取指定音频参数值,使用callback方式异步返回结果。
+getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
+获取指定流的最大音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | --------------------------- | ---- | ---------------------------- |
-| key | string | 是 | 待获取的音频参数的键。 |
-| callback | AsyncCallback<string> | 是 | 回调返回获取的音频参数的值。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ---------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回最大音量大小。 |
**示例:**
```js
-audioManager.getAudioParameter('key_example', (err, value) => {
+audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error(`Failed to obtain the value of the audio parameter. ${err}`);
+ console.error(`Failed to obtain the maximum volume. ${err}`);
return;
}
- console.info(`Callback invoked to indicate that the value of the audio parameter is obtained ${value}.`);
+ console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
});
```
-### getAudioParameter
-
-getAudioParameter(key: string): Promise<string>
+### getMaxVolume9+
-获取指定音频参数值,使用Promise方式异步返回结果。
+getMaxVolume(volumeType: AudioVolumeType): Promise<number>
-本接口的使用场景为根据硬件设备支持能力扩展音频配置。在不同的设备平台上,所支持的音频参数会存在差异。示例代码内使用样例参数,实际支持的音频配置参数见具体设备平台的资料描述。
+获取指定流的最大音量,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ------ | ---- | ---------------------- |
-| key | string | 是 | 待获取的音频参数的键。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------- | ----------------------------------- |
-| Promise<string> | Promise回调返回获取的音频参数的值。 |
+| 类型 | 说明 |
+| --------------------- | ----------------------------- |
+| Promise<number> | Promise回调返回最大音量大小。 |
**示例:**
```js
-audioManager.getAudioParameter('key_example').then((value) => {
- console.info(`Promise returned to indicate that the value of the audio parameter is obtained ${value}.`);
+audioVolumeGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
+ console.info('Promised returned to indicate that the maximum volume is obtained.');
});
```
-### getDevices
+### mute9+
-getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void
+mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void
-获取音频设备列表,使用callback方式异步返回结果。
+设置指定音量流静音,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
-| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回设备列表。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
+| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
**示例:**
+
```js
-audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
+audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
if (err) {
- console.error(`Failed to obtain the device list. ${err}`);
+ console.error(`Failed to mute the stream. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the device list is obtained.');
+ console.info('Callback invoked to indicate that the stream is muted.');
});
```
-### getDevices
+### mute9+
+
+mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
-getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
+设置指定音量流静音,使用Promise方式异步返回结果。
-获取音频设备列表,使用Promise方式异步返回结果。
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------- | ---- | ---------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------------------------------------------------ | ------------------------- |
-| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise回调返回设备列表。 |
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise回调表示成功还是失败。 |
**示例:**
```js
-audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
- console.info('Promise returned to indicate that the device list is obtained.');
+audioVolumeGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
+ console.info('Promise returned to indicate that the stream is muted.');
});
```
-### setDeviceActive
+### isMute9+
-setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void
+isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
-设置设备激活状态,使用callback方式异步返回结果。
+获取指定音量流是否被静音,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------- | ---- | ------------------------ |
-| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
-| active | boolean | 是 | 设备激活状态。 |
-| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回流静音状态,true为静音,false为非静音。 |
**示例:**
```js
-audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
+audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error(`Failed to set the active status of the device. ${err}`);
+ console.error(`Failed to obtain the mute status. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the device is set to the active status.');
+ console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
});
```
-### setDeviceActive
+### isMute9+
-setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void>
+isMute(volumeType: AudioVolumeType): Promise<boolean>
-设置设备激活状态,使用Promise方式异步返回结果。
+获取指定音量流是否被静音,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------- | ---- | ------------------ |
-| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
-| active | boolean | 是 | 设备激活状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ------------------------------- |
-| Promise<void> | Promise回调返回设置成功或失败。 |
+| 类型 | 说明 |
+| ---------------------- | ------------------------------------------------------ |
+| Promise<boolean> | Promise回调返回流静音状态,true为静音,false为非静音。 |
**示例:**
-
```js
-audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
- console.info('Promise returned to indicate that the device is set to the active status.');
+audioVolumeGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
});
```
-### isDeviceActive
+### setRingerMode9+
-isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): void
+setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
-获取指定设备的激活状态,使用callback方式异步返回结果。
+设置铃声模式,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅在静音和非静音状态切换时需要该权限。
+
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------- | ---- | ------------------------ |
-| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调返回设备的激活状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------------------- | ---- | ------------------------ |
+| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
```js
-audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
+audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
if (err) {
- console.error(`Failed to obtain the active status of the device. ${err}`);
+ console.error(`Failed to set the ringer mode. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the active status of the device is obtained.');
+ console.info('Callback invoked to indicate a successful setting of the ringer mode.');
});
```
+### setRingerMode9+
-### isDeviceActive
+setRingerMode(mode: AudioRingMode): Promise<void>
-isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean>
+设置铃声模式,使用Promise方式异步返回结果。
-获取指定设备的激活状态,使用Promise方式异步返回结果。
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+仅在静音和非静音状态切换时需要该权限。
+
+**系统接口:** 该接口为系统接口
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------- | ---- | ------------------ |
-| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ------------------------------- | ---- | -------------- |
+| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
**返回值:**
-| Type | Description |
-| ---------------------- | ------------------------------- |
-| Promise<boolean> | Promise回调返回设备的激活状态。 |
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
**示例:**
```js
-audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
- console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
+audioVolumeGroupManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
+ console.info('Promise returned to indicate a successful setting of the ringer mode.');
+});
+```
+
+### getRingerMode9+
+
+getRingerMode(callback: AsyncCallback<AudioRingMode>): void
+
+获取铃声模式,使用callback方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------------------- | ---- | ------------------------ |
+| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | 是 | 回调返回系统的铃声模式。 |
+
+**示例:**
+
+```js
+audioVolumeGroupManager.getRingerMode((err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the ringer mode. ${err}`);
+ return;
+ }
+ console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
+});
+```
+
+### getRingerMode9+
+
+getRingerMode(): Promise<AudioRingMode>
+
+获取铃声模式,使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**返回值:**
+
+| 类型 | 说明 |
+| ---------------------------------------------- | ------------------------------- |
+| Promise<[AudioRingMode](#audioringmode)> | Promise回调返回系统的铃声模式。 |
+
+**示例:**
+
+```js
+audioVolumeGroupManager.getRingerMode().then((value) => {
+ console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
});
```
-### setMicrophoneMute
+### on('ringerModeChange')9+
+
+on(type: 'ringerModeChange', callback: Callback\): void
+
+监听铃声模式变化事件。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'ringerModeChange'(铃声模式变化事件,检测到铃声模式改变时,触发该事件)。 |
+| callback | Callback<[AudioRingMode](#audioringmode)> | 是 | 回调方法。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
+
+**示例:**
+
+```js
+audioVolumeGroupManager.on('ringerModeChange', (ringerMode) => {
+ console.info(`Updated ringermode: ${ringerMode}`);
+});
+```
+### setMicrophoneMute9+
setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
设置麦克风静音状态,使用callback方式异步返回结果。
-**需要权限:** ohos.permission.MICROPHONE
+**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
@@ -1705,7 +1791,7 @@ setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
**示例:**
```js
-audioManager.setMicrophoneMute(true, (err) => {
+audioVolumeGroupManager.setMicrophoneMute(true, (err) => {
if (err) {
console.error(`Failed to mute the microphone. ${err}`);
return;
@@ -1714,15 +1800,15 @@ audioManager.setMicrophoneMute(true, (err) => {
});
```
-### setMicrophoneMute
+### setMicrophoneMute9+
setMicrophoneMute(mute: boolean): Promise<void>
设置麦克风静音状态,使用Promise方式异步返回结果。
-**需要权限:** ohos.permission.MICROPHONE
+**需要权限:** ohos.permission.MANAGE_AUDIO_CONFIG
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
@@ -1739,20 +1825,18 @@ setMicrophoneMute(mute: boolean): Promise<void>
**示例:**
```js
-audioManager.setMicrophoneMute(true).then(() => {
+audioVolumeGroupManager.setMicrophoneMute(true).then(() => {
console.info('Promise returned to indicate that the microphone is muted.');
});
```
-### isMicrophoneMute
+### isMicrophoneMute9+
isMicrophoneMute(callback: AsyncCallback<boolean>): void
获取麦克风静音状态,使用callback方式异步返回结果。
-**需要权限:** ohos.permission.MICROPHONE
-
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
@@ -1763,7 +1847,7 @@ isMicrophoneMute(callback: AsyncCallback<boolean>): void
**示例:**
```js
-audioManager.isMicrophoneMute((err, value) => {
+audioVolumeGroupManager.isMicrophoneMute((err, value) => {
if (err) {
console.error(`Failed to obtain the mute status of the microphone. ${err}`);
return;
@@ -1772,15 +1856,13 @@ audioManager.isMicrophoneMute((err, value) => {
});
```
-### isMicrophoneMute
+### isMicrophoneMute9+
isMicrophoneMute(): Promise<boolean>
获取麦克风静音状态,使用Promise方式异步返回结果。
-**需要权限:** ohos.permission.MICROPHONE
-
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**返回值:**
@@ -1790,20 +1872,17 @@ isMicrophoneMute(): Promise<boolean>
**示例:**
-
```js
-audioManager.isMicrophoneMute().then((value) => {
+audioVolumeGroupManager.isMicrophoneMute().then((value) => {
console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
});
```
-### on('volumeChange')8+
-
-on(type: 'volumeChange', callback: Callback\): void
+### on('micStateChange')9+
-监听系统音量变化事件。
+on(type: 'micStateChange', callback: Callback<MicStateChangeEvent>): void
-**系统接口:** 该接口为系统接口
+监听系统麦克风状态更改事件。
目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
@@ -1813,3675 +1892,4120 @@ on(type: 'volumeChange', callback: Callback\): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'volumeChange'(系统音量变化事件,检测到系统音量改变时,触发该事件)。 |
-| callback | Callback<[VolumeEvent](#volumeevent8)> | 是 | 回调方法。 |
-
-**示例:**
-
-```js
-audioManager.on('volumeChange', (volumeEvent) => {
- console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
- console.info(`Volume level: ${volumeEvent.volume} `);
- console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
-});
-```
-
-### on('ringerModeChange')8+
-
-on(type: 'ringerModeChange', callback: Callback\): void
-
-监听铃声模式变化事件。
-
-**系统接口:** 该接口为系统接口
+| type | string | 是 | 事件回调类型,支持的事件为:'micStateChange'(系统麦克风状态变化事件,检测到系统麦克风状态改变时,触发该事件)。 |
+| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 是 | 回调方法,返回变更后的麦克风状态。 |
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**错误码:**
-**参数:**
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'ringerModeChange'(铃声模式变化事件,检测到铃声模式改变时,触发该事件)。 |
-| callback | Callback<[AudioRingMode](#audioringmode)> | 是 | 回调方法。 |
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-audioManager.on('ringerModeChange', (ringerMode) => {
- console.info(`Updated ringermode: ${ringerMode}`);
+audioVolumeGroupManager.on('micStateChange', (micStateChange) => {
+ console.info(`Current microphone status is: ${micStateChange.mute} `);
});
```
-### on('deviceChange')
+## AudioStreamManager9+
-on(type: 'deviceChange', callback: Callback): void
+管理音频流。在使用AudioStreamManager的API前,需要使用[getStreamManager](#getstreammanager9)获取AudioStreamManager实例。
-设备更改。音频设备连接状态变化。
+### getCurrentAudioRendererInfoArray9+
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+getCurrentAudioRendererInfoArray(callback: AsyncCallback<AudioRendererChangeInfoArray>): void
+
+获取当前音频渲染器的信息。使用callback异步回调。
+
+**系统能力**: SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
-| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是 | 获取设备更新详情。 |
+| 名称 | 类型 | 必填 | 说明 |
+| -------- | ----------------------------------- | -------- | --------------------------- |
+| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是 | 回调函数,返回当前音频渲染器的信息。 |
**示例:**
```js
-audioManager.on('deviceChange', (deviceChanged) => {
- console.info(`device change type : ${deviceChanged.type} `);
- console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
- console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
- console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
+audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
+ console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
+ if (err) {
+ console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
+ } else {
+ if (AudioRendererChangeInfoArray != null) {
+ for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
+ let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
+ console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
+ console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
+ console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
+ console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
+ console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
+ for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
+ }
+ }
+ }
+ }
});
```
-### off('deviceChange')
+### getCurrentAudioRendererInfoArray9+
-off(type: 'deviceChange', callback?: Callback): void
+getCurrentAudioRendererInfoArray(): Promise<AudioRendererChangeInfoArray>
-取消订阅音频设备连接变化事件。
+获取当前音频渲染器的信息。使用Promise异步回调。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
-| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否 | 获取设备更新详情。 |
+| 类型 | 说明 |
+| ---------------------------------------------------------------------------------| --------------------------------------- |
+| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise对象,返回当前音频渲染器信息。 |
**示例:**
```js
-audioManager.off('deviceChange', (deviceChanged) => {
- console.info('Should be no callback.');
-});
+async function getCurrentAudioRendererInfoArray(){
+ await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
+ console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
+ if (AudioRendererChangeInfoArray != null) {
+ for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
+ let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
+ console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
+ console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
+ console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
+ console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
+ console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
+ for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
+ }
+ }
+ }
+ }).catch((err) => {
+ console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
+ });
+}
```
-### on('interrupt')
+### getCurrentAudioCapturerInfoArray9+
-on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\): void
+getCurrentAudioCapturerInfoArray(callback: AsyncCallback<AudioCapturerChangeInfoArray>): void
-请求焦点并开始监听音频打断事件(当应用程序的音频被另一个播放事件中断,回调通知此应用程序)
+获取当前音频采集器的信息。使用callback异步回调。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
-| interrupt | AudioInterrupt | 是 | 音频打断事件类型的参数。 |
-| callback | Callback<[InterruptAction](#interruptaction)> | 是 | 音频打断事件回调方法。 |
+| 名称 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
+| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是 | 回调函数,返回当前音频采集器的信息。 |
**示例:**
```js
-let interAudioInterrupt = {
- streamUsage:2,
- contentType:0,
- pauseWhenDucked:true
-};
-audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
- if (InterruptAction.actionType === 0) {
- console.info('An event to gain the audio focus starts.');
- console.info(`Focus gain event: ${InterruptAction} `);
- }
- if (InterruptAction.actionType === 1) {
- console.info('An audio interruption event starts.');
- console.info(`Audio interruption event: ${InterruptAction} `);
+audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
+ console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
+ if (err) {
+ console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
+ } else {
+ if (AudioCapturerChangeInfoArray != null) {
+ for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
+ console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
+ console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
+ console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
+ console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
+ for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
+ }
+ }
+ }
}
});
```
-### off('interrupt')
+### getCurrentAudioCapturerInfoArray9+
-off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\): void
+getCurrentAudioCapturerInfoArray(): Promise<AudioCapturerChangeInfoArray>
-取消监听音频打断事件(删除监听事件,取消打断)
+获取当前音频采集器的信息。使用Promise异步回调。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
-| interrupt | AudioInterrupt | 是 | 音频打断事件类型的参数。 |
-| callback | Callback<[InterruptAction](#interruptaction)> | 否 | 音频打断事件回调方法。 |
+| 类型 | 说明 |
+| -----------------------------------------------------------------------------| ----------------------------------- |
+| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise对象,返回当前音频渲染器信息。 |
**示例:**
```js
-let interAudioInterrupt = {
- streamUsage:2,
- contentType:0,
- pauseWhenDucked:true
-};
-audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
- if (InterruptAction.actionType === 0) {
- console.info('An event to release the audio focus starts.');
- console.info(`Focus release event: ${InterruptAction} `);
- }
-});
+async function getCurrentAudioCapturerInfoArray(){
+ await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
+ console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
+ if (AudioCapturerChangeInfoArray != null) {
+ for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
+ console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
+ console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
+ console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
+ console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
+ for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
+ }
+ }
+ }
+ }).catch((err) => {
+ console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
+ });
+}
```
-### setAudioScene8+
-
-setAudioScene\(scene: AudioScene, callback: AsyncCallback\): void
+### on('audioRendererChange')9+
-设置音频场景模式,使用callback方式异步返回结果。
+on(type: "audioRendererChange", callback: Callback<AudioRendererChangeInfoArray>): void
-**系统接口:** 该接口为系统接口
+监听音频渲染器更改事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :----------------------------------- | :--- | :------------------- |
-| scene | AudioScene | 是 | 音频场景模式。 |
-| callback | AsyncCallback | 是 | 用于返回结果的回调。 |
+| 名称 | 类型 | 必填 | 说明 |
+| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
+| type | string | 是 | 事件类型,支持的事件`'audioRendererChange'`:当音频渲染器发生更改时触发。 |
+| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是 | 回调函数。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
- if (err) {
- console.error(`Failed to set the audio scene mode. ${err}`);
- return;
+audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
+ for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
+ let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
+ console.info(`## RendererChange on is called for ${i} ##`);
+ console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
+ console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
+ console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
+ console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
+ console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
+ for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
+ }
}
- console.info('Callback invoked to indicate a successful setting of the audio scene mode.');
});
```
-### setAudioScene8+
-
-setAudioScene\(scene: AudioScene\): Promise
+### off('audioRendererChange')9+
-设置音频场景模式,使用Promise方式返回异步结果。
+off(type: "audioRendererChange"): void
-**系统接口:** 该接口为系统接口
+取消监听音频渲染器更改事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :----- | :----------------------------------- | :--- | :------------- |
-| scene | AudioScene | 是 | 音频场景模式。 |
+| 名称 | 类型 | 必填 | 说明 |
+| -------- | ------- | ---- | ---------------- |
+| type | string | 是 | 事件类型,支持的事件`'audioRendererChange'`:音频渲染器更改事件。 |
-**返回值:**
+**错误码:**
-| 类型 | 说明 |
-| :------------- | :------------------- |
-| Promise | 用于返回结果的回调。 |
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
- console.info('Promise returned to indicate a successful setting of the audio scene mode.');
-}).catch ((err) => {
- console.error(`Failed to set the audio scene mode ${err}`);
-});
+audioStreamManager.off('audioRendererChange');
+console.info('######### RendererChange Off is called #########');
```
-### getAudioScene8+
+### on('audioCapturerChange')9+
-getAudioScene\(callback: AsyncCallback\): void
+on(type: "audioCapturerChange", callback: Callback<AudioCapturerChangeInfoArray>): void
-获取音频场景模式,使用callback方式返回异步结果。
+监听音频采集器更改事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :-------------------------------------------------- | :--- | :--------------------------- |
-| callback | AsyncCallback<AudioScene> | 是 | 用于返回音频场景模式的回调。 |
+| 名称 | 类型 | 必填 | 说明 |
+| -------- | ------- | --------- | ----------------------------------------------------------------------- |
+| type | string | 是 | 事件类型,支持的事件`'audioCapturerChange'`:当音频采集器发生更改时触发。 |
+| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是 | 回调函数。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getAudioScene((err, value) => {
- if (err) {
- console.error(`Failed to obtain the audio scene mode. ${err}`);
- return;
+audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
+ for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
+ console.info(`## CapChange on is called for element ${i} ##`);
+ console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
+ console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
+ console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
+ console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
+ let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
+ for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
+ console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
+ console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
+ }
}
- console.info(`Callback invoked to indicate that the audio scene mode is obtained ${value}.`);
});
```
+### off('audioCapturerChange')9+
-### getAudioScene8+
-
-getAudioScene\(\): Promise
+off(type: "audioCapturerChange"): void;
-获取音频场景模式,使用Promise方式返回异步结果。
+取消监听音频采集器更改事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Communication
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-**返回值:**
+**参数:**
-| 类型 | 说明 |
-| :-------------------------------------------- | :--------------------------- |
-| Promise<AudioScene> | 用于返回音频场景模式的回调。 |
+| 名称 | 类型 | 必填 | 说明 |
+| -------- | -------- | --- | ------------------------------------------------------------- |
+| type | string |是 | 事件类型,支持的事件`'audioCapturerChange'`:音频采集器更改事件。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getAudioScene().then((value) => {
- console.info(`Promise returned to indicate that the audio scene mode is obtained ${value}.`);
-}).catch ((err) => {
- console.error(`Failed to obtain the audio scene mode ${err}`);
-});
-```
+audioStreamManager.off('audioCapturerChange');
+console.info('######### CapturerChange Off is called #########');
-### getVolumeGroups9+
+```
-getVolumeGroups(networkId: string, callback: AsyncCallback\): void
+### isActive9+
-获取音量组信息列表,使用callback方式异步返回结果。
+isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
-**系统接口:** 该接口为系统接口
+获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
-| networkId | string | 是 | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID ,也可以通过getRoutingManager().getDevices()获取全部networkId。 |
-| callback | AsyncCallback<[VolumeGroupInfos](#volumegroupinfos9)> | 是 | 回调,返回音量组信息列表。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回流的活跃状态,true为活跃,false为不活跃。 |
**示例:**
+
```js
-let audioManager = audio.getAudioManager();
-audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID, (err, value) => {
+audioStreamManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error(`Failed to obtain the volume group infos list. ${err}`);
+ console.error(`Failed to obtain the active status of the stream. ${err}`);
return;
}
- console.info('Callback invoked to indicate that the volume group infos list is obtained.');
+ console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
});
```
-### getVolumeGroups9+
-
-getVolumeGroups(networkId: string\): Promise
+### isActive9+
-获取音量组信息列表,使用promise方式异步返回结果。
+isActive(volumeType: AudioVolumeType): Promise<boolean>
-**系统接口:** 该接口为系统接口
+获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
-| networkId | string | 是 | 设备的网络id。本地设备audio.LOCAL_NETWORK_ID ,也可以通过getRoutingManager().getDevices()获取全部networkId。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise<[VolumeGroupInfos](#volumegroupinfos9)> | 音量组信息列表。 |
+| 类型 | 说明 |
+| ---------------------- | -------------------------------------------------------- |
+| Promise<boolean> | Promise回调返回流的活跃状态,true为活跃,false为不活跃。 |
**示例:**
```js
-async function getVolumeGroupInfos(){
- let volumegroupinfos = await audio.getAudioManager().getVolumeGroups(audio.LOCAL_NETWORK_ID);
- console.info('Promise returned to indicate that the volumeGroup list is obtained.'+JSON.stringify(volumegroupinfos))
-}
+audioStreamManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
+});
```
-### getGroupManager9+
+## AudioRoutingManager9+
-getGroupManager(groupId: number, callback: AsyncCallback\): void
+音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](#getroutingmanager9)获取AudioRoutingManager实例。
-获取音频组管理器,使用callback方式异步返回结果。
+### getDevices9+
-**系统接口:** 该接口为系统接口
+getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+获取音频设备列表,使用callback方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
-| groupId | number | 是 | 音量组id。 |
-| callback | AsyncCallback< [AudioGroupManager](#audiogroupmanager9) > | 是 | 回调,返回一个音量组实例。 |
+| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
+| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回设备列表。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let audioGroupManager;
-async function getGroupManager(){
- let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
- if (value.length > 0) {
- let groupid = value[0].groupId;
- audioManager.getGroupManager(groupid, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the volume group infos list. ${err}`);
- return;
- }
- audioGroupManager = value
- console.info('Callback invoked to indicate that the volume group infos list is obtained.');
- });
+audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the device list. ${err}`);
+ return;
}
-}
+ console.info('Callback invoked to indicate that the device list is obtained.');
+});
```
-### getGroupManager9+
-
-getGroupManager(groupId: number\): Promise
+### getDevices9+
-获取音频组管理器,使用promise方式异步返回结果。
+getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
-**系统接口:** 该接口为系统接口
+获取音频设备列表,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ---------------------------------------- | ---- | ---------------- |
-| groupId | number | 是 | 音量组id。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------- | ---- | ---------------- |
+| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise< [AudioGroupManager](#audiogroupmanager9) > | 音量组实例。 |
+| 类型 | 说明 |
+| ------------------------------------------------------------ | ------------------------- |
+| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise回调返回设备列表。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-async function getGroupManager(){
- let value = await audioManager.getVolumeGroups(audio.LOCAL_NETWORK_ID);
- if (value.length > 0) {
- let groupid = value[0].groupId;
- let audioGroupManager = await audioManager.getGroupManager(groupid)
- console.info('Callback invoked to indicate that the volume group infos list is obtained.');
- }
-}
+audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
+ console.info('Promise returned to indicate that the device list is obtained.');
+});
```
-### getStreamManager9+
+### on9+
-getStreamManager(callback: AsyncCallback\): void
+on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback): void
-获取音频流管理器实例。使用callback方式异步返回结果。
+设备更改。音频设备连接状态变化。
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | --------------------------------------------------------- | ---- | ---------------- |
-| callback | AsyncCallback<[AudioStreamManager](#audiostreammanager9)> | 是 | 返回音频流管理器实例。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
+| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
+| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
+| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是 | 获取设备更新详情。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let audioStreamManager;
-audioManager.getStreamManager((err, data) => {
- if (err) {
- console.error(`getStreamManager : Error: ${err}`);
- } else {
- console.info('getStreamManager : Success : SUCCESS');
- audioStreamManager = data;
- }
+audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
+ console.info('device change type : ' + deviceChanged.type);
+ console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
+ console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
+ console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
});
```
-### getStreamManager9+
+### off9+
+
+off(type: 'deviceChange', callback?: Callback): void
-getStreamManager(): Promise
+取消订阅音频设备连接变化事件。
-获取音频流管理器实例。使用Promise方式异步返回结果。
+**系统能力:** SystemCapability.Multimedia.Audio.Device
-**系统能力:** SystemCapability.Multimedia.Audio.Core
+**参数:**
-**返回值:**
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
+| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
+| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否 | 获取设备更新详情。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
-| 类型 | 说明 |
-| ---------------------------------------------------- | ---------------- |
-| Promise<[AudioStreamManager](#audiostreammanager9)> | 返回音频流管理器实例。 |
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let audioStreamManager;
-audioManager.getStreamManager().then((data) => {
- audioStreamManager = data;
- console.info('getStreamManager: Success!');
-}).catch((err) => {
- console.error(`getStreamManager: ERROR : ${err}`);
+audioRoutingManager.off('deviceChange', (deviceChanged) => {
+ console.info('Should be no callback.');
});
-
```
-### requestIndependentInterrupt9+
+### selectInputDevice9+
-requestIndependentInterrupt(focusType: FocusType, callback: AsyncCallback\): void
+selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
-申请独立焦点,获取独立SessionID,使用callback方式异步返回结果。
+选择音频输入设备,当前只能选择一个输入设备,使用callback方式异步返回结果。
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ----------------------------- | ---- | ----------------- |
-| focusType | [FocusType](#focustype) | 是 | 焦点类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调,返回焦点申请成功/失败状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
+| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输入设备类。 |
+| callback | AsyncCallback<void> | 是 | 回调,返回选择输入设备结果。 |
**示例:**
-
```js
-async function requestIndependentInterrupt(){
- let value = await audioManager.requestIndependentInterrupt(audio.FocusType.FOCUS_TYPE_RECORDING);
- if (value) {
- console.info('requestIndependentInterrupt interface for result callback: SUCCESS');
- } else {
- console.error('Result ERROR');
- }
+let inputAudioDeviceDescriptor = [{
+ "deviceRole":audio.DeviceRole.INPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
+
+async function selectInputDevice(){
+ audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
+ if (err) {
+ console.error(`Result ERROR: ${err}`);
+ } else {
+ console.info('Select input devices result callback: SUCCESS'); }
+ });
}
```
-### requestIndependentInterrupt9+
-requestIndependentInterrupt(focusType: FocusType): Promise
+### selectInputDevice9+
-申请独立焦点,获取独立SessionID,使用promise方式异步返回结果。
+selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise<void>
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+选择音频输入设备,当前只能选择一个输入设备,使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ---- | ---- | ---- |
-| focusType | [FocusType](#focustype) | 是 | 焦点类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
+| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输入设备类。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------------------------------------------- | ------------ |
-| Promise<boolean> | 返回申请焦点成功/失败状态。 |
+| 类型 | 说明 |
+| --------------------- | --------------------------- |
+| Promise<void> | Promise返回选择输入设备结果。 |
**示例:**
```js
-async function requestIndependentInterrupt(){
- audioManager.requestIndependentInterrupt(audio.FocusType.FOCUS_TYPE_RECORDING).then((value) => {
- console.info('Promise returned to succeed ');
- }).catch ((err) => {
- console.error('Failed to requestIndependentInterrupt');
- });
+let inputAudioDeviceDescriptor =[{
+ "deviceRole":audio.DeviceRole.INPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
+
+async function getRoutingManager(){
+ audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
+ console.info('Select input devices result promise: SUCCESS');
+ }).catch((err) => {
+ console.error(`Result ERROR: ${err}`);
+ });
}
```
-### abandonIndependentInterrupt9+
-abandonIndependentInterrupt(focusType: FocusType, callback: AsyncCallback\): void
+### setCommunicationDevice9+
-废除独立焦点,使用callback方式异步返回结果。
+setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean, callback: AsyncCallback<void>): void
-**系统接口:** 该接口为系统接口
+设置通信设备激活状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ----------------------------- | ---- | ----------------- |
-| focusType | [FocusType](#focustype) | 是 | 焦点类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调,返回废除焦点成功/失败状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------- | ---- | ------------------------ |
+| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是 | 音频设备类型。 |
+| active | boolean | 是 | 设备激活状态。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
```js
-async function abandonIndependentInterrupt(){
- let value = await audioManager.abandonIndependentInterrupt(audio.FocusType.FOCUS_TYPE_RECORDING);
- if (value) {
- console.info('abandonIndependentInterrupt interface for result callback: SUCCESS');
- } else {
- console.error('Result ERROR');
+audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true, (err) => {
+ if (err) {
+ console.error(`Failed to set the active status of the device. ${err}`);
+ return;
}
-}
+ console.info('Callback invoked to indicate that the device is set to the active status.');
+});
```
-### abandonIndependentInterrupt9+
-abandonIndependentInterrupt(focusType: FocusType): Promise
+### setCommunicationDevice9+
-废除独立焦点,使用promise方式异步返回结果。
+setCommunicationDevice(deviceType: CommunicationDeviceType, active: boolean): Promise<void>
-**系统接口:** 该接口为系统接口
+设置通信设备激活状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ---- | ---- | ---- |
-| focusType | [FocusType](#focustype) | 是 | 焦点类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------------------------- | ---- | ------------------ |
+| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是 | 活跃音频设备类型。 |
+| active | boolean | 是 | 设备激活状态。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------------------------------------------- | ------------ |
-| Promise<boolean> | 返回废除焦点成功/失败状态。 |
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
**示例:**
```js
-async function abandonIndependentInterrupt(){
- audioManager.abandonIndependentInterrupt(audio.FocusType.FOCUS_TYPE_RECORDING).then((value) => {
- console.info('Promise returned to succeed');
- }).catch ((err) => {
- console.error('Failed to abandonIndependentInterrupt');
- });
-}
+audioRoutingManager.setCommunicationDevice(audio.CommunicationDeviceType.SPEAKER, true).then(() => {
+ console.info('Promise returned to indicate that the device is set to the active status.');
+});
```
-## AudioGroupManager9+
-管理音频组音量。在调用AudioGroupManager的接口前,需要先通过 [getGroupManager](#getgroupmanager9) 创建实例。
-
-**系统接口:** 该接口为系统接口
-
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
-
-### setVolume9+
-
-setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void
-
-设置指定流的音量,使用callback方式异步返回结果。
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+### isCommunicationDeviceActive9+
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+isCommunicationDeviceActive(deviceType: CommunicationDeviceType, callback: AsyncCallback<boolean>): void
-**系统接口:** 该接口为系统接口
+获取指定通信设备的激活状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
-| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ---------------------------------------------------- | ---- | ------------------------ |
+| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是 | 活跃音频设备类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回设备的激活状态。 |
**示例:**
```js
-audioGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
+audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER, (err, value) => {
if (err) {
- console.error(`Failed to set the volume. ${err}`);
+ console.error(`Failed to obtain the active status of the device. ${err}`);
return;
}
- console.info('Callback invoked to indicate a successful volume setting.');
+ console.info('Callback invoked to indicate that the active status of the device is obtained.');
});
```
-### setVolume9+
-
-setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
-
-设置指定流的音量,使用Promise方式异步返回结果。
-
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+### isCommunicationDeviceActive9+
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+isCommunicationDeviceActive(deviceType: CommunicationDeviceType): Promise<boolean>
-**系统接口:** 该接口为系统接口
+获取指定通信设备的激活状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ---------------------------------------------------- | ---- | ------------------ |
+| deviceType | [CommunicationDeviceType](#communicationdevicetype9) | 是 | 活跃音频设备类型。 |
**返回值:**
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise<void> | Promise回调表示成功还是失败。 |
+| Type | Description |
+| ---------------------- | ------------------------------- |
+| Promise<boolean> | Promise回调返回设备的激活状态。 |
**示例:**
```js
-audioGroupManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
- console.info('Promise returned to indicate a successful volume setting.');
+audioRoutingManager.isCommunicationDeviceActive(audio.CommunicationDeviceType.SPEAKER).then((value) => {
+ console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
});
```
-### getVolume9+
+### selectOutputDevice9+
-getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
-获取指定流的音量,使用callback方式异步返回结果。
+选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回音量大小。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
+| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
+| callback | AsyncCallback<void> | 是 | 回调,返回获取输出设备结果。 |
**示例:**
-
```js
-audioGroupManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the volume. ${err}`);
- return;
- }
- console.info('Callback invoked to indicate that the volume is obtained.');
-});
+let outputAudioDeviceDescriptor = [{
+ "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
+async function selectOutputDevice(){
+ audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
+ if (err) {
+ console.error(`Result ERROR: ${err}`);
+ } else {
+ console.info('Select output devices result callback: SUCCESS'); }
+ });
+}
```
-### getVolume9+
-
-getVolume(volumeType: AudioVolumeType): Promise<number>
+### selectOutputDevice9+
-获取指定流的音量,使用Promise方式异步返回结果。
+selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise<void>
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
+| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------- | ------------------------- |
-| Promise<number> | Promise回调返回音量大小。 |
+| 类型 | 说明 |
+| --------------------- | --------------------------- |
+| Promise<void> | Promise返回选择输出设备结果。 |
**示例:**
```js
-audioGroupManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promise returned to indicate that the volume is obtained ${value}.`);
-});
-```
+let outputAudioDeviceDescriptor =[{
+ "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
-### getMinVolume9+
+async function selectOutputDevice(){
+ audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
+ console.info('Select output devices result promise: SUCCESS');
+ }).catch((err) => {
+ console.error(`Result ERROR: ${err}`);
+ });
+}
+```
-getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+### selectOutputDeviceByFilter9+
-获取指定流的最小音量,使用callback方式异步返回结果。
+selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回最小音量。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
+| filter | [AudioRendererFilter](#audiorendererfilter9) | 是 | 过滤条件类。 |
+| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
+| callback | AsyncCallback<void> | 是 | 回调,返回获取输出设备结果。 |
**示例:**
-
```js
-audioGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the minimum volume. ${err}`);
- return;
- }
- console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
-});
-```
+let outputAudioRendererFilter = {
+ "uid":20010041,
+ "rendererInfo": {
+ "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
+ "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
+ "rendererFlags":0 },
+ "rendererId":0 };
+let outputAudioDeviceDescriptor = [{
+ "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
-### getMinVolume9+
+async function selectOutputDeviceByFilter(){
+ audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
+ if (err) {
+ console.error(`Result ERROR: ${err}`);
+ } else {
+ console.info('Select output devices by filter result callback: SUCCESS'); }
+ });
+}
+```
-getMinVolume(volumeType: AudioVolumeType): Promise<number>
+### selectOutputDeviceByFilter9+
-获取指定流的最小音量,使用Promise方式异步返回结果。
+selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise<void>
**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
+| filter | [AudioRendererFilter](#audiorendererfilter9) | 是 | 过滤条件类。 |
+| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------- | ------------------------- |
-| Promise<number> | Promise回调返回最小音量。 |
+| 类型 | 说明 |
+| --------------------- | --------------------------- |
+| Promise<void> | Promise返回选择输出设备结果。 |
**示例:**
```js
-audioGroupManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promised returned to indicate that the minimum volume is obtained ${value}.`);
-});
+let outputAudioRendererFilter = {
+ "uid":20010041,
+ "rendererInfo": {
+ "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
+ "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
+ "rendererFlags":0 },
+ "rendererId":0 };
+let outputAudioDeviceDescriptor = [{
+ "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
+ "networkId":audio.LOCAL_NETWORK_ID,
+ "interruptGroupId":1,
+ "volumeGroupId":1 }];
+
+async function selectOutputDeviceByFilter(){
+ audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
+ console.info('Select output devices by filter result promise: SUCCESS');
+ }).catch((err) => {
+ console.error(`Result ERROR: ${err}`);
+ })
+}
```
-### getMaxVolume9+
+## AudioRendererChangeInfo9+
-getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
+描述音频渲染器更改信息。
-获取指定流的最大音量,使用callback方式异步返回结果。
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-**系统接口:** 该接口为系统接口
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
+| streamId | number | 是 | 否 | 音频流唯一id。 |
+| clientUid | number | 是 | 否 | 音频渲染器客户端应用程序的Uid。
此接口为系统接口。 |
+| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 是 | 否 | 音频渲染器信息。 |
+| rendererState | [AudioState](#audiostate) | 是 | 否 | 音频状态。
此接口为系统接口。|
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+## AudioRendererChangeInfoArray9+
-**参数:**
+AudioRenderChangeInfo数组,只读。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ---------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<number> | 是 | 回调返回最大音量大小。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**示例:**
```js
-audioGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
+import audio from '@ohos.multimedia.audio';
+
+let audioStreamManager;
+let resultFlag = false;
+let audioManager = audio.getAudioManager();
+
+audioManager.getStreamManager((err, data) => {
if (err) {
- console.error(`Failed to obtain the maximum volume. ${err}`);
- return;
+ console.error(`Get AudioStream Manager : ERROR : ${err}`);
+ } else {
+ audioStreamManager = data;
+ console.info('Get AudioStream Manager : Success');
}
- console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
});
-```
-### getMaxVolume9+
-
-getMaxVolume(volumeType: AudioVolumeType): Promise<number>
+audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
+ for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
+ console.info(`## RendererChange on is called for ${i} ##`);
+ console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
+ console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`);
+ console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
+ console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
+ console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
+ console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`);
+ let devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
+ for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
+ console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
+ console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
+ }
+ if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
+ resultFlag = true;
+ console.info(`ResultFlag for ${i} is: ${resultFlag}`);
+ }
+ }
+});
+```
-获取指定流的最大音量,使用Promise方式异步返回结果。
+## AudioCapturerChangeInfo9+
-**系统接口:** 该接口为系统接口
+描述音频采集器更改信息。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Capturer
-**参数:**
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
+| streamId | number | 是 | 否 | 音频流唯一id。 |
+| clientUid | number | 是 | 否 | 音频采集器客户端应用程序的Uid。
此接口为系统接口。 |
+| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | 是 | 否 | 音频采集器信息。 |
+| capturerState | [AudioState](#audiostate) | 是 | 否 | 音频状态。
此接口为系统接口。|
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+## AudioCapturerChangeInfoArray9+
-**返回值:**
+AudioCapturerChangeInfo数组,只读。
-| 类型 | 说明 |
-| --------------------- | ----------------------------- |
-| Promise<number> | Promise回调返回最大音量大小。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**示例:**
```js
-audioGroupManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
- console.info('Promised returned to indicate that the maximum volume is obtained.');
+import audio from '@ohos.multimedia.audio';
+
+const audioManager = audio.getAudioManager();
+let audioStreamManager;
+audioManager.getStreamManager((err, data) => {
+ if (err) {
+ console.error(`getStreamManager : Error: ${err}`);
+ } else {
+ console.info('getStreamManager : Success : SUCCESS');
+ audioStreamManager = data;
+ }
+});
+
+let resultFlag = false;
+audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
+ for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
+ console.info(`## CapChange on is called for element ${i} ##`);
+ console.info(`StrId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
+ console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
+ console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
+ console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
+ console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
+ let devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
+ for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
+ console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
+ console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
+ console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
+ console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
+ console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
+ console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
+ console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
+ console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
+ }
+ if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
+ resultFlag = true;
+ console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
+ }
+ }
});
```
-### mute9+
+## AudioDeviceDescriptor
-mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void
+描述音频设备。
-设置指定音量流静音,使用callback方式异步返回结果。
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
+| deviceRole | [DeviceRole](#devicerole) | 是 | 否 | 设备角色。 |
+| deviceType | [DeviceType](#devicetype) | 是 | 否 | 设备类型。 |
+| id9+ | number | 是 | 否 | 设备id。 |
+| name9+ | string | 是 | 否 | 设备名称。 |
+| address9+ | string | 是 | 否 | 设备地址。 |
+| sampleRates9+ | Array<number> | 是 | 否 | 支持的采样率。 |
+| channelCounts9+ | Array<number> | 是 | 否 | 支持的通道数。 |
+| channelMasks9+ | Array<number> | 是 | 否 | 支持的通道掩码。 |
+| networkId9+ | string | 是 | 否 | 设备组网的ID。
此接口为系统接口。 |
+| interruptGroupId9+ | number | 是 | 否 | 设备所处的焦点组ID。
此接口为系统接口。 |
+| volumeGroupId9+ | number | 是 | 否 | 设备所处的音量组ID。
此接口为系统接口。 |
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+## AudioDeviceDescriptors
-**系统接口:** 该接口为系统接口
+设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**示例:**
-**参数:**
+```js
+import audio from '@ohos.multimedia.audio';
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
-| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
-
-**示例:**
+function displayDeviceProp(value) {
+ deviceRoleValue = value.deviceRole;
+ deviceTypeValue = value.deviceType;
+}
-```js
-audioGroupManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
- if (err) {
- console.error(`Failed to mute the stream. ${err}`);
- return;
+let deviceRoleValue = null;
+let deviceTypeValue = null;
+const promise = audio.getAudioManager().getDevices(1);
+promise.then(function (value) {
+ console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
+ value.forEach(displayDeviceProp);
+ if (deviceTypeValue != null && deviceRoleValue != null){
+ console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS');
+ } else {
+ console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL');
}
- console.info('Callback invoked to indicate that the stream is muted.');
});
```
-### mute9+
+## AudioRendererFilter9+
-mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
+过滤条件类。在调用selectOutputDeviceByFilter接口前,需要先创建AudioRendererFilter实例。
-设置指定音量流静音,使用Promise方式异步返回结果。
+**系统接口:** 该接口为系统接口
-**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+| 名称 | 类型 | 必填 | 说明 |
+| -------------| ---------------------------------------- | ---- | -------------- |
+| uid | number | 是 | 表示应用ID。
**系统能力:** SystemCapability.Multimedia.Audio.Core|
+| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 否 | 表示渲染器信息。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer|
+| rendererId | number | 否 | 音频流唯一id。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer|
-仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+**示例:**
-**系统接口:** 该接口为系统接口
+```js
+let outputAudioRendererFilter = {
+ "uid":20010041,
+ "rendererInfo": {
+ "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
+ "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
+ "rendererFlags":0 },
+ "rendererId":0 };
+```
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+## AudioRenderer8+
-**参数:**
+提供音频渲染的相关接口。在调用AudioRenderer的接口前,需要先通过[createAudioRenderer](#audiocreateaudiorenderer8)创建实例。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
+### 属性
-**返回值:**
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise<void> | Promise回调表示成功还是失败。 |
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| ----- | -------------------------- | ---- | ---- | ------------------ |
+| state8+ | [AudioState](#audiostate8) | 是 | 否 | 音频渲染器的状态。 |
**示例:**
```js
-audioGroupManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
- console.info('Promise returned to indicate that the stream is muted.');
-});
+let state = audioRenderer.state;
```
-### isMute9+
-
-isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
+### getRendererInfo8+
-获取指定音量流是否被静音,使用callback方式异步返回结果。
+getRendererInfo(callback: AsyncCallback): void
-**系统接口:** 该接口为系统接口
+获取当前被创建的音频渲染器的信息,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
-| callback | AsyncCallback<boolean> | 是 | 回调返回流静音状态,true为静音,false为非静音。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------------------------------------------- | :--- | :--------------------- |
+| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是 | 返回音频渲染器的信息。 |
**示例:**
```js
-audioGroupManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the mute status. ${err}`);
- return;
- }
- console.info(`Callback invoked to indicate that the mute status of the stream is obtained ${value}.`);
+audioRenderer.getRendererInfo((err, rendererInfo) => {
+ console.info('Renderer GetRendererInfo:');
+ console.info(`Renderer content: ${rendererInfo.content}`);
+ console.info(`Renderer usage: ${rendererInfo.usage}`);
+ console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
});
```
-### isMute9+
-
-isMute(volumeType: AudioVolumeType): Promise<boolean>
-
-获取指定音量流是否被静音,使用Promise方式异步返回结果。
-
-**系统接口:** 该接口为系统接口
+### getRendererInfo8+
-**系统能力:** SystemCapability.Multimedia.Audio.Volume
+getRendererInfo(): Promise
-**参数:**
+获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | ---- | ------------ |
-| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**返回值:**
-| 类型 | 说明 |
-| ---------------------- | ------------------------------------------------------ |
-| Promise<boolean> | Promise回调返回流静音状态,true为静音,false为非静音。 |
+| 类型 | 说明 |
+| -------------------------------------------------- | ------------------------------- |
+| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise用于返回音频渲染器信息。 |
**示例:**
```js
-audioGroupManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
- console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
+audioRenderer.getRendererInfo().then((rendererInfo) => {
+ console.info('Renderer GetRendererInfo:');
+ console.info(`Renderer content: ${rendererInfo.content}`);
+ console.info(`Renderer usage: ${rendererInfo.usage}`);
+ console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
+}).catch((err) => {
+ console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
});
```
-## AudioStreamManager9+
-
-管理音频流。在使用AudioStreamManager的API前,需要使用[getStreamManager](#getstreammanager9)获取AudioStreamManager实例。
-
-### getCurrentAudioRendererInfoArray9+
+### getStreamInfo8+
-getCurrentAudioRendererInfoArray(callback: AsyncCallback<AudioRendererChangeInfoArray>): void
+getStreamInfo(callback: AsyncCallback): void
-获取当前音频渲染器的信息。使用callback异步回调。
+获取音频流信息,使用callback方式异步返回结果。
-**系统能力**: SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 名称 | 类型 | 必填 | 说明 |
-| -------- | ----------------------------------- | -------- | --------------------------- |
-| callback | AsyncCallback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是 | 回调函数,返回当前音频渲染器的信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :------------------- |
+| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是 | 回调返回音频流信息。 |
**示例:**
```js
-audioStreamManager.getCurrentAudioRendererInfoArray(async (err, AudioRendererChangeInfoArray) => {
- console.info('getCurrentAudioRendererInfoArray **** Get Callback Called ****');
- if (err) {
- console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
- } else {
- if (AudioRendererChangeInfoArray != null) {
- for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
- let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
- console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
- console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
- console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
- console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
- console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
- for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
- }
- }
- }
- }
+audioRenderer.getStreamInfo((err, streamInfo) => {
+ console.info('Renderer GetStreamInfo:');
+ console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
+ console.info(`Renderer channel: ${streamInfo.channels}`);
+ console.info(`Renderer format: ${streamInfo.sampleFormat}`);
+ console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
});
```
-### getCurrentAudioRendererInfoArray9+
+### getStreamInfo8+
-getCurrentAudioRendererInfoArray(): Promise<AudioRendererChangeInfoArray>
+getStreamInfo(): Promise
-获取当前音频渲染器的信息。使用Promise异步回调。
+获取音频流信息,使用Promise方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**返回值:**
-| 类型 | 说明 |
-| ---------------------------------------------------------------------------------| --------------------------------------- |
-| Promise<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | Promise对象,返回当前音频渲染器信息。 |
+| 类型 | 说明 |
+| :--------------------------------------------- | :--------------------- |
+| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise返回音频流信息. |
**示例:**
```js
-async function getCurrentAudioRendererInfoArray(){
- await audioStreamManager.getCurrentAudioRendererInfoArray().then( function (AudioRendererChangeInfoArray) {
- console.info(`getCurrentAudioRendererInfoArray ######### Get Promise is called ##########`);
- if (AudioRendererChangeInfoArray != null) {
- for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
- let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
- console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
- console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
- console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
- console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
- console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
- for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
- }
- }
- }
- }).catch((err) => {
- console.error(`getCurrentAudioRendererInfoArray :ERROR: ${err}`);
- });
-}
+audioRenderer.getStreamInfo().then((streamInfo) => {
+ console.info('Renderer GetStreamInfo:');
+ console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
+ console.info(`Renderer channel: ${streamInfo.channels}`);
+ console.info(`Renderer format: ${streamInfo.sampleFormat}`);
+ console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### getCurrentAudioCapturerInfoArray9+
+### getAudioStreamId9+
-getCurrentAudioCapturerInfoArray(callback: AsyncCallback<AudioCapturerChangeInfoArray>): void
+getAudioStreamId(callback: AsyncCallback): void
-获取当前音频采集器的信息。使用callback异步回调。
+获取音频流id,使用callback方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 名称 | 类型 | 必填 | 说明 |
-| ---------- | ----------------------------------- | --------- | -------------------------------------------------------- |
-| callback | AsyncCallback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是 | 回调函数,返回当前音频采集器的信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :------------------- |
+| callback | AsyncCallback | 是 | 回调返回音频流id。 |
**示例:**
```js
-audioStreamManager.getCurrentAudioCapturerInfoArray(async (err, AudioCapturerChangeInfoArray) => {
- console.info('getCurrentAudioCapturerInfoArray **** Get Callback Called ****');
- if (err) {
- console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
- } else {
- if (AudioCapturerChangeInfoArray != null) {
- for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
- console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
- console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
- console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
- console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
- for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
- }
- }
- }
- }
+audioRenderer.getAudioStreamId((err, streamid) => {
+ console.info(`Renderer GetStreamId: ${streamid}`);
});
```
-### getCurrentAudioCapturerInfoArray9+
+### getAudioStreamId9+
-getCurrentAudioCapturerInfoArray(): Promise<AudioCapturerChangeInfoArray>
+getAudioStreamId(): Promise
-获取当前音频采集器的信息。使用Promise异步回调。
+获取音频流id,使用Promise方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**返回值:**
-| 类型 | 说明 |
-| -----------------------------------------------------------------------------| ----------------------------------- |
-| Promise<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | Promise对象,返回当前音频渲染器信息。 |
+| 类型 | 说明 |
+| :--------------------------------------------- | :--------------------- |
+| Promise | Promise返回音频流id。 |
**示例:**
```js
-async function getCurrentAudioCapturerInfoArray(){
- await audioStreamManager.getCurrentAudioCapturerInfoArray().then( function (AudioCapturerChangeInfoArray) {
- console.info('getCurrentAudioCapturerInfoArray **** Get Promise Called ****');
- if (AudioCapturerChangeInfoArray != null) {
- for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
- console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
- console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
- console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
- console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
- for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
- }
- }
- }
- }).catch((err) => {
- console.error(`getCurrentAudioCapturerInfoArray :ERROR: ${err}`);
- });
-}
+audioRenderer.getAudioStreamId().then((streamid) => {
+ console.info(`Renderer getAudioStreamId: ${streamid}`);
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### on('audioRendererChange')9+
+### start8+
-on(type: "audioRendererChange", callback: Callback<AudioRendererChangeInfoArray>): void
+start(callback: AsyncCallback): void
-监听音频渲染器更改事件。
+启动音频渲染器。使用callback方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 名称 | 类型 | 必填 | 说明 |
-| -------- | ---------- | --------- | ------------------------------------------------------------------------ |
-| type | string | 是 | 事件类型,支持的事件`'audioRendererChange'`:当音频渲染器发生更改时触发。 |
-| callback | Callback<[AudioRendererChangeInfoArray](#audiorendererchangeinfoarray9)> | 是 | 回调函数。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ---------- |
+| callback | AsyncCallback\ | 是 | 回调函数。 |
**示例:**
```js
-audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
- for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
- let AudioRendererChangeInfo = AudioRendererChangeInfoArray[i];
- console.info(`## RendererChange on is called for ${i} ##`);
- console.info(`StreamId for ${i} is: ${AudioRendererChangeInfo.streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfo.clientUid}`);
- console.info(`Content ${i} is: ${AudioRendererChangeInfo.rendererInfo.content}`);
- console.info(`Stream ${i} is: ${AudioRendererChangeInfo.rendererInfo.usage}`);
- console.info(`Flag ${i} is: ${AudioRendererChangeInfo.rendererInfo.rendererFlags}`);
- console.info(`State for ${i} is: ${AudioRendererChangeInfo.rendererState}`);
- for (let j = 0;j < AudioRendererChangeInfo.deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCount ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioRendererChangeInfo.deviceDescriptors[j].channelMasks}`);
- }
+audioRenderer.start((err) => {
+ if (err) {
+ console.error('Renderer start failed.');
+ } else {
+ console.info('Renderer start success.');
}
});
```
-### off('audioRendererChange')9+
+### start8+
-off(type: "audioRendererChange");
+start(): Promise
-取消监听音频渲染器更改事件。
+启动音频渲染器。使用Promise方式异步返回结果。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 名称 | 类型 | 必填 | 说明 |
-| -------- | ------- | ---- | ---------------- |
-| type | string | 是 | 事件类型,支持的事件`'audioRendererChange'`:音频渲染器更改事件。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise方式异步返回结果。 |
**示例:**
```js
-audioStreamManager.off('audioRendererChange');
-console.info('######### RendererChange Off is called #########');
+audioRenderer.start().then(() => {
+ console.info('Renderer started');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### on('audioCapturerChange')9+
+### pause8+
-on(type: "audioCapturerChange", callback: Callback<AudioCapturerChangeInfoArray>): void
+pause(callback: AsyncCallback\): void
-监听音频采集器更改事件。
+暂停渲染。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 名称 | 类型 | 必填 | 说明 |
-| -------- | ------- | --------- | ----------------------------------------------------------------------- |
-| type | string | 是 | 事件类型,支持的事件`'audioCapturerChange'`:当音频采集器发生更改时触发。 |
-| callback | Callback<[AudioCapturerChangeInfoArray](#audiocapturerchangeinfoarray9)> | 是 | 回调函数。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
**示例:**
```js
-audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
- for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
- console.info(`## CapChange on is called for element ${i} ##`);
- console.info(`StreamId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
- console.info(`Source for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
- console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
- console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
- var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
- for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
- console.info(`Address: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
- console.info(`SampleRates: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
- console.info(`ChannelCounts ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
- console.info(`ChannelMask: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
- }
+audioRenderer.pause((err) => {
+ if (err) {
+ console.error('Renderer pause failed');
+ } else {
+ console.info('Renderer paused.');
}
});
```
-### off('audioCapturerChange')9+
+### pause8+
-off(type: "audioCapturerChange");
+pause(): Promise\
-取消监听音频采集器更改事件。
+暂停渲染。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 名称 | 类型 | 必填 | 说明 |
-| -------- | -------- | --- | ------------------------------------------------------------- |
-| type | string |是 | 事件类型,支持的事件`'audioCapturerChange'`:音频采集器更改事件。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise方式异步返回结果。 |
**示例:**
```js
-audioStreamManager.off('audioCapturerChange');
-console.info('######### CapturerChange Off is called #########');
-
+audioRenderer.pause().then(() => {
+ console.info('Renderer paused');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-## AudioRoutingManager9+
-
-音频路由管理。在使用AudioRoutingManager的接口前,需要使用[getRoutingManager](#getroutingmanager9)获取AudioRoutingManager实例。
-### getDevices9+
+### drain8+
-getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void
+drain(callback: AsyncCallback\): void
-获取音频设备列表,使用callback方式异步返回结果。
+检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
-| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回设备列表。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getRoutingManager((err,AudioRoutingManager)=>{
+audioRenderer.drain((err) => {
if (err) {
- console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
+ console.error('Renderer drain failed');
} else {
- AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
- if (err) {
- console.error(`Failed to obtain the device list. ${err}`);
- return;
- }
- console.info('Callback invoked to indicate that the device list is obtained.');
- });
+ console.info('Renderer drained.');
}
-})
+});
```
-### getDevices9+
-
-getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
-
-获取音频设备列表,使用Promise方式异步返回结果。
+### drain8+
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+drain(): Promise\
-**参数:**
+检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ------------------------- | ---- | ---------------- |
-| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**返回值:**
-| 类型 | 说明 |
-| ------------------------------------------------------------ | ------------------------- |
-| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise回调返回设备列表。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise方式异步返回结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getRoutingManager((err,AudioRoutingManager)=>{
- if (err) {
- console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
- }
- else {
- AudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
- console.info('Promise returned to indicate that the device list is obtained.');
- });
- }
+audioRenderer.drain().then(() => {
+ console.info('Renderer drained successfully');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
});
```
-### on9+
+### stop8+
-on(type: 'deviceChange', deviceFlag: DeviceFlag, callback: Callback): void
+stop(callback: AsyncCallback\): void
-设备更改。音频设备连接状态变化。
+停止渲染。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
-| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
-| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是 | 获取设备更新详情。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getRoutingManager((err,AudioRoutingManager)=>{
+audioRenderer.stop((err) => {
if (err) {
- console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
- }
- else {
- AudioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
- console.info('device change type : ' + deviceChanged.type);
- console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
- console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole);
- console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType);
- });
+ console.error('Renderer stop failed');
+ } else {
+ console.info('Renderer stopped.');
}
});
```
-### off9+
+### stop8+
-off(type: 'deviceChange', callback?: Callback): void
+stop(): Promise\
-取消订阅音频设备连接变化事件。
+停止渲染。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
-| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
-| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否 | 获取设备更新详情。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise方式异步返回结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getRoutingManager((err,AudioRoutingManager)=>{
- if (err) {
- console.error(`AudioFrameworkTest:Callback:failed to get RoutingManager ${err}`);
- } else {
- AudioRoutingManager.off('deviceChange', (deviceChanged) => {
- console.info('Should be no callback.');
- });
- }
+audioRenderer.stop().then(() => {
+ console.info('Renderer stopped successfully');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
});
```
-### selectInputDevice9+
-
-selectInputDevice(inputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
+### release8+
-选择音频输入设备,当前只能选择一个输入设备,使用callback方式异步返回结果。
+release(callback: AsyncCallback\): void
-**系统接口:** 该接口为系统接口
+释放音频渲染器。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
-| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输入设备类。 |
-| callback | AsyncCallback<void> | 是 | 回调,返回选择输入设备结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
**示例:**
-```js
-let audioManager = audio.getAudioManager();
-let inputAudioDeviceDescriptor = [{
- "deviceRole":audio.DeviceRole.INPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor, (err) => {
- if (err) {
- console.error(`Result ERROR: ${err}`);
- } else {
- console.info('Select input devices result callback: SUCCESS'); }
- });
- });
-}
+```js
+audioRenderer.release((err) => {
+ if (err) {
+ console.error('Renderer release failed');
+ } else {
+ console.info('Renderer released.');
+ }
+});
```
-### on('micStateChange')9+
-
-on(type: 'micStateChange', callback: Callback<MicStateChangeEvent>): void
+### release8+
-监听系统麦克风状态更改事件
+release(): Promise\
-目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
+释放渲染器。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'micStateChange'(系统麦克风状态变化事件,检测到系统麦克风状态改变时,触发该事件)。 |
-| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 是 | 回调方法,返回变更后的麦克风状态。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise方式异步返回结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-audioManager.getRoutingManager.on('micStateChange', (micStateChange) => {
- console.info(`Current microphone status is: ${micStateChange.mute} `);
+audioRenderer.release().then(() => {
+ console.info('Renderer released successfully');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
});
```
-### selectInputDevice9+
-
-selectInputDevice(inputAudioDevices: AudioDeviceDescriptors): Promise<void>
+### write8+
-**系统接口:** 该接口为系统接口
+write(buffer: ArrayBuffer, callback: AsyncCallback\): void
-选择音频输入设备,当前只能选择一个输入设备,使用Promise方式异步返回结果。
+写入缓冲区。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
-| inputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输入设备类。 |
-
-**返回值:**
-
-| 类型 | 说明 |
-| --------------------- | --------------------------- |
-| Promise<void> | Promise返回选择输入设备结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------- | ---- | --------------------------------------------------- |
+| buffer | ArrayBuffer | 是 | 要写入缓冲区的数据。 |
+| callback | AsyncCallback\ | 是 | 回调如果成功,返回写入的字节数,否则返回errorcode。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let inputAudioDeviceDescriptor =[{
- "deviceRole":audio.DeviceRole.INPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
-
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectInputDevice(inputAudioDeviceDescriptor).then(() => {
- console.info('Select input devices result promise: SUCCESS');
- }).catch((err) => {
- console.error(`Result ERROR: ${err}`);
- });
+let bufferSize;
+audioRenderer.getBufferSize().then((data)=> {
+ console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
+ bufferSize = data;
+ }).catch((err) => {
+ console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
});
+console.info(`Buffer size: ${bufferSize}`);
+let context = featureAbility.getContext();
+let path;
+async function getCacheDir(){
+ path = await context.getCacheDir();
}
+let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
+let ss = fileio.createStreamSync(filePath, 'r');
+let buf = new ArrayBuffer(bufferSize);
+ss.readSync(buf);
+audioRenderer.write(buf, (err, writtenbytes) => {
+ if (writtenbytes < 0) {
+ console.error('write failed.');
+ } else {
+ console.info(`Actual written bytes: ${writtenbytes}`);
+ }
+});
```
-### selectOutputDevice9+
-
-selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
+### write8+
-选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
+write(buffer: ArrayBuffer): Promise\
-**系统接口:** 该接口为系统接口
+写入缓冲区。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+**返回值:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
-| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
-| callback | AsyncCallback<void> | 是 | 回调,返回获取输出设备结果。 |
+| 类型 | 说明 |
+| ---------------- | ------------------------------------------------------------ |
+| Promise\ | Promise返回结果,如果成功,返回写入的字节数,否则返回errorcode。 |
**示例:**
-```js
-let audioManager = audio.getAudioManager();
-let outputAudioDeviceDescriptor = [{
- "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor, (err) => {
- if (err) {
- console.error(`Result ERROR: ${err}`);
- } else {
- console.info('Select output devices result callback: SUCCESS'); }
- });
+```js
+let bufferSize;
+audioRenderer.getBufferSize().then((data) => {
+ console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
+ bufferSize = data;
+ }).catch((err) => {
+ console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
});
+console.info(`BufferSize: ${bufferSize}`);
+let context = featureAbility.getContext();
+let path;
+async function getCacheDir(){
+ path = await context.getCacheDir();
}
+let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
+let ss = fileio.createStreamSync(filePath, 'r');
+let buf = new ArrayBuffer(bufferSize);
+ss.readSync(buf);
+audioRenderer.write(buf).then((writtenbytes) => {
+ if (writtenbytes < 0) {
+ console.error('write failed.');
+ } else {
+ console.info(`Actual written bytes: ${writtenbytes}`);
+ }
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### selectOutputDevice9+
-
-selectOutputDevice(outputAudioDevices: AudioDeviceDescriptors): Promise<void>
+### getAudioTime8+
-**系统接口:** 该接口为系统接口
+getAudioTime(callback: AsyncCallback\): void
-选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
+获取时间戳(从 1970 年 1 月 1 日开始)。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
-| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------- | ---- | ---------------- |
+| callback | AsyncCallback\ | 是 | 回调返回时间戳。 |
+
+**示例:**
+
+```js
+audioRenderer.getAudioTime((err, timestamp) => {
+ console.info(`Current timestamp: ${timestamp}`);
+});
+```
+
+### getAudioTime8+
+
+getAudioTime(): Promise\
+
+获取时间戳(从 1970 年 1 月 1 日开始)。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**返回值:**
-| 类型 | 说明 |
-| --------------------- | --------------------------- |
-| Promise<void> | Promise返回选择输出设备结果。 |
+| 类型 | 描述 |
+| ---------------- | ----------------------- |
+| Promise\ | Promise回调返回时间戳。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let outputAudioDeviceDescriptor =[{
- "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
-
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectOutputDevice(outputAudioDeviceDescriptor).then(() => {
- console.info('Select output devices result promise: SUCCESS');
- }).catch((err) => {
- console.error(`Result ERROR: ${err}`);
- });
- });
-}
+audioRenderer.getAudioTime().then((timestamp) => {
+ console.info(`Current timestamp: ${timestamp}`);
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### selectOutputDeviceByFilter9+
-
-selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors, callback: AsyncCallback<void>): void
+### getBufferSize8+
-**系统接口:** 该接口为系统接口
+getBufferSize(callback: AsyncCallback\): void
-根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用callback方式异步返回结果。
+获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- |
-| filter | [AudioRendererFilter](#audiorendererfilter9) | 是 | 过滤条件类。 |
-| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
-| callback | AsyncCallback<void> | 是 | 回调,返回获取输出设备结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------- | ---- | -------------------- |
+| callback | AsyncCallback\ | 是 | 回调返回缓冲区大小。 |
**示例:**
+
```js
-let audioManager = audio.getAudioManager();
-let outputAudioRendererFilter = {
- "uid":20010041,
- "rendererInfo": {
- "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
- "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
- "rendererFlags":0 },
- "rendererId":0 };
-let outputAudioDeviceDescriptor = [{
- "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
+let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
+ if (err) {
+ console.error('getBufferSize error');
+ }
+});
+```
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor, (err) => {
- if (err) {
- console.error(`Result ERROR: ${err}`);
- } else {
- console.info('Select output devices by filter result callback: SUCCESS'); }
- });
- });
-}
+### getBufferSize8+
+
+getBufferSize(): Promise\
+
+获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**返回值:**
+
+| 类型 | 说明 |
+| ---------------- | --------------------------- |
+| Promise\ | promise回调返回缓冲区大小。 |
+
+**示例:**
+
+```js
+let bufferSize;
+audioRenderer.getBufferSize().then((data) => {
+ console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
+ bufferSize = data;
+}).catch((err) => {
+ console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
+});
```
-### selectOutputDeviceByFilter9+
+### setRenderRate8+
-selectOutputDeviceByFilter(filter: AudioRendererFilter, outputAudioDevices: AudioDeviceDescriptors): Promise<void>
+setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\): void
-**系统接口:** 该接口为系统接口
+设置音频渲染速率。使用callback方式异步返回结果。
-根据过滤条件,选择音频输出设备,当前只能选择一个输出设备,使用Promise方式异步返回结果。
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-**系统能力:** SystemCapability.Multimedia.Audio.Device
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------- | ---- | ------------------------ |
+| rate | [AudioRendererRate](#audiorendererrate8) | 是 | 渲染的速率。 |
+| callback | AsyncCallback\ | 是 | 用于返回执行结果的回调。 |
+
+**示例:**
+
+```js
+audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
+ if (err) {
+ console.error('Failed to set params');
+ } else {
+ console.info('Callback invoked to indicate a successful render rate setting.');
+ }
+});
+```
+
+### setRenderRate8+
+
+setRenderRate(rate: AudioRendererRate): Promise\
+
+设置音频渲染速率。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- |
-| filter | [AudioRendererFilter](#audiorendererfilter9) | 是 | 过滤条件类。 |
-| outputAudioDevices | [AudioDeviceDescriptors](#audiodevicedescriptors) | 是 | 输出设备类。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ---------------------------------------- | ---- | ------------ |
+| rate | [AudioRendererRate](#audiorendererrate8) | 是 | 渲染的速率。 |
**返回值:**
-| 类型 | 说明 |
-| --------------------- | --------------------------- |
-| Promise<void> | Promise返回选择输出设备结果。 |
+| 类型 | 说明 |
+| -------------- | ------------------------- |
+| Promise\ | Promise用于返回执行结果。 |
**示例:**
```js
-let audioManager = audio.getAudioManager();
-let outputAudioRendererFilter = {
- "uid":20010041,
- "rendererInfo": {
- "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
- "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
- "rendererFlags":0 },
- "rendererId":0 };
-let outputAudioDeviceDescriptor = [{
- "deviceRole":audio.DeviceRole.OUTPUT_DEVICE,
- "networkId":audio.LOCAL_NETWORK_ID,
- "interruptGroupId":1,
- "volumeGroupId":1 }];
-let audioRoutingManager;
+audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
+ console.info('setRenderRate SUCCESS');
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
+```
-async function getRoutingManager(){
- await audioManager.getRoutingManager().then((value) => {
- audioRoutingManager = value;
- audioRoutingManager.selectOutputDeviceByFilter(outputAudioRendererFilter, outputAudioDeviceDescriptor).then(() => {
- console.info('Select output devices by filter result promise: SUCCESS');
- }).catch((err) => {
- console.error(`Result ERROR: ${err}`);
- })
- });
-}
+### getRenderRate8+
+
+getRenderRate(callback: AsyncCallback\): void
+
+获取当前渲染速率。使用callback方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------------------------------------------- | ---- | ------------------ |
+| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是 | 回调返回渲染速率。 |
+
+**示例:**
+
+```js
+audioRenderer.getRenderRate((err, renderrate) => {
+ console.info(`getRenderRate: ${renderrate}`);
+});
```
-## AudioRendererChangeInfo9+
+### getRenderRate8+
+
+getRenderRate(): Promise\
+
+获取当前渲染速率。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------------------------------------- | ------------------------- |
+| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise回调返回渲染速率。 |
+
+**示例:**
+
+```js
+audioRenderer.getRenderRate().then((renderRate) => {
+ console.info(`getRenderRate: ${renderRate}`);
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
+```
+### setInterruptMode9+
+
+setInterruptMode(mode: InterruptMode): Promise<void>
+
+设置应用的焦点模型。使用Promise异步回调。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ---------------------------------- | ------ | ---------- |
+| mode | [InterruptMode](#interruptmode9) | 是 | 焦点模型。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | 以Promise对象返回结果,设置成功时返回undefined,否则返回error。 |
+
+**示例:**
+
+```js
+let mode = 0;
+audioRenderer.setInterruptMode(mode).then(data=>{
+ console.info('setInterruptMode Success!');
+}).catch((err) => {
+ console.error(`setInterruptMode Fail: ${err}`);
+});
+```
+### setInterruptMode9+
+
+setInterruptMode(mode: InterruptMode, callback: AsyncCallback\): void
+
+设置应用的焦点模型。使用Callback回调返回执行结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ------- | ----------------------------------- | ------ | -------------- |
+|mode | [InterruptMode](#interruptmode9) | 是 | 焦点模型。|
+|callback | AsyncCallback\ | 是 |回调返回执行结果。|
+
+**示例:**
+
+```js
+let mode = 1;
+audioRenderer.setInterruptMode(mode, (err, data)=>{
+ if(err){
+ console.error(`setInterruptMode Fail: ${err}`);
+ }
+ console.info('setInterruptMode Success!');
+});
+```
+
+### setVolume9+
+
+setVolume(volume: number): Promise<void>
+
+设置应用的音量。使用Promise异步回调。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------- | ------ | ---------- |
+| volume | number | 是 | 音量值。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | 以Promise对象返回结果,设置成功时返回undefined,否则返回error。 |
+
+**示例:**
+
+```js
+audioRenderer.setVolume(10).then(data=>{
+ console.info('setVolume Success!');
+}).catch((err) => {
+ console.error(`setVolume Fail: ${err}`);
+});
+```
+### setVolume9+
+
+setVolume(volume: number, callback: AsyncCallback\): void
+
+设置应用的音量。使用Callback回调返回执行结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ------- | -----------| ------ | -------------- |
+|volume | number | 是 | 音量值。|
+|callback | AsyncCallback\ | 是 |回调返回执行结果。|
+
+**示例:**
+
+```js
+audioRenderer.setVolume(10, (err, data)=>{
+ if(err){
+ console.error(`setVolume Fail: ${err}`);
+ }
+ console.info('setVolume Success!');
+});
+```
+
+### on('audioInterrupt')9+
+
+on(type: 'audioInterrupt', callback: Callback\): void
+
+监听音频中断事件。使用callback获取中断事件。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Interrupt
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'audioInterrupt'(中断事件被触发,音频播放被中断。) |
+| callback | Callback<[InterruptEvent](#interruptevent9)> | 是 | 被监听的中断事件的回调。 |
+
+**错误码:**
+
+以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。
+
+| 错误码ID | 错误信息 |
+| ------- | --------------------------------------------|
+| 6800101 | if input parameter value error. |
+
+**示例:**
+
+```js
+let isPlay;
+let started;
+audioRenderer.on('audioInterrupt', async(interruptEvent) => {
+ if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
+ switch (interruptEvent.hintType) {
+ case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
+ console.info('Force paused. Stop writing');
+ isPlay = false;
+ break;
+ case audio.InterruptHint.INTERRUPT_HINT_STOP:
+ console.info('Force stopped. Stop writing');
+ isPlay = false;
+ break;
+ }
+ } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
+ switch (interruptEvent.hintType) {
+ case audio.InterruptHint.INTERRUPT_HINT_RESUME:
+ console.info('Resume force paused renderer or ignore');
+ await audioRenderer.start().then(async function () {
+ console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
+ started = true;
+ }).catch((err) => {
+ console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err}`);
+ started = false;
+ });
+ if (started) {
+ isPlay = true;
+ console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`);
+ } else {
+ console.error('AudioInterruptMusic Renderer start failed');
+ }
+ break;
+ case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
+ console.info('Choose to pause or ignore');
+ if (isPlay == true) {
+ isPlay == false;
+ console.info('AudioInterruptMusic: Media PAUSE : TRUE');
+ } else {
+ isPlay = true;
+ console.info('AudioInterruptMusic: Media PLAY : TRUE');
+ }
+ break;
+ }
+ }
+});
+```
+
+### on('markReach')8+
+
+on(type: "markReach", frame: number, callback: Callback<number>): void
+
+订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被调用。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :----------------------- | :--- | :---------------------------------------- |
+| type | string | 是 | 事件回调类型,支持的事件为:'markReach'。 |
+| frame | number | 是 | 触发事件的帧数。 该值必须大于 0。 |
+| callback | Callback\ | 是 | 触发事件时调用的回调。 |
+
+**示例:**
+
+```js
+audioRenderer.on('markReach', 1000, (position) => {
+ if (position == 1000) {
+ console.info('ON Triggered successfully');
+ }
+});
+```
+
+
+### off('markReach') 8+
+
+off(type: 'markReach'): void
+
+取消订阅标记事件。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :----- | :----- | :--- | :------------------------------------------------ |
+| type | string | 是 | 要取消订阅事件的类型。支持的事件为:'markReach'。 |
+
+**示例:**
+
+```js
+audioRenderer.off('markReach');
+```
+
+### on('periodReach') 8+
+
+on(type: "periodReach", frame: number, callback: Callback<number>): void
+
+订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被循环调用。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :----------------------- | :--- | :------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'periodReach'。 |
+| frame | number | 是 | 触发事件的帧数。 该值必须大于 0。 |
+| callback | Callback\ | 是 | 触发事件时调用的回调。 |
+
+**示例:**
+
+```js
+audioRenderer.on('periodReach', 1000, (position) => {
+ if (position == 1000) {
+ console.info('ON Triggered successfully');
+ }
+});
+```
+
+### off('periodReach') 8+
+
+off(type: 'periodReach'): void
+
+取消订阅标记事件。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :----- | :----- | :--- | :-------------------------------------------------- |
+| type | string | 是 | 要取消订阅事件的类型。支持的事件为:'periodReach'。 |
+
+**示例:**
+
+```js
+audioRenderer.off('periodReach')
+```
+
+### on('stateChange') 8+
+
+on(type: 'stateChange', callback: Callback): void
+
+订阅监听状态变化。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------------- | :--- | :------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'stateChange'。 |
+| callback | [AudioState](#audiostate8) | 是 | 返回监听的状态。 |
+
+**示例:**
+
+```js
+audioRenderer.on('stateChange', (state) => {
+ if (state == 1) {
+ console.info('audio renderer state is: STATE_PREPARED');
+ }
+ if (state == 2) {
+ console.info('audio renderer state is: STATE_RUNNING');
+ }
+});
+```
+
+## AudioCapturer8+
+
+提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。
+
+### 属性
+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+
+| 名称 | 类型 | 可读 | 可写 | 说明 |
+| :---- | :------------------------- | :--- | :--- | :--------------- |
+| state8+ | [AudioState](#audiostate8) | 是 | 否 | 音频采集器状态。 |
+
+**示例:**
+
+```js
+let state = audioCapturer.state;
+```
-描述音频渲染器更改信息。
+### getCapturerInfo8+
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
+getCapturerInfo(callback: AsyncCallback): void
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
-| streamId | number | 是 | 否 | 音频流唯一id。 |
-| clientUid | number | 是 | 否 | 音频渲染器客户端应用程序的Uid。
此接口为系统接口,三方应用不支持调用。 |
-| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 是 | 否 | 音频渲染器信息。 |
-| rendererState | [AudioState](#audiostate) | 是 | 否 | 音频状态。
此接口为系统接口,三方应用不支持调用。|
+获取采集器信息。使用callback方式异步返回结果。
-## AudioRendererChangeInfoArray9+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-AudioRenderChangeInfo数组,只读。
+**参数:**
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :-------------------------------- | :--- | :----------------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回采集器信息。 |
**示例:**
```js
-import audio from '@ohos.multimedia.audio';
-
-let audioStreamManager;
-let resultFlag = false;
-let audioManager = audio.getAudioManager();
-
-audioManager.getStreamManager((err, data) => {
+audioCapturer.getCapturerInfo((err, capturerInfo) => {
if (err) {
- console.error(`Get AudioStream Manager : ERROR : ${err}`);
+ console.error('Failed to get capture info');
} else {
- audioStreamManager = data;
- console.info('Get AudioStream Manager : Success');
- }
-});
-
-audioStreamManager.on('audioRendererChange', (AudioRendererChangeInfoArray) => {
- for (let i = 0; i < AudioRendererChangeInfoArray.length; i++) {
- console.info(`## RendererChange on is called for ${i} ##`);
- console.info(`StreamId for ${i} is: ${AudioRendererChangeInfoArray[i].streamId}`);
- console.info(`ClientUid for ${i} is: ${AudioRendererChangeInfoArray[i].clientUid}`);
- console.info(`Content for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.content}`);
- console.info(`Stream for ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.usage}`);
- console.info(`Flag ${i} is: ${AudioRendererChangeInfoArray[i].rendererInfo.rendererFlags}`);
- console.info(`State for ${i} is: ${AudioRendererChangeInfoArray[i].rendererState}`);
- var devDescriptor = AudioRendererChangeInfoArray[i].deviceDescriptors;
- for (let j = 0; j < AudioRendererChangeInfoArray[i].deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].name}`);
- console.info(`Addr: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].address}`);
- console.info(`SR: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
- console.info(`C ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
- console.info(`CM: ${i} : ${AudioRendererChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
- }
- if (AudioRendererChangeInfoArray[i].rendererState == 1 && devDescriptor != null) {
- resultFlag = true;
- console.info(`ResultFlag for ${i} is: ${resultFlag}`);
- }
+ console.info('Capturer getCapturerInfo:');
+ console.info(`Capturer source: ${capturerInfo.source}`);
+ console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
}
});
```
-## AudioCapturerChangeInfo9+
-描述音频采集器更改信息。
+### getCapturerInfo8+
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Capturer
+getCapturerInfo(): Promise
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| -------------------| ----------------------------------------- | ---- | ---- | ---------------------------- |
-| streamId | number | 是 | 否 | 音频流唯一id。 |
-| clientUid | number | 是 | 否 | 音频采集器客户端应用程序的Uid。
此接口为系统接口,三方应用不支持调用。 |
-| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | 是 | 否 | 音频采集器信息。 |
-| capturerState | [AudioState](#audiostate) | 是 | 否 | 音频状态。
此接口为系统接口,三方应用不支持调用。|
+获取采集器信息。使用Promise方式异步返回结果。
-## AudioCapturerChangeInfoArray9+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-AudioCapturerChangeInfo数组,只读。
+**返回值:**
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+| 类型 | 说明 |
+| :------------------------------------------------ | :---------------------------------- |
+| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | 使用Promise方式异步返回采集器信息。 |
**示例:**
```js
-import audio from '@ohos.multimedia.audio';
-
-const audioManager = audio.getAudioManager();
-let audioStreamManager;
-audioManager.getStreamManager((err, data) => {
- if (err) {
- console.error(`getStreamManager : Error: ${err}`);
+audioCapturer.getCapturerInfo().then((audioParamsGet) => {
+ if (audioParamsGet != undefined) {
+ console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
+ console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
+ console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
} else {
- console.info('getStreamManager : Success : SUCCESS');
- audioStreamManager = data;
+ console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
+ console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
}
+}).catch((err) => {
+ console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
});
+```
-let resultFlag = false;
-audioStreamManager.on('audioCapturerChange', (AudioCapturerChangeInfoArray) => {
- for (let i = 0; i < AudioCapturerChangeInfoArray.length; i++) {
- console.info(`## CapChange on is called for element ${i} ##`);
- console.info(`StrId for ${i} is: ${AudioCapturerChangeInfoArray[i].streamId}`);
- console.info(`CUid for ${i} is: ${AudioCapturerChangeInfoArray[i].clientUid}`);
- console.info(`Src for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.source}`);
- console.info(`Flag ${i} is: ${AudioCapturerChangeInfoArray[i].capturerInfo.capturerFlags}`);
- console.info(`State for ${i} is: ${AudioCapturerChangeInfoArray[i].capturerState}`);
- var devDescriptor = AudioCapturerChangeInfoArray[i].deviceDescriptors;
- for (let j = 0; j < AudioCapturerChangeInfoArray[i].deviceDescriptors.length; j++) {
- console.info(`Id: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].id}`);
- console.info(`Type: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceType}`);
- console.info(`Role: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].deviceRole}`);
- console.info(`Name: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].name}`);
- console.info(`Addr: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].address}`);
- console.info(`SR: ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].sampleRates[0]}`);
- console.info(`C ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelCounts[0]}`);
- console.info(`CM ${i} : ${AudioCapturerChangeInfoArray[i].deviceDescriptors[j].channelMasks}`);
- }
- if (AudioCapturerChangeInfoArray[i].capturerState == 1 && devDescriptor != null) {
- resultFlag = true;
- console.info(`ResultFlag for element ${i} is: ${resultFlag}`);
- }
+### getStreamInfo8+
+
+getStreamInfo(callback: AsyncCallback): void
+
+获取采集器流信息。使用callback方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
+| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是 | 使用callback方式异步返回流信息。 |
+
+**示例:**
+
+```js
+audioCapturer.getStreamInfo((err, streamInfo) => {
+ if (err) {
+ console.error('Failed to get stream info');
+ } else {
+ console.info('Capturer GetStreamInfo:');
+ console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
+ console.info(`Capturer channel: ${streamInfo.channels}`);
+ console.info(`Capturer format: ${streamInfo.sampleFormat}`);
+ console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
}
});
```
-## AudioDeviceDescriptor
+### getStreamInfo8+
-描述音频设备。
+getStreamInfo(): Promise
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
+获取采集器流信息。使用Promise方式异步返回结果。
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| ----------------------------- | -------------------------- | ---- | ---- | ---------- |
-| deviceRole | [DeviceRole](#devicerole) | 是 | 否 | 设备角色。 |
-| deviceType | [DeviceType](#devicetype) | 是 | 否 | 设备类型。 |
-| id9+ | number | 是 | 否 | 设备id。 |
-| name9+ | string | 是 | 否 | 设备名称。 |
-| address9+ | string | 是 | 否 | 设备地址。 |
-| sampleRates9+ | Array<number> | 是 | 否 | 支持的采样率。 |
-| channelCounts9+ | Array<number> | 是 | 否 | 支持的通道数。 |
-| channelMasks9+ | Array<number> | 是 | 否 | 支持的通道掩码。 |
-| networkId9+ | string | 是 | 否 | 设备组网的ID。
此接口为系统接口,三方应用不支持调用。 |
-| interruptGroupId9+ | number | 是 | 否 | 设备所处的焦点组ID。
此接口为系统接口,三方应用不支持调用。 |
-| volumeGroupId9+ | number | 是 | 否 | 设备所处的音量组ID。
此接口为系统接口,三方应用不支持调用。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-## AudioDeviceDescriptors
+**返回值:**
-设备属性数组类型,为[AudioDeviceDescriptor](#audiodevicedescriptor)的数组,只读。
+| 类型 | 说明 |
+| :--------------------------------------------- | :------------------------------ |
+| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | 使用Promise方式异步返回流信息。 |
**示例:**
```js
-import audio from '@ohos.multimedia.audio';
-
-function displayDeviceProp(value) {
- deviceRoleValue = value.deviceRole;
- deviceTypeValue = value.deviceType;
-}
-
-let deviceRoleValue = null;
-let deviceTypeValue = null;
-const promise = audio.getAudioManager().getDevices(1);
-promise.then(function (value) {
- console.info('AudioFrameworkTest: Promise: getDevices OUTPUT_DEVICES_FLAG');
- value.forEach(displayDeviceProp);
- if (deviceTypeValue != null && deviceRoleValue != null){
- console.info('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : PASS');
- } else {
- console.error('AudioFrameworkTest: Promise: getDevices : OUTPUT_DEVICES_FLAG : FAIL');
- }
+audioCapturer.getStreamInfo().then((audioParamsGet) => {
+ console.info('getStreamInfo:');
+ console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
+ console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
+ console.info(`channels: ${audioParamsGet.channels}`);
+ console.info(`encodingType: ${audioParamsGet.encodingType}`);
+}).catch((err) => {
+ console.error(`getStreamInfo :ERROR: ${err}`);
});
```
-## AudioRendererFilter9+
+### getAudioStreamId9+
-过滤条件类。在调用selectOutputDeviceByFilter接口前,需要先创建AudioRendererFilter实例。
+getAudioStreamId(callback: AsyncCallback): void
-**系统接口:** 该接口为系统接口
+获取音频流id,使用callback方式异步返回结果。
-| 名称 | 类型 | 必填 | 说明 |
-| -------------| ---------------------------------------- | ---- | -------------- |
-| uid | number | 是 | 表示应用ID。
**系统能力:** SystemCapability.Multimedia.Audio.Core|
-| rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 否 | 表示渲染器信息。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer|
-| rendererId | number | 否 | 音频流唯一id。
**系统能力:** SystemCapability.Multimedia.Audio.Renderer|
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :------------------- |
+| callback | AsyncCallback | 是 | 回调返回音频流id。 |
**示例:**
```js
-let outputAudioRendererFilter = {
- "uid":20010041,
- "rendererInfo": {
- "contentType":audio.ContentType.CONTENT_TYPE_MUSIC,
- "streamUsage":audio.StreamUsage.STREAM_USAGE_MEDIA,
- "rendererFlags":0 },
- "rendererId":0 };
+audioCapturer.getAudioStreamId((err, streamid) => {
+ console.info(`audioCapturer GetStreamId: ${streamid}`);
+});
```
-## AudioRenderer8+
+### getAudioStreamId9+
-提供音频渲染的相关接口。在调用AudioRenderer的接口前,需要先通过[createAudioRenderer](#audiocreateaudiorenderer8)创建实例。
+getAudioStreamId(): Promise
-### 属性
+获取音频流id,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| ----- | -------------------------- | ---- | ---- | ------------------ |
-| state8+ | [AudioState](#audiostate8) | 是 | 否 | 音频渲染器的状态。 |
+**返回值:**
+
+| 类型 | 说明 |
+| :----------------| :--------------------- |
+| Promise | Promise返回音频流id。 |
**示例:**
```js
-let state = audioRenderer.state;
+audioCapturer.getAudioStreamId().then((streamid) => {
+ console.info(`audioCapturer getAudioStreamId: ${streamid}`);
+}).catch((err) => {
+ console.error(`ERROR: ${err}`);
+});
```
-### getRendererInfo8+
+### start8+
-getRendererInfo(callback: AsyncCallback): void
+start(callback: AsyncCallback): void
-获取当前被创建的音频渲染器的信息,使用callback方式异步返回结果。
+启动音频采集器。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------------------------------------------- | :--- | :--------------------- |
-| callback | AsyncCallback<[AudioRendererInfo](#audiorendererinfo8)\> | 是 | 返回音频渲染器的信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getRendererInfo((err, rendererInfo) => {
- console.info('Renderer GetRendererInfo:');
- console.info(`Renderer content: ${rendererInfo.content}`);
- console.info(`Renderer usage: ${rendererInfo.usage}`);
- console.info(`Renderer flags: ${rendererInfo.rendererFlags}`);
+audioCapturer.start((err) => {
+ if (err) {
+ console.error('Capturer start failed.');
+ } else {
+ console.info('Capturer start success.');
+ }
});
```
-### getRendererInfo8+
-getRendererInfo(): Promise
+### start8+
+
+start(): Promise
-获取当前被创建的音频渲染器的信息,使用Promise方式异步返回结果。
+启动音频采集器。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**返回值:**
-| 类型 | 说明 |
-| -------------------------------------------------- | ------------------------------- |
-| Promise<[AudioRendererInfo](#audiorendererinfo8)\> | Promise用于返回音频渲染器信息。 |
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getRendererInfo().then((rendererInfo) => {
- console.info('Renderer GetRendererInfo:');
- console.info(`Renderer content: ${rendererInfo.content}`);
- console.info(`Renderer usage: ${rendererInfo.usage}`);
- console.info(`Renderer flags: ${rendererInfo.rendererFlags}`)
+audioCapturer.start().then(() => {
+ console.info('AudioFrameworkRecLog: ---------START---------');
+ console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
+ console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
+ console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
+ if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
+ console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
+ }
}).catch((err) => {
- console.error(`AudioFrameworkRenderLog: RendererInfo :ERROR: ${err}`);
+ console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
});
```
-### getStreamInfo8+
+### stop8+
-getStreamInfo(callback: AsyncCallback): void
+stop(callback: AsyncCallback): void
-获取音频流信息,使用callback方式异步返回结果。
+停止采集。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------------------------------------- | :--- | :------------------- |
-| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是 | 回调返回音频流信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getStreamInfo((err, streamInfo) => {
- console.info('Renderer GetStreamInfo:');
- console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
- console.info(`Renderer channel: ${streamInfo.channels}`);
- console.info(`Renderer format: ${streamInfo.sampleFormat}`);
- console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
+audioCapturer.stop((err) => {
+ if (err) {
+ console.error('Capturer stop failed');
+ } else {
+ console.info('Capturer stopped.');
+ }
});
```
-### getStreamInfo8+
-getStreamInfo(): Promise
+### stop8+
-获取音频流信息,使用Promise方式异步返回结果。
+stop(): Promise
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+停止采集。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**返回值:**
-| 类型 | 说明 |
-| :--------------------------------------------- | :--------------------- |
-| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | Promise返回音频流信息. |
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getStreamInfo().then((streamInfo) => {
- console.info('Renderer GetStreamInfo:');
- console.info(`Renderer sampling rate: ${streamInfo.samplingRate}`);
- console.info(`Renderer channel: ${streamInfo.channels}`);
- console.info(`Renderer format: ${streamInfo.sampleFormat}`);
- console.info(`Renderer encoding type: ${streamInfo.encodingType}`);
+audioCapturer.stop().then(() => {
+ console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
+ console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
+ if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
+ console.info('AudioFrameworkRecLog: State is Stopped:');
+ }
}).catch((err) => {
- console.error(`ERROR: ${err}`);
+ console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
});
```
-### start8+
+### release8+
-start(callback: AsyncCallback): void
+release(callback: AsyncCallback): void
-启动音频渲染器。使用callback方式异步返回结果。
+释放采集器。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | ---------- |
-| callback | AsyncCallback\ | 是 | 回调函数。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :---------------------------------- |
+| callback | AsyncCallback | 是 | Callback used to return the result. |
**示例:**
```js
-audioRenderer.start((err) => {
+audioCapturer.release((err) => {
if (err) {
- console.error('Renderer start failed.');
+ console.error('capturer release failed');
} else {
- console.info('Renderer start success.');
+ console.info('capturer released.');
}
});
```
-### start8+
-start(): Promise
+### release8+
-启动音频渲染器。使用Promise方式异步返回结果。
+release(): Promise
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+释放采集器。使用Promise方式异步返回结果。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**返回值:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.start().then(() => {
- console.info('Renderer started');
+let stateFlag;
+audioCapturer.release().then(() => {
+ console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
+ console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
+ console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
+ console.info(`AudioFrameworkRecLog: stateFlag : ${stateFlag}`);
}).catch((err) => {
- console.error(`ERROR: ${err}`);
+ console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
});
```
-### pause8+
+### read8+
-pause(callback: AsyncCallback\): void
+read(size: number, isBlockingRead: boolean, callback: AsyncCallback): void
-暂停渲染。使用callback方式异步返回结果。
+读入缓冲区。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | ---------------- |
-| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------------- | :-------------------------- | :--- | :------------------------------- |
+| size | number | 是 | 读入的字节数。 |
+| isBlockingRead | boolean | 是 | 是否阻塞读操作。 |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回缓冲区。 |
**示例:**
```js
-audioRenderer.pause((err) => {
- if (err) {
- console.error('Renderer pause failed');
- } else {
- console.info('Renderer paused.');
+let bufferSize;
+audioCapturer.getBufferSize().then((data) => {
+ console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
+ bufferSize = data;
+ }).catch((err) => {
+ console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
+ });
+audioCapturer.read(bufferSize, true, async(err, buffer) => {
+ if (!err) {
+ console.info('Success in reading the buffer data');
}
});
```
-### pause8+
+### read8+
-pause(): Promise\
+read(size: number, isBlockingRead: boolean): Promise
-暂停渲染。使用Promise方式异步返回结果。
+读入缓冲区。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------------- | :------ | :--- | :--------------- |
+| size | number | 是 | 读入的字节数。 |
+| isBlockingRead | boolean | 是 | 是否阻塞读操作。 |
**返回值:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| :-------------------- | :----------------------------------------------------- |
+| Promise | 如果操作成功,返回读取的缓冲区数据;否则返回错误代码。 |
**示例:**
```js
-audioRenderer.pause().then(() => {
- console.info('Renderer paused');
+let bufferSize;
+audioCapturer.getBufferSize().then((data) => {
+ console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
+ bufferSize = data;
+ }).catch((err) => {
+ console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
+ });
+console.info(`Buffer size: ${bufferSize}`);
+audioCapturer.read(bufferSize, true).then((buffer) => {
+ console.info('buffer read successfully');
}).catch((err) => {
- console.error(`ERROR: ${err}`);
+ console.info(`ERROR : ${err}`);
});
```
-### drain8+
+### getAudioTime8+
-drain(callback: AsyncCallback\): void
+getAudioTime(callback: AsyncCallback): void
-检查缓冲区是否已被耗尽。使用callback方式异步返回结果。
+获取时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | ---------------- |
-| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-audioRenderer.drain((err) => {
- if (err) {
- console.error('Renderer drain failed');
- } else {
- console.info('Renderer drained.');
- }
+audioCapturer.getAudioTime((err, timestamp) => {
+ console.info(`Current timestamp: ${timestamp}`);
});
```
-### drain8+
+### getAudioTime8+
-drain(): Promise\
+getAudioTime(): Promise
-检查缓冲区是否已被耗尽。使用Promise方式异步返回结果。
+获取时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**返回值:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| :--------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.drain().then(() => {
- console.info('Renderer drained successfully');
+audioCapturer.getAudioTime().then((audioTime) => {
+ console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
}).catch((err) => {
- console.error(`ERROR: ${err}`);
+ console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
});
```
-### stop8+
+### getBufferSize8+
-stop(callback: AsyncCallback\): void
+getBufferSize(callback: AsyncCallback): void
-停止渲染。使用callback方式异步返回结果。
+获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | ---------------- |
-| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------- | :--- | :----------------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回缓冲区大小。 |
**示例:**
-```js
-audioRenderer.stop((err) => {
- if (err) {
- console.error('Renderer stop failed');
- } else {
- console.info('Renderer stopped.');
+```js
+audioCapturer.getBufferSize((err, bufferSize) => {
+ if (!err) {
+ console.info(`BufferSize : ${bufferSize}`);
+ audioCapturer.read(bufferSize, true).then((buffer) => {
+ console.info(`Buffer read is ${buffer}`);
+ }).catch((err) => {
+ console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
+ });
}
});
```
-### stop8+
+### getBufferSize8+
-stop(): Promise\
+getBufferSize(): Promise
-停止渲染。使用Promise方式异步返回结果。
+获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**返回值:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| :--------------- | :---------------------------------- |
+| Promise | 使用Promise方式异步返回缓冲区大小。 |
**示例:**
```js
-audioRenderer.stop().then(() => {
- console.info('Renderer stopped successfully');
+let bufferSize;
+audioCapturer.getBufferSize().then((data) => {
+ console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
+ bufferSize = data;
}).catch((err) => {
- console.error(`ERROR: ${err}`);
+ console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
});
```
-### release8+
+### on('markReach')8+
-release(callback: AsyncCallback\): void
+on(type: "markReach", frame: number, callback: Callback<number>): void
-释放音频渲染器。使用callback方式异步返回结果。
+订阅标记到达的事件。 当采集的帧数达到 frame 参数的值时,回调被触发。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | ---------------- |
-| callback | AsyncCallback\ | 是 | 返回回调的结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :---------------------- | :--- | :----------------------------------------- |
+| type | string | 是 | 事件回调类型,支持的事件为:'markReach'。 |
+| frame | number | 是 | 触发事件的帧数。 该值必须大于0。 |
+| callback | Callback\ | 是 | 使用callback方式异步返回被触发事件的回调。 |
**示例:**
```js
-audioRenderer.release((err) => {
- if (err) {
- console.error('Renderer release failed');
- } else {
- console.info('Renderer released.');
+audioCapturer.on('markReach', 1000, (position) => {
+ if (position == 1000) {
+ console.info('ON Triggered successfully');
}
});
```
-### release8+
+### off('markReach')8+
-release(): Promise\
+off(type: 'markReach'): void
-释放渲染器。使用Promise方式异步返回结果。
+取消订阅标记到达的事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-**返回值:**
+**参数:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :----- | :----- | :--- | :-------------------------------------------- |
+| type | string | 是 | 取消事件回调类型,支持的事件为:'markReach'。 |
**示例:**
```js
-audioRenderer.release().then(() => {
- console.info('Renderer released successfully');
-}).catch((err) => {
- console.error(`ERROR: ${err}`);
-});
+audioCapturer.off('markReach');
```
-### write8+
+### on('periodReach')8+
-write(buffer: ArrayBuffer, callback: AsyncCallback\): void
+on(type: "periodReach", frame: number, callback: Callback<number>): void
-写入缓冲区。使用callback方式异步返回结果。
+订阅到达标记的事件。 当采集的帧数达到 frame 参数的值时,回调被循环调用。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------- | ---- | --------------------------------------------------- |
-| buffer | ArrayBuffer | 是 | 要写入缓冲区的数据。 |
-| callback | AsyncCallback\ | 是 | 回调如果成功,返回写入的字节数,否则返回errorcode。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :----------------------- | :--- | :------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'periodReach'。 |
+| frame | number | 是 | 触发事件的帧数。 该值必须大于0。 |
+| callback | Callback\ | 是 | 使用callback方式异步返回被触发事件的回调 |
**示例:**
```js
-let bufferSize;
-audioRenderer.getBufferSize().then((data)=> {
- console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
- bufferSize = data;
- }).catch((err) => {
- console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
- });
-console.info(`Buffer size: ${bufferSize}`);
-let context = featureAbility.getContext();
-let path;
-async function getCacheDir(){
- path = await context.getCacheDir();
-}
-let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
-let ss = fileio.createStreamSync(filePath, 'r');
-let buf = new ArrayBuffer(bufferSize);
-ss.readSync(buf);
-audioRenderer.write(buf, (err, writtenbytes) => {
- if (writtenbytes < 0) {
- console.error('write failed.');
- } else {
- console.info(`Actual written bytes: ${writtenbytes}`);
+audioCapturer.on('periodReach', 1000, (position) => {
+ if (position == 1000) {
+ console.info('ON Triggered successfully');
}
});
```
-### write8+
+### off('periodReach')8+
-write(buffer: ArrayBuffer): Promise\
+off(type: 'periodReach'): void
-写入缓冲区。使用Promise方式异步返回结果。
+取消订阅标记到达的事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
-**返回值:**
+**参数:**
-| 类型 | 说明 |
-| ---------------- | ------------------------------------------------------------ |
-| Promise\ | Promise返回结果,如果成功,返回写入的字节数,否则返回errorcode。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :----- | :----- | :--- | :---------------------------------------------- |
+| type | string | 是 | 取消事件回调类型,支持的事件为:'periodReach'。 |
**示例:**
```js
-let bufferSize;
-audioRenderer.getBufferSize().then((data) => {
- console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
- bufferSize = data;
- }).catch((err) => {
- console.info(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
- });
-console.info(`BufferSize: ${bufferSize}`);
-let context = featureAbility.getContext();
-let path;
-async function getCacheDir(){
- path = await context.getCacheDir();
-}
-let filePath = path + '/StarWars10s-2C-48000-4SW.wav';
-let ss = fileio.createStreamSync(filePath, 'r');
-let buf = new ArrayBuffer(bufferSize);
-ss.readSync(buf);
-audioRenderer.write(buf).then((writtenbytes) => {
- if (writtenbytes < 0) {
- console.error('write failed.');
- } else {
- console.info(`Actual written bytes: ${writtenbytes}`);
- }
-}).catch((err) => {
- console.error(`ERROR: ${err}`);
-});
+audioCapturer.off('periodReach')
```
-### getAudioTime8+
+### on('stateChange') 8+
-getAudioTime(callback: AsyncCallback\): void
+on(type: 'stateChange', callback: Callback): void
-获取时间戳(从 1970 年 1 月 1 日开始)。使用callback方式异步返回结果。
+订阅监听状态变化。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Capturer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------- | ---- | ---------------- |
-| callback | AsyncCallback\ | 是 | 回调返回时间戳。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------------- | :--- | :------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'stateChange'。 |
+| callback | [AudioState](#audiostate8) | 是 | 返回监听的状态。 |
**示例:**
```js
-audioRenderer.getAudioTime((err, timestamp) => {
- console.info(`Current timestamp: ${timestamp}`);
+audioCapturer.on('stateChange', (state) => {
+ if (state == 1) {
+ console.info('audio capturer state is: STATE_PREPARED');
+ }
+ if (state == 2) {
+ console.info('audio capturer state is: STATE_RUNNING');
+ }
});
```
-### getAudioTime8+
+## ToneType 9+
-getAudioTime(): Promise\
+枚举,播放器的音调类型。
-获取时间戳(从 1970 年 1 月 1 日开始)。使用Promise方式异步返回结果。
+**系统接口:** 该接口为系统接口
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Tone
-**返回值:**
+| 名称 | 默认值 | 描述 |
+| :------------------------------------------------ | :----- | :----------------------------|
+| TONE_TYPE_DIAL_0 | 0 | 键0的DTMF音。 |
+| TONE_TYPE_DIAL_1 | 1 | 键1的DTMF音。 |
+| TONE_TYPE_DIAL_2 | 2 | 键2的DTMF音。 |
+| TONE_TYPE_DIAL_3 | 3 | 键3的DTMF音。 |
+| TONE_TYPE_DIAL_4 | 4 | 键4的DTMF音。 |
+| TONE_TYPE_DIAL_5 | 5 | 键5的DTMF音。 |
+| TONE_TYPE_DIAL_6 | 6 | 键6的DTMF音。 |
+| TONE_TYPE_DIAL_7 | 7 | 键7的DTMF音。 |
+| TONE_TYPE_DIAL_8 | 8 | 键8的DTMF音。 |
+| TONE_TYPE_DIAL_9 | 9 | 键9的DTMF音。 |
+| TONE_TYPE_DIAL_S | 10 | 键*的DTMF音。 |
+| TONE_TYPE_DIAL_P | 11 | 键#的DTMF音。 |
+| TONE_TYPE_DIAL_A | 12 | 键A的DTMF音。 |
+| TONE_TYPE_DIAL_B | 13 | 键B的DTMF音。 |
+| TONE_TYPE_DIAL_C | 14 | 键C的DTMF音。 |
+| TONE_TYPE_DIAL_D | 15 | 键D的DTMF音。 |
+| TONE_TYPE_COMMON_SUPERVISORY_DIAL | 100 | 呼叫监管音调,拨号音。 |
+| TONE_TYPE_COMMON_SUPERVISORY_BUSY | 101 | 呼叫监管音调,忙。 |
+| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION | 102 | 呼叫监管音调,拥塞。 |
+| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK | 103 | 呼叫监管音调,无线电 ACK。 |
+| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104 | 呼叫监管音调,无线电不可用。 |
+| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING | 106 | 呼叫监管音调,呼叫等待。 |
+| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE | 107 | 呼叫监管音调,铃声。 |
+| TONE_TYPE_COMMON_PROPRIETARY_BEEP | 200 | 专有声调,一般蜂鸣声。 |
+| TONE_TYPE_COMMON_PROPRIETARY_ACK | 201 | 专有声调,ACK。 |
+| TONE_TYPE_COMMON_PROPRIETARY_PROMPT | 203 | 专有声调,PROMPT。 |
+| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP | 204 | 专有声调,双重蜂鸣声。 |
-| 类型 | 描述 |
-| ---------------- | ----------------------- |
-| Promise\ | Promise回调返回时间戳。 |
+## TonePlayer9+
-**示例:**
+提供播放和管理DTMF(Dual Tone Multi Frequency,双音多频)音调的方法,包括各种系统监听音调、专有音调,如拨号音、通话回铃音等。
-```js
-audioRenderer.getAudioTime().then((timestamp) => {
- console.info(`Current timestamp: ${timestamp}`);
-}).catch((err) => {
- console.error(`ERROR: ${err}`);
-});
-```
+**系统接口:** 该接口为系统接口
-### getBufferSize8+
+### load9+
-getBufferSize(callback: AsyncCallback\): void
+load(type: ToneType, callback: AsyncCallback<void>): void
-获取音频渲染器的最小缓冲区大小。使用callback方式异步返回结果。
+加载DTMF音调配置。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------- | ---- | -------------------- |
-| callback | AsyncCallback\ | 是 | 回调返回缓冲区大小。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :--------------| :-------------------------- | :-----| :------------------------------ |
+| type | ToneType(#tonetype9) | 是 | 配置的音调类型。 |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-let bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
+tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
if (err) {
- console.error('getBufferSize error');
+ console.error(`callback call load failed error: ${err.message}`);
+ return;
+ } else {
+ console.info('callback call load success');
}
});
```
-### getBufferSize8+
+### load9+
-getBufferSize(): Promise\
+load(type: ToneType): Promise<void>
-获取音频渲染器的最小缓冲区大小。使用Promise方式异步返回结果。
+加载DTMF音调配置。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| :------------- | :--------------------- | :--- | ---------------- |
+| type | ToneType(#tonetype9) | 是 | 配置的音调类型。 |
**返回值:**
-| 类型 | 说明 |
-| ---------------- | --------------------------- |
-| Promise\ | promise回调返回缓冲区大小。 |
+| 类型 | 说明 |
+| :--------------| :-------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-let bufferSize;
-audioRenderer.getBufferSize().then((data) => {
- console.info(`AudioFrameworkRenderLog: getBufferSize: SUCCESS ${data}`);
- bufferSize = data;
-}).catch((err) => {
- console.error(`AudioFrameworkRenderLog: getBufferSize: ERROR: ${err}`);
+tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
+ console.info('promise call load ');
+}).catch(() => {
+ console.error('promise call load fail');
});
```
-### setRenderRate8+
+### start9+
-setRenderRate(rate: AudioRendererRate, callback: AsyncCallback\): void
+start(callback: AsyncCallback<void>): void
-设置音频渲染速率。使用callback方式异步返回结果。
+启动DTMF音调播放。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------- | ---- | ------------------------ |
-| rate | [AudioRendererRate](#audiorendererrate8) | 是 | 渲染的速率。 |
-| callback | AsyncCallback\ | 是 | 用于返回执行结果的回调。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL, (err) => {
+tonePlayer.start((err) => {
if (err) {
- console.error('Failed to set params');
+ console.error(`callback call start failed error: ${err.message}`);
+ return;
} else {
- console.info('Callback invoked to indicate a successful render rate setting.');
+ console.info('callback call start success');
}
});
```
-### setRenderRate8+
-
-setRenderRate(rate: AudioRendererRate): Promise\
-
-设置音频渲染速率。使用Promise方式异步返回结果。
+### start9+
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+start(): Promise<void>
-**参数:**
+启动DTMF音调播放。使用Promise方式异步返回结果。
-| 参数名 | 类型 | 必填 | 说明 |
-| ------ | ---------------------------------------- | ---- | ------------ |
-| rate | [AudioRendererRate](#audiorendererrate8) | 是 | 渲染的速率。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
**返回值:**
-| 类型 | 说明 |
-| -------------- | ------------------------- |
-| Promise\ | Promise用于返回执行结果。 |
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.setRenderRate(audio.AudioRendererRate.RENDER_RATE_NORMAL).then(() => {
- console.info('setRenderRate SUCCESS');
-}).catch((err) => {
- console.error(`ERROR: ${err}`);
+tonePlayer.start().then(() => {
+ console.info('promise call start');
+}).catch(() => {
+ console.error('promise call start fail');
});
```
-### getRenderRate8+
+### stop9+
-getRenderRate(callback: AsyncCallback\): void
+stop(callback: AsyncCallback<void>): void
-获取当前渲染速率。使用callback方式异步返回结果。
+停止当前正在播放的音调。使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ------------------------------------------------------- | ---- | ------------------ |
-| callback | AsyncCallback<[AudioRendererRate](#audiorendererrate8)> | 是 | 回调返回渲染速率。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :----------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getRenderRate((err, renderrate) => {
- console.info(`getRenderRate: ${renderrate}`);
+tonePlayer.stop((err) => {
+ if (err) {
+ console.error(`callback call stop error: ${err.message}`);
+ return;
+ } else {
+ console.error('callback call stop success ');
+ }
});
```
-### getRenderRate8+
+### stop9+
-getRenderRate(): Promise\
+stop(): Promise<void>
-获取当前渲染速率。使用Promise方式异步返回结果。
+停止当前正在播放的音调。使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
**返回值:**
-| 类型 | 说明 |
-| ------------------------------------------------- | ------------------------- |
-| Promise<[AudioRendererRate](#audiorendererrate8)> | Promise回调返回渲染速率。 |
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-audioRenderer.getRenderRate().then((renderRate) => {
- console.info(`getRenderRate: ${renderRate}`);
-}).catch((err) => {
- console.error(`ERROR: ${err}`);
+tonePlayer.stop().then(() => {
+ console.info('promise call stop finish');
+}).catch(() => {
+ console.error('promise call stop fail');
});
```
-### setInterruptMode9+
-
-setInterruptMode(mode: InterruptMode): Promise<void>
-设置应用的焦点模型。使用Promise异步回调。
+### release9+
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+release(callback: AsyncCallback<void>): void
-**参数:**
+释放与此TonePlay对象关联的资源。使用callback方式异步返回结果。
-| 参数名 | 类型 | 必填 | 说明 |
-| ---------- | ---------------------------------- | ------ | ---------- |
-| mode | [InterruptMode](#interruptmode9) | 是 | 焦点模型。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
-**返回值:**
+**参数:**
-| 类型 | 说明 |
-| ------------------- | ----------------------------- |
-| Promise<void> | 以Promise对象返回结果,设置成功时返回undefined,否则返回error。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :------------------- | :--- | :---------------------------- |
+| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
**示例:**
```js
-let mode = 0;
-audioRenderer.setInterruptMode(mode).then(data=>{
- console.info('setInterruptMode Success!');
-}).catch((err) => {
- console.error(`setInterruptMode Fail: ${err}`);
+tonePlayer.release((err) => {
+ if (err) {
+ console.error(`callback call release failed error: ${err.message}`);
+ return;
+ } else {
+ console.info('callback call release success ');
+ }
});
```
-### setInterruptMode9+
-setInterruptMode(mode: InterruptMode, callback: AsyncCallback\): void
+### release9+
-设置应用的焦点模型。使用Callback回调返回执行结果。
+release(): Promise<void>
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+释放与此TonePlay对象关联的资源。使用Promise方式异步返回结果。
-**参数:**
+**系统能力:** SystemCapability.Multimedia.Audio.Tone
-| 参数名 | 类型 | 必填 | 说明 |
-| ------- | ----------------------------------- | ------ | -------------- |
-|mode | [InterruptMode](#interruptmode9) | 是 | 焦点模型。|
-|callback | AsyncCallback\ | 是 |回调返回执行结果。|
+**返回值:**
+
+| 类型 | 说明 |
+| :------------- | :---------------------------- |
+| Promise | 使用Promise方式异步返回结果。 |
**示例:**
```js
-let mode = 1;
-audioRenderer.setInterruptMode(mode, (err, data)=>{
- if(err){
- console.error(`setInterruptMode Fail: ${err}`);
- }
- console.info('setInterruptMode Success!');
+tonePlayer.release().then(() => {
+ console.info('promise call release');
+}).catch(() => {
+ console.error('promise call release fail');
});
```
-### on('interrupt')9+
-on(type: 'interrupt', callback: Callback\): void
-
-监听音频中断事件。使用callback获取中断事件。
+## ActiveDeviceType(deprecated)
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+枚举,活跃设备类型。
-**参数:**
+> **说明:**
+> 从 API version 9 开始废弃,建议使用[CommunicationDeviceType](#communicationdevicetype9)替代。
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'interrupt'(中断事件被触发,音频播放被中断。) |
-| callback | Callback<[InterruptEvent](#interruptevent9)> | 是 | 被监听的中断事件的回调。 |
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Device
-**示例:**
+| 名称 | 默认值 | 描述 |
+| ------------- | ------ | ---------------------------------------------------- |
+| SPEAKER | 2 | 扬声器。 |
+| BLUETOOTH_SCO | 7 | 蓝牙设备SCO(Synchronous Connection Oriented)连接。 |
-```js
-let isPlay;
-let started;
-audioRenderer.on('interrupt', async(interruptEvent) => {
- if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
- switch (interruptEvent.hintType) {
- case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
- console.info('Force paused. Stop writing');
- isPlay = false;
- break;
- case audio.InterruptHint.INTERRUPT_HINT_STOP:
- console.info('Force stopped. Stop writing');
- isPlay = false;
- break;
- }
- } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
- switch (interruptEvent.hintType) {
- case audio.InterruptHint.INTERRUPT_HINT_RESUME:
- console.info('Resume force paused renderer or ignore');
- await audioRenderer.start().then(async function () {
- console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
- started = true;
- }).catch((err) => {
- console.error(`AudioInterruptMusic: renderInstant start :ERROR : ${err}`);
- started = false;
- });
- if (started) {
- isPlay = true;
- console.info(`AudioInterruptMusic Renderer started : isPlay : ${isPlay}`);
- } else {
- console.error('AudioInterruptMusic Renderer start failed');
- }
- break;
- case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
- console.info('Choose to pause or ignore');
- if (isPlay == true) {
- isPlay == false;
- console.info('AudioInterruptMusic: Media PAUSE : TRUE');
- } else {
- isPlay = true;
- console.info('AudioInterruptMusic: Media PLAY : TRUE');
- }
- break;
- }
- }
-});
-```
+## InterruptActionType(deprecated)
-### on('markReach')8+
+枚举,中断事件返回类型。
-on(type: "markReach", frame: number, callback: Callback<number>): void
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃。
-订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被调用。
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+| 名称 | 默认值 | 描述 |
+| -------------- | ------ | ------------------ |
+| TYPE_ACTIVATED | 0 | 表示触发焦点事件。 |
+| TYPE_INTERRUPT | 1 | 表示音频打断事件。 |
-**参数:**
+## AudioInterrupt(deprecated)
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :----------------------- | :--- | :---------------------------------------- |
-| type | string | 是 | 事件回调类型,支持的事件为:'markReach'。 |
-| frame | number | 是 | 触发事件的帧数。 该值必须大于 0。 |
-| callback | Callback\ | 是 | 触发事件时调用的回调。 |
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃。
-**示例:**
+音频监听事件传入的参数。
-```js
-audioRenderer.on('markReach', 1000, (position) => {
- if (position == 1000) {
- console.info('ON Triggered successfully');
- }
-});
-```
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
+| 名称 | 类型 | 必填 | 说明 |
+| --------------- | --------------------------- | ---- | ------------------------------------------------------------ |
+| streamUsage | [StreamUsage](#streamusage) | 是 | 音频流使用类型。 |
+| contentType | [ContentType](#contenttype) | 是 | 音频打断媒体类型。 |
+| pauseWhenDucked | boolean | 是 | 音频打断时是否可以暂停音频播放(true表示音频播放可以在音频打断期间暂停,false表示相反)。 |
-### off('markReach') 8+
+## InterruptAction(deprecated)
-off(type: 'markReach'): void
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃。
-取消订阅标记事件。
+音频打断/获取焦点事件的回调方法。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
-**参数:**
+| 名称 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
+| actionType | [InterruptActionType](#interruptactiontype) | 是 | 事件返回类型。TYPE_ACTIVATED为焦点触发事件,TYPE_INTERRUPT为音频打断事件。 |
+| type | [InterruptType](#interrupttype) | 否 | 打断事件类型。 |
+| hint | [InterruptHint](#interrupthint) | 否 | 打断事件提示。 |
+| activated | boolean | 否 | 获得/释放焦点。true表示焦点获取/释放成功,false表示焦点获得/释放失败。 |
-| 参数名 | 类型 | 必填 | 说明 |
-| :----- | :----- | :--- | :------------------------------------------------ |
-| type | string | 是 | 要取消订阅事件的类型。支持的事件为:'markReach'。 |
+### setVolume(deprecated)
-**示例:**
+setVolume(volumeType: AudioVolumeType, volume: number, callback: AsyncCallback<void>): void
-```js
-audioRenderer.off('markReach');
-```
+设置指定流的音量,使用callback方式异步返回结果。
-### on('periodReach') 8+
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setVolume](#setvolume9)替代。
-on(type: "periodReach", frame: number, callback: Callback<number>): void
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-订阅到达标记的事件。 当渲染的帧数达到 frame 参数的值时,回调被循环调用。
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :----------------------- | :--- | :------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'periodReach'。 |
-| frame | number | 是 | 触发事件的帧数。 该值必须大于 0。 |
-| callback | Callback\ | 是 | 触发事件时调用的回调。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
+| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
**示例:**
```js
-audioRenderer.on('periodReach', 1000, (position) => {
- if (position == 1000) {
- console.info('ON Triggered successfully');
+audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10, (err) => {
+ if (err) {
+ console.error(`Failed to set the volume. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate a successful volume setting.');
});
```
-### off('periodReach') 8+
+### setVolume(deprecated)
-off(type: 'periodReach'): void
+setVolume(volumeType: AudioVolumeType, volume: number): Promise<void>
-取消订阅标记事件。
+设置指定流的音量,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setVolume](#setvolume9)替代。
+
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :----- | :----- | :--- | :-------------------------------------------------- |
-| type | string | 是 | 要取消订阅事件的类型。支持的事件为:'periodReach'。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| volume | number | 是 | 音量等级,可设置范围通过getMinVolume和getMaxVolume获取。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise回调表示成功还是失败。 |
**示例:**
```js
-audioRenderer.off('periodReach')
+audioManager.setVolume(audio.AudioVolumeType.MEDIA, 10).then(() => {
+ console.info('Promise returned to indicate a successful volume setting.');
+});
```
-### on('stateChange') 8+
+### getVolume(deprecated)
-on(type: 'stateChange', callback: Callback): void
+getVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-订阅监听状态变化。
+获取指定流的音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Renderer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------------- | :--- | :------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'stateChange'。 |
-| callback | [AudioState](#audiostate8) | 是 | 返回监听的状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回音量大小。 |
**示例:**
```js
-audioRenderer.on('stateChange', (state) => {
- if (state == 1) {
- console.info('audio renderer state is: STATE_PREPARED');
- }
- if (state == 2) {
- console.info('audio renderer state is: STATE_RUNNING');
+audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the volume. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the volume is obtained.');
});
```
-## AudioCapturer8+
+### getVolume(deprecated)
-提供音频采集的相关接口。在调用AudioCapturer的接口前,需要先通过[createAudioCapturer](#audiocreateaudiocapturer8)创建实例。
+getVolume(volumeType: AudioVolumeType): Promise<number>
-### 属性
+获取指定流的音量,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getVolume](#getvolume9)替代。
-| 名称 | 类型 | 可读 | 可写 | 说明 |
-| :---- | :------------------------- | :--- | :--- | :--------------- |
-| state8+ | [AudioState](#audiostate8) | 是 | 否 | 音频采集器状态。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise回调返回音量大小。 |
**示例:**
```js
-let state = audioCapturer.state;
+audioManager.getVolume(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the volume is obtained ${value} .`);
+});
```
-### getCapturerInfo8+
+### getMinVolume(deprecated)
-getCapturerInfo(callback: AsyncCallback): void
+getMinVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-获取采集器信息。使用callback方式异步返回结果。
+获取指定流的最小音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :-------------------------------- | :--- | :----------------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回采集器信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回最小音量。 |
**示例:**
```js
-audioCapturer.getCapturerInfo((err, capturerInfo) => {
+audioManager.getMinVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error('Failed to get capture info');
- } else {
- console.info('Capturer getCapturerInfo:');
- console.info(`Capturer source: ${capturerInfo.source}`);
- console.info(`Capturer flags: ${capturerInfo.capturerFlags}`);
+ console.error(`Failed to obtain the minimum volume. ${err}`);
+ return;
}
+ console.info(`Callback invoked to indicate that the minimum volume is obtained. ${value}`);
});
```
+### getMinVolume(deprecated)
-### getCapturerInfo8+
+getMinVolume(volumeType: AudioVolumeType): Promise<number>
-getCapturerInfo(): Promise
+获取指定流的最小音量,使用Promise方式异步返回结果。
-获取采集器信息。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMinVolume](#getminvolume9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| :------------------------------------------------ | :---------------------------------- |
-| Promise<[AudioCapturerInfo](#audiocapturerinfo)\> | 使用Promise方式异步返回采集器信息。 |
+| 类型 | 说明 |
+| --------------------- | ------------------------- |
+| Promise<number> | Promise回调返回最小音量。 |
**示例:**
```js
-audioCapturer.getCapturerInfo().then((audioParamsGet) => {
- if (audioParamsGet != undefined) {
- console.info('AudioFrameworkRecLog: Capturer CapturerInfo:');
- console.info(`AudioFrameworkRecLog: Capturer SourceType: ${audioParamsGet.source}`);
- console.info(`AudioFrameworkRecLog: Capturer capturerFlags: ${audioParamsGet.capturerFlags}`);
- } else {
- console.info(`AudioFrameworkRecLog: audioParamsGet is : ${audioParamsGet}`);
- console.info('AudioFrameworkRecLog: audioParams getCapturerInfo are incorrect');
- }
-}).catch((err) => {
- console.error(`AudioFrameworkRecLog: CapturerInfo :ERROR: ${err}`);
+audioManager.getMinVolume(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promised returned to indicate that the minimum volume is obtained. ${value}`);
});
```
-### getStreamInfo8+
+### getMaxVolume(deprecated)
-getStreamInfo(callback: AsyncCallback): void
+getMaxVolume(volumeType: AudioVolumeType, callback: AsyncCallback<number>): void
-获取采集器流信息。使用callback方式异步返回结果。
+获取指定流的最大音量,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------------------------------------- | :--- | :------------------------------- |
-| callback | AsyncCallback<[AudioStreamInfo](#audiostreaminfo8)\> | 是 | 使用callback方式异步返回流信息。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ---------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<number> | 是 | 回调返回最大音量大小。 |
**示例:**
```js
-audioCapturer.getStreamInfo((err, streamInfo) => {
+audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error('Failed to get stream info');
- } else {
- console.info('Capturer GetStreamInfo:');
- console.info(`Capturer sampling rate: ${streamInfo.samplingRate}`);
- console.info(`Capturer channel: ${streamInfo.channels}`);
- console.info(`Capturer format: ${streamInfo.sampleFormat}`);
- console.info(`Capturer encoding type: ${streamInfo.encodingType}`);
+ console.error(`Failed to obtain the maximum volume. ${err}`);
+ return;
}
+ console.info(`Callback invoked to indicate that the maximum volume is obtained. ${value}`);
});
```
-### getStreamInfo8+
+### getMaxVolume(deprecated)
-getStreamInfo(): Promise
+getMaxVolume(volumeType: AudioVolumeType): Promise<number>
-获取采集器流信息。使用Promise方式异步返回结果。
+获取指定流的最大音量,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getMaxVolume](#getmaxvolume9)替代。
-**返回值:**
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
-| 类型 | 说明 |
-| :--------------------------------------------- | :------------------------------ |
-| Promise<[AudioStreamInfo](#audiostreaminfo8)\> | 使用Promise方式异步返回流信息。 |
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| --------------------- | ----------------------------- |
+| Promise<number> | Promise回调返回最大音量大小。 |
**示例:**
```js
-audioCapturer.getStreamInfo().then((audioParamsGet) => {
- console.info('getStreamInfo:');
- console.info(`sampleFormat: ${audioParamsGet.sampleFormat}`);
- console.info(`samplingRate: ${audioParamsGet.samplingRate}`);
- console.info(`channels: ${audioParamsGet.channels}`);
- console.info(`encodingType: ${audioParamsGet.encodingType}`);
-}).catch((err) => {
- console.error(`getStreamInfo :ERROR: ${err}`);
+audioManager.getMaxVolume(audio.AudioVolumeType.MEDIA).then((data) => {
+ console.info('Promised returned to indicate that the maximum volume is obtained.');
});
```
-### start8+
+### mute(deprecated)
-start(callback: AsyncCallback): void
+mute(volumeType: AudioVolumeType, mute: boolean, callback: AsyncCallback<void>): void
-启动音频采集器。使用callback方式异步返回结果。
+设置指定音量流静音,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[mute](#mute9)替代。
+
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :----------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
+| callback | AsyncCallback<void> | 是 | 回调表示成功还是失败。 |
**示例:**
```js
-audioCapturer.start((err) => {
+audioManager.mute(audio.AudioVolumeType.MEDIA, true, (err) => {
if (err) {
- console.error('Capturer start failed.');
- } else {
- console.info('Capturer start success.');
+ console.error(`Failed to mute the stream. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the stream is muted.');
});
```
+### mute(deprecated)
-### start8+
+mute(volumeType: AudioVolumeType, mute: boolean): Promise<void>
-start(): Promise
+设置指定音量流静音,使用Promise方式异步返回结果。
-启动音频采集器。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[mute](#mute9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅设置铃声(即volumeType为AudioVolumeType.RINGTONE)在静音和非静音状态切换时需要该权限。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| mute | boolean | 是 | 静音状态,true为静音,false为非静音。 |
**返回值:**
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| ------------------- | ----------------------------- |
+| Promise<void> | Promise回调表示成功还是失败。 |
**示例:**
+
```js
-audioCapturer.start().then(() => {
- console.info('AudioFrameworkRecLog: ---------START---------');
- console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
- console.info(`AudioFrameworkRecLog: AudioCapturer: STATE: ${audioCapturer.state}`);
- console.info('AudioFrameworkRecLog: Capturer started: SUCCESS');
- if ((audioCapturer.state == audio.AudioState.STATE_RUNNING)) {
- console.info('AudioFrameworkRecLog: AudioCapturer is in Running State');
- }
-}).catch((err) => {
- console.info(`AudioFrameworkRecLog: Capturer start :ERROR : ${err}`);
+audioManager.mute(audio.AudioVolumeType.MEDIA, true).then(() => {
+ console.info('Promise returned to indicate that the stream is muted.');
});
```
-### stop8+
+### isMute(deprecated)
-stop(callback: AsyncCallback): void
+isMute(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
-停止采集。使用callback方式异步返回结果。
+获取指定音量流是否被静音,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :----------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ----------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回流静音状态,true为静音,false为非静音。 |
**示例:**
```js
-audioCapturer.stop((err) => {
+audioManager.isMute(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error('Capturer stop failed');
- } else {
- console.info('Capturer stopped.');
+ console.error(`Failed to obtain the mute status. ${err}`);
+ return;
}
+ console.info(`Callback invoked to indicate that the mute status of the stream is obtained. ${value}`);
});
```
+### isMute(deprecated)
-### stop8+
+isMute(volumeType: AudioVolumeType): Promise<boolean>
-stop(): Promise
+获取指定音量流是否被静音,使用Promise方式异步返回结果。
-停止采集。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMute](#ismute9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| ---------------------- | ------------------------------------------------------ |
+| Promise<boolean> | Promise回调返回流静音状态,true为静音,false为非静音。 |
**示例:**
```js
-audioCapturer.stop().then(() => {
- console.info('AudioFrameworkRecLog: ---------STOP RECORD---------');
- console.info('AudioFrameworkRecLog: Capturer stopped: SUCCESS');
- if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
- console.info('AudioFrameworkRecLog: State is Stopped:');
- }
-}).catch((err) => {
- console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
+audioManager.isMute(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the mute status of the stream is obtained ${value}.`);
});
```
-### release8+
+### isActive(deprecated)
-release(callback: AsyncCallback): void
+isActive(volumeType: AudioVolumeType, callback: AsyncCallback<boolean>): void
-释放采集器。使用callback方式异步返回结果。
+获取指定音量流是否为活跃状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :---------------------------------- |
-| callback | AsyncCallback | 是 | Callback used to return the result. |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------------------------------------------- |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回流的活跃状态,true为活跃,false为不活跃。 |
**示例:**
```js
-audioCapturer.release((err) => {
+audioManager.isActive(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
- console.error('capturer release failed');
- } else {
- console.info('capturer released.');
+ console.error(`Failed to obtain the active status of the stream. ${err}`);
+ return;
}
+ console.info(`Callback invoked to indicate that the active status of the stream is obtained ${value}.`);
});
```
+### isActive(deprecated)
-### release8+
+isActive(volumeType: AudioVolumeType): Promise<boolean>
-release(): Promise
+获取指定音量流是否为活跃状态,使用Promise方式异步返回结果。
-释放采集器。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioStreamManager中的[isActive](#isactive9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ----------------------------------- | ---- | ------------ |
+| volumeType | [AudioVolumeType](#audiovolumetype) | 是 | 音量流类型。 |
**返回值:**
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| ---------------------- | -------------------------------------------------------- |
+| Promise<boolean> | Promise回调返回流的活跃状态,true为活跃,false为不活跃。 |
**示例:**
```js
-let stateFlag;
-audioCapturer.release().then(() => {
- console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
- console.info('AudioFrameworkRecLog: Capturer release : SUCCESS');
- console.info(`AudioFrameworkRecLog: AudioCapturer : STATE : ${audioCapturer.state}`);
- console.info(`AudioFrameworkRecLog: stateFlag : ${stateFlag}`);
-}).catch((err) => {
- console.info(`AudioFrameworkRecLog: Capturer stop: ERROR: ${err}`);
+audioManager.isActive(audio.AudioVolumeType.MEDIA).then((value) => {
+ console.info(`Promise returned to indicate that the active status of the stream is obtained ${value}.`);
});
```
+### setRingerMode(deprecated)
-### read8+
+setRingerMode(mode: AudioRingMode, callback: AsyncCallback<void>): void
-read(size: number, isBlockingRead: boolean, callback: AsyncCallback): void
+设置铃声模式,使用callback方式异步返回结果。
-读入缓冲区。使用callback方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setRingerMode](#setringermode9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
+
+仅在静音和非静音状态切换时需要该权限。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------------- | :-------------------------- | :--- | :------------------------------- |
-| size | number | 是 | 读入的字节数。 |
-| isBlockingRead | boolean | 是 | 是否阻塞读操作。 |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回缓冲区。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------------------- | ---- | ------------------------ |
+| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
```js
-let bufferSize;
-audioCapturer.getBufferSize().then((data) => {
- console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
- bufferSize = data;
- }).catch((err) => {
- console.error(`AudioFrameworkRecLog: getBufferSize: ERROR: ${err}`);
- });
-audioCapturer.read(bufferSize, true, async(err, buffer) => {
- if (!err) {
- console.info('Success in reading the buffer data');
+audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL, (err) => {
+ if (err) {
+ console.error(`Failed to set the ringer mode. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate a successful setting of the ringer mode.');
});
```
+### setRingerMode(deprecated)
-### read8+
-
-read(size: number, isBlockingRead: boolean): Promise
-
-读入缓冲区。使用Promise方式异步返回结果。
+setRingerMode(mode: AudioRingMode): Promise<void>
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+设置铃声模式,使用Promise方式异步返回结果。
-**参数:**
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setRingerMode](#setringermode9)替代。
-| 参数名 | 类型 | 必填 | 说明 |
-| :------------- | :------ | :--- | :--------------- |
-| size | number | 是 | 读入的字节数。 |
-| isBlockingRead | boolean | 是 | 是否阻塞读操作。 |
+**需要权限:** ohos.permission.ACCESS_NOTIFICATION_POLICY
-**返回值:**
+仅在静音和非静音状态切换时需要该权限。
-| 类型 | 说明 |
-| :-------------------- | :----------------------------------------------------- |
-| Promise | 如果操作成功,返回读取的缓冲区数据;否则返回错误代码。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
-**示例:**
+**参数:**
-```js
-let bufferSize;
-audioCapturer.getBufferSize().then((data) => {
- console.info(`AudioFrameworkRecLog: getBufferSize: SUCCESS ${data}`);
- bufferSize = data;
- }).catch((err) => {
- console.info(`AudioFrameworkRecLog: getBufferSize: ERROR ${err}`);
- });
-console.info(`Buffer size: ${bufferSize}`);
-audioCapturer.read(bufferSize, true).then((buffer) => {
- console.info('buffer read successfully');
-}).catch((err) => {
- console.info(`ERROR : ${err}`);
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ------------------------------- | ---- | -------------- |
+| mode | [AudioRingMode](#audioringmode) | 是 | 音频铃声模式。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
+
+**示例:**
+
+```js
+audioManager.setRingerMode(audio.AudioRingMode.RINGER_MODE_NORMAL).then(() => {
+ console.info('Promise returned to indicate a successful setting of the ringer mode.');
});
```
+### getRingerMode(deprecated)
-### getAudioTime8+
+getRingerMode(callback: AsyncCallback<AudioRingMode>): void
-getAudioTime(callback: AsyncCallback): void
+获取铃声模式,使用callback方式异步返回结果。
-获取时间戳(从1970年1月1日开始),单位为纳秒。使用callback方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------- | :--- | :----------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------------------- | ---- | ------------------------ |
+| callback | AsyncCallback<[AudioRingMode](#audioringmode)> | 是 | 回调返回系统的铃声模式。 |
**示例:**
```js
-audioCapturer.getAudioTime((err, timestamp) => {
- console.info(`Current timestamp: ${timestamp}`);
+audioManager.getRingerMode((err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the ringer mode. ${err}`);
+ return;
+ }
+ console.info(`Callback invoked to indicate that the ringer mode is obtained ${value}.`);
});
```
+### getRingerMode(deprecated)
-### getAudioTime8+
+getRingerMode(): Promise<AudioRingMode>
-getAudioTime(): Promise
+获取铃声模式,使用Promise方式异步返回结果。
-获取时间戳(从1970年1月1日开始),单位为纳秒。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[getRingerMode](#getringermode9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
**返回值:**
-| 类型 | 说明 |
-| :--------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| ---------------------------------------------- | ------------------------------- |
+| Promise<[AudioRingMode](#audioringmode)> | Promise回调返回系统的铃声模式。 |
**示例:**
```js
-audioCapturer.getAudioTime().then((audioTime) => {
- console.info(`AudioFrameworkRecLog: AudioCapturer getAudioTime : Success ${audioTime}`);
-}).catch((err) => {
- console.info(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
+audioManager.getRingerMode().then((value) => {
+ console.info(`Promise returned to indicate that the ringer mode is obtained ${value}.`);
});
```
+### getDevices(deprecated)
-### getBufferSize8+
+getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback<AudioDeviceDescriptors>): void
-getBufferSize(callback: AsyncCallback): void
+获取音频设备列表,使用callback方式异步返回结果。
-获取采集器合理的最小缓冲区大小。使用callback方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :--------------------- | :--- | :----------------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回缓冲区大小。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------------------------------ | ---- | -------------------- |
+| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
+| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回设备列表。 |
**示例:**
-
```js
-audioCapturer.getBufferSize((err, bufferSize) => {
- if (!err) {
- console.info(`BufferSize : ${bufferSize}`);
- audioCapturer.read(bufferSize, true).then((buffer) => {
- console.info(`Buffer read is ${buffer}`);
- }).catch((err) => {
- console.error(`AudioFrameworkRecLog: AudioCapturer Created : ERROR : ${err}`);
- });
+audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the device list. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the device list is obtained.');
});
```
+### getDevices(deprecated)
-### getBufferSize8+
+getDevices(deviceFlag: DeviceFlag): Promise<AudioDeviceDescriptors>
-getBufferSize(): Promise
+获取音频设备列表,使用Promise方式异步返回结果。
-获取采集器合理的最小缓冲区大小。使用Promise方式异步返回结果。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[getDevices](#getdevices9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Device
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------- | ---- | ---------------- |
+| deviceFlag | [DeviceFlag](#deviceflag) | 是 | 设备类型的flag。 |
**返回值:**
-| 类型 | 说明 |
-| :--------------- | :---------------------------------- |
-| Promise | 使用Promise方式异步返回缓冲区大小。 |
+| 类型 | 说明 |
+| ------------------------------------------------------------ | ------------------------- |
+| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise回调返回设备列表。 |
**示例:**
```js
-let bufferSize;
-audioCapturer.getBufferSize().then((data) => {
- console.info(`AudioFrameworkRecLog: getBufferSize :SUCCESS ${data}`);
- bufferSize = data;
-}).catch((err) => {
- console.info(`AudioFrameworkRecLog: getBufferSize :ERROR : ${err}`);
+audioManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
+ console.info('Promise returned to indicate that the device list is obtained.');
});
```
+### setDeviceActive(deprecated)
-### on('markReach')8+
+setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void
-on(type: "markReach", frame: number, callback: Callback<number>): void
+设置设备激活状态,使用callback方式异步返回结果。
-订阅标记到达的事件。 当采集的帧数达到 frame 参数的值时,回调被触发。
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :---------------------- | :--- | :----------------------------------------- |
-| type | string | 是 | 事件回调类型,支持的事件为:'markReach'。 |
-| frame | number | 是 | 触发事件的帧数。 该值必须大于0。 |
-| callback | Callback\ | 是 | 使用callback方式异步返回被触发事件的回调。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------- | ---- | ------------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
+| active | boolean | 是 | 设备激活状态。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
```js
-audioCapturer.on('markReach', 1000, (position) => {
- if (position == 1000) {
- console.info('ON Triggered successfully');
+audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
+ if (err) {
+ console.error(`Failed to set the active status of the device. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the device is set to the active status.');
});
```
-### off('markReach')8+
+### setDeviceActive(deprecated)
-off(type: 'markReach'): void
+setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void>
-取消订阅标记到达的事件。
+设置设备激活状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[setCommunicationDevice](#setcommunicationdevice9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :----- | :----- | :--- | :-------------------------------------------- |
-| type | string | 是 | 取消事件回调类型,支持的事件为:'markReach'。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------- | ---- | ------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
+| active | boolean | 是 | 设备激活状态。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
**示例:**
+
```js
-audioCapturer.off('markReach');
+audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
+ console.info('Promise returned to indicate that the device is set to the active status.');
+});
```
-### on('periodReach')8+
+### isDeviceActive(deprecated)
-on(type: "periodReach", frame: number, callback: Callback<number>): void
+isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): void
-订阅到达标记的事件。 当采集的帧数达到 frame 参数的值时,回调被循环调用。
+获取指定设备的激活状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :----------------------- | :--- | :------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'periodReach'。 |
-| frame | number | 是 | 触发事件的帧数。 该值必须大于0。 |
-| callback | Callback\ | 是 | 使用callback方式异步返回被触发事件的回调 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------- | ---- | ------------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
+| callback | AsyncCallback<boolean> | 是 | 回调返回设备的激活状态。 |
**示例:**
```js
-audioCapturer.on('periodReach', 1000, (position) => {
- if (position == 1000) {
- console.info('ON Triggered successfully');
+audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
+ if (err) {
+ console.error(`Failed to obtain the active status of the device. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the active status of the device is obtained.');
});
```
-### off('periodReach')8+
+### isDeviceActive(deprecated)
-off(type: 'periodReach'): void
+isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean>
-取消订阅标记到达的事件。
+获取指定设备的激活状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[isCommunicationDeviceActive](#iscommunicationdeviceactive9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :----- | :----- | :--- | :---------------------------------------------- |
-| type | string | 是 | 取消事件回调类型,支持的事件为:'periodReach'。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| ---------- | ------------------------------------- | ---- | ------------------ |
+| deviceType | [ActiveDeviceType](#activedevicetype) | 是 | 活跃音频设备类型。 |
+
+**返回值:**
+
+| Type | Description |
+| ---------------------- | ------------------------------- |
+| Promise<boolean> | Promise回调返回设备的激活状态。 |
**示例:**
```js
-audioCapturer.off('periodReach')
+audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
+ console.info(`Promise returned to indicate that the active status of the device is obtained ${value}.`);
+});
```
-### on('stateChange') 8+
+### setMicrophoneMute(deprecated)
-on(type: 'stateChange', callback: Callback): void
+setMicrophoneMute(mute: boolean, callback: AsyncCallback<void>): void
-订阅监听状态变化。
+设置麦克风静音状态,使用callback方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Capturer
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setMicrophoneMute](#setmicrophonemute9)替代。
+
+**需要权限:** ohos.permission.MICROPHONE
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------------- | :--- | :------------------------------------------ |
-| type | string | 是 | 事件回调类型,支持的事件为:'stateChange'。 |
-| callback | [AudioState](#audiostate8) | 是 | 返回监听的状态。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ------------------------- | ---- | --------------------------------------------- |
+| mute | boolean | 是 | 待设置的静音状态,true为静音,false为非静音。 |
+| callback | AsyncCallback<void> | 是 | 回调返回设置成功或失败。 |
**示例:**
```js
-audioCapturer.on('stateChange', (state) => {
- if (state == 1) {
- console.info('audio capturer state is: STATE_PREPARED');
- }
- if (state == 2) {
- console.info('audio capturer state is: STATE_RUNNING');
+audioManager.setMicrophoneMute(true, (err) => {
+ if (err) {
+ console.error(`Failed to mute the microphone. ${err}`);
+ return;
}
+ console.info('Callback invoked to indicate that the microphone is muted.');
});
```
-## ToneType 9+
+### setMicrophoneMute(deprecated)
-枚举,播放器的音调类型。
+setMicrophoneMute(mute: boolean): Promise<void>
+
+设置麦克风静音状态,使用Promise方式异步返回结果。
+
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[setMicrophoneMute](#setmicrophonemute9)替代。
+
+**需要权限:** ohos.permission.MICROPHONE
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| ------ | ------- | ---- | --------------------------------------------- |
+| mute | boolean | 是 | 待设置的静音状态,true为静音,false为非静音。 |
+
+**返回值:**
+
+| 类型 | 说明 |
+| ------------------- | ------------------------------- |
+| Promise<void> | Promise回调返回设置成功或失败。 |
-**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Tone
+**示例:**
-| 名称 | 默认值 | 描述 |
-| :------------------------------------------------ | :----- | :----------------------------|
-| TONE_TYPE_DIAL_0 | 0 | 键0的DTMF音。 |
-| TONE_TYPE_DIAL_1 | 1 | 键1的DTMF音。 |
-| TONE_TYPE_DIAL_2 | 2 | 键2的DTMF音。 |
-| TONE_TYPE_DIAL_3 | 3 | 键3的DTMF音。 |
-| TONE_TYPE_DIAL_4 | 4 | 键4的DTMF音。 |
-| TONE_TYPE_DIAL_5 | 5 | 键5的DTMF音。 |
-| TONE_TYPE_DIAL_6 | 6 | 键6的DTMF音。 |
-| TONE_TYPE_DIAL_7 | 7 | 键7的DTMF音。 |
-| TONE_TYPE_DIAL_8 | 8 | 键8的DTMF音。 |
-| TONE_TYPE_DIAL_9 | 9 | 键9的DTMF音。 |
-| TONE_TYPE_DIAL_S | 10 | 键*的DTMF音。 |
-| TONE_TYPE_DIAL_P | 11 | 键#的DTMF音。 |
-| TONE_TYPE_DIAL_A | 12 | 键A的DTMF音。 |
-| TONE_TYPE_DIAL_B | 13 | 键B的DTMF音。 |
-| TONE_TYPE_DIAL_C | 14 | 键C的DTMF音。 |
-| TONE_TYPE_DIAL_D | 15 | 键D的DTMF音。 |
-| TONE_TYPE_COMMON_SUPERVISORY_DIAL | 100 | 呼叫监管音调,拨号音。 |
-| TONE_TYPE_COMMON_SUPERVISORY_BUSY | 101 | 呼叫监管音调,忙。 |
-| TONE_TYPE_COMMON_SUPERVISORY_CONGESTION | 102 | 呼叫监管音调,拥塞。 |
-| TONE_TYPE_COMMON_SUPERVISORY_RADIO_ACK | 103 | 呼叫监管音调,无线电 ACK。 |
-| TONE_TYPE_COMMON_SUPERVISORY_RADIO_NOT_AVAILABLE | 104 | 呼叫监管音调,无线电不可用。 |
-| TONE_TYPE_COMMON_SUPERVISORY_CALL_WAITING | 106 | 呼叫监管音调,呼叫等待。 |
-| TONE_TYPE_COMMON_SUPERVISORY_RINGTONE | 107 | 呼叫监管音调,铃声。 |
-| TONE_TYPE_COMMON_PROPRIETARY_BEEP | 200 | 专有声调,一般蜂鸣声。 |
-| TONE_TYPE_COMMON_PROPRIETARY_ACK | 201 | 专有声调,ACK。 |
-| TONE_TYPE_COMMON_PROPRIETARY_PROMPT | 203 | 专有声调,PROMPT。 |
-| TONE_TYPE_COMMON_PROPRIETARY_DOUBLE_BEEP | 204 | 专有声调,双重蜂鸣声。 |
+```js
+audioManager.setMicrophoneMute(true).then(() => {
+ console.info('Promise returned to indicate that the microphone is muted.');
+});
+```
-## TonePlayer9+
+### isMicrophoneMute(deprecated)
-提供播放和管理DTMF(Dual Tone Multi Frequency,双音多频)音调的方法,包括各种系统监听音调、专有音调,如拨号音、通话回铃音等。
+isMicrophoneMute(callback: AsyncCallback<boolean>): void
-### load9+
+获取麦克风静音状态,使用callback方式异步返回结果。
-load(type: ToneType, callback: AsyncCallback<void>): void
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
-加载DTMF音调配置。使用callback方式异步返回结果。
+**需要权限:** ohos.permission.MICROPHONE
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :--------------| :-------------------------- | :-----| :------------------------------ |
-| type | ToneType(#tonetype9) | 是 | 配置的音调类型。 |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------- | ---- | ------------------------------------------------------- |
+| callback | AsyncCallback<boolean> | 是 | 回调返回系统麦克风静音状态,true为静音,false为非静音。 |
**示例:**
```js
-tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_5, (err) => {
+audioManager.isMicrophoneMute((err, value) => {
if (err) {
- console.error(`callback call load failed error: ${err.message}`);
+ console.error(`Failed to obtain the mute status of the microphone. ${err}`);
return;
- } else {
- console.info('callback call load success');
}
+ console.info(`Callback invoked to indicate that the mute status of the microphone is obtained ${value}.`);
});
```
-### load9+
+### isMicrophoneMute(deprecated)
-load(type: ToneType): Promise<void>
+isMicrophoneMute(): Promise<boolean>
-加载DTMF音调配置。使用Promise方式异步返回结果。
+获取麦克风静音状态,使用Promise方式异步返回结果。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[isMicrophoneMute](#ismicrophonemute9)替代。
-**参数:**
+**需要权限:** ohos.permission.MICROPHONE
-| 参数名 | 类型 | 必填 | 说明 |
-| :------------- | :--------------------- | :--- | ---------------- |
-| type | ToneType(#tonetype9) | 是 | 配置的音调类型。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**返回值:**
-| 类型 | 说明 |
-| :--------------| :-------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+| 类型 | 说明 |
+| ---------------------- | ------------------------------------------------------------ |
+| Promise<boolean> | Promise回调返回系统麦克风静音状态,true为静音,false为非静音。 |
**示例:**
```js
-tonePlayer.load(audio.ToneType.TONE_TYPE_DIAL_1).then(() => {
- console.info('promise call load ');
-}).catch(() => {
- console.error('promise call load fail');
+audioManager.isMicrophoneMute().then((value) => {
+ console.info(`Promise returned to indicate that the mute status of the microphone is obtained ${value}.`);
});
```
-### start9+
+### on('volumeChange')(deprecated)
-start(callback: AsyncCallback<void>): void
+on(type: 'volumeChange', callback: Callback\): void
-启动DTMF音调播放。使用callback方式异步返回结果。
+> **说明:**
+> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeManager中的[on](#on9)替代。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+监听系统音量变化事件。
+
+**系统接口:** 该接口为系统接口
+
+目前此订阅接口在单进程多AudioManager实例的使用场景下,仅最后一个实例的订阅生效,其他实例的订阅会被覆盖(即使最后一个实例没有进行订阅),因此推荐使用单一AudioManager实例进行开发。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Volume
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :----------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'volumeChange'(系统音量变化事件,检测到系统音量改变时,触发该事件)。 |
+| callback | Callback<[VolumeEvent](#volumeevent8)> | 是 | 回调方法。 |
**示例:**
```js
-tonePlayer.start((err) => {
- if (err) {
- console.error(`callback call start failed error: ${err.message}`);
- return;
- } else {
- console.info('callback call start success');
- }
+audioManager.on('volumeChange', (volumeEvent) => {
+ console.info(`VolumeType of stream: ${volumeEvent.volumeType} `);
+ console.info(`Volume level: ${volumeEvent.volume} `);
+ console.info(`Whether to updateUI: ${volumeEvent.updateUi} `);
});
```
-### start9+
+### on('ringerModeChange')(deprecated)
-start(): Promise<void>
+on(type: 'ringerModeChange', callback: Callback\): void
-启动DTMF音调播放。使用Promise方式异步返回结果。
+监听铃声模式变化事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 8 开始支持,从 API version 9 开始废弃,建议使用AudioVolumeGroupManager中的[on('ringerModeChange')](#onringermodechange9)替代。
-**返回值:**
+**系统接口:** 该接口为系统接口
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+**系统能力:** SystemCapability.Multimedia.Audio.Communication
+
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 事件回调类型,支持的事件为:'ringerModeChange'(铃声模式变化事件,检测到铃声模式改变时,触发该事件)。 |
+| callback | Callback<[AudioRingMode](#audioringmode)> | 是 | 回调方法。 |
**示例:**
```js
-tonePlayer.start().then(() => {
- console.info('promise call start');
-}).catch(() => {
- console.error('promise call start fail');
+audioManager.on('ringerModeChange', (ringerMode) => {
+ console.info(`Updated ringermode: ${ringerMode}`);
});
```
-### stop9+
+### on('deviceChange')(deprecated)
-stop(callback: AsyncCallback<void>): void
+on(type: 'deviceChange', callback: Callback): void
-停止当前正在播放的音调。使用callback方式异步返回结果。
+设备更改。音频设备连接状态变化。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[on](#on9)替代。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Device
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :----------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- |
+| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
+| callback | Callback<[DeviceChangeAction](#devicechangeaction)\> | 是 | 获取设备更新详情。 |
**示例:**
```js
-tonePlayer.stop((err) => {
- if (err) {
- console.error(`callback call stop error: ${err.message}`);
- return;
- } else {
- console.error('callback call stop success ');
- }
+audioManager.on('deviceChange', (deviceChanged) => {
+ console.info(`device change type : ${deviceChanged.type} `);
+ console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length} `);
+ console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole} `);
+ console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType} `);
});
```
-### stop9+
+### off('deviceChange')(deprecated)
-stop(): Promise<void>
+off(type: 'deviceChange', callback?: Callback): void
-停止当前正在播放的音调。使用Promise方式异步返回结果。
+取消订阅音频设备连接变化事件。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃,建议使用AudioRoutingManager中的[off](#off9)替代。
-**返回值:**
+**系统能力:** SystemCapability.Multimedia.Audio.Device
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | --------------------------------------------------- | ---- | ------------------------------------------ |
+| type | string | 是 | 订阅的事件的类型。支持事件:'deviceChange' |
+| callback | Callback<[DeviceChangeAction](#devicechangeaction)> | 否 | 获取设备更新详情。 |
**示例:**
```js
-tonePlayer.stop().then(() => {
- console.info('promise call stop finish');
-}).catch(() => {
- console.error('promise call stop fail');
+audioManager.off('deviceChange', (deviceChanged) => {
+ console.info('Should be no callback.');
});
```
-### release9+
+### on('interrupt')(deprecated)
-release(callback: AsyncCallback<void>): void
+on(type: 'interrupt', interrupt: AudioInterrupt, callback: Callback\): void
-释放与此TonePlay对象关联的资源。使用callback方式异步返回结果。
+请求焦点并开始监听音频打断事件(当应用程序的音频被另一个播放事件中断,回调通知此应用程序)。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃。
+
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
**参数:**
-| 参数名 | 类型 | 必填 | 说明 |
-| :------- | :------------------- | :--- | :---------------------------- |
-| callback | AsyncCallback | 是 | 使用callback方式异步返回结果。 |
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
+| interrupt | AudioInterrupt | 是 | 音频打断事件类型的参数。 |
+| callback | Callback<[InterruptAction](#interruptaction)> | 是 | 音频打断事件回调方法。 |
**示例:**
```js
-tonePlayer.release((err) => {
- if (err) {
- console.error(`callback call release failed error: ${err.message}`);
- return;
- } else {
- console.info('callback call release success ');
+let interAudioInterrupt = {
+ streamUsage:2,
+ contentType:0,
+ pauseWhenDucked:true
+};
+audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
+ if (InterruptAction.actionType === 0) {
+ console.info('An event to gain the audio focus starts.');
+ console.info(`Focus gain event: ${InterruptAction} `);
+ }
+ if (InterruptAction.actionType === 1) {
+ console.info('An audio interruption event starts.');
+ console.info(`Audio interruption event: ${InterruptAction} `);
}
});
```
-### release9+
+### off('interrupt')(deprecated)
-release(): Promise<void>
+off(type: 'interrupt', interrupt: AudioInterrupt, callback?: Callback\): void
-释放与此TonePlay对象关联的资源。使用Promise方式异步返回结果。
+取消监听音频打断事件(删除监听事件,取消打断)。
-**系统能力:** SystemCapability.Multimedia.Audio.Tone
+> **说明:**
+> 从 API version 7 开始支持,从 API version 9 开始废弃。
-**返回值:**
+**系统能力:** SystemCapability.Multimedia.Audio.Renderer
-| 类型 | 说明 |
-| :------------- | :---------------------------- |
-| Promise | 使用Promise方式异步返回结果。 |
+**参数:**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | 是 | 音频打断事件回调类型,支持的事件为:'interrupt'(多应用之间第二个应用会打断第一个应用,触发该事件)。 |
+| interrupt | AudioInterrupt | 是 | 音频打断事件类型的参数。 |
+| callback | Callback<[InterruptAction](#interruptaction)> | 否 | 音频打断事件回调方法。 |
**示例:**
```js
-tonePlayer.release().then(() => {
- console.info('promise call release');
-}).catch(() => {
- console.error('promise call release fail');
+let interAudioInterrupt = {
+ streamUsage:2,
+ contentType:0,
+ pauseWhenDucked:true
+};
+audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
+ if (InterruptAction.actionType === 0) {
+ console.info('An event to release the audio focus starts.');
+ console.info(`Focus release event: ${InterruptAction} `);
+ }
});
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-bundle-defaultAppManager.md b/zh-cn/application-dev/reference/apis/js-apis-bundle-defaultAppManager.md
index 1508fd7c192fc20c0c38699176d3fe0b6c1206c3..202f1042a292d31e6882f77383e71cc1a936cd33 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-bundle-defaultAppManager.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-bundle-defaultAppManager.md
@@ -9,7 +9,7 @@
## 导入模块
```
-import defaultAppMgr from '@ohos.bundle.defaultAppManager'
+import defaultAppMgr from '@ohos.bundle.defaultAppManager';
```
## defaultAppMgr.ApplicationType
diff --git a/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md b/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
index 80e40eb4bb410bf40425842e56f0e7a0bf9a8582..d8e5e1b251feb62851336d77d58c040d39b77b9c 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md
@@ -60,7 +60,7 @@ buffer数组的列表。
## EncodingBlob
-证书链数据,在证书链校验时,作为入参传入。
+带编码格式的证书二进制数组。
### 属性
@@ -1029,7 +1029,7 @@ console.info("key hex:" + uint8ArrayToShowStr(encodedKey.data)); // 输出全
getEncoded() : DataBlob
-以同步方法,获取二进制形式的密钥内容。
+以同步方法,获取二进制形式的密钥内容。公钥格式满足ASN.1语法、X.509规范、DER编码格式。
**系统能力:** SystemCapability.Security.CryptoFramework
@@ -1065,7 +1065,7 @@ console.info("key encoded:" + Uint8ArrayToShowStr(encodedKey.data));
getEncoded() : DataBlob
-以同步方法,获取二进制形式的密钥内容。
+以同步方法,获取二进制形式的密钥内容。私钥格式满足ASN.1语法,PKCS#8规范、DER编码方式。
**系统能力:** SystemCapability.Security.CryptoFramework
@@ -1437,11 +1437,9 @@ keyGenPromise.then( keyPair => {
**密钥转换说明**
-1. RSA二进制密钥数据,按keysize(32位) ,nsize(keysize/8), esize(e实际长度),dsize(keysize/8),nval(大数n的二进制数据),eval(大数e的二进制数据),dval(大数d的二进制数据)拼接形成。
-2. RSA二进制密钥数据中,nsize和dsize为密钥位数/8,esize为具体的实际长度。
-3. RSA私钥数据需要包含keysize,nsize,esize,dsize,nval,eval,dval的全部数据,公钥材料中dsize设置为0,缺省dval的数据。
-4. RSA二进制密钥数据中,keysize、nsize、esize和dsize为32位二进制数据,数据的大小端格式请按设备CPU默认格式,密钥材料(nval、eval、dval)统一为大端格式。
-5. convertKey接口中,公钥和私钥二进制数据为可选项,可单独传入公钥或私钥的数据,生成对应只包含公钥或私钥的KeyPair对象。
+1. 非对称密钥(RSA、ECC)的公钥和私钥调用getEncoded()方法后,分别返回X.509格式和PKCS#8格式的二进制数据,此数据可用于跨应用传输或持久化存储。
+2. 当调用convertKey方法将外来二进制数据转换为算法库非对称密钥对象时,公钥应满足ASN.1语法、X.509规范、DER编码格式,私钥应满足ASN.1语法、PKCS#8规范、DER编码格式。
+3. convertKey方法中,公钥和密钥二进制数据非必选项,可单独传入公钥或私钥的数据,生成对应只包含公钥或私钥的KeyPair对象。
## cryptoFramework.createCipher
diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md b/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md
index 38b19761bb45edb344fac038c4dd78e11a075d82..80e01c8b59697f412eb6f10f1a8b0f844fae0b2f 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-fileAccess.md
@@ -77,10 +77,12 @@ createFileAccessHelper(context: Context, wants: Array<Want>) : FileAccessH
let fileAccesssHelper = null;
// wantInfo 从getFileAccessAbilityInfo()获取
// 创建只连接媒体库服务的helper对象
- let wantInfo = {
- "bundleName": "com.ohos.medialibrary.medialibrarydata",
- "abilityName": "FileExtensionAbility",
- }
+ let wantInfos = [
+ {
+ "bundleName": "com.ohos.medialibrary.medialibrarydata",
+ "abilityName": "FileExtensionAbility",
+ },
+ ]
try {
fileAccesssHelper = fileAccess.createFileAccessHelper(this.context, wantInfos);
if (!fileAccesssHelper)
@@ -211,7 +213,7 @@ listFile(filter?: Filter) : FileIterator
let fileIterator = rootInfo.listFile();
// 含过滤器实现的listFile
// let fileIterator = rootInfo.listFile(filter);
- if (fileIterator) {
+ if (!fileIterator) {
console.error("listFile interface returns an undefined object");
return;
}
@@ -261,7 +263,7 @@ scanFile(filter?: Filter) : FileIterator
let fileIterator = rootInfo.scanFile();
// 含过滤器实现的scanFile
// let fileIterator = rootInfo.scanFile(filter);
- if (fileIterator) {
+ if (!fileIterator) {
console.error("scanFile interface returns undefined object");
return;
}
@@ -311,7 +313,7 @@ listFile(filter?: Filter) : FileIterator
let fileIterator = fileInfoDir.listFile();
// 含过滤器实现的listFile
// let fileIterator = rootInfo.listFile(filter);
- if (fileIterator) {
+ if (!fileIterator) {
console.error("listFile interface returns an undefined object");
return;
}
@@ -362,7 +364,7 @@ scanFile(filter?: Filter) : FileIterator;
let fileIterator = fileInfoDir.scanFile();
// 含过滤器实现的scanFile
// let fileIterator = rootInfo.scanFile(filter);
- if (fileIterator) {
+ if (!fileIterator) {
console.error("scanFile interface returns an undefined object");
return;
}
@@ -451,12 +453,12 @@ mkDir(parentUri: string, displayName: string) : Promise<string>
let dirName = "dirTest"
let dirUri = null;
try {
- dirUri = await fileAccessHelper.mkDir(sourceUri, displayName)
+ dirUri = await fileAccessHelper.mkDir(sourceUri, dirName)
if (!dirUri) {
console.error("mkDir return undefined object");
return;
}
- console.log("mkDir sucess, fileUri: " + JSON.stringify(fileUri));
+ console.log("mkDir sucess, dirUri: " + JSON.stringify(dirUri));
} catch (error) {
console.error("mkDir failed, error " + error);
};
diff --git a/zh-cn/application-dev/reference/apis/js-apis-fileio.md b/zh-cn/application-dev/reference/apis/js-apis-fileio.md
index 25d4499022f4a77670b49ac4f79ddae7d27316b1..9ba948beaccf86693e6d13fe257ab5554212659b 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-fileio.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-fileio.md
@@ -68,7 +68,7 @@ stat(path: string): Promise<Stat>
```js
let filePath = pathDir + "test.txt";
fileio.stat(filePath).then(function(stat){
- console.info("getFileInfo succeed:"+ JSON.stringify(stat));
+ console.info("getFileInfo succeed, the size of file is " + stat.size);
}).catch(function(err){
console.info("getFileInfo failed with error:"+ err);
});
@@ -153,7 +153,7 @@ opendir(path: string): Promise<Dir>
```js
let dirPath = pathDir + "/testDir";
fileio.opendir(dirPath).then(function(dir){
- console.info("opendir succeed:"+ JSON.stringify(dir));
+ console.info("opendir succeed");
}).catch(function(err){
console.info("opendir failed with error:"+ err);
});
@@ -1178,7 +1178,7 @@ fstat(fd: number): Promise<Stat>
let filePath = pathDir + "/test.txt";
let fd = fileio.openSync(filePath);
fileio.fstat(fd).then(function(stat){
- console.info("fstat succeed:"+ JSON.stringify(stat));
+ console.info("fstat succeed, the size of file is "+ stat.size);
}).catch(function(err){
console.info("fstat failed with error:"+ err);
});
@@ -1525,7 +1525,7 @@ lstat(path: string): Promise<Stat>
```js
let filePath = pathDir + "/test.txt";
fileio.lstat(filePath).then(function(stat){
- console.info("get link status succeed:"+ JSON.stringify(stat));
+ console.info("get link status succeed, " + the size of file is + stat.size);
}).catch(function(err){
console.info("get link status failed with error:"+ err);
});
@@ -3166,7 +3166,7 @@ read(): Promise<Dirent>
```js
dir.read().then(function (dirent){
- console.log("read succeed:"+JSON.stringify(dirent));
+ console.log("read succeed, the name of dirent is " + dirent.name);
}).catch(function(err){
console.info("read failed with error:"+ err);
});
@@ -3193,7 +3193,7 @@ read(callback: AsyncCallback<Dirent>): void
dir.read(function (err, dirent) {
if (dirent) {
// do something
- console.log("read succeed:"+JSON.stringify(dirent));
+ console.log("read succeed, the name of file is " + dirent.name);
}
});
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
index 2551e73891f1692e7589c807e52a2dc44cef6de9..96022038df5110f77024b83733eec4c9e126267e 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md
@@ -1,6 +1,6 @@
# 组合按键
-InputConsumer模块提供对按键事件的监听。
+组合按键订阅模块,用于处理组合按键的订阅。
> **说明:**
>
@@ -21,7 +21,7 @@ import inputConsumer from '@ohos.multimodalInput.inputConsumer';
on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): void
-开始监听组合按键事件, 当满足条件的组合按键输入事件发生时,将keyOptions回调到入参callback表示的回调函数上。
+订阅组合按键,当满足条件的组合按键输入事件发生时,使用Callback异步方式上报组合按键数据。
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
@@ -29,22 +29,20 @@ on(type: "key", keyOptions: KeyOptions, callback: Callback<KeyOptions>): v
| 参数 | 类型 | 必填 | 说明 |
| ---------- | -------------------------- | ---- | ---------------------------------------- |
-| type | string | 是 | 监听输入事件类型,只支持“key”。 |
-| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项,用来指定组合键输入时应该符合的条件。 |
-| callback | Callback<KeyOptions> | 是 | 回调函数。当满足条件的按键输入产生时,回调到此函数,以传入的KeyOptions为入参。 |
+| type | string | 是 | 事件类型,目前只支持”key“。 |
+| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项。 |
+| callback | Callback<KeyOptions> | 是 | 回调函数,当满足条件的组合按键输入事件发生时,异步上报组合按键数据。 |
**示例:**
```js
-let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
-let callback = function (keyOptions) {
- console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
- "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
-}
+let powerKeyCode = 18;
try {
- inputConsumer.on(inputConsumer.SubscribeType.KEY, keyOptions, callback);
+ inputConsumer.on("key", {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0}, keyOptions => {
+ console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
+ });
} catch (error) {
- console.info(`inputConsumer.on, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
+ console.log(`Subscribe failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -53,7 +51,7 @@ try {
off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>): void
-停止监听组合按键事件。
+取消订阅组合按键。
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
@@ -61,35 +59,49 @@ off(type: "key", keyOptions: KeyOptions, callback?: Callback<KeyOptions>):
| 参数 | 类型 | 必填 | 说明 |
| ---------- | -------------------------- | ---- | ------------------------------- |
-| type | string | 是 | 监听输入事件类型,只支持“key”。 |
-| keyOptions | [keyOptions](#keyoptions) | 是 | 开始监听时传入的keyOptions。 |
-| callback | Callback<KeyOptions> | 是 | 开始监听时与KeyOption一同传入的回调函数 。 |
+| type | string | 是 | 事件类型,当前只支持”key“。 |
+| keyOptions | [keyOptions](#keyoptions) | 是 | 组合键选项。 |
+| callback | Callback<KeyOptions> | 否 | 需要取消订阅的回调函数,若无此参数,则取消当前应用的组合键选项已订阅的所有回调函数。 |
**示例:**
```js
-let keyOptions = { preKeys: [], finalKey: 18, isFinalKeyDown: true, finalKeyDownDuration: 0 }
+// 取消订阅单个回调函数
+let callback = function (keyOptions) {
+ console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
+}
+let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
+try {
+ inputConsumer.on("key", keyOption, callback);
+ inputConsumer.off("key", keyOption, callback);
+} catch (error) {
+ console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
+}
+```
+```js
+// 取消订阅所有回调函数
let callback = function (keyOptions) {
- console.info("preKeys: " + keyOptions.preKeys, "finalKey: " + keyOptions.finalKey,
- "isFinalKeyDown: " + keyOptions.isFinalKeyDown, "finalKeyDownDuration: " + keyOptions.finalKeyDownDuration)
+ console.log(`keyOptions: ${JSON.stringify(keyOptions)}`);
}
+let keyOption = {preKeys: [], finalKey: powerKeyCode, isFinalKeyDown: true, finalKeyDownDuration: 0};
try {
- inputConsumer.off(inputConsumer.SubscribeType.KEY, keyOptions, callback);
+ inputConsumer.on("key", keyOption, callback);
+ inputConsumer.off("key", keyOption);
} catch (error) {
- console.info(`inputConsumer.off, error.code=${JSON.stringify(error.code)}, error.msg=${JSON.stringify(error.message)}`);
+ console.log(`Execute failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## KeyOptions
-组合键输入事件发生时,组合键满足的选项。
+组合键选项。
**系统能力:** SystemCapability.MultimodalInput.Input.InputConsumer
| 参数 | 类型 | 必填 | 说明 |
| -------------------- | ------- | ---- | ------------------------ |
-| preKeys | Array | 是 | 组合键前置按键集合,可为空,前置按键无顺序要求。 |
-| finalKey | Number | 是 | 组合键最后按键,不能为空。 |
-| isFinalKeyDown | boolean | 是 | 组合键最后按键是按下还是抬起,默认是按下。 |
-| finalKeyDownDuration | Number | 是 | 组合键最后按键按下持续时长,默认无时长要求。 |
+| preKeys | Array | 是 | 前置按键集合,数量范围[0, 4],前置按键无顺序要求。 |
+| finalKey | Number | 是 | 最终按键,此项必填,最终按键触发上报回调函数。 |
+| isFinalKeyDown | boolean | 是 | 最终按键状态。 |
+| finalKeyDownDuration | Number | 是 | 最终按键保持按下持续时间,为0时立即触发回调函数,大于0时,当isFinalKeyDown为true,则最终按键按下超过此时长后触发回调函数,当isFinalKeyDown为false,则最终按键按下到抬起时间小于此时长时触发回调函数。 |
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md b/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
index b255b0a2f4a3fc86fb06170ae182267c33d3c339..5ddc299f650e5fed2f429f7cbd1458c3d9f552f3 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputdevice.md
@@ -1,7 +1,7 @@
# 输入设备
-输入设备管理模块,用于监听输入设备连接、断开和变化,并查看输入设备相关信息。比如监听鼠标插拔,并获取鼠标的id、name和指针移动速度等信息。
+输入设备管理模块,用于监听输入设备连接和断开状态,查询输入设备相关信息。
> **说明**:
@@ -20,15 +20,15 @@ import inputDevice from '@ohos.multimodalInput.inputDevice';
getDeviceList(callback: AsyncCallback<Array<number>>): void
-获取所有输入设备的id列表,使用callback方式作为异步方法。
+获取所有输入设备的id列表,使用AsyncCallback异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------- | ---- | ---------- |
-| callback | AsyncCallback<Array<number>> | 是 | 回调函数。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
+| callback | AsyncCallback<Array<number>> | 是 | 回调函数,异步返回所有输入设备的id列表。 |
**示例**:
@@ -36,15 +36,13 @@ getDeviceList(callback: AsyncCallback<Array<number>>): void
try {
inputDevice.getDeviceList((error, ids) => {
if (error) {
- console.log(`Failed to get device list.
- error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
- this.data = ids;
- console.log("The device ID list is: " + ids);
+ console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
- console.info("getDeviceList " + error.code + " " + error.message);
+ console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -52,25 +50,25 @@ try {
getDeviceList(): Promise<Array<number>>
-获取所有输入设备的id列表,使用Promise方式作为异步方法。
+获取所有输入设备的id列表,使用Promise异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**返回值**:
-| 参数 | 说明 |
-| ---------------------------------- | ------------------------------- |
-| Promise<Array<number>> | Promise实例,用于异步获取结果。 |
+| 参数 | 说明 |
+| ---------------------------------- | ------------------------------------------- |
+| Promise<Array<number>> | Promise对象,异步返回所有输入设备的id列表。 |
**示例**:
```js
try {
inputDevice.getDeviceList().then((ids) => {
- console.log("The device ID list is: " + ids);
+ console.log(`Device id list: ${JSON.stringify(ids)}`);
});
} catch (error) {
- console.info("getDeviceList " + error.code + " " + error.message);
+ console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -78,7 +76,7 @@ try {
getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
-获取输入设备的描述信息,使用callback方式作为异步方法。
+获取指定输入设备的信息,使用AsyncCallback异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
@@ -86,24 +84,23 @@ getDeviceInfo(deviceId: number, callback: AsyncCallback<InputDeviceData>):
| 参数 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------------------- | ---- | --------------------------------------- |
-| deviceId | number | 是 | 需要获取信息的设备id。 |
-| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回InputDeviceData对象。 |
+| deviceId | number | 是 | 输入设备id。 |
+| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回输入设备信息。 |
**示例**:
```js
-// 示例获取设备id为1的设备name信息。
+// 获取输入设备id为1的设备信息。
try {
- inputDevice.getDeviceInfo(1, (error, inputDevice) => {
+ inputDevice.getDeviceInfo(1, (error, deviceData) => {
if (error) {
- console.log(`Failed to get device information.
- error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
- console.log("The device name is: " + inputDevice.name);
+ console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
- console.info("getDeviceInfo " + error.code + " " + error.message);
+ console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -111,7 +108,7 @@ try {
getDeviceInfo(deviceId: number): Promise<InputDeviceData>
-获取输入设备的描述信息,使用Promise方式作为异步方法。
+获取指定输入设备的信息,使用Promise异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
@@ -119,30 +116,30 @@ getDeviceInfo(deviceId: number): Promise<InputDeviceData>
| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- |
-| deviceId | number | 是 | 需要获取信息的设备id。 |
+| deviceId | number | 是 | 输入设备id。 |
**返回值**:
| 参数 | 说明 |
| -------------------------------------------------- | ------------------------------- |
-| Promise<[InputDeviceData](#inputdevicedata)> | Promise实例,用于异步获取结果。 |
+| Promise<[InputDeviceData](#inputdevicedata)> | Promise对象,异步返回输入设备信息。 |
**示例**:
```js
-// 示例获取设备id为1的设备name信息。
+// 获取输入设备id为1的设备信息。
try {
- inputDevice.getDeviceInfo(id).then((inputDevice) => {
- console.log("The device name is: " + inputDevice.name);
+ inputDevice.getDeviceInfo(1).then((deviceData) => {
+ console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
} catch (error) {
- console.info("getDeviceInfo " + error.code + " " + error.message);
+ console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.on9+
-on(type: “change”, listener: Callback<DeviceListener>): void
+on(type: "change", listener: Callback<DeviceListener>): void
监听输入设备的热插拔事件。
@@ -153,7 +150,7 @@ on(type: “change”, listener: Callback<DeviceListener>): void
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 |
-| listener | Callback<[DeviceListener](#devicelistener9)> | 是 | 可上报的输入设备事件。 |
+| listener | Callback<[DeviceListener](#devicelistener9)> | 是 | 回调函数,异步上报输入设备热插拔事件。 |
**示例**:
@@ -161,13 +158,13 @@ on(type: “change”, listener: Callback<DeviceListener>): void
let isPhysicalKeyboardExist = true;
try {
inputDevice.on("change", (data) => {
- console.log("type: " + data.type + ", deviceId: " + data.deviceId);
- inputDevice.getKeyboardType(data.deviceId, (err, ret) => {
- console.log("The keyboard type of the device is: " + ret);
- if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
+ console.log(`Device event info: ${JSON.stringify(data)}`);
+ inputDevice.getKeyboardType(data.deviceId, (err, type) => {
+ console.log("The keyboard type is: " + type);
+ if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'add') {
// 监听物理键盘已连接。
isPhysicalKeyboardExist = true;
- } else if (ret == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
+ } else if (type == inputDevice.KeyboardType.ALPHABETIC_KEYBOARD && data.type == 'remove') {
// 监听物理键盘已断开。
isPhysicalKeyboardExist = false;
}
@@ -175,13 +172,13 @@ try {
});
// 根据isPhysicalKeyboardExist的值决定软键盘是否弹出。
} catch (error) {
- console.info("oninputdevcie " + error.code + " " + error.message);
+ console.log(`Get device info failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## inputDevice.off9+
-off(type: “change”, listener?: Callback<DeviceListener>): void
+off(type: "change", listener?: Callback<DeviceListener>): void
取消监听输入设备的热插拔事件。
@@ -192,42 +189,41 @@ off(type: “change”, listener?: Callback<DeviceListener>): void
| 参数 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ----------- |
| type | string | 是 | 输入设备的事件类型。 |
-| listener | Callback<[DeviceListener](#devicelistener9)> | 否 | 可上报的输入设备事件。 |
+| listener | Callback<[DeviceListener](#devicelistener9)> | 否 | 取消监听的回调函数。 |
**示例**:
```js
callback: function(data) {
- console.log("type: " + data.type + ", deviceId: " + data.deviceId);
+ console.log(`Report device event info: ${JSON.stringify(data, [`type`, `deviceId`])}`);
}
try {
inputDevice.on("change", this.callback);
} catch (error) {
- console.info("oninputdevcie " + error.code + " " + error.message)
+ console.log(`Listen device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
-// 单独取消listener的监听。
+// 取消指定的监听。
try {
inputDevice.off("change", this.callback);
} catch (error) {
- console.info("offinputdevcie " + error.code + " " + error.message)
+ console.log(`Cancel listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 取消所有监听。
try {
inputDevice.off("change");
} catch (error) {
- console.info("offinputdevcie " + error.code + " " + error.message);
+ console.log(`Cancel all listening device event failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
-// 取消监听后,软键盘默认都弹出。
```
## inputDevice.getDeviceIds(deprecated)
getDeviceIds(callback: AsyncCallback<Array<number>>): void
-获取所有输入设备的id列表,使用callback方式作为异步方法。
+获取所有输入设备的id列表,使用AsyncCallback异步方式返回结果。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
@@ -235,15 +231,19 @@ getDeviceIds(callback: AsyncCallback<Array<number>>): void
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------- | ---- | ----- |
-| callback | AsyncCallback<Array<number>> | 是 | 回调函数。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ---------------------------------------- | ---- | ---------------------------------------- |
+| callback | AsyncCallback<Array<number>> | 是 | 回调函数,异步返回所有输入设备的id列表。 |
**示例**:
```js
-inputDevice.getDeviceIds((ids)=>{
- console.log("The device ID list is: " + ids);
+inputDevice.getDeviceList((error, ids) => {
+ if (error) {
+ console.log(`Failed to get device id list, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ return;
+ }
+ console.log(`Device id list: ${JSON.stringify(ids)}`);
});
```
@@ -251,7 +251,7 @@ inputDevice.getDeviceIds((ids)=>{
getDeviceIds(): Promise<Array<number>>
-获取所有输入设备的id列表,使用Promise方式作为异步方法。
+获取所有输入设备的id列表,使用Promise异步方式返回结果。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceList](#inputdevicegetdevicelist9)代替。
@@ -259,15 +259,15 @@ getDeviceIds(): Promise<Array<number>>
**返回值**:
-| 参数 | 说明 |
-| ---------------------------------- | ------------------- |
-| Promise<Array<number>> | Promise实例,用于异步获取结果。 |
+| 参数 | 说明 |
+| ---------------------------------- | ------------------------------------------- |
+| Promise<Array<number>> | Promise对象,异步返回所有输入设备的id列表。 |
**示例**:
```js
-inputDevice.getDeviceIds().then((ids)=>{
- console.log("The device ID list is: " + ids);
+inputDevice.getDeviceList().then((ids) => {
+ console.log(`Device id list: ${JSON.stringify(ids)}`);
});
```
@@ -275,7 +275,7 @@ inputDevice.getDeviceIds().then((ids)=>{
getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): void
-获取输入设备的描述信息,使用callback方式作为异步方法。
+获取指定输入设备的信息,使用AsyncCallback异步方式返回结果。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
@@ -283,17 +283,21 @@ getDevice(deviceId: number, callback: AsyncCallback<InputDeviceData>): voi
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------- | ---- | --------------------------- |
-| deviceId | number | 是 | 需要获取信息的设备id。 |
-| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回InputDeviceData对象。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | -------------------------------------------------------- | ---- | -------------------------------- |
+| deviceId | number | 是 | 输入设备id。 |
+| callback | AsyncCallback<[InputDeviceData](#inputdevicedata)> | 是 | 回调函数,异步返回输入设备信息。 |
**示例**:
```js
-// 示例获取设备id为1的设备name信息。
-inputDevice.getDevice(1, (inputDevice)=>{
- console.log("The device name is: " + inputDevice.name);
+// 获取输入设备id为1的设备信息。
+inputDevice.getDeviceInfo(1, (error, deviceData) => {
+ if (error) {
+ console.log(`Failed to get device info, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ return;
+ }
+ console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
```
@@ -301,7 +305,7 @@ inputDevice.getDevice(1, (inputDevice)=>{
getDevice(deviceId: number): Promise<InputDeviceData>
-获取输入设备的描述信息,使用Promise方式作为异步方法。
+获取指定输入设备的信息,使用Promise异步方式返回结果。
从API version 9 开始不再维护,建议使用[inputDevice.getDeviceInfo](#inputdevicegetdeviceinfo9)代替。
@@ -309,22 +313,22 @@ getDevice(deviceId: number): Promise<InputDeviceData>
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
+| 参数 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
-| deviceId | number | 是 | 需要获取信息的设备id。 |
+| deviceId | number | 是 | 输入设备id。 |
**返回值**:
-| 参数 | 说明 |
-| ---------------------------------------- | ------------------- |
-| Promise<[InputDeviceData](#inputdevicedata)> | Promise实例,用于异步获取结果。 |
+| 参数 | 说明 |
+| -------------------------------------------------- | ----------------------------------- |
+| Promise<[InputDeviceData](#inputdevicedata)> | Promise对象,异步返回输入设备信息。 |
**示例**:
```js
-// 示例获取设备id为1的设备name信息。
-inputDevice.getDevice(1).then((inputDevice)=>{
- console.log("The device name is: " + inputDevice.name);
+// 获取输入设备id为1的设备信息。
+inputDevice.getDeviceInfo(1).then((deviceData) => {
+ console.log(`Device info: ${JSON.stringify(deviceData)}`);
});
```
@@ -332,28 +336,28 @@ inputDevice.getDevice(1).then((inputDevice)=>{
supportKeys(deviceId: number, keys: Array<KeyCode>, callback: Callback<Array<boolean>>): void
-获取输入设备支持的键码值,使用callback方式作为异步方法。
+获取输入设备是否支持指定的键码值,使用Callback异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | ------------------------------------ | ---- | --------------------------------- |
-| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
-| keys | Array<KeyCode> | 是 | 需要查询的键码值,最多支持5个按键查询。 |
-| callback | Callback<Array<boolean>> | 是 | 回调函数,异步返回查询结果。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ------------------------------------ | ---- | ------------------------------------------------------ |
+| deviceId | number | 是 | 输入设备id,同一个物理设备反复插拔,设备id会发生变化。 |
+| keys | Array<KeyCode> | 是 | 需要查询的键码值,最多支持5个按键查询。 |
+| callback | Callback<Array<boolean>> | 是 | 回调函数,异步返回查询结果。 |
**示例**:
```js
-// 示例查询id为1的设备对于17、22和2055按键的支持情况。
+// 查询id为1的输入设备对于17、22和2055按键的支持情况。
try {
- inputDevice.supportKeys(1, [17, 22, 2055], (error, ret) => {
- console.log("The query result is as follows: " + ret);
+ inputDevice.supportKeys(1, [17, 22, 2055], (error, supportResult) => {
+ console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
- console.info("supportKeys " + error.code + " " + error.message);
+ console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -361,33 +365,33 @@ try {
supportKeys(deviceId: number, keys: Array<KeyCode>): Promise<Array<boolean>>
-获取输入设备支持的键码值,使用Promise方式作为异步方法。
+获取输入设备是否支持指定的键码值,使用Promise异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | -------------------- | ---- | --------------------------------- |
-| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
-| keys | Array<KeyCode> | 是 | 需要查询的键码值,最多支持5个按键查询。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | -------------------- | ---- | ------------------------------------------------------ |
+| deviceId | number | 是 | 输入设备id,同一个物理设备反复插拔,设备id会发生变化。 |
+| keys | Array<KeyCode> | 是 | 需要查询的键码值,最多支持5个按键查询。 |
**返回值**:
-| 参数 | 说明 |
-| ----------------------------------- | ------------------- |
-| Promise<Array<boolean>> | Promise实例,用于异步获取结果。 |
+| 参数 | 说明 |
+| ----------------------------------- | ------------------------------- |
+| Promise<Array<boolean>> | Promise对象,异步返回查询结果。 |
**示例**:
```js
-// 示例查询id为1的设备对于17、22和2055按键的支持情况。
+// 查询id为1的输入设备对于17、22和2055按键的支持情况。
try {
- inputDevice.supportKeys(1, [17, 22, 2055]).then((ret) => {
- console.log("The query result is as follows: " + ret);
+ inputDevice.supportKeys(1, [17, 22, 2055]).then((supportResult) => {
+ console.log(`Query result: ${JSON.stringify(supportResult)}`);
});
} catch (error) {
- console.info("supportKeys " + error.code + " " + error.message);
+ console.log(`Query failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -395,32 +399,31 @@ try {
getKeyboardType(deviceId: number, callback: AsyncCallback<KeyboardType>): void
-查询输入设备的键盘类型,使用callback方式作为异步方法。
+获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
**参数**:
-| 参数 | 类型 | 必填 | 说明 |
-| -------- | ---------------------------------------- | ---- | --------------------------------- |
-| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
-| callback | AsyncCallback<[KeyboardType](#keyboardtype9)> | 是 | 回调函数,异步返回查询结果。 |
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
+| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
+| callback | AsyncCallback<[KeyboardType](#keyboardtype9)> | 是 | 回调函数,异步返回查询结果。 |
**示例**:
```js
-// 示例查询设备id为1的设备键盘类型。
+// 查询id为1的输入设备的键盘类型。
try {
- inputDevice.getKeyboardType(1, (error, number) => {
+ inputDevice.getKeyboardType(1, (error, type) => {
if (error) {
- console.log(`Failed to get keyboardtype.
- error code=${JSON.stringify(err.code)} msg=${JSON.stringify(err.message)}`);
+ console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
return;
}
- console.log("The keyboard type of the device is: " + number);
+ console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
- console.info("getKeyboardType " + error.code + " " + error.message);
+ console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -428,39 +431,45 @@ try {
getKeyboardType(deviceId: number): Promise<KeyboardType>
-查询输入设备的键盘类型,使用Promise方式作为异步方法。
+获取输入设备的键盘类型,使用AsyncCallback异步方式返回结果。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
+**参数**:
+
+| 参数 | 类型 | 必填 | 说明 |
+| -------- | ------ | ---- | ------------------------------------------------------------ |
+| deviceId | number | 是 | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
+
**返回值**:
-| 参数 | 说明 |
-| ---------------------------------------- | ------------------- |
-| Promise<[KeyboardType](#keyboardtype9)> | Promise实例,用于异步获取结果。 |
+| 参数 | 说明 |
+| --------------------------------------------- | ------------------------------- |
+| Promise<[KeyboardType](#keyboardtype9)> | Promise对象,异步返回查询结果。 |
**示例**:
```js
// 示例查询设备id为1的设备键盘类型。
try {
- inputDevice.getKeyboardType(1).then((number) => {
- console.log("The keyboard type of the device is: " + number);
+ inputDevice.getKeyboardType(1).then((type) => {
+ console.log(`Keyboard type: ${JSON.stringify(type)}`);
});
} catch (error) {
- console.info("getKeyboardType " + error.code + " " + error.message);
+ console.log(`Failed to get keyboard type, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## DeviceListener9+
-输入设备的描述信息。
+输入设备热插拔的描述信息。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
-| 名称 | 参数类型 | 说明 |
-| -------- | --------------------------- | --------------------------------- |
-| type | [ChangedType](#changedtype) | 表示输入设备插入或者移除。 |
-| deviceId | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
+| 名称 | 参数类型 | 说明 |
+| -------- | --------------------------- | ------------------------------------------------------------ |
+| type | [ChangedType](#changedtype) | 输入设备插入或者移除。 |
+| deviceId | number | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
## InputDeviceData
@@ -468,18 +477,18 @@ try {
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
-| 名称 | 参数类型 | 说明 |
-| -------------------- | -------------------------------------- | ---------------------------------------- |
-| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,其设备id会发生变化。 |
-| name | string | 输入设备的名字。 |
+| 名称 | 参数类型 | 说明 |
+| -------------------- | -------------------------------------- | ------------------------------------------------------------ |
+| id | number | 输入设备的唯一标识,同一个物理设备反复插拔,设备id会发生变化。 |
+| name | string | 输入设备的名字。 |
| sources | Array<[SourceType](#sourcetype)> | 输入设备支持的源类型。比如有的键盘上附带触摸板,则此设备有keyboard和touchpad两种输入源。 |
-| axisRanges | Array<[axisRanges](#axisrange)> | 输入设备的轴信息。 |
-| bus9+ | number | 输入设备的总线类型。 |
-| product9+ | number | 输入设备的产品信息。 |
-| vendor9+ | number | 输入设备的厂商信息。 |
-| version9+ | number | 输入设备的版本信息。 |
-| phys9+ | string | 输入设备的物理地址。 |
-| uniq9+ | string | 输入设备的唯一标识。 |
+| axisRanges | Array<[axisRanges](#axisrange)> | 输入设备的轴信息。 |
+| bus9+ | number | 输入设备的总线类型。 |
+| product9+ | number | 输入设备的产品信息。 |
+| vendor9+ | number | 输入设备的厂商信息。 |
+| version9+ | number | 输入设备的版本信息。 |
+| phys9+ | string | 输入设备的物理地址。 |
+| uniq9+ | string | 输入设备的唯一标识。 |
## AxisType9+
@@ -517,7 +526,7 @@ try {
## SourceType
-定义这个轴的输入源类型。比如鼠标设备可上报x轴事件,则x轴的源就是鼠标。
+轴的输入源类型。比如鼠标设备可上报x轴事件,则x轴的输入源就是鼠标。
**系统能力**:SystemCapability.MultimodalInput.Input.InputDevice
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md b/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
index 9654433e873c5803fb1d52def20ecd00e5efea07..80d1a26688e276daea5ed1572764368ef93fb8ba 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md
@@ -1,6 +1,6 @@
-# 注入按键
+# 按键注入
-InputEventClient模块提供了注入按键能力。
+按键注入模块,提供按键注入能力。
> **说明:**
>
@@ -21,7 +21,7 @@ import inputEventClient from '@ohos.multimodalInput.inputEventClient';
injectEvent({KeyEvent: KeyEvent}): void
-注入按键,KeyEvent为注入按键的描述信息。
+按键注入,当前仅支持返回键(键值2)注入。
**系统能力:** SystemCapability.MultimodalInput.Input.InputSimulator
@@ -29,41 +29,43 @@ injectEvent({KeyEvent: KeyEvent}): void
| 参数 | 类型 | 必填 | 说明 |
| -------- | --------------------- | ---- | --------- |
-| KeyEvent | [KeyEvent](#keyevent) | 是 | 注入按键的描述信息 |
+| KeyEvent | [KeyEvent](#keyevent) | 是 | 按键注入描述信息。 |
**示例:**
```js
try {
- var keyEvent = {
+ let backKeyDown = {
isPressed: true,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
}
- inputEventClient.injectKeyEvent({ KeyEvent: keyEvent });
- var keyEvent1 = {
+ inputEventClient.injectKeyEvent({ KeyEvent: backKeyDown });
+
+ let backKeyUp = {
isPressed: false,
keyCode: 2,
keyDownDuration: 0,
isIntercepted: false
};
- inputEventClient.injectKeyEvent({ KeyEvent: keyEvent1 });
+ inputEventClient.injectKeyEvent({ KeyEvent: backKeyUp });
} catch (error) {
- console.info("injectKeyEvent " + error.code + " " + error.message);
+ console.log(`Failed to inject KeyEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
## KeyEvent
-注入按键的描述信息。
+按键注入描述信息。
**系统能力:** SystemCapability.MultimodalInput.Input.InputSimulator
-| 参数 | 类型 | 必填 | 说明 |
-| --------------- | ------- | ---- | --------- |
-| isPressed | boolean | 是 | 按键是否按下 |
-| keyCode | number | 是 | 按键键值 |
-| keyDownDuration | number | 是 | 按键按下持续时间 |
-| isIntercepted | boolean | 是 | 按键是否可以被拦截 |
+| 参数 | 类型 | 必填 | 说明 |
+| --------------- | ------- | ---- | -------------------------- |
+| isPressed | boolean | 是 | 按键是否按下。 |
+| keyCode | number | 是 | 按键键值,当前只支持back键。 |
+| keyDownDuration | number | 是 | 按键按下持续时间。 |
+| isIntercepted | boolean | 是 | 按键是否可以被拦截。 |
+
diff --git a/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md b/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
index 56743cb2b46490eb8ca89050e3e891e7b5cf064e..235bbab8b80bc9dd1ad89a0896e39cd9725dabfe 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-inputmonitor.md
@@ -37,11 +37,11 @@ on(type: "touch", receiver: TouchEventReceiver): void
```js
try {
inputMonitor.on("touch", (data)=> {
- console.info(`monitorOnTouchEvent success ${JSON.stringify(data)}`);
+ console.log(`Monitor on TouchEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
- console.info("onMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -66,11 +66,11 @@ on(type: "mouse", receiver: Callback<MouseEvent>): void
```js
try {
inputMonitor.on("mouse", (data)=> {
- console.info(`monitorOnMouseEvent success ${JSON.stringify(data)}`);
+ console.log(`Monitor on MouseEvent success ${JSON.stringify(data)}`);
return false;
});
} catch (error) {
- console.info("onMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -95,25 +95,25 @@ off(type: "touch", receiver?: TouchEventReceiver): void
**示例:**
```js
-// 取消所有监听。
+// 取消监听全局触屏事件
try {
inputMonitor.off("touch");
} catch (error) {
- console.info("offMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
- console.info(`call success ${JSON.stringify(data)}`);
+ console.log(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("touch", this.callback);
} catch (error) {
- console.info("onTouchMonitor " + error.code + " " + error.message)
-},
+ console.log(`Failed to monitor on TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
+},
try {
inputMonitor.off("touch",this.callback);
} catch (error) {
- console.info("offTouchMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -135,25 +135,25 @@ off(type: "mouse", receiver?: Callback<MouseEvent>): void
**示例:**
```js
-// 取消所有监听。
+// 取消监听全局鼠标事件
try {
inputMonitor.off("mouse");
} catch (error) {
- console.info("offMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
// 单独取消receiver的监听。
callback:function(data) {
- console.info(`call success ${JSON.stringify(data)}`);
+ console.log(`call success ${JSON.stringify(data)}`);
},
try {
inputMonitor.on("mouse", this.callback);
} catch (error) {
- console.info("onMouseMonitor " + error.code + " " + error.message)
-},
+ console.log(`Failed to monitor on MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
+},
try {
inputMonitor.off("mouse", this.callback);
} catch (error) {
- console.info("offMouseMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor off MouseEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
@@ -187,6 +187,6 @@ try {
});
inputMonitor.off("touch");
} catch (error) {
- console.info("offMonitor " + error.code + " " + error.message)
+ console.log(`Failed to monitor off TouchEvent, error: ${JSON.stringify(error, [`code`, `message`])}`);
}
```
diff --git a/zh-cn/application-dev/reference/apis/js-apis-keycode.md b/zh-cn/application-dev/reference/apis/js-apis-keycode.md
index 26f56165a23e232b68ac20f7d867a053a2631032..072408de7c4db11a84a00f3742f0104eaaf2f52f 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-keycode.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-keycode.md
@@ -8,7 +8,7 @@ KeyCode模块提供了按键类设备的键值。
## 导入模块
```js
-import {KeyCode} from '@ohos.multimodalInput.keyCode'
+import {KeyCode} from '@ohos.multimodalInput.keyCode';
```
## KeyCode
diff --git a/zh-cn/application-dev/reference/apis/js-apis-keyevent.md b/zh-cn/application-dev/reference/apis/js-apis-keyevent.md
index 2dcf562d995aa43115528998f8fb14e625ab884d..45d91a8953f4e477a073562f8b7fa13e937ed306 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-keyevent.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-keyevent.md
@@ -9,44 +9,44 @@ KeyEvent模块提供了设备可以上报的按键事件。
## 导入模块
```js
-import {Action,Key,KeyEvent} from '@ohos.multimodalInput.keyEvent';
+import {Action, Key, KeyEvent} from '@ohos.multimodalInput.keyEvent';
```
## Action
**系统能力**:SystemCapability.MultimodalInput.Input.Core
-| 名称 | 参数类型 | 可读 | 可写 | 描述 |
-| ------ | ------ | ---- | ---- | ---- |
-| CANCEL | number | 是 | 否 | 取消 |
-| DOWN | number | 是 | 否 | 按下按钮 |
-| UP | number | 是 | 否 | 抬起按钮 |
+| 名称 | 参数类型 | 可读 | 可写 | 描述 |
+| ------ | -------- | ---- | ---- | -------- |
+| CANCEL | number | 是 | 否 | 取消按钮 |
+| DOWN | number | 是 | 否 | 按下按钮 |
+| UP | number | 是 | 否 | 抬起按钮 |
## Key
**系统能力**:SystemCapability.MultimodalInput.Input.Core
-| 名称 | 参数类型 | 可读 | 可写 | 描述 |
-| ----------- | ------- | ---- | ---- | ------ |
-| code | KeyCode | 是 | 否 | 按键码 |
-| pressedTime | number | 是 | 否 | 按下时间 |
-| deviceId | number | 是 | 否 | 按键所属设备 |
+| 名称 | 参数类型 | 可读 | 可写 | 描述 |
+| ----------- | -------- | ---- | ---- | -------------- |
+| code | KeyCode | 是 | 否 | 按键码 |
+| pressedTime | number | 是 | 否 | 按下持续的时间 |
+| deviceId | number | 是 | 否 | 按键所属设备 |
## KeyEvent
**系统能力**:SystemCapability.MultimodalInput.Input.Core
-| 名称 | 参数类型 | 可读 | 可写 | 描述 |
-| ----------- | ------- | ---- | ---- | -------------------- |
-| action | Action | 是 | 否 | 按键动作 |
-| key | Key | 是 | 否 | 当前发生变化的按键 |
-| unicodeChar | number | 是 | 否 | 按键对应的uniCode字符 |
-| keys | Key[] | 是 | 否 | 当前处于按下状态的按键列表 |
-| ctrlKey | boolean | 是 | 否 | 当前ctrlKey是否处于按下状态 |
-| altKey | boolean | 是 | 否 | 当前altKey是否处于按下状态 |
-| shiftKey | boolean | 是 | 否 | 当前shiftKey是否处于按下状态 |
-| logoKey | boolean | 是 | 否 | 当前logoKey是否处于按下状态 |
-| fnKey | boolean | 是 | 否 | 当前fnKey是否处于按下状态 |
-| capsLock | boolean | 是 | 否 | 当前capsLock是否处于激活状态 |
-| numLock | boolean | 是 | 否 | 当前numLock是否处于激活状态 |
-| scrollLock | boolean | 是 | 否 | 当前scrollLock是否处于激活状态 |
\ No newline at end of file
+| 名称 | 参数类型 | 可读 | 可写 | 描述 |
+| ----------- | -------- | ---- | ---- | ------------------------------ |
+| action | Action | 是 | 否 | 按键动作 |
+| key | Key | 是 | 否 | 当前发生变化的按键 |
+| unicodeChar | number | 是 | 否 | 按键对应的uniCode字符 |
+| keys | Key[] | 是 | 否 | 当前处于按下状态的按键列表 |
+| ctrlKey | boolean | 是 | 否 | 当前ctrlKey是否处于按下状态 |
+| altKey | boolean | 是 | 否 | 当前altKey是否处于按下状态 |
+| shiftKey | boolean | 是 | 否 | 当前shiftKey是否处于按下状态 |
+| logoKey | boolean | 是 | 否 | 当前logoKey是否处于按下状态 |
+| fnKey | boolean | 是 | 否 | 当前fnKey是否处于按下状态 |
+| capsLock | boolean | 是 | 否 | 当前capsLock是否处于激活状态 |
+| numLock | boolean | 是 | 否 | 当前numLock是否处于激活状态 |
+| scrollLock | boolean | 是 | 否 | 当前scrollLock是否处于激活状态 |
diff --git a/zh-cn/application-dev/reference/apis/js-apis-mouseevent.md b/zh-cn/application-dev/reference/apis/js-apis-mouseevent.md
index b47a5d9bd5dcfaaae274b736ec7cf3052eb22703..557a6a1a8554f9fa895bbba2680069370e0a6510 100755
--- a/zh-cn/application-dev/reference/apis/js-apis-mouseevent.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-mouseevent.md
@@ -15,15 +15,15 @@ import {Action,Button,Axis,AxisValue,MouseEvent} from '@ohos.multimodalInput.mou
**系统能力**:SystemCapability.MultimodalInput.Input.Core
-| 名称 | 参数类型 | 可读 | 可写 | 描述 |
-| ----------- | ------ | ---- | ---- | ---------- |
-| CANCEL | number | 是 | 否 | 取消 |
-| MOVE | number | 是 | 否 | 鼠标移动 |
-| BUTTON_DOWN | number | 是 | 否 | 鼠标按钮按下 |
-| BUTTON_UP | number | 是 | 否 | 鼠标按钮抬起 |
-| AXIS_BEGIN | number | 是 | 否 | 鼠标关联的轴事件开始 |
-| AXIS_UPDATE | number | 是 | 否 | 鼠标关联的轴事件更新 |
-| AXIS_END | number | 是 | 否 | 鼠标关联的轴事件结束 |
+| 名称 | 参数类型 | 可读 | 可写 | 描述 |
+| ----------- | -------- | ---- | ---- | -------------------- |
+| CANCEL | number | 是 | 否 | 取消动作 |
+| MOVE | number | 是 | 否 | 鼠标移动 |
+| BUTTON_DOWN | number | 是 | 否 | 鼠标按钮按下 |
+| BUTTON_UP | number | 是 | 否 | 鼠标按钮抬起 |
+| AXIS_BEGIN | number | 是 | 否 | 鼠标关联的轴事件开始 |
+| AXIS_UPDATE | number | 是 | 否 | 鼠标关联的轴事件更新 |
+| AXIS_END | number | 是 | 否 | 鼠标关联的轴事件结束 |
## Button
diff --git a/zh-cn/application-dev/reference/apis/js-apis-nfcTag.md b/zh-cn/application-dev/reference/apis/js-apis-nfcTag.md
index 3cccd741b976c1b9122a871a11601e411fa18c55..71a0bee5b2b0e60b8ee2984768de9fa1c4891da5 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-nfcTag.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-nfcTag.md
@@ -64,29 +64,57 @@ import tag from '@ohos.nfc.tag';
import tag from '@ohos.nfc.tag';
onCreate(want, launchParam) {
- // add other code here
+ // add other code here...
// want is initialized by nfc service, contains tag info for this found tag
- var tagInfo = tag.getTagInfo(want);
- if (tagInfo == undefined) {
+ var tagInfo;
+ try {
+ tag.getTagInfo(want);
+ } catch (error) {
+ console.log("tag.getTagInfo catched error: " + error);
+ }
+ if (tagInfo == null || tagInfo == undefined) {
console.log("no TagInfo to be created, ignore it.");
return;
}
+
+ // get the supported technologies for this found tag.
var isNfcATag = false;
+ var isIsoDepTag = false;
for (var i = 0; i < tagInfo.technology.length; i++) {
if (tagInfo.technology[i] == tag.NFC_A) {
isNfcATag = true;
- break;
}
- // also check for technology: tag.NFC_B/NFC_F/NFC_V/ISO_DEP/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
+
+ if (tagInfo.technology[i] == tag.ISO_DEP) {
+ isIsoDepTag = true;
+ }
+ // also check for technology: tag.NFC_B/NFC_F/NFC_V/NDEF/MIFARE_CLASSIC/MIFARE_ULTRALIGHT/NDEF_FORMATABLE
}
+
+ // use NfcA APIs to access the found tag.
if (isNfcATag) {
- var nfcA = tag.getNfcATag(taginfo);
+ var nfcA;
+ try {
+ nfcA = tag.getNfcATag(taginfo);
+ } catch (error) {
+ console.log("tag.getNfcATag catched error: " + error);
+ }
// other code to read or write this found tag.
}
- // use the same code to handle for "NfcA/NfcB/NfcF/NfcV/IsoDep/Ndef/MifareClassic/MifareUL/NdefFormatable", such as:
- // var isoDep = tag.getIsoDepTag(taginfo);
+ // use getIsoDep APIs to access the found tag.
+ if (isIsoDepTag) {
+ var isoDep;
+ try {
+ isoDep = tag.getIsoDep(taginfo);
+ } catch (error) {
+ console.log("tag.getIsoDep catched error: " + error);
+ }
+ // other code to read or write this found tag.
+ }
+
+ // use the same code to handle for "NfcA/NfcB/NfcF/NfcV/Ndef/MifareClassic/MifareUL/NdefFormatable".
}
```
@@ -154,99 +182,135 @@ getNfcVTag(tagInfo: [TagInfo](#taginfo)): [NfcVTag](js-apis-nfctech.md#nfcvtag)
| -------- | ---------------- |
| [NfcVTag](js-apis-nfctech.md#nfcvtag) | NFC V类型Tag对象。 |
-## tag.getIsoDepTag9+
+## tag.getIsoDep9+
-getIsoDepTag(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
+getIsoDep(tagInfo: [TagInfo](#taginfo)): [IsoDepTag](js-apis-nfctech.md#isoDepTag9 )
-获取IsoDep类型Tag对象,通过该对象可访问Iso Dep技术类型的Tag。
-
-**需要权限**:ohos.permission.NFC_TAG
+获取IsoDep类型Tag对象,通过该对象可访问支持IsoDep技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core
-**返回值:**
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------------------------- | ---- | ---------------------------------------- |
+| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
+**返回值:**
| **类型** | **说明** |
| ---------- | ------------------|
-| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | Iso Dep类型Tag对象。 |
-
-## tag.getNdefTag9+
+| [IsoDepTag](js-apis-nfctech.md#isodeptag9) | IsoDep类型Tag对象,通过该对象访问IsoDep类型的相关接口。 |
-getNdefTag(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state of service is abnormal. |
-获取Ndef类型Tag对象,通过该对象可访问Ndef技术类型的Tag。
+## tag.getNdef9+
+getNdef(tagInfo: [TagInfo](#taginfo)): [NdefTag](js-apis-nfctech.md#ndeftag9)
-**需要权限**:ohos.permission.NFC_TAG
+获取NDEF类型Tag对象,通过该对象可访问支持NDEF技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core
-**返回值:**
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------------------------- | ---- | ---------------------------------------- |
+| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
+**返回值:**
| **类型** | **说明** |
| ---------| -------------- |
-| [NdefTag](js-apis-nfctech.md#ndeftag9) | Ndef类型Tag对象。|
+| [NdefTag](js-apis-nfctech.md#ndeftag9) | NDEF类型Tag对象,通过该对象访问NDEF类型的相关接口。|
-## tag.getMifareClassicTag9+
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state of service is abnormal. |
-getMifareClassicTag(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
+## tag.getMifareClassic9+
-获取Mifare Classic类型Tag对象,通过该对象访问Mifare Classic技术类型的Tag。
+getMifareClassic(tagInfo: [TagInfo](#taginfo)): [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9)
-**需要权限**:ohos.permission.NFC_TAG
+获取MIFARE Classic类型Tag对象,通过该对象访问支持MIFARE Classic技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core
-**返回值:**
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------------------------- | ---- | ---------------------------------------- |
+| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
+**返回值:**
| **类型** | **说明** |
| ----------------- | ------------------------|
-| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | Mifare Classic类型Tag对象。 |
+| [MifareClassicTag](js-apis-nfctech.md#mifareclassictag-9) | MIFARE Classic类型Tag对象,通过该对象访问MIFARE Classic类型的相关接口。 |
-## tag.getMifareUltralightTag9+
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state of service is abnormal. |
-getMifareUltralightTag(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
+## tag.getMifareUltralight9+
-获取Mifare Ultralight类型Tag对象,通过该对象可访问Mifare Ultralight技术类型的Tag。
+getMifareUltralight(tagInfo: [TagInfo](#taginfo)): [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9)
-**需要权限**:ohos.permission.NFC_TAG
+获取MIFARE Ultralight类型Tag对象,通过该对象可访问支持MIFARE Ultralight技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core
-**返回值:**
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------------------------- | ---- | ---------------------------------------- |
+| taginfo | [TagInfo](#taginfo) | 是 | 包含Tag技术类型和相关参数,从tag.getTagInfo(want: Want)获取。 |
+**返回值:**
| **类型** | **说明** |
| -------------------- | ---------------------------|
-| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | Mifare Ultralight类型Tag对象。 |
+| [MifareUltralightTag](js-apis-nfctech.md#mifareultralighttag9) | MIFARE Ultralight类型Tag对象,通过该对象访问MIFARE Ultralight类型的相关接口。 |
-## tag.getNdefFormatableTag9+
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state of service is abnormal. |
-getNdefFormatableTag(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
+## tag.getNdefFormatable9+
-获取Ndef Formatable类型Tag对象,通过该对象可访问Ndef Formatable技术类型的Tag。
+getNdefFormatable(tagInfo: [TagInfo](#taginfo)): [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag9)
-**需要权限**:ohos.permission.NFC_TAG
+获取NDEF Formatable类型Tag对象,通过该对象可访问支持NDEF Formatable技术类型的Tag。
**系统能力**:SystemCapability.Communication.NFC.Core
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | Ndef Formatable类型Tag对象。 |
+| [NdefFormatableTag](js-apis-nfctech.md#ndefformatabletag) | NDEF Formatable类型Tag对象,通过该对象访问NDEF Formatable类型的相关接口。 |
+
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state of service is abnormal. |
## tag.getTagInfo9+
-getTagInfo(want: Want): [TagInfo](#taginfo)
+getTagInfo(want: [Want](js-apis-application-Want.md#Want)): [TagInfo](#taginfo)
从Want中获取TagInfo,Want是被NFC服务初始化,包含了TagInfo所需的属性值。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
-**返回值:**
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| --------- | ------------------------- | ---- | ---------------------------------------- |
+| want | [Want](js-apis-application-Want.md#Want) | 是 | 分发Ability时,在系统onCreate入口函数的参数中获取。 |
+**返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
| [TagInfo](#taginfo) | TagInfo对象,用于获取不同技术类型的Tag对象。 |
@@ -255,8 +319,6 @@ getTagInfo(want: Want): [TagInfo](#taginfo)
NFC服务在读取到标签时给出的对象,通过改对象属性,应用知道该标签支持哪些技术类型,并使用匹配的技术类型来调用相关接口。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** |
@@ -268,8 +330,6 @@ NFC服务在读取到标签时给出的对象,通过改对象属性,应用
## NdefRecord9+
NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **类型** | **说明** |
| -------- | -------- | -------- |
@@ -281,8 +341,6 @@ NDEF标签Record属性的定义,参考NDEF标签技术规范《NFCForum-TS-NDE
## 技术类型定义
NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
@@ -292,15 +350,13 @@ NFC Tag有多种不同的技术类型,定义常量描述不同的技术类型
| NFC_F | 4 | NFC-F(JIS 6319-4)技术。|
| NFC_V | 5 | NFC-V(ISO 15693)技术。|
| NDEF | 6 | NDEF技术。|
-| MIFARE_CLASSIC | 8 | Mifare Classic技术。|
-| MIFARE_ULTRALIGHT | 9 | Mifare Utralight技术。|
+| MIFARE_CLASSIC | 8 | MIFARE Classic技术。|
+| MIFARE_ULTRALIGHT | 9 | MIFARE Utralight技术。|
| NDEF_FORMATABLE9+ | 10 | 可以格式化的NDEF技术。|
## TnfType9+
NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
@@ -315,8 +371,6 @@ NDEF Record的TNF(Type Name Field)类型值,参考NDEF标签技术规范《NFC
## NDEF Record RTD类型定义
NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规范《NFCForum-TS-NDEF_1.0》的定义细节。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
@@ -326,8 +380,6 @@ NDEF Record的RTD(Record Type Definition)类型值,参考NDEF标签技术规
## NfcForumType9+
NFC Forum标准里面Tag类型的定义。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
@@ -335,25 +387,21 @@ NFC Forum标准里面Tag类型的定义。
| NFC_FORUM_TYPE_2 | 2 | NFC论坛类型2。 |
| NFC_FORUM_TYPE_3 | 3 | NFC论坛类型3。 |
| NFC_FORUM_TYPE_4 | 4 | NFC论坛类型4。 |
-| MIFARE_CLASSIC | 101 | Mifare Classic类型。 |
+| MIFARE_CLASSIC | 101 | MIFARE Classic类型。 |
## MifareClassicType9+
-MifareClassic标签类型的定义。
-
-**需要权限**:ohos.permission.NFC_TAG
+MIFARE Classic标签类型的定义。
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
-| TYPE_UNKNOWN | -1 | 未知Mifare类型。 |
-| TYPE_CLASSIC | 0 | Mifare Classic类型。|
-| TYPE_PLUS | 1 | Mifare Plus类型。|
-| TYPE_PRO | 2 | Mifare Pro类型。 |
+| TYPE_UNKNOWN | 0 | 未知MIFARE类型。 |
+| TYPE_CLASSIC | 1 | MIFARE Classic类型。|
+| TYPE_PLUS | 2 | MIFARE Plus类型。|
+| TYPE_PRO | 3 | MIFARE Pro类型。 |
## MifareClassicSize9+
-MifareClassic标签存储大小的定义。
-
-**需要权限**:ohos.permission.NFC_TAG
+MIFARE Classic标签存储大小的定义。
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
@@ -363,15 +411,13 @@ MifareClassic标签存储大小的定义。
| MC_SIZE_2K | 2048 | 每个标签32个扇区,每个扇区4个块。 |
| MC_SIZE_4K | 4096 | 每个标签40个扇区,每个扇区4个块。|
-### MifareUltralightType9+
-MifareUltralight标签类型的定义。
-
-**需要权限**:ohos.permission.NFC_TAG
+## MifareUltralightType9+
+MIFARE Ultralight标签类型的定义。
**系统能力**:SystemCapability.Communication.NFC.Core
| **参数名** | **常量值** | **说明** |
| -------- | -------- | -------- |
-| TYPE_UNKOWN | -1 | 未知的 Mifare 类型。 |
-| TYPE_ULTRALIGHT | 1 | Mifare Ultralight类型。|
-| TYPE_ULTRALIGHT_C | 2 | Mifare UltralightC 类型。 |
+| TYPE_UNKOWN | 0 | 未知的 MIFARE 类型。 |
+| TYPE_ULTRALIGHT | 1 | MIFARE Ultralight类型。|
+| TYPE_ULTRALIGHT_C | 2 | MIFARE UltralightC 类型。 |
\ No newline at end of file
diff --git a/zh-cn/application-dev/reference/apis/js-apis-nfctech.md b/zh-cn/application-dev/reference/apis/js-apis-nfctech.md
index 2ddd53f960a95e6d2b230017b8c34d17f1c8617f..f198cca93ffad384df83c41be315cc0a0c252b7c 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-nfctech.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-nfctech.md
@@ -15,7 +15,7 @@ import tag from '@ohos.nfc.tag';
NfcATag 提供 NFC-A(ISO 14443-3A)技术的属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是NfcATag的独有接口。
@@ -40,8 +40,7 @@ getSak(): number
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcA' correctly.
-
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcA' correctly.
let sak = nfcA.getSak();
console.log("nfcA sak: " + sak);
```
@@ -67,7 +66,7 @@ getAtqa(): number[]
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcA' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcA' correctly.
let atqa = nfcA.getAtqa();
console.log("nfcA atqa: " + atqa);
```
@@ -76,7 +75,7 @@ console.log("nfcA atqa: " + atqa);
NfcBTag 提供对NFC-B(ISO 14443-3B)技术的属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类,提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类,提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是NfcBTag的独有接口。
@@ -101,7 +100,7 @@ getRespAppData(): number[]
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcB' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcB' correctly.
let respAppData = nfcB.getRespAppData();
console.log("nfcB respAppData: " + respAppData);
```
@@ -127,7 +126,7 @@ getRespProtocol(): number[]
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcB' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcB' correctly.
let respProtocol = nfcB.getRespProtocol();
console.log("nfcB respProtocol: " + respProtocol);
```
@@ -136,7 +135,7 @@ console.log("nfcB respProtocol: " + respProtocol);
NfcFTag 提供对NFC-F(JIS 6319-4)技术的属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是NfcFTag的独有接口。
@@ -161,7 +160,7 @@ getSystemCode(): number[]
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcF' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcF' correctly.
let systemCode = nfcF.getSystemCode();
console.log("nfcF systemCode: " + systemCode);
```
@@ -187,7 +186,7 @@ getPmm(): number[]
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcF' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcF' correctly.
let pmm = nfcF.getPmm();
console.log("nfcF pmm: " + pmm);
```
@@ -196,7 +195,7 @@ console.log("nfcF pmm: " + pmm);
NfcVTag 提供对NFC-V(ISO 15693)技术的属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是NfcVTag的独有接口。
@@ -221,7 +220,7 @@ getResponseFlags(): number
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcV' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcV' correctly.
let responseFlags = nfcV.getResponseFlags();
console.log("nfcV responseFlags: " + responseFlags);
```
@@ -247,7 +246,7 @@ getDsfId(): number
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'nfcV' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'nfcV' correctly.
let dsfId = nfcV.getDsfId();
console.log("nfcV dsfId: " + dsfId);
```
@@ -256,7 +255,7 @@ console.log("nfcV dsfId: " + dsfId);
IsoDepTag 提供对ISO-DEP(ISO 14443-4)技术的属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是IsoDepTag的独有接口。
@@ -264,24 +263,20 @@ TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送
getHistoricalBytes(): number[]
-获取标签的历史字节。
-
-**需要权限**:ohos.permission.NFC_TAG
+获取标签的历史字节,针对基于NfcA通信技术的IsoDep卡片。
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| number[] | IsoDepTag 标签的历史字节,每个number十六进制表示,范围是0x00~0xFF。|
+| number[] | IsoDepTag 标签的历史字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcB技术的,则该返回值为空。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'isoDep' correctly.
let historicalBytes = isoDep.getHistoricalBytes();
console.log("isoDep historicalBytes: " + historicalBytes);
```
@@ -290,24 +285,20 @@ console.log("isoDep historicalBytes: " + historicalBytes);
getHiLayerResponse(): number[]
-获取标签的HiLayer响应字节。
-
-**需要权限**:ohos.permission.NFC_TAG
+获取标签的更高层响应字节,针对基于NfcB通信技术的IsoDep卡片。
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| number[] | IsoDepTag 标签的HiLayer响应字节,每个number十六进制表示,范围是0x00~0xFF。|
+| number[] | IsoDepTag 标签的更高层响应字节,每个number十六进制表示,范围是0x00~0xFF。如果该IsoDep类型Tag是基于NfcA技术的,则该返回值为空。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'isoDep' correctly.
let hiLayerResponse = isoDep.getHiLayerResponse();
console.log("isoDep hiLayerResponse: " + hiLayerResponse);
```
@@ -316,137 +307,368 @@ console.log("isoDep hiLayerResponse: " + hiLayerResponse);
isExtendedApduSupported(): Promise<boolean>
-检查是否支持扩展的APDU,使用promise方式作为异步方法。
+检查是否支持扩展的APDU,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| Promise<boolean> | 检查结果,true: 支持, false: 不支持。|
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
-isoDep.isExtendedApduSupported()
- .then((data) => {
- console.log("isoDep isExtendedApduSupported data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'isoDep' correctly.
+
+// connect the tag at first if not connected.
+if (!isoDep.isTagConnected()) {
+ if (!isoDep.connectTag()) {
+ console.log("isoDep connectTag failed.");
+ return;
+ }
+}
+
+try {
+ isoDep.isExtendedApduSupported().then((response) => {
+ console.log("isoDep isExtendedApduSupported Promise response: " + response);
}).catch((err)=> {
- console.log("isoDep isExtendedApduSupported err: " + err);
+ console.log("isoDep isExtendedApduSupported Promise err: " + err);
});
+} catch (busiError) {
+ console.log("isoDep isExtendedApduSupported Promise busiError: " + busiError);
+}
+
```
### IsoDepTag.isExtendedApduSupported9+
isExtendedApduSupported(callback: AsyncCallback\): void
-检查是否支持扩展的APDU,使用callback方式作为异步方法。
+检查是否支持扩展的APDU,使用AsyncCallback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | 是 | 回调函数,true: 支持, false: 不支持。 |
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'isoDep' correctly.
-isoDep.isExtendedApduSupported((err, data)=> {
- if (err) {
- console.log("isoDep isExtendedApduSupported err: " + err);
- } else {
- console.log("isoDep isExtendedApduSupported data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'isoDep' correctly.
+
+// connect the tag at first if not connected.
+if (!isoDep.isTagConnected()) {
+ if (!isoDep.connectTag()) {
+ console.log("isoDep connectTag failed.");
+ return;
}
-});
+}
+
+try {
+ isoDep.isExtendedApduSupported((err, response)=> {
+ if (err) {
+ console.log("isoDep isExtendedApduSupported AsyncCallback err: " + err);
+ } else {
+ console.log("isoDep isExtendedApduSupported AsyncCallback response: " + response);
+ }
+ });
+} catch (busiError) {
+ console.log("isoDep isExtendedApduSupported AsyncCallback busiError: " + busiError);
+}
```
-## NdefTag9+
+## NdefMessage9+
-提供对已格式化为NDEF的NFC标签的数据和操作的访问,继承自TagSession。
+### NdefMessage.getNdefRecords9+
-TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+getNdefRecords(): [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[]
-以下是NdefTag的独有接口。
+获取NDEF消息中的所有记录。
-### NdefTag.createNdefMessage9+
+**系统能力**:SystemCapability.Communication.NFC
-createNdefMessage(data: number[]): [NdefMessage](#ndefmessage9)
+**返回值:**
+| **类型** | **说明** |
+| ------------------ | --------------------------|
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
-使用原始字节创建ndef消息。
+**示例:**
+```js
+import tag from '@ohos.nfc.tag';
-**需要权限**:ohos.permission.NFC_TAG
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage.
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
-**系统能力**:SystemCapability.Communication.NFC
+let ndefRecords = ndefMessage.getNdefRecords();
+console.log("ndef ndefRecords number: " + ndefRecords.length);
+```
+
+### NdefMessage.makeUriRecord9+
+
+makeUriRecord(uri: string): [NdefRecord](js-apis-nfcTag.md#ndefrecord9);
+
+根据输入的URI,构建NDEF标签的Record数据对象。
+**系统能力**:SystemCapability.Communication.NFC
**参数:**
-| **参数名** | **类型** | **必填** | **说明** |
-| -------- | -------- | -------- | -------- |
-| data | number[] | 是 | 原始字节,每个number十六进制表示,范围是0x00~0xFF |
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| uri | string | 是 | 写入到NDEF Record里面的数据内容。 |
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**示例:**
+```js
+import tag from '@ohos.nfc.tag';
+
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage. Such as:
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
+try {
+ let uri = "https://gitee.com/openharmony"; // change it to be correct.
+ let ndefRecord = ndefMessage.makeUriRecord(uri);
+ if (ndefRecord != undefined) {
+ console.log("ndefMessage makeUriRecord rtdType: " + ndefRecord.rtdType);
+ console.log("ndefMessage makeUriRecord payload: " + ndefRecord.payload);
+ } else {
+ console.log("ndefMessage makeUriRecord ndefRecord: " + ndefRecord);
+ }
+} catch (busiError) {
+ console.log("ndefMessage makeUriRecord catched busiError: " + busiError);
+}
+```
+
+### NdefMessage.makeTextRecord9+
+
+makeTextRecord(text: string, locale: string): [NdefRecord](js-apis-nfcTag.md#ndefrecord9);
+
+根据输入的文本数据和编码类型,构建NDEF标签的Record。
+
+**系统能力**:SystemCapability.Communication.NFC
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| text | string | 是 | 写入到NDEF Record里面的文本数据内容。 |
+| locale | string | 是 | 文本数据内容的编码方式。 |
+
+**返回值:**
+| **类型** | **说明** |
+| ------------------ | --------------------------|
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let rawData = [0x00, 0xa4, 0x04, ......]; // change the raw data bytes tobe correct.
-let ndefMessage = ndef.createNdefMessage(rawData);
-console.log("ndef ndefMessage: " + ndefMessage);
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage. Such as:
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
+
+try {
+ let text = "Hello World"; // change it to be correct.
+ let locale = "utf8"; // change it to be correct.
+ let ndefRecord = ndefMessage.makeTextRecord(text, locale);
+ if (ndefRecord != undefined) {
+ console.log("ndefMessage makeTextRecord rtdType: " + ndefRecord.rtdType);
+ console.log("ndefMessage makeTextRecord payload: " + ndefRecord.payload);
+ } else {
+ console.log("ndefMessage makeTextRecord ndefRecord: " + ndefRecord);
+ }
+} catch (busiError) {
+ console.log("ndefMessage makeTextRecord catched busiError: " + busiError);
+}
```
-## NdefMessage9+
-### NdefMessage.getNdefRecords9+
+### NdefMessage.makeMimeRecord9+
-getNdefRecords(): [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[ ]
+makeMimeRecord(mimeType: string, mimeData: number[]): [NdefRecord](js-apis-nfcTag.md#ndefrecord9);
-获取ndef消息的所有记录。
+根据输入的MIME数据和类型,构建NDEF标签的Record。
-**需要权限**:ohos.permission.NFC_TAG
+**系统能力**:SystemCapability.Communication.NFC
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| mimeType | string | 是 | MIME数据的类型。 |
+| mimeData | number[] | 是 | MIME数据内容。 |
+
+**返回值:**
+| **类型** | **说明** |
+| ------------------ | --------------------------|
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+
+**示例:**
+```js
+import tag from '@ohos.nfc.tag';
+
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage. Such as:
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
+
+try {
+ let mimeType = "media"; // change it to be correct.
+ let mimeData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
+ let ndefRecord = ndefMessage.makeMimeRecord(mimeType, mimeData);
+ if (ndefRecord != undefined) {
+ console.log("ndefMessage makeMimeRecord rtdType: " + ndefRecord.rtdType);
+ console.log("ndefMessage makeMimeRecord payload: " + ndefRecord.payload);
+ } else {
+ console.log("ndefMessage makeMimeRecord ndefRecord: " + ndefRecord);
+ }
+} catch (busiError) {
+ console.log("ndefMessage makeMimeRecord catched busiError: " + busiError);
+}
+```
+### NdefMessage.makeExternalRecord9+
+
+makeExternalRecord(domainName: string, serviceName: string, externalData: number[]): [NdefRecord](js-apis-nfcTag.md#ndefrecord9);
+
+根据应用程序特定的外部数据,构建NDEF标签的Record。
**系统能力**:SystemCapability.Communication.NFC
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| domainName | string | 是 | 外部数据发布组织的域名,一般是应用程序的包名。 |
+| serviceName | string | 是 | 外部数据的指定类型。 |
+| externalData | number[] | 是 | 外部数据内容。 |
**返回值:**
+| **类型** | **说明** |
+| ------------------ | --------------------------|
+| [NdefRecord](js-apis-nfcTag.md#ndefrecord9) | NDEF标签的Record,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+
+**示例:**
+```js
+import tag from '@ohos.nfc.tag';
+
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage. Such as:
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
+
+try {
+ let domainName = "ohos.nfc.application"; // change it to be correct.
+ let type = "nfc"; // change it to be correct.
+ let externalData = [0x01, 0x02, 0x03, 0x04]; // change it to be correct.
+ let ndefRecord = ndefMessage.makeExternalRecord(domainName, type, externalData);
+ if (ndefRecord != undefined) {
+ console.log("ndefMessage makeExternalRecord rtdType: " + ndefRecord.rtdType);
+ console.log("ndefMessage makeExternalRecord payload: " + ndefRecord.payload);
+ } else {
+ console.log("ndefMessage makeExternalRecord ndefRecord: " + ndefRecord);
+ }
+} catch (busiError) {
+ console.log("ndefMessage makeExternalRecord catched busiError: " + busiError);
+}
+```
+
+### NdefMessage.messageToBytes9+
+
+messageToBytes(ndefMessage: [NdefMessage](#ndefmessage9)): number[];
+
+把输入的NDEF消息数据对象,转换为字节格式的数据。
+**系统能力**:SystemCapability.Communication.NFC
+**参数:**
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| ndefMessage | [NdefMessage](#ndefmessage9) | 是 | NDEF消息数据对象。 |
+
+**返回值:**
| **类型** | **说明** |
| ------------------ | --------------------------|
-| [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[ ] | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+| number[] | NDEF消息数据对象,所转换成的字节格式的数据。每个number十六进制表示,范围是0x00~0xFF。 |
**示例:**
+```js
+import tag from '@ohos.nfc.tag';
+
+// see NdefTag, obtains ndefMessage from ndefTag.createNdefMessage or ndefTag.getNdefMessage. Such as:
+// var ndefMessage = ndefTag.createNdefMessage(...);
+// var ndefMessage = ndefTag.getNdefMessage();
+
+try {
+ // the parameter 'ndefMessage' can be different from the instance object.
+ let rawData = ndefMessage.messageToBytes(ndefMessage);
+ console.log("ndefMessage messageToBytes rawData: " + rawData);
+} catch (busiError) {
+ console.log("ndefMessage messageToBytes catched busiError: " + busiError);
+}
+```
+
+## NdefTag9+
+
+提供对已格式化为NDEF的NFC标签的数据和操作的访问,继承自TagSession。
+
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+
+以下是NdefTag的独有接口。
+
+### NdefTag.createNdefMessage9+
+
+createNdefMessage(data: number[]): [NdefMessage](#ndefmessage9)
+
+使用原始字节数据创建NDEF标签的Message。该数据必须符合NDEF Record数据格式,如果不符合格式,则返回的NdeMessage数据对象,所包含的NDE Record列表会为空。
+
+**系统能力**:SystemCapability.Communication.NFC
+
+**参数:**
+| **参数名** | **类型** | **必填** | **说明** |
+| -------- | -------- | -------- | -------- |
+| data | number[] | 是 | 原始字节,每个number十六进制表示,范围是0x00~0xFF。 |
+**返回值:**
+| **类型** | **说明** |
+| ------------------ | --------------------------|
+| [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
+
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefRecords = ndef.getNdefRecords();
-console.log("ndef ndefRecords number: " + ndefRecords.length);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+let rawData = [0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]; // change the raw data bytes to be correct.
+let ndefMessage;
+try {
+ ndefMessage = ndefTag.createNdefMessage(rawData);
+ console.log("ndef createNdefMessage, ndefMessage: " + ndefMessage);
+} catch (busiError) {
+ console.log("ndef createNdefMessage busiError: " + busiError);
+}
```
### NdefTag.createNdefMessage9+
createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9)
-使用记录列表创建NDEF消息。
-
-**需要权限**:ohos.permission.NFC_TAG
+使用NDEF Records列表,创建NDEF Message。
**系统能力**:SystemCapability.Communication.NFC
@@ -456,17 +678,15 @@ createNdefMessage(ndefRecords: NdefRecord[]): [NdefMessage](#ndefmessage9)
| ndefRecords | [NdefRecord](js-apis-nfcTag.md#ndefrecord9)[] | 是 | NDEF标签的Record列表,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。 |
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
let ndefRecords = [
// record format: tnf, rtdType, id, payload
// 1st record:
@@ -477,33 +697,34 @@ let ndefRecords = [
// other record if has one ...
];
-let ndefMessage = ndef.createNdefMessage(ndefRecords);
-console.log("ndef ndefMessage: " + ndefMessage);
+let ndefMessage;
+try {
+ ndefMessage = ndefTag.createNdefMessage(ndefRecords);
+ console.log("ndef createNdefMessage ndefMessage: " + ndefMessage);
+} catch (busiError) {
+ console.log("ndef createNdefMessage busiError: " + busiError);
+}
```
### NdefTag.getNdefTagType9+
getNdefTagType(): NfcForumType
-获取Ndef标签的类型。
-
-**需要权限**:ohos.permission.NFC_TAG
+获取NDEF标签的类型。
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefTagType = ndef.getNdefTagType();
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+let ndefTagType = ndefTag.getNdefTagType();
console.log("ndef ndefTagType: " + ndefTagType);
```
@@ -513,217 +734,237 @@ getNdefMessage(): NdefMessage
获取发现NDEF标签时,从标签读取的Message。
-**需要权限**:ohos.permission.NFC_TAG
-
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| [NdefMessage](#ndefmessage9) | NDEF标签的Message,详见NDEF技术规范《NFCForum-TS-NDEF_1.0》。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefMessage = ndef.getNdefMessage();
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+let ndefMessage = ndefTag.getNdefMessage();
console.log("ndef ndefMessage: " + ndefMessage);
```
### NdefTag.isNdefWritable9+
-isNdefWritable(): Promise<boolean>
-
-检查NDEF标签是否可写,使用promise方式作为异步方法。
+isNdefWritable(): boolean;
-**需要权限**:ohos.permission.NFC_TAG
+检查NDEF标签是否可写。在调用写数据接口前,需要先判断是否支持写操作。
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| Promise<boolean> | 检查结果,true: 可写, false: 不可写。|
+| boolean | 检查结果,true: 可写, false: 不可写。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.isNdefWritable()
- .then((data) => {
- console.log("ndef isNdefWritable data: " + data);
- }).catch((err)=> {
- console.log("ndef isNdefWritable err: " + err);
- });
-```
-
-### NdefTag.isNdefWritable9+
-
-isNdefWritable(callback: AsyncCallback<boolean>): void;
-
-检查ndef标签是否可写,使用callback方式作为异步方法。
-
-**需要权限**:ohos.permission.NFC_TAG
-
-**系统能力**:SystemCapability.Communication.NFC
-
-**参数:**
-
-| 参数名 | 类型 | 必填 | 说明 |
-| -------- | ----------------------- | ---- | -------------------------------------- |
-| callback | AsyncCallback\ | 是 | 回调函数,NDEF标签可写,返回true。 |
-
-**示例:**
-
-```js
-import tag from '@ohos.nfc.tag';
-
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.isNdefWritable((err, data)=> {
- if (err) {
- console.log("ndef isNdefWritable err: " + err);
- } else {
- console.log("ndef isNdefWritable data: " + data);
- }
-});
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+var isWritable = ndefTag.isNdefWritable();
+console.log("ndef isNdefWritable: " + isWritable);
```
### NdefTag.readNdef9+
readNdef(): Promise\
-读取标签上的ndef消息,使用promise方式作为异步方法。
+读取标签上的NDEF消息,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
-| Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从NDEF标签中读取到的Message信息。|
+| Promise\<[NdefMessage](#ndefmessage9)> | 以Promise形式返回从NDEF标签中读取到的Message数据对象。|
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.readNdef()
- .then((data) => {
- console.log("ndef readNdef data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
+ }
+}
+
+try {
+ ndefTag.readNdef().then((ndefmessage) => {
+ console.log("ndef readNdef Promise ndefmessage: " + ndefmessage);
}).catch((err)=> {
- console.log("ndef readNdef err: " + err);
+ console.log("ndef readNdef Promise err: " + err);
});
+} catch (busiError) {
+ console.log("ndef readNdef Promise catched busiError: " + busiError);
+}
```
### NdefTag.readNdef9+
readNdef(callback: AsyncCallback\<[NdefMessage](#ndefmessage9)>): void
-读取标签上的ndef消息,使用callback方式作为异步方法。
+读取标签上的NDEF消息,使用AsyncCallback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| callback | AsyncCallback\<[NdefMessage](#ndefmessage9)> | 是 | 回调函数。|
+| callback | AsyncCallback\<[NdefMessage](#ndefmessage9)> | 是 | 回调函数,返回从NDEF标签中读取到的Message信息。|
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.readNdef((err, data)=> {
- if (err) {
- console.log("ndef readNdef err: " + err);
- } else {
- console.log("ndef readNdef data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
}
-});
+}
+
+try {
+ ndefTag.readNdef((err, ndefmessage)=> {
+ if (err) {
+ console.log("ndef readNdef AsyncCallback err: " + err);
+ } else {
+ console.log("ndef readNdef AsyncCallback ndefmessage: " + ndefmessage);
+ }
+ });
+} catch (busiError) {
+ console.log("ndef readNdef AsyncCallback catched busiError: " + busiError);
+}
```
### NdefTag.writeNdef9+
-writeNdef(msg: NdefMessage): Promise\;
+writeNdef(msg: NdefMessage): Promise\;
-将ndef消息写入标签,使用promise方式作为异步方法。
+将NDEF Messsage数据对象写入标签,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| msg | NdefMessage | 是 | Ndef消息。|
-
-**返回值:**
+| msg | NdefMessage | 是 | NDEF Message数据对象。|
-| **类型** | **说明** |
-| ------------------ | --------------------------|
-| Promise\ | 以Promise形式返回,写入执行后的错误代码。如果返回0,则表示成功。 |
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+// ndefMessage created from raw data, such as:
+let ndefMessage = ndefTag.createNdefMessage([0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]); // change the raw data to be correct.
+// or ndefMessage created from ndefTag.createNdefMessage(ndefRecords: NdefRecord[])
-ndef.writeNdef(ndefMessage)
- .then((data) => {
- console.log("ndef writeNdef data: " + data);
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
+ }
+}
+
+try {
+ ndefTag.writeNdef(ndefMessage).then(() => {
+ console.log("ndef writeNdef Promise success.");
}).catch((err)=> {
console.log("ndef writeNdef err: " + err);
});
+} catch (busiError) {
+ console.log("ndef writeNdef Promise catch busiError: " + busiError);
+}
```
### NdefTag.writeNdef9+
-writeNdef(msg: NdefMessage, callback: AsyncCallback\): void
+writeNdef(msg: NdefMessage, callback: AsyncCallback\): void
-将ndef消息写入此标签,使用callback方式作为异步方法。
+将NDEF Message数据对象写入此标签,使用AsyncCallback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| msg | NdefMessage | 是 | Ndef消息 |
-| callback | AsyncCallback\ | 是 | 回调函数。 |
+| msg | NdefMessage | 是 | NDEF Message数据对象。 |
+| callback | AsyncCallback\ | 是 | 回调函数。 |
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefMessage = ndef.createNdefMessage([0x01, 0x02, ...]); // change the raw data to be correct.
-ndef.writeNdef(ndefMessage, (err, data)=> {
- if (err) {
- console.log("ndef writeNdef err: " + err);
- } else {
- console.log("ndef writeNdef data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+// ndefMessage created from raw data, such as:
+let ndefMessage = ndefTag.createNdefMessage([0xD1, 0x01, 0x03, 0x54, 0x4E, 0x46, 0x43]); // change the raw data to be correct.
+// or ndefMessage created from ndefTag.createNdefMessage(ndefRecords: NdefRecord[])
+
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
}
-});
+}
+
+try {
+ ndefTag.writeNdef(ndefMessage, (err)=> {
+ if (err) {
+ console.log("ndef writeNdef AsyncCallback err: " + err);
+ } else {
+ console.log("ndef writeNdef AsyncCallback success.");
+ }
+ });
+} catch (busiError) {
+ console.log("ndef writeNdef AsyncCallback catch busiError: " + busiError);
+}
```
### NdefTag.canSetReadOnly9+
@@ -737,659 +978,874 @@ canSetReadOnly(): boolean
**系统能力**:SystemCapability.Communication.NFC
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| boolean| true: NDEF标签可设置为只读, false: NDEF标签不可设置为只读。 |
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-var canSetReadOnly = ndef.canSetReadOnly();
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+var canSetReadOnly = ndefTag.canSetReadOnly();
console.log("ndef canSetReadOnly: " + canSetReadOnly);
```
### NdefTag.setReadOnly9+
-setReadOnly(): Promise\
+setReadOnly(): Promise\
-将Ndef标签设置为只读,使用promise方式作为异步方法。
+将NDEF标签设置为只读,使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
-**返回值:**
-
-| **类型** | **说明** |
-| ------------------ | --------------------------|
-| Promise<number> | 0: 设置成功, 其它: 错误编码。 |
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.setReadOnly()
- .then((data) => {
- console.log("ndef setReadOnly data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
+ }
+}
+
+try {
+ ndefTag.setReadOnly().then(() => {
+ console.log("ndef setReadOnly Promise success.");
}).catch((err)=> {
- console.log("ndef setReadOnly err: " + err);
+ console.log("ndef setReadOnly Promise err: " + err);
});
+} catch (busiError) {
+ console.log("ndef setReadOnly Promise catch busiError: " + busiError);
+}
```
### NdefTag.setReadOnly9+
-setReadOnly(callback: AsyncCallback\): void
+setReadOnly(callback: AsyncCallback\): void
-将Ndef标签设置为只读,使用callback方式作为异步方法。
+将NDEF标签设置为只读,使用AsyncCallback方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| callback | AsyncCallback\ | 是 | 回调函数。 |
+| callback | AsyncCallback\ | 是 | 回调函数。 |
-**示例:**
+**错误码:**
+以下错误码的详细介绍请参见[NFC错误码](../errorcodes/errorcode-nfc.md)。
+| 错误码ID | 错误信息|
+| ------- | -------|
+| 3100201 | Tag running state is abnormal in service. |
+**示例:**
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-ndef.setReadOnly((err, data)=> {
- if (err) {
- console.log("ndef setReadOnly err: " + err);
- } else {
- console.log("ndef setReadOnly data: " + data);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+
+// connect the tag at first if not connected.
+if (!ndefTag.isTagConnected()) {
+ if (!ndefTag.connectTag()) {
+ console.log("ndefTag connectTag failed.");
+ return;
}
-});
+}
+
+try {
+ ndefTag.setReadOnly((err)=> {
+ if (err) {
+ console.log("ndef setReadOnly AsyncCallback err: " + err);
+ } else {
+ console.log("ndef setReadOnly AsyncCallback success.");
+ }
+ });
+} catch (busiError) {
+ console.log("ndef setReadOnly AsyncCallback catch busiError: " + busiError);
+}
```
### NdefTag.getNdefTagTypeString9+
getNdefTagTypeString(type: [NfcForumType](js-apis-nfcTag.md#nfcforumtype9)): string
-将Nfc论坛类型转换为Nfc论坛中定义的字节数组。
-
-**需要权限**:ohos.permission.NFC_TAG
+将NFC论坛类型,转换为NFC论坛中定义的字符串描述。
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| type | [NfcForumType](js-apis-nfcTag.md#nfcforumtype9) | 是 | NDEF标签类型,包括NFC FORUM TYPE 1/2/3/4等。 |
**返回值:**
-
| **类型** | **说明** |
| ------------------ | --------------------------|
| string | NFC论坛类型的字符串描述。|
**示例:**
-
```js
import tag from '@ohos.nfc.tag';
-// see 'tag.TagInfo' at 'js-apis-nfcTag', has obtained the 'ndef' correctly.
-let ndefTypeString = ndef.getNdefTagTypeString(tag.NFC_FORUM_TYPE_1);
-console.log("ndef ndefTypeString: " + ndefTypeString);
+// see 'tag.TagInfo' at 'js-apis-nfcTag.md', obtains the 'ndefTag' correctly.
+
+try {
+ let ndefTypeString = ndefTag.getNdefTagTypeString(tag.NFC_FORUM_TYPE_1);
+ console.log("ndef ndefTypeString: " + ndefTypeString);
+} catch (busiError) {
+ console.log("ndef getNdefTagTypeString catch busiError: " + busiError);
+}
```
## MifareClassicTag9+
-MifareClassicTag提供对MIFARE经典属性和I/O操作的访问,继承自TagSession。
+MifareClassicTag提供对MIFARE Classic属性和I/O操作的访问,继承自TagSession。
-TagSession是所有Nfc tag 技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
+TagSession是所有NFC Tag技术类型的基类, 提供建立连接和发送数据等共同接口。具体请参见[TagSession](js-apis-tagSession.md)。
以下是MifareClassicTag的独有接口。
### MifareClassicTag.authenticateSector9+
-authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise\
+authenticateSector(sectorIndex: number, key: number[], isKeyA: boolean): Promise\
-使用密钥对扇区进行身份验证,只有身份验证成功的扇区可以进行操作。使用promise方式作为异步方法。
+使用密钥对扇区进行身份验证,只有身份验证成功的扇区可以进行操作。使用Promise方式作为异步方法。
**需要权限**:ohos.permission.NFC_TAG
**系统能力**:SystemCapability.Communication.NFC
**参数:**
-
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
-| sectorIndex | number | 是 | 待验证的扇区索引 |
-| key | number[]| 是 | 用于身份验证的密钥(6字节) |
+| sectorIndex | number | 是 | 待验证的扇区索引,从0开始。 |
+| key | number[]| 是 | 用于扇区验证的密钥(6字节)。 |
| isKeyA | boolean | 是 | isKeyA标志。true 表示KeyA,false 表示KeyB。|
-**返回值:**
-
-| **类型** | **说明** |
-| ------------------ | --------------------------|
-| Promise\