diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/.gitignore b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/app.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..530edd98abd603959b51947f534038b2032e1589 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.samples.AVImageGeneratorArkTS", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9ea1b19fe6f249adc9c4d784529afe2314f283d7 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVImageGeneratorArkTS" + } + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/README.md b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..bbec397ffc09b0905325042c3b761d1a6ce1df0e --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/README.md @@ -0,0 +1,65 @@ +# AVImageGeneratorArkTS + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用AVImageGenerator提取视频指定时间图像(ArkTS)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/avimagegenerator.md)的配套示例工程。 + +本示例展示了如何获取视频资源的缩略图。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +AVImageGeneratorArkTS +entry/src/main/ets/ +└── pages + └── Index.ets (获取缩略图界面) +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── H264_AAC.mp4(视频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/build-profile.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a2b572d947cd6f7dfba85072fb0313ca83f317c --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/.gitignore b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/build-profile.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..982dbb524bd63408e05cfbed7204dd87a31dd681 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/build-profile.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/hvigorfile.ts b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/oh-package.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9833de65487c05e70797a05302f99f1e06b4c879 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { media } from '@kit.MediaKit'; +import { image } from '@kit.ImageKit'; +import { common } from '@kit.AbilityKit'; + +const TAG = 'MetadataDemo'; +@Entry +@Component +struct Index { + // pixelMap对象声明,用于图片显示。 + @State pixelMap: image.PixelMap | undefined = undefined; + + build() { + Row() { + Column() { + Button() { + Text($r('app.string.FetchFrame')) + .fontSize(26) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('60%') + .height('5%') + .onClick(async () => { + // 设置fdSrc, 获取视频的缩略图。 + await this.testFetchFrameByTime(); + }) + .id('FetchFrameButton') + Image(this.pixelMap).width(300).height(300) + .margin({ + top: 20 + }) + } + .width('100%') + } + .height('100%') + } + + // 在以下demo中,使用资源管理接口获取打包在HAP内的视频文件,通过设置fdSrc属性。 + // 获取视频指定时间的缩略图,并通过Image控件显示在屏幕上。 + async testFetchFrameByTime() { + try { + // 创建AVImageGenerator对象。 + let avImageGenerator: media.AVImageGenerator = await media.createAVImageGenerator(); + // 设置fdSrc。 + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + avImageGenerator.fdSrc = await context.resourceManager.getRawFd('H264_AAC.mp4'); + + // 初始化入参。 + let timeUs = 0; + let queryOption = media.AVImageQueryOptions.AV_IMAGE_QUERY_NEXT_SYNC; + let param: media.PixelMapParams = { + width : 300, + height : 300 + }; + + // 获取缩略图(promise模式)。 + this.pixelMap = await avImageGenerator.fetchFrameByTime(timeUs, queryOption, param); + + // 释放资源(promise模式)。 + avImageGenerator.release(); + console.info(TAG, `release success.`); + } catch (err) { + console.error(`FetchFrameByTime errCode is ${err.code}, message is ${err.message}`); + } + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/module.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9847f338dc03ee5236a5b2ea61939973588f0129 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "获取缩略图ArkTS" + }, + { + "name": "FetchFrame", + "value": "获取缩略图" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4b1e20e73501523f801a942f84f91ed6334161fa --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7277b0e4910c52a8614d4f2162af3c03ad8589100f32e80dc36a9c96ba797ecd +size 1894335 diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..851e98caf1cfb63a8432dd7a130d383e3b4a4f6a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVImageGenerator]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AVImageGeneratorArkTS_001', 0, async (done: Function) => { + console.info(TAG, 'AVImageGeneratorArkTS_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('FetchFrameButton')); + await button.click(); + await driver.delayMs(3000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVImageGeneratorArkTS_001 end'); + }) + }) +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/List.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigorfile.ts b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/oh-package.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/ohosTest.md b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..5c23aeab43003897f35a63c73025c8178951d9ea --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/ohosTest.md @@ -0,0 +1,7 @@ +# AVImageGeneratorArkTS测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并获取缩略图 | 设备正常运行 | | 获取成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/screenshots/AVImageGeneratorArkTS.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/screenshots/AVImageGeneratorArkTS.png new file mode 100644 index 0000000000000000000000000000000000000000..6f4c3fcdff0972d309958d35729879e7004feec1 Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorArkTS/screenshots/AVImageGeneratorArkTS.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/.gitignore b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/app.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d5e0efedb9131cab56bf825c087dc617b3a065ca --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.samples.AVImageGeneratorNDK", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f5f0ec704bbb8ec48f3d70bda3ccf06045164d06 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVImageGeneratorNDK" + } + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/README.md b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/README.md new file mode 100644 index 0000000000000000000000000000000000000000..6471eb0e7423d9acbe1021b5948845851b831d79 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/README.md @@ -0,0 +1,65 @@ +# AVImageGeneratorNDK + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用AVImageGenerator获取视频帧(C/C++)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/using-ndk-avimagegenerator-for-video.md)的配套示例工程。 + +本示例展示了如何获取视频资源的缩略图。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +AVImageGeneratorNDK +entry/src/main/ets/ +└── pages + └── Index.ets (获取缩略图界面) +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── H264_AAC.mp4(视频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/build-profile.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a2b572d947cd6f7dfba85072fb0313ca83f317c --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/.gitignore b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/build-profile.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9bf154bd51072d27832bec1764cd98af35290ca3 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["armeabi-v7a", "arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/hvigorfile.ts b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/oh-package.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3c03cc6d380389d57e0120a980bda3b75099adee --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6efb82a01d9af8615909533224144b522ab5cf11 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,23 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(AVMetadataExtractorNDK) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC + libace_napi.z.so + libavimage_generator.so + libhilog_ndk.z.so + libpixelmap.so + libpixelmap_ndk.z.so + libavmetadata_extractor.so + libnative_media_core.so +) diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5c39ff8f9bfefa85ec9806cf75edbd3a448f0302 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "napi/native_api.h" + +#include +#include +#include +#include +#include "multimedia/player_framework/avmetadata_extractor.h" +#include "multimedia/player_framework/avmetadata_extractor_base.h" + +#include + +#define LOG_PRINT_DOMAIN 0xFF00 +#define APP_LOG_DOMAIN 0x0001 +constexpr const char *APP_LOG_TAG = "AVImageGenerator"; +const int FETCH_FRAME_ARG_NUM = 5; +const int GET_DURATION_ARG_NUM = 3; +const int FIRST_PARAM = 0; +const int SECOND_PARAM = 1; +const int THIRD_PARAM = 2; +const int FOUTRH_PARAM = 3; +const int FIFTH_PARAM = 4; +#define H_LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) + +// 辅助函数:检查参数数量和类型。 +bool CheckArgs(napi_env env, napi_callback_info info, size_t expectedArgc) +{ + size_t argc; + napi_value thisArg; + void* data; + napi_get_cb_info(env, info, &argc, nullptr, &thisArg, &data); + if (argc < expectedArgc) { + napi_throw_error(env, "EINVAL", "Insufficient arguments"); + return false; + } + napi_value argv[expectedArgc]; + napi_get_cb_info(env, info, &argc, argv, &thisArg, &data); + for (size_t i = 0; i < expectedArgc; ++i) { + napi_valuetype type; + napi_typeof(env, argv[i], &type); + if (type != napi_number) { + napi_throw_type_error(env, "EINVAL", "All arguments must be numbers"); + return false; + } + } + return true; +} + +// 辅助函数:获取 int32 类型值并进行错误处理。 +bool GetInt32Value(napi_env env, napi_value value, int32_t* result) +{ + napi_status status = napi_get_value_int32(env, value, result); + if (status != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to get int32 value"); + return false; + } + return true; +} + +// 辅助函数:获取 int64 类型值并进行错误处理。 +bool GetInt64Value(napi_env env, napi_value value, int64_t* result) +{ + napi_status status = napi_get_value_int64(env, value, result); + if (status != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to get int64 value"); + return false; + } + return true; +} + +// FetchFrameByTime的输入参数 +struct FetchFrameParams { + int64_t timeUs = 0; + int64_t offset = 0; + int32_t fileDescribe = -1; + int32_t fileSize = 0; + int32_t options = OH_AVIMAGE_GENERATOR_QUERY_CLOSEST; +}; + +// 辅助函数:获取FetchFrameByTime的输入参数 +bool GetFetchFrameByTimeParams(napi_env env, napi_callback_info info, FetchFrameParams &fetchFrameParams) +{ + if (!CheckArgs(env, info, FETCH_FRAME_ARG_NUM)) { + return false; + } + size_t argc = FETCH_FRAME_ARG_NUM; + napi_value argv[FETCH_FRAME_ARG_NUM]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (!GetInt32Value(env, argv[FIRST_PARAM], &fetchFrameParams.fileDescribe)) { + return false; + } + if (!GetInt32Value(env, argv[SECOND_PARAM], &fetchFrameParams.fileSize)) { + return false; + } + if (!GetInt64Value(env, argv[THIRD_PARAM], &fetchFrameParams.timeUs)) { + return false; + } + if (!GetInt32Value(env, argv[FOUTRH_PARAM], &fetchFrameParams.options)) { + return false; + } + if (!GetInt64Value(env, argv[FIFTH_PARAM], &fetchFrameParams.offset)) { + return false; + } + if (fetchFrameParams.options < OH_AVIMAGE_GENERATOR_QUERY_NEXT_SYNC || + fetchFrameParams.options > OH_AVIMAGE_GENERATOR_QUERY_CLOSEST) { + napi_throw_range_error(env, "EINVAL", "Invalid options value"); + return false; + } + return true; +} + +/** + * 需要在index.d.ts文件内描述映射的OhAvImageGeneratorFetchFrameByTime方法。 + * export const OhAvImageGeneratorFetchFrameByTime: (fdsrc : number, size : number, timeus : number, + * options : number, offset : number) => image.PixelMap; + * 需要传入媒体文件描述符fdsrc、媒体文件大小size、指定的时间timeus(单位us)、 + * 指定时间点与视频帧的对应关系options、媒体源在文件描述符中的偏移量offset。 + * 返回PixelMap对象。 + */ +static napi_value OhAvImageGeneratorFetchFrameByTime(napi_env env, napi_callback_info info) +{ + FetchFrameParams fetchFrameParams; + if (!GetFetchFrameByTimeParams(env, info, fetchFrameParams)) { + return nullptr; + } + int64_t timeUs = fetchFrameParams.timeUs; + int64_t offset = fetchFrameParams.offset; + int32_t fileDescribe = fetchFrameParams.fileDescribe; + int32_t fileSize = fetchFrameParams.fileSize; + int32_t options = fetchFrameParams.options; + // 创建OH_AVImageGenerator实例。 + OH_AVImageGenerator* generator = OH_AVImageGenerator_Create(); + // 异常处理。 + if (!generator) { + napi_throw_error(env, "EFAILED", "Create generator failed"); + return nullptr; + } + // 设置视频资源的文件描述符。 + OH_AVErrCode avErrCode = OH_AVImageGenerator_SetFDSource(generator, fileDescribe, offset, fileSize); + // 异常处理。 + if (avErrCode != AV_ERR_OK) { + OH_AVImageGenerator_Release(generator); + napi_throw_error(env, "EFAILED", "SetFDSource failed"); + return nullptr; + } + // 取指定时间的视频帧。 + OH_PixelmapNative* pixelMap = nullptr; + avErrCode = OH_AVImageGenerator_FetchFrameByTime(generator, timeUs, + (OH_AVImageGenerator_QueryOptions)options, &pixelMap); + // 异常处理。 + if (avErrCode != AV_ERR_OK || !pixelMap) { + OH_AVImageGenerator_Release(generator); + napi_throw_error(env, "EFAILED", "FetchFrameByTime failed"); + return nullptr; + } + // 将nativePixelMap对象转换为PixelMapnapi对象。 + napi_value pixelmapNapi = nullptr; + Image_ErrorCode errCode = OH_PixelmapNative_ConvertPixelmapNativeToNapi(env, pixelMap, &pixelmapNapi); + // 释放OH_PixelmapNative资源。 + OH_PixelmapNative_Release(pixelMap); + // 释放OH_AVImageGenerator资源。 + OH_AVImageGenerator_Release(generator); + // 异常处理。 + if (errCode != IMAGE_SUCCESS) { + napi_throw_error(env, "EFAILED", "Convert PixelMap failed"); + return nullptr; + } + return pixelmapNapi; +} + +// 辅助函数:获取GetDuration的输入参数 +bool GetGetDurationParams(napi_env env, napi_callback_info info, int64_t &offset, int32_t &fileDescribe, + int64_t &fileSize) +{ + if (!CheckArgs(env, info, GET_DURATION_ARG_NUM)) { + return false; + } + size_t argc = GET_DURATION_ARG_NUM; + napi_value argv[GET_DURATION_ARG_NUM]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (!GetInt32Value(env, argv[FIRST_PARAM], &fileDescribe)) { + return false; + } + if (!GetInt64Value(env, argv[SECOND_PARAM], &fileSize)) { + return false; + } + if (!GetInt64Value(env, argv[THIRD_PARAM], &offset)) { + return false; + } + return true; +} + +static napi_value OhAVMetadataExtractorGetDuration(napi_env env, napi_callback_info info) +{ + int64_t offset = 0; + int32_t fileDescribe = -1; + int64_t fileSize = 0; + if (!GetGetDurationParams(env, info, offset, fileDescribe, fileSize)) { + return nullptr; + } + OH_AVMetadataExtractor* mainExtractor = OH_AVMetadataExtractor_Create(); + if (!mainExtractor) { + napi_throw_error(env, "EFAILED", "Create metadata extractor failed"); + return nullptr; + } + OH_AVErrCode avErrCode = OH_AVMetadataExtractor_SetFDSource(mainExtractor, fileDescribe, offset, fileSize); + if (avErrCode != AV_ERR_OK) { + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "SetFDSource for metadata extractor failed"); + return nullptr; + } + OH_AVFormat* avMetadata = OH_AVFormat_Create(); + avErrCode = OH_AVMetadataExtractor_FetchMetadata(mainExtractor, avMetadata); + if (avErrCode != AV_ERR_OK) { + OH_AVFormat_Destroy(avMetadata); + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Fetch metadata failed"); + return nullptr; + } + int64_t out; + if (!OH_AVFormat_GetLongValue(avMetadata, OH_AVMETADATA_EXTRACTOR_DURATION, &out)) { + OH_AVFormat_Destroy(avMetadata); + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Get duration failed"); + return nullptr; + } + napi_value duration; + napi_create_int64(env, out, &duration); + OH_AVFormat_Destroy(avMetadata); + OH_AVMetadataExtractor_Release(mainExtractor); + return duration; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "OhAvImageGeneratorFetchFrameByTime", nullptr, OhAvImageGeneratorFetchFrameByTime, nullptr, nullptr, nullptr, + napi_default, nullptr }, + { "OhAVMetadataExtractorGetDuration", nullptr, OhAVMetadataExtractorGetDuration, nullptr, nullptr, nullptr, + napi_default, nullptr }, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..430afce44bac24a571b4ed11f9114d904c681eaa --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { image } from "@kit.ImageKit"; + +export const OhAvImageGeneratorFetchFrameByTime: (fdsrc : number, size : number, timeus : number, options : number, offset : number) => image.PixelMap; +export const OhAVMetadataExtractorGetDuration: (fdsrc : number, fileSize : number, offset : number) => number; diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f46aeb4a4fa2fa8023596a85e291a48b0dd2deeb --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..28a8e6c49ceedb17310f0d0e805c8cb81a09d20b --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { image } from '@kit.ImageKit'; +import avimagegenerator from 'libentry.so'; +import {promptAction} from '@kit.ArkUI'; +import { common } from '@kit.AbilityKit'; + +@Entry +@Component +struct Index { + @State totalDuration: number = 0; + @State queryOption: string = 'next sync' + @State arrowPosition: ArrowPosition = ArrowPosition.END + @State space: number = 8 + // pixelMap对象声明,用于图片显示。 + @State pixelMap: image.PixelMap | undefined = undefined; + @State queryOptionIndex: number = 0 + private videoName: string = 'H264_AAC.mp4'; + + build() { + Column() { + + Text(this.videoName).fontSize(20).fontWeight(FontWeight.Bold) + + Select([{ value: $r('app.string.nextSync') }, + { value: $r('app.string.previousSync') }, + { value: $r('app.string.closestSync') }, + { value: $r('app.string.closest') }]) + .selected(this.queryOptionIndex) + .value(this.queryOption) + .font({ size: 16, weight: 500 }) + .fontColor('#182431') + .selectedOptionFont({ size: 16, weight: 400 }) + .optionFont({ size: 16, weight: 400 }) + .space(this.space) + .arrowPosition(this.arrowPosition) + .menuAlign(MenuAlignType.START, {dx:0, dy:0}) + .margin({ + top: 20 + }) + .width('60%') + .onSelect((index:number, text?: string | undefined)=>{ + console.info('Select:' + index) + this.queryOptionIndex = index; + if(text){ + this.queryOption = text; + } + }) + + Button() { + Text($r('app.string.FetchFrame')) + .fontSize(30) + .fontWeight(FontWeight.Bold); + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('60%') + .height('5%') + .onClick(() => { + this.testFetchFrameByTime(); + }) + .id('FetchFrameButton'); + + Row () { + if (this.pixelMap) { + Image(this.pixelMap) + .width(300) + .height(300) + .margin({ + top: 20 + }) + .borderWidth(2) + .borderColor('#0D9FFB').objectFit(ImageFit.Fill) + } else { + Image(null) + .width('16.67%') + .margin({ + top: 20 + }) + .borderWidth(0) + .borderColor('#0D9FFB') + } + } + + Button($r('app.string.ClearPictures'), { type: ButtonType.Normal }) + .onClick(() => { + this.pixelMap = undefined; + promptAction.showToast({ + message:$r('app.string.ClearPicturesFinish'), + duration:2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom:80 + }) + }) + .id('ClearPicturesButton'); + }.width('100%').height('100%') + } + + async testFetchFrameByTime() { + try { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let avFileDescriptor = await context.resourceManager.getRawFd(this.videoName); + let fdsrc : number = avFileDescriptor.fd; + let size : number = avFileDescriptor.length; + let offset : number = avFileDescriptor.offset; + let timeMs : number = 0; + timeMs = avimagegenerator.OhAVMetadataExtractorGetDuration(fdsrc, size, offset); + this.totalDuration = timeMs / 1_000; + this.pixelMap = avimagegenerator.OhAvImageGeneratorFetchFrameByTime(fdsrc, size, timeMs * 1000 / 5, + this.queryOptionIndex, offset); + } catch (err) { + console.error(`OhAVMetadataExtractorGetDuration errCode is ${err.code}, message is ${err.message}`); + } + } + +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/module.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d28ff26be237141285e247119e05c7bc983f0248 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/element/string.json @@ -0,0 +1,44 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "获取缩略图NDK" + }, + { + "name": "nextSync", + "value": "next sync" + }, + { + "name": "previousSync", + "value": "previous sync" + }, + { + "name": "closestSync", + "value": "closest sync" + }, + { + "name": "closest", + "value": "closest" + }, + { + "name": "FetchFrame", + "value": "开始抽帧" + }, + { + "name": "ClearPictures", + "value": "清除图片" + }, + { + "name": "ClearPicturesFinish", + "value": "已清除图片" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/rawfile/H264_AAC.mp4 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/rawfile/H264_AAC.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4b1e20e73501523f801a942f84f91ed6334161fa --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/main/resources/rawfile/H264_AAC.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7277b0e4910c52a8614d4f2162af3c03ad8589100f32e80dc36a9c96ba797ecd +size 1894335 diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a2f76ebd321544ce1936d4dbe4ccf9cd96e4eb6 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVImageGeneratorNDK]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AVImageGeneratorNDK_001', 0, async (done: Function) => { + console.info(TAG, 'AVImageGeneratorNDK_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('FetchFrameButton')); + await button.click(); + await driver.delayMs(2000); + const button2 = await driver.findComponent(ON.id('ClearPicturesButton')); + await button2.click(); + await driver.delayMs(2000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVImageGeneratorNDK_001 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/List.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigorfile.ts b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/oh-package.json5 b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/ohosTest.md b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..fb61c4f98416b04581899e543b2c17809f57c688 --- /dev/null +++ b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/ohosTest.md @@ -0,0 +1,7 @@ +# AVImageGeneratorNDK测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并获取缩略图 | 设备正常运行 | | 获取成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/screenshots/AVImageGeneratorNDK.png b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/screenshots/AVImageGeneratorNDK.png new file mode 100644 index 0000000000000000000000000000000000000000..5ec62a9da7cda7a0d89dfd04fbda55d03bcb60b3 Binary files /dev/null and b/code/DocsSample/Media/AVImageGenerator/AVImageGeneratorNDK/screenshots/AVImageGeneratorNDK.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/.gitignore b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/app.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..8fd03c7e22d0faf9268bd7c6ab322c70e7de682c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.samples.AVMetadataExtractorArkTS", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c667fafdd6b692262f3f0f2d04c0cf45f012819c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVMetadataExtractorArkTS" + } + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/README.md b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..88313e7977e4f05c71df0dec244abf89258fa99c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/README.md @@ -0,0 +1,65 @@ +# AVMetadataExtractorArkTS + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用AVMetadataExtractor提取音视频元数据信息(ArkTS)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/avmetadataextractor.md)的配套示例工程。 + +本示例展示了如何获取一个音频资源的元数据。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +AVMetadataExtractorArkTS +entry/src/main/ets/ +└── pages + └── Index.ets (获取元数据界面) +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── test.mp3(音频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/build-profile.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a705bc1cb2b918d64bdda76a08b4f000129647e7 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/.gitignore b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/build-profile.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..982dbb524bd63408e05cfbed7204dd87a31dd681 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/build-profile.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/hvigorfile.ts b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/oh-package.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60294cd76caa83804a07c004ac092f7d4a3ec4d --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { media } from '@kit.MediaKit'; +import { image } from '@kit.ImageKit'; +import { common } from '@kit.AbilityKit'; +import { fileIo as fs, ReadOptions } from '@kit.CoreFileKit'; + +const TAG = 'MetadataDemo'; + +@Entry +@Component +struct Index { + // pixelMap对象声明,用于图片显示。 + @State pixelMap: image.PixelMap | undefined = undefined; + context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; + rootPath: string = this.context.filesDir; + testFilename: string = '/test.mp3'; + + build() { + Row() { + Column() { + Button() { + Text($r('app.string.FetchMetadata')) + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('60%') + .height('5%') + .onClick(async () => { + // 设置fdSrc, 获取音频元数据和专辑封面(异步接口以Callback形式调用)。 + await this.testFetchMetadataFromFdSrcByCallback(); + // 设置fdSrc, 获取音频元数据和专辑封面(异步接口以Promise形式调用)。 + await this.testFetchMetadataFromFdSrcByPromise(); + // 通过fdSrc获取沙箱路径下音频元数据和专辑封面(文件必须在沙箱路径里存在)。 + await this.testFetchMetadataFromFdSrc(); + // 设置dataSrc, 获取沙箱路径下音频元数据和专辑封面(文件必须在沙箱路径里存在)。 + await this.testFetchMetadataFromDataSrc(); + }) + .id('FetchMetadataButton') + + Image(this.pixelMap).width(300).height(300) + .margin({ + top: 20 + }) + } + .width('100%') + } + .height('100%') + } + + // 在以下demo中,使用资源管理接口获取打包在HAP内的媒体资源文件,通过设置fdSrc属性,获取音频元数据并打印。 + // 获取音频专辑封面并通过Image控件显示在屏幕上。该demo以Callback形式进行异步接口调用。 + async testFetchMetadataFromFdSrcByCallback() { + if (canIUse('SystemCapability.Multimedia.Media.AVMetadataExtractor')) { + try { + // 创建AVMetadataExtractor对象。 + let avMetadataExtractor: media.AVMetadataExtractor = await media.createAVMetadataExtractor(); + // 设置fdSrc。 + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + avMetadataExtractor.fdSrc = await context.resourceManager.getRawFd('test.mp3'); + + // 获取元数据(callback模式)。 + avMetadataExtractor.fetchMetadata((error, metadata) => { + if (error) { + console.error(TAG, `fetchMetadata callback failed, err = ${JSON.stringify(error)}`); + return; + } + console.info(TAG, `fetchMetadata callback success, genre: ${metadata.genre}`); + }) + + //获取专辑封面(callback模式)。 + avMetadataExtractor.fetchAlbumCover((err, pixelMap) => { + if (err) { + console.error(TAG, `fetchAlbumCover callback failed, err = ${JSON.stringify(err)}`); + return; + } + this.pixelMap = pixelMap; + + // 释放资源(callback模式)。 + avMetadataExtractor.release((error) => { + if (error) { + console.error(TAG, `release failed, err = ${JSON.stringify(error)}`); + return; + } + console.info(TAG, `release success.`); + }) + }) + } catch (e) { + console.error(TAG + `FetchMetadataFromFdSrcByCallback, code is ${e.code}, message is ${e.message}`); + } + } + } + + // 在以下demo中,使用资源管理接口获取打包在HAP内的媒体资源文件,通过设置fdSrc属性,获取音频元数据并打印。 + // 获取音频专辑封面并通过Image控件显示在屏幕上。该demo以Promise形式进行异步接口调用。 + async testFetchMetadataFromFdSrcByPromise() { + if (canIUse('SystemCapability.Multimedia.Media.AVMetadataExtractor')) { + try { + // 创建AVMetadataExtractor对象。 + let avMetadataExtractor: media.AVMetadataExtractor = await media.createAVMetadataExtractor(); + + // 设置fdSrc。 + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + avMetadataExtractor.fdSrc = await context.resourceManager.getRawFd('test.mp3'); + + // 获取元数据(promise模式)。 + let metadata = await avMetadataExtractor.fetchMetadata(); + console.info(TAG, `get meta data, hasAudio: ${metadata.hasAudio}`); + + // 获取专辑封面(promise模式)。 + this.pixelMap = await avMetadataExtractor.fetchAlbumCover(); + + // 释放资源(promise模式)。 + avMetadataExtractor.release(); + console.info(TAG, `release success.`); + } catch (e) { + console.error(TAG + `FetchMetadataFromFdSrcByPromise, code is ${e.code}, message is ${e.message}`); + } + } + } + + // 在以下demo中,使用fs文件系统打开沙箱地址获取媒体文件地址,设置fdSrc属性,获取音频元数据并打印。 + // 获取音频专辑封面并通过Image控件显示在屏幕上。 + async testFetchMetadataFromFdSrc() { + if (canIUse('SystemCapability.Multimedia.Media.AVMetadataExtractor')) { + try { + // 创建AVMetadataExtractor对象。 + let avMetadataExtractor = await media.createAVMetadataExtractor(); + + // 设置fdSrc。 + console.info(TAG, `path: ${this.rootPath + this.testFilename}`); + avMetadataExtractor.fdSrc = fs.openSync(this.rootPath + this.testFilename); + + // 获取元数据(promise模式)。 + let metadata = await avMetadataExtractor.fetchMetadata(); + console.info(TAG, `get meta data, mimeType: ${metadata.mimeType}`); + + // 获取专辑封面(promise模式)。 + this.pixelMap = await avMetadataExtractor.fetchAlbumCover(); + + // 释放资源(promise模式)。 + avMetadataExtractor.release(); + console.info(TAG, `release data source success.`); + } catch (e) { + console.error(TAG + `FetchMetadataFromFdSrc, code is ${e.code}, message is ${e.message}`); + } + } + } + + // 在以下demo中,使用fs文件系统打开沙箱地址获取媒体文件地址,设置dataSrc属性,获取音频元数据并打印。 + // 获取音频专辑封面并通过Image控件显示在屏幕上。 + async testFetchMetadataFromDataSrc() { + if (canIUse('SystemCapability.Multimedia.Media.AVMetadataExtractor')) { + try { + // 通过UIAbilityContext获取沙箱地址filesDir(以Stage模型为例)。 + let fd: number = fs.openSync(this.rootPath + this.testFilename).fd; + let fileSize: number = fs.statSync(this.rootPath + this.testFilename).size; + // 设置dataSrc描述符,通过callback从文件中获取资源,写入buffer中。 + let dataSrc: media.AVDataSrcDescriptor = { + fileSize: fileSize, + callback: (buffer, len, pos) => { + if (buffer == undefined || len == undefined || pos == undefined) { + console.error(TAG, `dataSrc callback param invalid`); + return -1; + } + let options: ReadOptions = { + offset: pos, + length: len + }; + let num = fs.readSync(fd, buffer, options); + console.info(TAG, 'readAt end, num: ' + num); + if (num > 0 && fileSize >= pos) { + return num; + } + return -1; + } + }; + + // 创建AVMetadataExtractor对象。 + let avMetadataExtractor = await media.createAVMetadataExtractor(); + // 设置dataSrc。 + avMetadataExtractor.dataSrc = dataSrc; + + // 获取元数据(promise模式)。 + let metadata = await avMetadataExtractor.fetchMetadata(); + console.info(TAG, `get meta data, mimeType: ${metadata.mimeType}`); + + // 获取专辑封面(promise模式)。 + this.pixelMap = await avMetadataExtractor.fetchAlbumCover(); + + // 释放资源(promise模式)。 + avMetadataExtractor.release(); + console.info(TAG, `release data source success.`); + } catch (e) { + console.error(TAG + `FetchMetadataFromDataSrc, code is ${e.code}, message is ${e.message}`); + } + } + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/module.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..09cd726f273c7c90004a43ccab0dc87f5ccb8563 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "获取元数据ArkTS" + }, + { + "name": "FetchMetadata", + "value": "获取元数据信息" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/rawfile/test.mp3 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/rawfile/test.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d282626586e8d699e9d8c809b9d1dbe26970270c Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/main/resources/rawfile/test.mp3 differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..deab52e2bf6d092b73e6f1360ae1b149e4761d64 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVMetadataExtractor]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AVMetadataExtractorArkTS_001', 0, async (done: Function) => { + console.info(TAG, 'AVMetadataExtractorArkTS_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('FetchMetadataButton')); + await button.click(); + await driver.delayMs(5000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVMetadataExtractorArkTS_001 end'); + }) + }) +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/List.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigorfile.ts b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/oh-package.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/ohosTest.md b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..24e60ec28ba579c5525172febf05d121610e397a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/ohosTest.md @@ -0,0 +1,7 @@ +# AVMetadataExtractorArkTS测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并获取元信息 | 设备正常运行 | | 获取成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/screenshots/AVMetadataExtractorArkTS.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/screenshots/AVMetadataExtractorArkTS.png new file mode 100644 index 0000000000000000000000000000000000000000..d1643f76ba0443b8522a270b84cd58ef77766902 Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorArkTS/screenshots/AVMetadataExtractorArkTS.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/.gitignore b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/app.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..c67ebdf8650f278ac2bb20690fa2eec4dc980c10 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.samples.AVMetadataExtractorNDK", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2a4fc3662e1ddee38a714c4f21accbafa884ffd9 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVMetadataExtractorNDK" + } + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/README.md b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3b353297df941c2c04fc598d130efbd6e3d81a5c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/README.md @@ -0,0 +1,66 @@ +# AVMetadataExtractorNDK + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用AVMetadataExtractor获取元数据(C/C++)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/using-ndk-avmetadataextractor-for-media.md)的配套示例工程。 + +本示例展示了如何获取一个音频资源的元数据。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + + +## 工程目录 + +``` +AVMetadataExtractorNDK +entry/src/main/ets/ +└── pages + └── Index.ets (获取元数据界面) +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── test.mp3(音频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/build-profile.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a705bc1cb2b918d64bdda76a08b4f000129647e7 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/build-profile.json5 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/.gitignore b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/build-profile.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9bf154bd51072d27832bec1764cd98af35290ca3 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/build-profile.json5 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "externalNativeOptions": { + "path": "./src/main/cpp/CMakeLists.txt", + "arguments": "", + "cppFlags": "", + "abiFilters": ["armeabi-v7a", "arm64-v8a", "x86_64"] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + }, + "nativeLib": { + "debugSymbol": { + "strip": true, + "exclude": [] + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/hvigorfile.ts b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/oh-package.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5b21e253af246edab8b6ef4f10938f4417e8bc25 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/oh-package.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": { + "libentry.so": "file:./src/main/cpp/types/libentry" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/CMakeLists.txt b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..102fb0f38ef1402aa2955640539143a363e3a0f7 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/CMakeLists.txt @@ -0,0 +1,22 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.5.0) +project(AVImageGeneratorNDK) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +if(DEFINED PACKAGE_FIND_FILE) + include(${PACKAGE_FIND_FILE}) +endif() + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(entry SHARED napi_init.cpp) +target_link_libraries(entry PUBLIC + libace_napi.z.so + libhilog_ndk.z.so + libpixelmap.so + libavmetadata_extractor.so + libpixelmap_ndk.z.so + libnative_media_core.so +) diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/napi_init.cpp b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/napi_init.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3030c509bc752489adbe9de0d28d959036ae164 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/napi_init.cpp @@ -0,0 +1,418 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "napi/native_api.h" + +#include +#include +#include +#include +#include +#include + +#include + +#define LOG_PRINT_DOMAIN 0xFF00 +#define APP_LOG_DOMAIN 0x0001 +constexpr const char *APP_LOG_TAG = "AVMetadataExtractor"; +const int ARG_NUM = 3; +const int FIRST_PARAM = 0; +const int SECOND_PARAM = 1; +const int THIRD_PARAM = 2; +const int STRING_VALUE = 0; +const int INT_VALUE = 1; +#define H_LOGI(...) ((void)OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, APP_LOG_TAG, __VA_ARGS__)) + +// 辅助函数:检查参数数量和类型。 +bool CheckArgs(napi_env env, napi_callback_info info, size_t expectedArgc) +{ + size_t argc; + napi_value thisArg; + void* data; + napi_get_cb_info(env, info, &argc, nullptr, &thisArg, &data); + if (argc < expectedArgc) { + napi_throw_error(env, "EINVAL", "Insufficient arguments"); + return false; + } + napi_value argv[expectedArgc]; + napi_get_cb_info(env, info, &argc, argv, &thisArg, &data); + for (size_t i = 0; i < expectedArgc; ++i) { + napi_valuetype type; + napi_typeof(env, argv[i], &type); + if (type != napi_number) { + napi_throw_type_error(env, "EINVAL", "All arguments must be numbers"); + return false; + } + } + return true; +} + +// 辅助函数:获取 int32 类型值并进行错误处理。 +bool GetInt32Value(napi_env env, napi_value value, int32_t* result) +{ + napi_status status = napi_get_value_int32(env, value, result); + if (status != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to get int32 value"); + return false; + } + return true; +} + +// 辅助函数:获取 int64 类型值并进行错误处理。 +bool GetInt64Value(napi_env env, napi_value value, int64_t* result) +{ + napi_status status = napi_get_value_int64(env, value, result); + if (status != napi_ok) { + napi_throw_error(env, "EINVAL", "Failed to get int64 value"); + return false; + } + return true; +} + +// 辅助函数:将 string 类型值转为napi对象并进行错误处理。 +bool SetPropertyString(napi_env env, napi_value &obj, const std::string &key, const std::string &value) +{ + napi_value keyNapi = nullptr; + napi_status status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyNapi); + if (status != napi_ok) { + return false; + } + napi_value valueNapi = nullptr; + status = napi_create_string_utf8(env, value.c_str(), NAPI_AUTO_LENGTH, &valueNapi); + if (status != napi_ok) { + return false; + } + status = napi_set_property(env, obj, keyNapi, valueNapi); + if (status != napi_ok) { + return false; + } + return true; +} + +// 辅助函数:将 double 类型值转为napi对象并进行错误处理。 +bool SetPropertyDouble(napi_env env, napi_value &obj, const std::string &key, double value) +{ + napi_value keyNapi = nullptr; + napi_status status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyNapi); + if (status != napi_ok) { + return false; + } + napi_value valueNapi = nullptr; + status = napi_create_double(env, value, &valueNapi); + if (status != napi_ok) { + return false; + } + status = napi_set_property(env, obj, keyNapi, valueNapi); + if (status != napi_ok) { + return false; + } + return true; +} + +// 辅助函数:将 int 类型值转为napi对象并进行错误处理。 +bool SetPropertyInt(napi_env env, napi_value &obj, const std::string &key, int value) +{ + napi_value keyNapi = nullptr; + napi_status status = napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyNapi); + if (status != napi_ok) { + return false; + } + napi_value valueNapi = nullptr; + status = napi_create_int32(env, value, &valueNapi); + if (status != napi_ok) { + return false; + } + status = napi_set_property(env, obj, keyNapi, valueNapi); + if (status != napi_ok) { + return false; + } + return true; +} + +// 辅助函数:获取FetchAlbumCover、FetchMetadata的输入参数 +bool GetInputParams(napi_env env, napi_callback_info info, int64_t &offset, int32_t &fileDescribe, + int64_t &fileSize) +{ + if (!CheckArgs(env, info, ARG_NUM)) { + return false; + } + size_t argc = ARG_NUM; + napi_value argv[ARG_NUM]; + napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr); + if (!GetInt32Value(env, argv[FIRST_PARAM], &fileDescribe)) { + return false; + } + if (!GetInt64Value(env, argv[SECOND_PARAM], &fileSize)) { + return false; + } + if (!GetInt64Value(env, argv[THIRD_PARAM], &offset)) { + return false; + } + return true; +} + +/** + * 获取专辑封面。 + * 需要在index.d.ts文件内描述映射的OhAVMetadataExtractorFetchAlbumCover方法。 + * export const OhAVMetadataExtractorFetchAlbumCover: (fdsrc : number, size : number, + * offset : number) => image.PixelMap; + * 需要传入媒体文件描述符fdsrc、媒体文件大小size、媒体源在文件描述符中的偏移量offset。 + * 返回PixelMap对象。 + */ +static napi_value OhAVMetadataExtractorFetchAlbumCover(napi_env env, napi_callback_info info) +{ + int64_t offset = 0; + int32_t fileDescribe = -1; + int64_t fileSize = 0; + if (!GetInputParams(env, info, offset, fileDescribe, fileSize)) { + return nullptr; + } + // 创建OH_AVMetadataExtractor实例。 + OH_AVMetadataExtractor* mainExtractor = OH_AVMetadataExtractor_Create(); + // 处理异常。 + if (!mainExtractor) { + napi_throw_error(env, "EFAILED", "Create metadata extractor failed"); + return nullptr; + } + // 设置视频资源的文件描述符。 + OH_AVErrCode avErrCode = OH_AVMetadataExtractor_SetFDSource(mainExtractor, fileDescribe, offset, fileSize); + // 处理异常。 + if (avErrCode != AV_ERR_OK) { + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "SetFDSource for metadata extractor failed"); + return nullptr; + } + // 获取专辑封面。 + OH_PixelmapNative* pixelMap = nullptr; + avErrCode = OH_AVMetadataExtractor_FetchAlbumCover(mainExtractor, &pixelMap); + // 处理异常。 + if (avErrCode != AV_ERR_OK || !pixelMap) { + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Fetch album cover failed"); + return nullptr; + } + // 将nativePixelMap对象转换为PixelMapnapi对象。 + napi_value pixelmapNapi = nullptr; + Image_ErrorCode errCode = OH_PixelmapNative_ConvertPixelmapNativeToNapi(env, pixelMap, &pixelmapNapi); + // 释放OH_PixelmapNative资源。 + OH_PixelmapNative_Release(pixelMap); + // 释放OH_AVMetadataExtractor资源。 + OH_AVMetadataExtractor_Release(mainExtractor); + // 处理异常。 + if (errCode != IMAGE_SUCCESS) { + napi_throw_error(env, "EFAILED", "Convert PixelMap failed"); + return nullptr; + } + return pixelmapNapi; +} + +// 辅助函数:从OH_AVFormat对象中解析出string类型的元数据值,再保存到JS所需的AVMetadata中。 +void GetStringMetaData(struct OH_AVFormat *avMetadata, napi_env env, napi_value &JsMetadata, const char* &key) +{ + const char* out = nullptr; + bool ret = false; + ret = OH_AVFormat_GetStringValue(avMetadata, key, &out); + std::string result = std::string(key) + " : %{public}s"; + H_LOGI(result.c_str(), out); + if (ret && out) { + SetPropertyString(env, JsMetadata, key, out); + } +} + +// 辅助函数:从OH_AVFormat对象中解析出string类型的元数据值,再保存到JS所需的AVMetadata中。 +void GetStringValueFromAVFormat(struct OH_AVFormat *avMetadata, napi_env env, napi_value &JsMetadata) +{ + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_ALBUM); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_ALBUM_ARTIST); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_ARTIST); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_AUTHOR); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_DATE_TIME); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_DATE_TIME_FORMAT); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_COMPOSER); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_GENRE); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_MIME_TYPE); + GetStringMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_TITLE); +} + +// 辅助函数:从OH_AVFormat对象中解析出int类型的元数据值,再保存到JS所需的AVMetadata中。 +void GetIntMetaData(struct OH_AVFormat *avMetadata, napi_env env, napi_value &JsMetadata, const char* &key) +{ + const char* out = nullptr; + bool ret = false; + int32_t value = 0; + ret = OH_AVFormat_GetIntValue(avMetadata, key, &value); + std::string result = std::string(key) + " : %{public}d"; + H_LOGI(result.c_str(), value); + if (ret) { + out = std::to_string(value).c_str(); + SetPropertyString(env, JsMetadata, key, out); + } +} + +// 辅助函数:从OH_AVFormat对象中解析出int类型的元数据值,再保存到JS所需的AVMetadata中。 +void GetIntValueFromAVFormat(struct OH_AVFormat *avMetadata, napi_env env, napi_value &JsMetadata) +{ + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_HAS_AUDIO); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_HAS_VIDEO); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_TRACK_COUNT); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_SAMPLE_RATE); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_VIDEO_HEIGHT); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_VIDEO_WIDTH); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_VIDEO_ORIENTATION); + GetIntMetaData(avMetadata, env, JsMetadata, OH_AVMETADATA_EXTRACTOR_HAS_AUDIO); + + bool ret = false; + int32_t hdrType; + ret = OH_AVFormat_GetIntValue(avMetadata, OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID, &hdrType); + H_LOGI("OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID : %{public}d ret %{public}d", hdrType, ret); + if (ret) { + bool hh = SetPropertyInt(env, JsMetadata, OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID, hdrType); + H_LOGI("OH_AVMETADATA_EXTRACTOR_VIDEO_IS_HDR_VIVID : %{public}d hh %{public}d", hdrType, hh); + } +} + +// 辅助函数:从OH_AVFormat对象中解析出float、long类型的元数据值,再保存到JS所需的AVMetadata中。 +void GetOtherValueFromAVFormat(struct OH_AVFormat *avMetadata, napi_env env, napi_value &JsMetadata) +{ + const char* out = nullptr; + bool ret = false; + + int64_t duration = 0; + ret = OH_AVFormat_GetLongValue(avMetadata, OH_AVMETADATA_EXTRACTOR_DURATION, &duration); + H_LOGI("OH_AVMETADATA_EXTRACTOR_DURATION : %{public}lld", duration); + if (ret) { + out = std::to_string(duration).c_str(); + SetPropertyString(env, JsMetadata, OH_AVMETADATA_EXTRACTOR_DURATION, out); + } + + napi_value location = nullptr; + napi_create_object(env, &location); + float latitude; + bool retLatitude = OH_AVFormat_GetFloatValue(avMetadata, OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE, &latitude); + H_LOGI("OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE : %{public}f", latitude); + if (retLatitude) { + SetPropertyDouble(env, location, OH_AVMETADATA_EXTRACTOR_LOCATION_LATITUDE, latitude); + } + + float longitude; + bool retLongitude = OH_AVFormat_GetFloatValue(avMetadata, OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE, &longitude); + H_LOGI("OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE : %{public}f", longitude); + if (retLongitude) { + SetPropertyDouble(env, location, OH_AVMETADATA_EXTRACTOR_LOCATION_LONGITUDE, longitude); + } + + if (retLatitude || retLongitude) { + napi_value keyNapi = nullptr; + std::string key = "location"; + napi_create_string_utf8(env, key.c_str(), NAPI_AUTO_LENGTH, &keyNapi); + napi_set_property(env, JsMetadata, keyNapi, location); + } +} + +/** + * 获取元数据。 + * 需要在index.d.ts文件内描述映射的OhAVMetadataExtractorFetchMetadata方法。 + * export const OhAVMetadataExtractorFetchMetadata: (fdsrc : number, size : number, + * offset : number) => media.AVMetadata; + * 需要传入媒体文件描述符fdsrc、媒体文件大小size、媒体源在文件描述符中的偏移量offset。 + * 返回AVMetadata对象。 + */ +static napi_value OhAVMetadataExtractorFetchMetadata(napi_env env, napi_callback_info info) +{ + int64_t offset = 0; + int32_t fileDescribe = -1; + int64_t fileSize = 0; + if (!GetInputParams(env, info, offset, fileDescribe, fileSize)) { + return nullptr; + } + // 创建OH_AVMetadataExtractor实例。 + OH_AVMetadataExtractor* mainExtractor = OH_AVMetadataExtractor_Create(); + // 异常处理。 + if (!mainExtractor) { + napi_throw_error(env, "EFAILED", "Create metadata extractor failed"); + return nullptr; + } + // 设置视频资源的文件描述符。 + OH_AVErrCode avErrCode = OH_AVMetadataExtractor_SetFDSource(mainExtractor, fileDescribe, offset, fileSize); + // 异常处理。 + if (avErrCode != AV_ERR_OK) { + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "SetFDSource for metadata extractor failed"); + return nullptr; + } + // 创建OH_AVFormat对象。 + OH_AVFormat* avMetadata = OH_AVFormat_Create(); + // 异常处理。 + if (!avMetadata) { + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Create AVFormat failed"); + return nullptr; + } + // 获取元数据。 + avErrCode = OH_AVMetadataExtractor_FetchMetadata(mainExtractor, avMetadata); + // 异常处理。 + if (avErrCode != AV_ERR_OK) { + OH_AVFormat_Destroy(avMetadata); + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Fetch metadata failed"); + return nullptr; + } + napi_value JsMetadata = nullptr; + napi_status status = napi_create_object(env, &JsMetadata); + // 异常处理。 + if (status != napi_ok) { + OH_AVFormat_Destroy(avMetadata); + OH_AVMetadataExtractor_Release(mainExtractor); + napi_throw_error(env, "EFAILED", "Create JavaScript object failed"); + return nullptr; + } + // 从OH_AVFormat对象中解析出各个元数据值,再保存到JS所需的AVMetadata中。 + GetStringValueFromAVFormat(avMetadata, env, JsMetadata); + GetIntValueFromAVFormat(avMetadata, env, JsMetadata); + GetOtherValueFromAVFormat(avMetadata, env, JsMetadata); + // 释放OH_AVFormat资源。 + OH_AVFormat_Destroy(avMetadata); + // 释放OH_AVMetadataExtractor资源。 + OH_AVMetadataExtractor_Release(mainExtractor); + return JsMetadata; +} + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "OhAVMetadataExtractorFetchAlbumCover", nullptr, OhAVMetadataExtractorFetchAlbumCover, nullptr, nullptr, + nullptr, napi_default, nullptr }, + { "OhAVMetadataExtractorFetchMetadata", nullptr, OhAVMetadataExtractorFetchMetadata, nullptr, nullptr, + nullptr, napi_default, nullptr }, + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "entry", + .nm_priv = ((void *)0), + .reserved = {0}, +}; + +extern "C" __attribute__((constructor)) void RegisterEntryModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/Index.d.ts b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/Index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f28cce8c42992025927dfb9c83d986497365354 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/Index.d.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { image } from "@kit.ImageKit"; +import { media } from '@kit.MediaKit'; + +export const OhAVMetadataExtractorFetchAlbumCover: (a:number,b:number,c:number) => image.PixelMap; +export const OhAVMetadataExtractorFetchMetadata: (a:number,b:number,c:number) => media.AVMetadata; \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..f46aeb4a4fa2fa8023596a85e291a48b0dd2deeb --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/cpp/types/libentry/oh-package.json5 @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "libentry.so", + "types": "./Index.d.ts", + "version": "1.0.0", + "description": "Please describe the basic information." +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e470c89821cef8bcdc515f12c0b5b564f81c12a9 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,227 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { image } from '@kit.ImageKit'; +import { media } from '@kit.MediaKit'; +import avmetadataextractor from 'libentry.so'; +import { promptAction } from '@kit.ArkUI'; +import { common } from '@kit.AbilityKit'; + +const TAG: string = 'AvImageGenerator Demo:' + +@Entry +@Component +struct Index { + private videoName: string = 'test.mp3'; + @State coverPixelMap: image.PixelMap | undefined = undefined; + @State metadata: media.AVMetadata | undefined = undefined; + @State show: boolean = true; + + build() { + Column() { + Text(this.videoName).fontSize(20).fontWeight(FontWeight.Bold) + Row () { + Column() { + Button($r('app.string.FetchCover'), { type: ButtonType.Capsule }) + .margin({ top: 30 }) + .onClick(async() => { + await this.getSelectedVideoCover(); + this.show = true; + promptAction.showToast({ + message:$r('app.string.FetchCoverStart'), + duration:2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom:80 + }) + }) + .id('FetchCover') + } + Column() { + Button($r('app.string.FetchMetaData'), { type: ButtonType.Capsule }) + .margin({ top: 30 }) + .onClick(async() => { + this.coverPixelMap = undefined; + await this.getMetadata(); + this.show = false; + promptAction.showToast({ + message:$r('app.string.FetchMetaDataStart'), + duration:2000, + showMode: promptAction.ToastShowMode.DEFAULT, + bottom:80 + }) + }) + .id('FetchMetaData') + } + } + + Row () { + if (this.show) { + Image(this.coverPixelMap) + .width('70%') + .height(300) + .margin({ + top: 50 + }) + .borderWidth(2) + .borderColor('#0D9FFB') + } else { + Column() { + Text($r('app.string.album')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.albumArtist')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.artist')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.author')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.dateTime')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.dateTimeFormat')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.composer')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.duration')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.genre')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.hasAudio')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.hasVideo')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.mimeType')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.trackCount')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.sampleRate')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.title')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.videoHeight')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.videoWidth')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.videoOrientation')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.hdrType')).fontSize(15).fontWeight(FontWeight.Bold) + Text($r('app.string.location')).fontSize(15).fontWeight(FontWeight.Bold) + } + .width('50%') + .margin({ + top: 50 + }) + + Column() { + Text(this.metadata ? this.metadata.album + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.albumArtist + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.artist + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.author + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.dateTime + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.dateTimeFormat + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.composer + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.duration + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.genre + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.hasAudio + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.hasVideo + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.mimeType + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.trackCount + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.sampleRate + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.title + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.videoHeight + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.videoWidth + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.videoOrientation + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? this.metadata.hdrType + ' ' : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + + Text(this.metadata ? `${JSON.stringify(this.metadata.location)} ` : $r('app.string.noValue')) + .fontSize(15) + .fontWeight(FontWeight.Bold) + } + .width('50%') + .margin({ + top: 50 + }) + } + + } + }.width('100%').height('100%') + } + + async getSelectedVideoCover() { + this.coverPixelMap = undefined; + console.info(TAG + 'getSelectedVideoCover: start') + try { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let avFileDescriptor = await context.resourceManager.getRawFd(this.videoName); + let fdsrc : number = avFileDescriptor.fd; + let size : number = avFileDescriptor.length; + let offset : number = avFileDescriptor.offset; + this.coverPixelMap = avmetadataextractor.OhAVMetadataExtractorFetchAlbumCover(fdsrc, size, offset); + } catch (e) { + console.error(TAG + `getSelectedVideoCover, code is ${e.code}, message is ${e.message}`); + } + console.info(TAG + 'getSelectedVideoCover: start') + } + + async getMetadata() { + console.debug(TAG + 'getMeter START') + try { + let context = this.getUIContext().getHostContext() as common.UIAbilityContext; + let avFileDescriptor = await context.resourceManager.getRawFd(this.videoName); + let fdsrc : number = avFileDescriptor.fd; + let size : number = avFileDescriptor.length; + let offset : number = avFileDescriptor.offset; + this.metadata = avmetadataextractor.OhAVMetadataExtractorFetchMetadata(fdsrc, size, offset) + } catch (e) { + console.error(TAG + 'getMetadata' + JSON.stringify(e)); + } + console.debug(TAG + 'getMeter END') + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/module.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..5002b04f5deacf23f88dbd49534ff93b8750db15 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/element/string.json @@ -0,0 +1,116 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "获取元数据NDK" + }, + { + "name": "FetchCover", + "value": "获取视频的封面" + }, + { + "name": "FetchCoverStart", + "value": "开始获取视频的封面" + }, + { + "name": "FetchMetaData", + "value": "获取视频的元数据" + }, + { + "name": "FetchMetaDataStart", + "value": "开始获取视频的元数据" + }, + { + "name": "album", + "value": "album" + }, + { + "name": "albumArtist", + "value": "albumArtist" + }, + { + "name": "artist", + "value": "artist" + }, + { + "name": "author", + "value": "author" + }, + { + "name": "dateTime", + "value": "dateTime" + }, + { + "name": "dateTimeFormat", + "value": "dateTimeFormat" + }, + { + "name": "composer", + "value": "composer" + }, + { + "name": "duration", + "value": "duration" + }, + { + "name": "genre", + "value": "genre" + }, + { + "name": "hasAudio", + "value": "hasAudio" + }, + { + "name": "hasVideo", + "value": "hasVideo" + }, + { + "name": "mimeType", + "value": "mimeType" + }, + { + "name": "trackCount", + "value": "trackCount" + }, + { + "name": "sampleRate", + "value": "sampleRate" + }, + { + "name": "title", + "value": "title" + }, + { + "name": "videoHeight", + "value": "videoHeight" + }, + { + "name": "videoWidth", + "value": "videoWidth" + }, + { + "name": "videoOrientation", + "value": "videoOrientation" + }, + { + "name": "hdrType", + "value": "hdrType" + }, + { + "name": "location", + "value": "location" + }, + { + "name": "noValue", + "value": "无" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/rawfile/test.mp3 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/rawfile/test.mp3 new file mode 100644 index 0000000000000000000000000000000000000000..d282626586e8d699e9d8c809b9d1dbe26970270c Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/main/resources/rawfile/test.mp3 differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad8cf4ba61ff3d3791005887ffb13cca6d3b66ec --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVMetadataExtractorNDK]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AVMetadataExtractorNDK_001', 0, async (done: Function) => { + console.info(TAG, 'AVMetadataExtractorNDK_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('FetchCover')); + await button.click(); + await driver.delayMs(2000); + const button2 = await driver.findComponent(ON.id('FetchMetaData')); + await button2.click(); + await driver.delayMs(2000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVMetadataExtractorNDK_001 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/List.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigorfile.ts b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/oh-package.json5 b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/ohosTest.md b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..baed9b17f7f718d4e75205c94cc2fb0fad5b4dfa --- /dev/null +++ b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/ohosTest.md @@ -0,0 +1,7 @@ +# AVMetadataExtractorNDK测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并获取元信息 | 设备正常运行 | | 获取成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchCover.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchCover.png new file mode 100644 index 0000000000000000000000000000000000000000..f614b270bb1c069601e8d872d4e72e553025257e Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchCover.png differ diff --git a/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchMetaData.png b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchMetaData.png new file mode 100644 index 0000000000000000000000000000000000000000..99435ff6588d3b70fd8d71d8f0f1217c0c550e04 Binary files /dev/null and b/code/DocsSample/Media/AVMetadataExtractor/AVMetadataExtractorNDK/screenshots/FetchMetaData.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/.gitignore b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/app.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..67eb7477adfd59da092a4937dc171e544496f3d6 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/app.json5 @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.samples.AVTranscoderArkTS", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d3bb8ff4256854629adf939e6949747596513b8c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AVTranscoderArkTS" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/README.md b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..573fc14cace1254d7e8ed14d60ac520906f3d8ef --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/README.md @@ -0,0 +1,69 @@ +# AVTranscoderArkTS + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用AVTranscoder实现视频转码(ArkTS)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/using-avtranscoder-for-transcodering.md)的配套示例工程。 + +本示例以“开始转码-暂停转码-恢复转码-转码完成”的一次流程为示例,展示AVTranscoder视频转码相关功能。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +AVTranscoderArkTS +entry/src/main/ets/ +└── pages +│ └── Index.ets (转码界面) +│ +└── transcoder + └── AVTranscoderManager.ets(转码功能) + +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── H264_AAC.mp4 (视频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a2b572d947cd6f7dfba85072fb0313ca83f317c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/.gitignore b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..982dbb524bd63408e05cfbed7204dd87a31dd681 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/build-profile.json5 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3888cdb09d38032e0e3fb9467ec654de50a9cc3 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {AVTranscoderDemo} from '../transcoder/AVTranscoderManager' + +@Entry +@Component +struct Index { + private context:Context | undefined = this.getUIContext().getHostContext(); + @State avTranscoder: AVTranscoderDemo = new AVTranscoderDemo(this.context); + + build() { + RelativeContainer() { + Column() { + Button($r('app.string.StartTranscoder')) + .onClick(async () => { + console.info(`Button put`); + await this.avTranscoder.avTranscoderDemo(); + }) + .id('AVTranscoderButton') + Progress({ value: 0, total: 100, type: ProgressType.Linear }).value(this.avTranscoder.getCurrentProgress()) + .height(50) + .width('80%') + } + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .height('100%') + .width('100%') + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/transcoder/AVTranscoderManager.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/transcoder/AVTranscoderManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..78ed11206cd124de91125c3ebdf4b1483fa7cc3e --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/ets/transcoder/AVTranscoderManager.ets @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { media } from '@kit.MediaKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import { common } from '@kit.AbilityKit'; +import fs from '@ohos.file.fs'; + +export class AVTranscoderDemo { + private avTranscoder: media.AVTranscoder | undefined = undefined; + private context: Context | undefined; + private currentProgress: number = 0; + constructor(context: Context | undefined) { + if (context != undefined) { + this.context = context; + } + } + private avConfig: media.AVTranscoderConfig = { + audioBitrate: 100000, // 音频比特率。 + audioCodec: media.CodecMimeType.AUDIO_AAC, // 音频编码格式。 + fileFormat: media.ContainerFormatType.CFT_MPEG_4, // 封装格式。 + videoBitrate: 200000, // 视频比特率。 + videoCodec: media.CodecMimeType.VIDEO_AVC, // 视频编码格式。 + }; + + // 注册avTranscoder回调函数。 + setAVTranscoderCallback() { + if (canIUse('SystemCapability.Multimedia.Media.AVTranscoder')) { + if (this.avTranscoder != undefined) { + // 转码完成回调函数。 + this.avTranscoder.on('complete', async () => { + console.log(`AVTranscoder is completed`); + await this.releaseTranscoderingProcess(); + }); + // 错误上报回调函数。 + this.avTranscoder.on('error', (err: BusinessError) => { + console.error(`AVTranscoder failed, code is ${err.code}, message is ${err.message}`); + }); + // 进度上报回调函数 + this.avTranscoder.on('progressUpdate', (progress: number) => { + console.info(`AVTranscoder progressUpdate = ${progress}`); + this.currentProgress = progress; + }) + } + } + } + + // 开始转码对应的流程。 + async startTranscoderingProcess() { + if (canIUse('SystemCapability.Multimedia.Media.AVTranscoder')) { + if (this.avTranscoder != undefined) { + await this.avTranscoder.release(); + this.avTranscoder = undefined; + } + // 1.创建转码实例。 + this.avTranscoder = await media.createAVTranscoder(); + this.setAVTranscoderCallback(); + // 2.获取转码源文件fd和目标文件fd赋予avTranscoder;参考FilePicker文档。 + if (this.context != undefined) { + try { + // 获取输入文件fd,H264_AAC.mp4为rawfile目录下的预置资源,需要开发者根据实际情况进行替换。 + let fileDescriptor = await this.context.resourceManager.getRawFd('H264_AAC.mp4'); + this.avTranscoder.fdSrc = fileDescriptor; + } catch (error) { + console.error('Failed to get the file descriptor, please check the resource and path.'); + } + let outputFilePath = this.context.filesDir + '/output.mp4'; + let file = fs.openSync(outputFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + this.avTranscoder.fdDst = file.fd; + this.currentProgress = 0; + } + // 3.配置转码参数完成准备工作。 + await this.avTranscoder.prepare(this.avConfig); + // 4.开始转码。 + await this.avTranscoder.start(); + } + } + + // 暂停转码对应的流程。 + async pauseTranscoderingProcess() { + if (canIUse('SystemCapability.Multimedia.Media.AVTranscoder')) { + if (this.avTranscoder != undefined) { // 仅在调用start返回后调用pause为合理调用。 + await this.avTranscoder.pause(); + } + } + } + + // 恢复对应的转码流程。 + async resumeTranscoderingProcess() { + if (canIUse('SystemCapability.Multimedia.Media.AVTranscoder')) { + if (this.avTranscoder != undefined) { // 仅在调用pause返回后调用resume为合理调用。 + await this.avTranscoder.resume(); + } + } + } + + // 释放转码流程。 + async releaseTranscoderingProcess() { + if (canIUse('SystemCapability.Multimedia.Media.AVTranscoder')) { + if (this.avTranscoder != undefined) { + // 1.释放转码实例。 + await this.avTranscoder.release(); + this.avTranscoder = undefined; + // 2.关闭转码目标文件fd。 + fs.closeSync(this.avTranscoder!.fdDst); + } + } + } + + // 获取当前进度 + getCurrentProgress(): number { + console.info(`getCurrentProgress = ${this.currentProgress}`); + return this.currentProgress; + } + + // 一个完整的【开始转码-暂停转码-恢复转码-转码完成】示例。 + async avTranscoderDemo() { + await this.startTranscoderingProcess(); // 开始转码。 + await this.pauseTranscoderingProcess(); //暂停转码。 + await this.resumeTranscoderingProcess(); // 恢复转码。 + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/module.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e9f202514f24c3004040ac92771599168fb22878 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "视频转码ArkTS" + }, + { + "name": "StartTranscoder", + "value": "启动转码" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4b1e20e73501523f801a942f84f91ed6334161fa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/main/resources/rawfile/H264_AAC.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7277b0e4910c52a8614d4f2162af3c03ad8589100f32e80dc36a9c96ba797ecd +size 1894335 diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a3756ab985fbd257019c04836c98509e95f53f07 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AVTranscoder]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AVTranscoderTest_001', 0, async (done: Function) => { + console.info(TAG, 'AVTranscoderTest_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('AVTranscoderButton')); + await button.click(); + await driver.delayMs(9000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AVTranscoderTest_001 end'); + }) + }) +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/ohosTest.md b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c8595a3cb22b2a239eeecd4b0ba03a4c0c4b5ef4 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/ohosTest.md @@ -0,0 +1,7 @@ +# AVTranscoderArkTS测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并转码 | 设备正常运行 | | 转码成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/screenshots/AVTranscoderArkTS.png b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/screenshots/AVTranscoderArkTS.png new file mode 100644 index 0000000000000000000000000000000000000000..1de1bcda3d5cb5686d4b07c023cff08ee74047d5 Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AVTranscoderArkTS/screenshots/AVTranscoderArkTS.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/.gitignore b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/app.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..551bc577f6a39a2127ef39ce2981ee79ad4e0c28 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/app.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "bundleName": "com.samples.AsyncTranscoder", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d4d767f0f73795c784cfedac4124d3f6ec28deea --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AsyncTranscoder" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/background.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/README.md b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/README.md new file mode 100644 index 0000000000000000000000000000000000000000..93988cdb2076b0b4d980801b5c02c40fbe07c409 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/README.md @@ -0,0 +1,71 @@ +# AsyncTranscoder + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[创建异步线程执行AVTranscoder视频转码(ArkTS)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/avtranscoder-practice.md)的配套示例工程。 + +本示展示了使用worker线程的方式来实现异步线程进行转码。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +AsyncTranscoder +entry/src/main/ets/ +├── pages +│ └── Index.ets (转码界面) +├── util +│ └── SendableObject.ets (Sendable对象) +│ +└── workers + └── task.ets(转码任务) + +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── H264_AAC.mp4 (视频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/AVTranscoder/AsyncTranscoder/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a2b572d947cd6f7dfba85072fb0313ca83f317c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/.gitignore b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/build-profile.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..79369869089572f3970c5649d6135c5def8ca926 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/build-profile.json5 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "apiType": "stageMode", + "buildOption": { + "sourceOption": { + "workers": [ + "./src/main/ets/workers/task.ets", + ] + } + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..8774588471ede4c1563f09d9a1d22f764bb1fd9e --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/obfuscation-rules.txt b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..843c7f0c1f7b9a460e3dbbd2689e5b34016027d1 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..4ce6449f0e91914e73d4502c9f2e8e9a395ea4b1 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..8c21e1a1e208ff3b068c9018d19e3ecb4d51f9fa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ErrorEvent, MessageEvents, worker } from '@kit.ArkTS' +import { SendableObject } from '../util/SendableObject'; +import { common, sendableContextManager } from '@kit.AbilityKit'; + + +@Entry +@Component +struct Index { + private workerInstance?: worker.ThreadWorker; + private context: Context | undefined; + @State currentProgress: number = 0; + + build() { + RelativeContainer() { + Column() { + Button($r('app.string.StartTranscoder')) + .onClick(async () => { + console.info(`Button put`); + await this.startWorker(); + }) + .id('AsyncAVTranscoderButton') + Progress({ value: 0, total: 100, type: ProgressType.Linear }).value(this.currentProgress) + .height(50) + .width('80%') + } + .alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .height('100%') + .width('100%') + } + + + async startWorker() { + // 创建Worker对象 + this.workerInstance = new worker.ThreadWorker('entry/ets/workers/task.ets'); + + + // 注册onmessage回调,当宿主线程接收到来自其创建的Worker通过workerPort.postMessage接口发送的消息时被调用, + // 在宿主线程执行 + this.workerInstance.onmessage = (e: MessageEvents) => { + let data: string | number = e.data; + if (typeof data === 'string') { + console.info('workerInstance onmessage is: ', data); + if (data === 'complete') { + console.info('complete: ', data); + this.workerInstance?.terminate(); + } + } else if (typeof data === 'number') { + this.currentProgress = data; + } + } + + + // 注册onErrors回调,可以捕获Worker线程的onmessage回调、timer回调以及文件执行等流程产生的全局异常, + // 在宿主线程执行 + this.workerInstance.onerror = (err: ErrorEvent) => { + console.error('workerInstance onerror message is: ' + err.message); + } + + + // 注册onmessageerror回调,当Worker对象接收到一条无法被序列化的消息时被调用,在宿主线程执行 + this.workerInstance.onmessageerror = () => { + console.error('workerInstance onmessageerror'); + } + + + // 注册onexit回调,当Worker销毁时被调用,在宿主线程执行 + this.workerInstance.onexit = (e: number) => { + // 当Worker正常退出时code为0,异常退出时code为1 + console.info('workerInstance onexit code is: ', e); + } + + + // 向Worker线程发送消息 + this.context = this.getUIContext().getHostContext(); + if (this.context != undefined) { + const sendableContext: sendableContextManager.SendableContext =sendableContextManager.convertFromContext( + this.context); + const sendableObject: SendableObject = new SendableObject(sendableContext, 'some information'); + this.workerInstance.postMessageWithSharedSendable(sendableObject); + } + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/util/SendableObject.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/util/SendableObject.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cfbfa8ff91de4e9c2188635b0c68b26417e7cf3 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/util/SendableObject.ets @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { sendableContextManager } from '@kit.AbilityKit'; + + +//发送的参数必须加上@Sendable标注 +@Sendable +export class SendableObject { + constructor(sendableContext: sendableContextManager.SendableContext, data: string = '') { + this.sendableContext = sendableContext; + this.data = data; + } + + + private sendableContext: sendableContextManager.SendableContext; + private data: string; + + + public getSendableContext() { + return this.sendableContext; + } + + + public getData() { + return this.data; + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/workers/task.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/workers/task.ets new file mode 100644 index 0000000000000000000000000000000000000000..1246259fd084a1523cad523285c92d4bcc544c11 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/ets/workers/task.ets @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope, worker } from '@kit.ArkTS'; +import { media } from '@kit.MediaKit'; +import { BusinessError } from '@kit.BasicServicesKit'; +import fs from '@ohos.file.fs'; +import { SendableObject } from '../util/SendableObject'; +import { common, sendableContextManager } from '@kit.AbilityKit'; + +const workerPort: ThreadWorkerGlobalScope = worker.workerPort; + +workerPort.onmessage = async (event: MessageEvents) => { + console.info(`onmessage in`); + //worker线程接收参数 + const sendableObject: SendableObject = event.data; + const sendableContext: sendableContextManager.SendableContext = + sendableObject.getSendableContext() as sendableContextManager.SendableContext; + const context: common.Context = + sendableContextManager.convertToContext(sendableContext) as common.Context; + //执行转码逻辑 + await doSome(context); + // 向主线程发送消息 + workerPort.postMessage('start end'); +}; + +workerPort.onmessageerror = (event: MessageEvents) => { + console.info('workerPort onmessageerror'); +}; + +workerPort.onerror = (event: ErrorEvent) => { + console.info('workerPort onerror err is: ', event.message); +}; + +async function doSome(context: common.Context) { + console.info(`doSome in`); + try { + let transcoder = await media.createAVTranscoder(); + // 转码完成回调函数 + transcoder.on('complete', async () => { + console.info(`transcode complete`); + fs.closeSync(transcoder.fdDst); + await transcoder?.release() + // 向主线程发送转码结束的消息 + workerPort.postMessage('complete'); + }) + // 转码错误回调函数 + transcoder.on('error', async (err: BusinessError) => { + fs.closeSync(transcoder.fdDst); + await transcoder?.release(); + }) + // 转码进度更新 + transcoder.on('progressUpdate', (progress: number) => { + console.info(`AVTranscoder progressUpdate = ${progress}`); + workerPort.postMessage(progress); + }) + try { + // 获取输入文件fd,3.mkv为rawfile目录下的预置资源,需要开发者根据实际情况进行替换。 + let fileDescriptor = await context.resourceManager.getRawFd('H264_AAC.mp4'); + transcoder.fdSrc = fileDescriptor; + } catch (error) { + console.error('Failed to get the file descriptor, please check the resource and path.'); + } + let fdPath = context.filesDir + '/' + 'VID_' + Date.parse(new Date().toString()) + '.mp4'; + let file = fs.openSync(fdPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); + let fd = file.fd; + console.info(`file fd ${fd}`); + transcoder.fdDst = file.fd; + + let config: media.AVTranscoderConfig = { + fileFormat: media.ContainerFormatType.CFT_MPEG_4, + audioCodec: media.CodecMimeType.AUDIO_AAC, + videoCodec: media.CodecMimeType.VIDEO_AVC, + videoBitrate: 200000, + } + await transcoder?.prepare(config); + await transcoder?.start(); + } catch (e) { + console.error(`transcode error: code = ` + e.code.toString() + `, message = ${JSON.stringify(e.message)}`); + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/module.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ce393bdb985dc14dc42b0e8eadc5f889bc1373d3 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/module.json5 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..41ec77a69a6d148d7084866004ff216a4202e916 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "异步线程执行转码" + }, + { + "name": "StartTranscoder", + "value": "启动转码" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/rawfile/H264_AAC.mp4 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/rawfile/H264_AAC.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..4b1e20e73501523f801a942f84f91ed6334161fa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/main/resources/rawfile/H264_AAC.mp4 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7277b0e4910c52a8614d4f2162af3c03ad8589100f32e80dc36a9c96ba797ecd +size 1894335 diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..323d1d611fecf4ecb751976e3a71500b3712a445 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/mock/mock-config.json5 @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..850c3c6997b41532e0d7e686da3287b2ea9dd040 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_AsyncAVTranscoder]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + it('AsyncAVTranscoderTest_001', 0, async (done: Function) => { + console.info(TAG, 'AsyncAVTranscoderTest_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + try { + const button = await driver.findComponent(ON.id('AsyncAVTranscoderButton')); + await button.click(); + await driver.delayMs(9000); + done(); + } catch (exception) { + expect().assertFail(); + } + console.info(TAG, 'AsyncAVTranscoderTest_001 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c64e0b06938d246ce044186d4b2d02b500a89e14 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d3069fb7f9163da9f7e6ffe7366140c3368edc34 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/ohosTest/module.json5 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/List.test.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a60c87c5cbb0badf7c3fd8975034590e6fafa992 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..841bfd77e56060e50ec0924302a5ae624e76e3aa --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigor/hvigor-config.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigorfile.ts b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/oh-package.json5 b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/ohosTest.md b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..c1bd1b343c9338ade096d5fecdc48787fc58edbe --- /dev/null +++ b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/ohosTest.md @@ -0,0 +1,7 @@ +# AsyncTranscoder测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并转码 | 设备正常运行 | | 转码成功 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/screenshots/AsyncTranscoder.png b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/screenshots/AsyncTranscoder.png new file mode 100644 index 0000000000000000000000000000000000000000..1de1bcda3d5cb5686d4b07c023cff08ee74047d5 Binary files /dev/null and b/code/DocsSample/Media/AVTranscoder/AsyncTranscoder/screenshots/AsyncTranscoder.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/.gitignore b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..d2ff20141ceed86d87c0ea5d99481973005bab2b --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/.gitignore @@ -0,0 +1,12 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/app.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..bba3859a5fcd7a2ea9516a2df28b5be0f4f80aef --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "app": { + "bundleName": "com.samples.SoundPoolArkTS", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/element/string.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..a26e4e7f8e4b46f82159367f43ab3edadf5949fc --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SoundPoolArkTS" + } + ] +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/background.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/foreground.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/layered_image.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/AppScope/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/README.md b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f246b5b7d17a8e06e3042db88f70bef430443216 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/README.md @@ -0,0 +1,65 @@ +# SoundPoolArkTS + +## 介绍 + +本示例为媒体->Media Kit(媒体服务)->[使用SoundPool播放短音频(ArkTS)](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/media/media/using-soundpool-for-playback.md)的配套示例工程。 + +本示例展示了如何使用SoundPool进行低时延播放。 + +## 效果预览 + +| 预览 | +| -------------------------------------------- | + + + +## 工程目录 + +``` +SoundPoolArkTS +entry/src/main/ets/ +└── pages + └── Index.ets (播放界面) +entry/src/main/resources/ +├── base +│ ├── element +│ │ ├── color.json +│ │ ├── float.json +│ │ └── string.json +│ └── media +│ +└── rawfile + └── test.ogg (音频资源) +entry/src/ohosTest/ets/ +└── test + ├── Ability.test.ets (UI测试代码) + └── List.test.ets (测试套件列表) +``` + +## 相关权限 + +不涉及 + +## 依赖 + +不涉及 + +## 约束和限制 + +1. 本示例支持标准系统上运行,支持设备:RK3568; + +2. 本示例支持API20版本SDK,版本号:6.0.0.34; + +3. 本示例已支持使DevEco Studio 5.0.3 Release (构建版本:5.0.9.300,构建 2025年3月13日)编译运行 + +## 下载 + +如需单独下载本工程,执行如下命令: + +``` +git init +git config core.sparsecheckout true +echo code/DocsSample/Media/SoundPool/SoundPoolArkTS/ > .git/info/sparse-checkout +git remote add origin https://gitee.com/openharmony/applications_app_samples.git +git pull origin master +``` \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/build-profile.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5a2b572d947cd6f7dfba85072fb0313ca83f317c --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/build-profile.json5 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "app": { + "signingConfigs": [], + "products": [ + { + "name": "default", + "signingConfig": "default", + "compileSdkVersion": 20, + "targetSdkVersion": 20, + "compatibleSdkVersion": 20, + "runtimeOS": "OpenHarmony", + "buildOption": { + "strictMode": { + "caseSensitiveCheck": true, + "useNormalizedOHMUrl": true + } + } + } + ], + "buildModeSet": [ + { + "name": "debug", + }, + { + "name": "release" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/.gitignore b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..e2713a2779c5a3e0eb879efe6115455592caeea5 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/oh_modules +/.preview +/build +/.cxx +/.test \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/build-profile.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..e7569e3056e27af38e9991b7ea73ec10f3ba8a05 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/build-profile.json5 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "apiType": "stageMode", + "buildOption": { + }, + "buildOptionSet": [ + { + "name": "release", + "arkOptions": { + "obfuscation": { + "ruleOptions": { + "enable": false, + "files": [ + "./obfuscation-rules.txt" + ] + } + } + } + }, + ], + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/hvigorfile.ts b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..e4f43d54667f8327c367c8096bd08bb8c75aff54 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/hvigorfile.ts @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hapTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/obfuscation-rules.txt b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/obfuscation-rules.txt new file mode 100644 index 0000000000000000000000000000000000000000..272efb6ca3f240859091bbbfc7c5802d52793b0b --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/obfuscation-rules.txt @@ -0,0 +1,23 @@ +# Define project specific obfuscation rules here. +# You can include the obfuscation configuration files in the current module's build-profile.json5. +# +# For more details, see +# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 + +# Obfuscation options: +# -disable-obfuscation: disable all obfuscations +# -enable-property-obfuscation: obfuscate the property names +# -enable-toplevel-obfuscation: obfuscate the names in the global scope +# -compact: remove unnecessary blank spaces and all line feeds +# -remove-log: remove all console.* statements +# -print-namecache: print the name cache that contains the mapping from the old names to new names +# -apply-namecache: reuse the given cache file + +# Keep options: +# -keep-property-name: specifies property names that you want to keep +# -keep-global-name: specifies names that you want to keep in the global scope + +-enable-property-obfuscation +-enable-toplevel-obfuscation +-enable-filename-obfuscation +-enable-export-obfuscation \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/oh-package.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..10cda399b0aec3099b257299a57d284393e4e55a --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "name": "entry", + "version": "1.0.0", + "description": "Please describe the basic information.", + "main": "", + "author": "", + "license": "", + "dependencies": {} +} + diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entryability/EntryAbility.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3ee54d2beea61d38866762868bd056d3e39e3c9 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; + +const DOMAIN = 0x0000; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { + this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET); + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy(): void { + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + // Main window is created, set main page for this ability + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err) => { + if (err.code) { + hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err)); + return; + } + hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.'); + }); + } + + onWindowStageDestroy(): void { + // Main window is destroyed, release UI related resources + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground(): void { + // Ability has brought to foreground + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground(): void { + // Ability has back to background + hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..0a97e21bd7a15599af76a806695860ff1eb0ebfe --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit'; + +const DOMAIN = 0x0000; + +export default class EntryBackupAbility extends BackupExtensionAbility { + async onBackup() { + hilog.info(DOMAIN, 'testTag', 'onBackup ok'); + await Promise.resolve(); + } + + async onRestore(bundleVersion: BundleVersion) { + hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion)); + await Promise.resolve(); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/pages/Index.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f97cb00716ca997bc1013fbee82c56871ce947e --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { media } from '@kit.MediaKit'; +import { audio } from '@kit.AudioKit'; +import { BusinessError } from '@kit.BasicServicesKit'; + + +@Entry +@Component +struct Index { + @State message: string = 'Hello World'; + private soundPool: media.SoundPool | undefined = undefined; + private soundId: number = 0; + private streamId: number = 0; + + async aboutToAppear(): Promise { + this.create(); + } + + async aboutToDisappear() { + this.release(); + } + + build() { + RelativeContainer() { + Row() { + Button($r('app.string.playSoundPool')) + .width(100) + .height(100) + .onClick(() => { + this.PlaySoundPool() + }) + .id('playSoundPoolButton') + .type(ButtonType.Circle) + }.alignRules({ + center: { anchor: '__container__', align: VerticalAlign.Center }, + middle: { anchor: '__container__', align: HorizontalAlign.Center } + }) + } + .height('100%') + .width('100%') + } + + async create() { + try { + // audioRenderInfo中的参数usage取值为STREAM_USAGE_UNKNOWN,STREAM_USAGE_MUSIC,STREAM_USAGE_MOVIE。 + // STREAM_USAGE_AUDIOBOOK时,SoundPool播放短音时为混音模式,不会打断其他音频播放。 + let audioRendererInfo: audio.AudioRendererInfo = { + usage: audio.StreamUsage.STREAM_USAGE_MUSIC, // 音频流使用类型:音乐。根据业务场景配置,参考StreamUsage。 + rendererFlags: 1 // 音频渲染器标志。 + } + //创建soundPool实例。 + this.soundPool = await media.createSoundPool(14,audioRendererInfo); + //注册监听。 + this.loadCallback(); + this.finishPlayCallback(); + this.setErrorCallback(); + + // 加载音频资源。 + let context = this.getUIContext().getHostContext();; + let fileDescriptor = await context!.resourceManager.getRawFd('test.ogg'); + this.soundId = await this.soundPool!.load(fileDescriptor.fd, fileDescriptor.offset, fileDescriptor.length); + console.info(`load soundPool soundId: ${this.soundId}`) + } catch (e) { + console.error('createSoundPool error: ' + e); + } + } + + async loadCallback() { + // 加载完成回调。 + this.soundPool!.on('loadComplete', (soundId_: number) => { + this.soundId = soundId_; + console.info('loadComplete soundId: ' + soundId_); + }) + } + + //设置播放完成监听。 + async finishPlayCallback() { + this.soundPool!.on('playFinished', () => { + console.info('receive play finished message'); + // 可进行下次播放。 + }) + } + //设置错误类型监听。 + async setErrorCallback() { + this.soundPool!.on('error', (error: BusinessError) => { + console.error('error happened,message is :' + error.code); + console.error('error happened,message is :' + error.message); + }) + } + + async PlaySoundPool() { + let playParameters: media.PlayParameters = { + loop: 1, // 循环1次,即播放2次。 + rate: 1, // 1倍速播放。 + leftVolume: 0.5, // 取值范围0.0-1.0。 + rightVolume: 0.5, // 取值范围0.0-1.0。 + priority: 0, // 最低优先级。 + }; + // 开始播放,这边play也可带播放播放的参数PlayParameters,请在音频资源加载完毕,即收到loadComplete回调之后再执行play操作。 + this.soundPool!.play(this.soundId, playParameters, (error, streamID: number) => { + if (error) { + console.error(`play sound Error: errCode is ${error.code}, errMessage is ${error.message}`) + } else { + this.streamId = streamID; + console.info('play success soundid:' + this.streamId); + } + }); + // 设置循环播放次数。 + await this.soundPool!.setLoop(this.streamId, 2); // 播放3次。 + // 设置对应流的优先级。 + await this.soundPool!.setPriority(this.streamId, 1); + // 设置音量。 + await this.soundPool!.setVolume(this.streamId, 0.5, 0.5); + } + + async release() { + // 终止指定流的播放。 + await this.soundPool!.stop(this.streamId); + // 卸载音频资源。 + await this.soundPool!.unload(this.soundId); + //关闭监听。 + this.setOffCallback(); + // 释放SoundPool。 + await this.soundPool!.release(); + } + + + + async setOffCallback() { + this.soundPool!.off('loadComplete'); + this.soundPool!.off('playFinished'); + this.soundPool!.off('error'); + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/module.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..9bed6e6fd262f8e7273a9ff5dfdf67d826492b07 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/module.json5 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:EntryAbility_desc", + "icon": "$media:layered_image", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:startIcon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "EntryBackupAbility", + "srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets", + "type": "backup", + "exported": false, + "metadata": [ + { + "name": "ohos.extension.backup", + "resource": "$profile:backup_config" + } + ], + } + ] + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/color.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/float.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..33ea22304f9b1485b5f22d811023701b5d4e35b6 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/float.json @@ -0,0 +1,8 @@ +{ + "float": [ + { + "name": "page_text_font_size", + "value": "50fp" + } + ] +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/string.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..023606bd48a81157acfa52d4f92f221535673db2 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "低时延音频播放" + }, + { + "name": "playSoundPool", + "value": "播放RawFile" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/background.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/background.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/foreground.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/foreground.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/layered_image.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/layered_image.json @@ -0,0 +1,7 @@ +{ + "layered-image": + { + "background" : "$media:background", + "foreground" : "$media:foreground" + } +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/startIcon.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/startIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..205ad8b5a8a42e8762fbe4899b8e5e31ce822b8b Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/media/startIcon.png differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/backup_config.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/backup_config.json new file mode 100644 index 0000000000000000000000000000000000000000..78f40ae7c494d71e2482278f359ec790ca73471a --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/backup_config.json @@ -0,0 +1,3 @@ +{ + "allowToBackupRestore": true +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/main_pages.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/dark/element/color.json b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/dark/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..79b11c2747aec33e710fd3a7b2b3c94dd9965499 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/dark/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#000000" + } + ] +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/rawfile/test.ogg b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/rawfile/test.ogg new file mode 100644 index 0000000000000000000000000000000000000000..a4bc8b1db0c69505d7771ca9f10db8154c56bbf0 Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/main/resources/rawfile/test.ogg differ diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/mock/mock-config.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/mock/mock-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..b9a78e201535765168a92d3543c690273ecdc019 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/mock/mock-config.json5 @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/Ability.test.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/Ability.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4843922017538fb5a2d94bdd587e2a29c96d87fc --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/Ability.test.ets @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; +import { Driver, ON } from '@ohos.UiTest'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +export default function abilityTest() { + const TAG = '[Sample_SoundPool]'; + const driver = Driver.create(); + const abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + const bundleName = AbilityDelegatorRegistry.getArguments().bundleName; + + describe('ActsAbilityTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }) + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }) + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }) + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }) + + /** + * Test SoundPool play + */ + it('SoundPoolTest_001', 0, async (done: Function) => { + console.info(TAG, 'SoundPoolTest_001 begin'); + try { + await abilityDelegator.startAbility({ + bundleName: bundleName, + abilityName: 'EntryAbility' + }); + } catch (exception) { + expect().assertFail(); + } + await driver.delayMs(1000); + const button = await driver.findComponent(ON.id('playSoundPoolButton')); + await button.click(); + await driver.delayMs(2000); + await button.click(); + await driver.delayMs(2000); + done(); + console.info(TAG, 'SoundPoolTest_001 end'); + }) + }) +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/List.test.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1eac52fcebe8958e19a7b8fed2e8f39c520a3e42 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import abilityTest from './Ability.test'; + +export default function testsuite() { + abilityTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/module.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..6b9889e8ccb62f93825d6b26fa53db8e97a974c0 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/ohosTest/module.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +{ + "module": { + "name": "entry_test", + "type": "feature", + "deviceTypes": [ + "phone", + "tablet", + "2in1" + ], + "deliveryWithInstall": true, + "installationFree": false + } +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/List.test.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f1186b1f53c3a70930921c5dbd1417332bec56c9 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import localUnitTest from './LocalUnit.test'; + +export default function testsuite() { + localUnitTest(); +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/LocalUnit.test.ets b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/LocalUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7fc57c77dbf76d8df08a2b802a55b948e3fcf968 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/entry/src/test/LocalUnit.test.ets @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function localUnitTest() { + describe('localUnitTest', () => { + // Defines a test suite. Two parameters are supported: test suite name and test suite function. + beforeAll(() => { + // Presets an action, which is performed only once before all test cases of the test suite start. + // This API supports only one parameter: preset action function. + }); + beforeEach(() => { + // Presets an action, which is performed before each unit test case starts. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: preset action function. + }); + afterEach(() => { + // Presets a clear action, which is performed after each unit test case ends. + // The number of execution times is the same as the number of test cases defined by **it**. + // This API supports only one parameter: clear action function. + }); + afterAll(() => { + // Presets a clear action, which is performed after all test cases of the test suite end. + // This API supports only one parameter: clear action function. + }); + it('assertContain', 0, () => { + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. + let a = 'abc'; + let b = 'b'; + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. + expect(a).assertContain(b); + expect(a).assertEqual(a); + }); + }); +} \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigor/hvigor-config.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2f5b88411d60de67e1d9411dd6c49249aad9dae0 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigor/hvigor-config.json5 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "dependencies": { + }, + "execution": { + // "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */ + }, + "logging": { + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */ + }, + "debugging": { + // "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */ + }, + "nodeOptions": { + // "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/ + // "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/ + } +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigorfile.ts b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..6b365cacd0191d3b1178eb6b9807b1ae0add6271 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/hvigorfile.ts @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { appTasks } from '@ohos/hvigor-ohos-plugin'; + +export default { + system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */ + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */ +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/oh-package.json5 b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..3f6defffff76263f5bc8fffa1be4f07b4343414c --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +{ + "modelVersion": "5.0.3", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + "@ohos/hypium": "1.0.21", + "@ohos/hamock": "1.0.0" + } +} diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/ohosTest.md b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/ohosTest.md new file mode 100644 index 0000000000000000000000000000000000000000..4086f0ae5985c675089d6aed968cd5653968bce3 --- /dev/null +++ b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/ohosTest.md @@ -0,0 +1,7 @@ +# SoundPoolArkTS测试用例归档 + +## 用例表 + +| 测试功能 | 预置条件 | 输入 | 预期输出 | 是否自动 | 测试结果 | +| ---------------- | ------------------ | -------------------- | ---------------------------- | -------- | -------- | +| 拉起应用并播放 | 设备正常运行 | | 成功播放 | 是 | Pass | \ No newline at end of file diff --git a/code/DocsSample/Media/SoundPool/SoundPoolArkTS/screenshots/SoundPoolArkTS.png b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/screenshots/SoundPoolArkTS.png new file mode 100644 index 0000000000000000000000000000000000000000..7c57e2d54a527245a2886be4bb3d2d7436dedc85 Binary files /dev/null and b/code/DocsSample/Media/SoundPool/SoundPoolArkTS/screenshots/SoundPoolArkTS.png differ