diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..c25d7b5950f39023a315011209d636d0a97a4bab --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +/node_modules +/oh_modules +/local.properties +/.idea +**/build +/.hvigor +.cxx +/.clangd +/.clang-format +/.clang-tidy +**/.test +/.appanalyzer +.gitmodules +entry/oh_modules +entry/.preview +**/oh-package-lock.json5 \ No newline at end of file diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..d1d2c5a73821a1cd135177cf6065c922f9d4df0c --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023 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.example.avplayer_basic_control", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:layered_image", + "label": "$string:app_name" + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e1ab609a842ddb871d7bc6d573ce77479bd7c9e9 --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "avplayer_basic_control" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a39445dc87828b76fed6d2ec470dd455c45319e3 Binary files /dev/null and b/AppScope/resources/base/media/app_icon.png differ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..0210352ae2ade0dd7b4c841cb6e8ba08b4780038 --- /dev/null +++ b/LICENSE @@ -0,0 +1,78 @@ + Copyright (c) 2023 Huawei Device Co., Ltd. All rights reserved. + + 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. + +Apache License, Version 2.0 +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +1.You must give any other recipients of the Work or Derivative Works a copy of this License; and +2.You must cause any modified files to carry prominent notices stating that You changed the files; and +3.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +4.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + +You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.en.md b/README.en.md deleted file mode 100644 index ec06ed985ae15e9739f7fe740896a74dd10f8a66..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# AVPlayerBasicControl - -#### Description -AVPlayer自有基础播控能力,主要包括播放、暂停、跳转播放、静音播放、循环播放、窗口缩放模式设置、倍速设置、音量设置等场景。 - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 34b1dfe8494107572ff6285a8619513799e2c9e2..a105d314b8209b7abaa22d1d4a5d7e9b6a60e0d0 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,87 @@ -# AVPlayerBasicControl +# 基于AVPlayer实现视频基本播控功能 -#### 介绍 -AVPlayer自有基础播控能力,主要包括播放、暂停、跳转播放、静音播放、循环播放、窗口缩放模式设置、倍速设置、音量设置等场景。 +## 项目简介 -#### 软件架构 -软件架构说明 +本示例主要展示了如何基于AVPlayer系统播放器实现播放本地视频相关功能,指导开发者实现视频加载、播放、暂停、退出;跳转播放;静音播放;循环播放;窗口缩放模式设置;倍速设置;音量设置;字幕挂载等开发场景。 +## 效果预览 -#### 安装教程 +| 播放 | 暂停 | 倍速弹窗 | +|-----------------------------------------------------------------|------------------------------------------|----------------------------------------------------| +| | | | -1. xxxx -2. xxxx -3. xxxx +| 静音设置 | 音量设置 | 窗口缩放模式设置 | +|------------------------------------------------------|-------------------------------------------------|----------------------------------------------------| +| | | | -#### 使用说明 +## 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 下载sample,编译运行; +2. 运行成功后,视频自动开始播放; +3. 点击视频界面,唤起视频操作面板,再次点击操作面板消失,如果不做任何操作操作界面会5s自动消失; +4. 点击暂停/播放按钮,控制视频暂停播放; +5. 滑动视频进度条,视频跳转到指定位置,在视频中间会出现时间进度方便用户查看视频进度; +6. 点击倍速,可以选择1.0、1.25、1.75、2.0进行倍速调节; +7. 点击静音按钮,可以设置静音模式播放; +8. 点击窗口缩放模式按钮,可以选择拉伸至与窗口等大、缩放至最短边填满窗口; +9. 长按屏幕,控制视频2.0倍速播放; +10. 上下滑动屏幕,可以设置视频播放音量; +11. 视频下方显示字幕,并可以点击语言切换按钮切换字幕; +12. 视频自动循环播放; +13. 点击左上角退出箭头,退出应用。 -#### 参与贡献 +## 目录结构 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +``` +├──entry/src/main/ets // 代码区 +│ ├──common +│ │ ├──constants +│ │ │ └──CommonConstants.ets // 公共常量 +│ │ └──utils +│ │ ├──GlobalContext.ets // 公共工具类 +│ │ └──TimeUtils.ts // 视频时间帮助类 +│ ├──views +│ │ ├──languageDialog.ets // 弹幕语言切换弹窗 +│ │ ├──ScaleDialog.ets // 窗口缩放模式设置弹窗 +│ │ ├──SetVolumn.ets // 设置音量组件 +│ │ ├──SpeedDialog.ets // 播放倍速弹窗 +│ │ └──VideoOperate.ets // 视频操作组件 +│ ├──controller +│ │ └──AvPlayerController.ets // avplayer公共控制类 +│ ├──entryability +│ │ └──EntryAbility.ets // 应用入口Ability +│ ├──model +│ │ └──VideoData.ets // 视频数据类 +│ └──pages +│ └──Index.ets // 首页视频界面 +└──entry/src/main/resources // 应用资源目录 +``` +## 具体实现 -#### 特技 ++ +视频倍速切换、暂停、播放、切换视频、视频跳转的功能接口都封装在AvPlayerController.ets,源码参考:[AvPlayerController.ets](entry/src/main/ets/controller/AvPlayerController.ets); ++ 使用media.createAVPlayer()来获取AVPlayer对象; ++ 倍速切换:选择不同倍速时调用avPlayer.setSpeed(speed: PlaybackSpeed); ++ 暂停、播放:点击暂停、播放按钮时调用avPlayer.pause()、avPlayer.play(); ++ 视频跳转:在拖动滑动条时调用avPlayer.seek(); ++ 静音播放:点击静音按钮时调用avPlayer.setMediaMuted(); ++ 音量设置:为元素添加手势上下滑动监听PanGesture,滑动时时显示AVVolumePanel组件并根据滑动距离计算音量volume值; ++ 窗口缩放模式设置:选择不同的窗口缩放模式时设置avPlayer的videoScaleType属性值; ++ 长按倍速:为元素添加手势长按监听LongPressGesture,长按时调用avPlayer.setSpeed(speed: PlaybackSpeed); ++ 循环播放:在视频prepared状态下,设置avPlayer的loop属性值为true。 ++ 字幕挂载:视频初始化时调用avPlayer.addSubtitleFromFd()设置外挂字幕资源。 -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +## 相关权限 + +不涉及 + +## 约束与限制 + +1.本示例仅支持标准系统上运行,支持设备:华为手机。 + +2.HarmonyOS系统:HarmonyOS 5.1.0 Release及以上。 + +3.DevEco Studio版本:DevEco Studio 5.1.0 Release及以上。 + +4.HarmonyOS SDK版本:HarmonyOS 5.1.0 Release SDK及以上。 diff --git a/build-profile.json5 b/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..585bb4f1003262c2bc1eb8913de0ac7f833db8b0 --- /dev/null +++ b/build-profile.json5 @@ -0,0 +1,30 @@ +{ + "app": { + "signingConfigs": [ + + ], + "products": [ + { + "name": "default", + "signingConfig": "default", + "targetSdkVersion": "5.1.0(18)", + "compatibleSdkVersion": "5.1.0(18)", + "runtimeOS": "HarmonyOS" + } + ] + }, + "modules": [ + { + "name": "entry", + "srcPath": "./entry", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 new file mode 100644 index 0000000000000000000000000000000000000000..ddd6e5f1ac23a18a1d1d0d8d7470c6d4726ef66e --- /dev/null +++ b/entry/build-profile.json5 @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2023 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": { + }, + "targets": [ + { + "name": "default" + }, + { + "name": "ohosTest", + } + ] +} \ No newline at end of file diff --git a/entry/hvigorfile.ts b/entry/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..80e4ec5b81689f238c34614b167a0b9e9c83e8d9 --- /dev/null +++ b/entry/hvigorfile.ts @@ -0,0 +1,2 @@ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. +export { hapTasks } from '@ohos/hvigor-ohos-plugin'; diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..7d977f3b5e5864094b0525ba57ff0a0d6b9e9f65 --- /dev/null +++ b/entry/oh-package.json5 @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +{ + "license": "ISC", + "devDependencies": {}, + "name": "entry", + "description": "example description", + "version": "1.0.0", + "dependencies": { + } +} diff --git a/entry/src/main/ets/common/constants/CommonConstants.ets b/entry/src/main/ets/common/constants/CommonConstants.ets new file mode 100644 index 0000000000000000000000000000000000000000..217c4234a73405b135adf970376058f775f7d8d9 --- /dev/null +++ b/entry/src/main/ets/common/constants/CommonConstants.ets @@ -0,0 +1,136 @@ +/* + * 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 { emitter } from '@kit.BasicServicesKit'; + +export enum AVPlayerState { + /** + * Idle state of avPlayer. + */ + IDLE = 'idle', + + /** + * Initialized state of avPlayer. + */ + INITIALIZED = 'initialized', + + /** + * Prepared state of avPlayer. + */ + PREPARED = 'prepared', + + /** + * Playing state of avPlayer. + */ + PLAYING = 'playing', + + /** + * Pause state of avPlayer. + */ + PAUSED = 'paused', + + /** + * Completed state of avPlayer. + */ + COMPLETED = 'completed', + + /** + * Stopped state of avPlayer. + */ + STOPPED = 'stopped', + + /** + * Release state of avPlayer. + */ + RELEASED = 'released', + + /** + * Error state of avPlayer. + */ + ERROR = 'error', + UNDEFINED = 'undefined' +} + +export enum VideoDataType { + RAW_FILE = 1, + RAW_M3U8_FILE = 2, + URL = 3, + RAW_MP4_FILE = 4 +} + +export class CommonConstants { + static readonly AVPLAYER_IDLE: emitter.InnerEvent = { + eventId: 1, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_INITIALIZED: emitter.InnerEvent = { + eventId: 2, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_PREPARED: emitter.InnerEvent = { + eventId: 3, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_PLAYING: emitter.InnerEvent = { + eventId: 4, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_COMPLETED: emitter.InnerEvent = { + eventId: 5, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_PAUSED: emitter.InnerEvent = { + eventId: 6, + priority: emitter.EventPriority.HIGH + }; + static readonly AVPLAYER_STOPPED: emitter.InnerEvent = { + eventId: 7, + priority: emitter.EventPriority.HIGH + }; + static readonly innerEventFalse: emitter.InnerEvent = { + eventId: 11, + priority: emitter.EventPriority.HIGH + }; + static readonly innerEventTrue: emitter.InnerEvent = { + eventId: 12, + priority: emitter.EventPriority.HIGH + }; + static readonly innerEventWH: emitter.InnerEvent = { + eventId: 13, + priority: emitter.EventPriority.HIGH + }; + static readonly SLIDER_PROGRESS_MIN: number = 0 + static readonly SLIDER_PROGRESS_STEP: number = 0.1 + /** + * Full size. + */ + static readonly FULL_SIZE: string = '100%'; + /** + * Seek hour unit + */ + static readonly HOUR_UNIT: number = 60; + /** + * Second to Millisecond + */ + static readonly SECOND_TO_MS: number = 1000; + /** + * Time const number + */ + static readonly TIME_CONST_TEN: number = 10; + /** + * Hilog Domain. + */ + static readonly LOG_DOMAIN = 0x0000; +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/GlobalContext.ets b/entry/src/main/ets/common/utils/GlobalContext.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb17b8c77e7e7662670f006db28799561daff5f5 --- /dev/null +++ b/entry/src/main/ets/common/utils/GlobalContext.ets @@ -0,0 +1,37 @@ +/* + * 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. + */ + +export class GlobalContext { + private constructor() { + } + + private static instance: GlobalContext; + private _objects = new Map(); + + public static getContext(): GlobalContext { + if (!GlobalContext.instance) { + GlobalContext.instance = new GlobalContext(); + } + return GlobalContext.instance; + } + + getObject(value: string): Object | undefined { + return this._objects.get(value); + } + + setObject(key: string, objectClass: Object): void { + this._objects.set(key, objectClass); + } +} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/TimeUtils.ts b/entry/src/main/ets/common/utils/TimeUtils.ts new file mode 100644 index 0000000000000000000000000000000000000000..9d8e2231bed74f6c3ca5350226b17adf5cd40fe2 --- /dev/null +++ b/entry/src/main/ets/common/utils/TimeUtils.ts @@ -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. + */ + +const TIME_ONE = 60000; +const TIME_TWO = 1000; +const TIME_THREE = 10; + +export function timeConvert(time: number): string { + let min: number = Math.floor(time / TIME_ONE); + let second: string = ((time % TIME_ONE) / TIME_TWO).toFixed(0); + return `${min}:${(+second < TIME_THREE ? '0' : '') + second}`; +} + diff --git a/entry/src/main/ets/controller/AvPlayerController.ets b/entry/src/main/ets/controller/AvPlayerController.ets new file mode 100644 index 0000000000000000000000000000000000000000..9456c4c47dce6dfa7418851c0e22f5ed30da47f2 --- /dev/null +++ b/entry/src/main/ets/controller/AvPlayerController.ets @@ -0,0 +1,494 @@ +/* + * 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 { common } from '@kit.AbilityKit'; +import { media } from '@kit.MediaKit'; +import { audio } from '@kit.AudioKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { BusinessError, emitter } from '@kit.BasicServicesKit'; +import { CommonConstants, VideoDataType } from '../common/constants/CommonConstants'; +import { VideoData } from '../model/VideoData'; + +const TAG = '[AvPlayerController]'; +const CASE_ZERO = 0; +const CASE_ONE = 1; +const CASE_TWO = 2; +const CASE_THREE = 3; + +@Observed +export class AvPlayerController { + @Track surfaceID: string = ''; + @Track isPlaying: boolean = false; + @Track isReady: boolean = false; + @Track currentTime: number = 0; + @Track currentBufferTime: number = 0; + @Track isLoading: boolean = false; + @Track duration: number = 0; + @Track durationTime: number = 0; + @Track currentCaption: string = ''; + private avPlayer?: media.AVPlayer; + private curSource?: VideoData; + private context: common.UIAbilityContext | undefined = AppStorage.get('context'); + private seekTime?: number; + private isMuted: boolean | undefined = undefined; + private speedSelect: number = 0; + private windowScaleSelect: number = 0; + private index: number = 0; + + // [Start create_instance] + // Create an AVPlayer instance + public async initAVPlayer(source: VideoData, surfaceId: string, avPlayer?: media.AVPlayer) { + if (!this.context) { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer failed context not set`); + return + } + this.curSource = source; + if (source.seekTime) { + this.seekTime = source.seekTime; + } + if (source.isMuted) { + this.isMuted = source.isMuted; + } + if (source.index) { + this.index = source.index; + } + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer == this.curSource : ${JSON.stringify(this.curSource)}`); + if (!this.curSource) { + return; + } + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer == initCamera surfaceId == ${surfaceId}`); + this.surfaceID = surfaceId; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer == this.surfaceID surfaceId == ${this.surfaceID}`); + + try { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'initPlayer videoPlay avPlayerDemo'); + // Creates the avPlayer instance object. + this.avPlayer = avPlayer ? avPlayer : await media.createAVPlayer() + // Creates a callback function for state machine changes. + this.setAVPlayerCallback(); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'initPlayer videoPlay setAVPlayerCallback'); + + if (!this.context) { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer failed context not set`); + return + } + switch (this.curSource.type) { + case VideoDataType.RAW_FILE: + let fileDescriptor = await this.context.resourceManager.getRawFd(this.curSource.videoSrc); + this.avPlayer.fdSrc = fileDescriptor; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, + `initPlayer videoPlay src = ${JSON.stringify(this.avPlayer.fdSrc)}`); + break; + + case VideoDataType.URL: + this.avPlayer.url = this.curSource.videoSrc; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, + `initPlayer videoPlay url = ${JSON.stringify(this.avPlayer.url)}`); + break; + + case VideoDataType.RAW_M3U8_FILE: + let m3u8Fd = await this.context.resourceManager.getRawFd(this.curSource.videoSrc); + let fdUrl = 'fd://' + m3u8Fd.fd + '?offset=' + m3u8Fd.offset + '&size=' + m3u8Fd.length; + let mediaSource = media.createMediaSourceWithUrl(fdUrl); + mediaSource.setMimeType(media.AVMimeTypes.APPLICATION_M3U8); + let playbackStrategy: media.PlaybackStrategy = { preferredBufferDuration: 20, showFirstFrameOnPrepare: true }; + await this.avPlayer.setMediaSource(mediaSource, playbackStrategy); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer videoPlay fdUrl = ${JSON.stringify(fdUrl)}`); + break; + case VideoDataType.RAW_MP4_FILE: + let mp4Fd = await this.context.resourceManager.getRawFd(this.curSource.videoSrc); + let mp4FdUrl = 'fd://' + mp4Fd.fd; + this.avPlayer.url = mp4FdUrl; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `initPlayer videoPlay fdUrl = ${JSON.stringify(mp4FdUrl)}`); + break; + default: + break; + } + // [Start AddCaption] + if (this.curSource.caption) { + let fileDescriptorSub = await this.context.resourceManager.getRawFd(this.curSource.caption); + this.avPlayer.addSubtitleFromFd(fileDescriptorSub.fd, fileDescriptorSub.offset, fileDescriptorSub.length); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'initPlayer videoPlay addSubtitleFromFd'); + } + // [End AddCaption] + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `initPlayer initPlayer, code is ${err.code}, message is ${err.message}`); + } + } + + // [End create_instance] + + private setAVPlayerCallback() { + if (!this.avPlayer) { + return; + } + this.avPlayer!.on('error', (err: BusinessError) => { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, `AVPlayer error, code is ${err.code}, message is ${err.message}`); + this.avPlayer!.reset(); + }); + // Listening function for reporting time + this.avPlayer!.on('startRenderFrame', () => { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `AVPlayer start render frame`); + AppStorage.setOrCreate('StartRender', true); + }); + this.avPlayer!.on('durationUpdate', (time: number) => { + this.duration = time; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `AVPlayer duration update: ${time}`); + AppStorage.setOrCreate('DurationTime', time); + }); + this.avPlayer.on('timeUpdate', (time: number) => { + this.currentTime = time; + AppStorage.setOrCreate('CurrentTime', time); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, + `setAVPlayerCallback timeUpdate success, and new time is = ${this.currentTime}`); + }); + + // The error callback function is triggered when an error occurs during avPlayer operations, + // at which point the reset interface is called to initiate the reset process + this.avPlayer.on('error', (err: BusinessError) => { + if (!this.avPlayer) { + return; + } + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `Invoke avPlayer failed, code is ${err.code}, message is ${err.message}`); + this.avPlayer.reset(); // resets the resources and triggers the idle state + }) + this.subtitleUpdateFunction(); + this.setStateChangeCallback(); + } + + private setStateChangeCallback() { + if (!this.avPlayer) { + return; + } + // [Start loop_playback] + /** + * Loop playback + */ + // Callback function for state machine changes + this.avPlayer.on('stateChange', async (state) => { + if (!this.avPlayer) { + return; + } + switch (state) { + // [StartExclude state] + case 'idle': // This state machine is triggered after the reset interface is successfully invoked. + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state idle called.'); + break; + case 'initialized': // This status is reported after the playback source is set on the AVPlayer. + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state initialized called.'); + // Set the display screen. This parameter is not required when the resource to be played is audio-only. + this.avPlayer.surfaceId = this.surfaceID; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, + `setAVPlayerCallback this.avPlayer.surfaceId = ${this.avPlayer.surfaceId}`); + this.avPlayer.prepare(); + break; + // [EndExclude state] + case 'prepared': // This state machine is reported after the prepare interface is successfully invoked. + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state prepared called.'); + this.isReady = true; + this.avPlayer.loop = true + // [StartExclude prepared] + this.durationTime = this.avPlayer.duration; + this.currentTime = this.avPlayer.currentTime; + this.avPlayer.audioInterruptMode = audio.InterruptMode.SHARE_MODE; + if (this.seekTime) { + this.avPlayer!.seek(this.seekTime!, media.SeekMode.SEEK_CLOSEST); + } + let eventData: emitter.EventData = { + data: { + 'percent': this.avPlayer.width / this.avPlayer.height + } + }; + emitter.emit(CommonConstants.AVPLAYER_PREPARED, eventData); + if (this.isMuted) { + await this.avPlayer!.setMediaMuted(media.MediaType.MEDIA_TYPE_AUD, this.isMuted!) + } + + this.setWindowScale(); + + if (this.index === 0) { + this.avPlayer.play(); // Invoke the playback interface to start playback. + } + + this.setVideoSpeed(); + // [EndExclude prepared] + break; + // [StartExclude other_state] + case 'playing': // After the play interface is successfully invoked, the state machine is reported. + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state playing called.'); + this.isPlaying = true; + let eventDataTrue: emitter.EventData = { + data: { + 'flag': true + } + }; + let innerEventTrue: emitter.InnerEvent = { + eventId: 2, + priority: emitter.EventPriority.HIGH + }; + emitter.emit(innerEventTrue, eventDataTrue); + break; + case 'completed': // This state machine is triggered to report when the playback ends. + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state completed called.'); + this.currentTime = 0; + let eventDataFalse: emitter.EventData = { + data: { + 'flag': false + } + }; + let innerEvent: emitter.InnerEvent = { + eventId: 1, + priority: emitter.EventPriority.HIGH + }; + emitter.emit(innerEvent, eventDataFalse); + break; + default: + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'setAVPlayerCallback AVPlayer state unknown called.'); + break; + // [EndExclude other_state] + } + }); + // [End loop_playback] + } + + private setWindowScale() { + switch (this.windowScaleSelect) { + case CASE_ZERO: + this.videoScaleFit(); + break; + case CASE_ONE: + this.videoScaleFitCrop(); + break; + default: + break; + } + } + + private setVideoSpeed() { + switch (this.speedSelect) { + case CASE_ZERO: + this.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X); + break; + case CASE_ONE: + this.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_25_X); + break; + case CASE_TWO: + this.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_75_X); + break; + case CASE_THREE: + this.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X); + break; + default: + break; + } + } + + videoPlay(): void { + if (this.avPlayer) { + try { + this.avPlayer.play(); + this.isPlaying = true; + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoPlay failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + videoPause(): void { + if (this.avPlayer) { + try { + this.avPlayer.pause(); + this.isPlaying = false; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'videoPause'); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoPause failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // Toggle play/pause state + videoStop(): void { + if (this.avPlayer) { + try { + this.avPlayer.stop(); + this.isPlaying = false; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'videoPause'); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoPause failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // [Start video_muted_fun] + /** + * Video muted + * @param isMuted + * @returns + */ + async videoMuted(isMuted: boolean): Promise { + if (this.avPlayer) { + try { + this.isMuted = isMuted; + await this.avPlayer!.setMediaMuted(media.MediaType.MEDIA_TYPE_AUD, isMuted) + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'videoMuted'); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoMuted failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // [End video_muted_fun] + + // [Start video_speed_fun] + videoSpeed(speed: number): void { + if (this.avPlayer) { + try { + this.avPlayer.setSpeed(speed); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'videoSpeed'); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoSpeed failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // [End video_speed_fun] + + videoSeek(seekTime: number): void { + if (this.avPlayer) { + try { + this.avPlayer.seek(seekTime, media.SeekMode.SEEK_CLOSEST); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `videoSeek== ${seekTime}`); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoSeek failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + async videoReset(): Promise { + if (!this.avPlayer) { + return; + } + try { + await this.avPlayer.reset(); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, `videoReset failed, code is ${err.code}, message is ${err.message}`); + } + + } + + async videoRelease(): Promise { + if (!this.avPlayer) { + return; + } + this.avPlayer.release((err) => { + if (err === null) { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'videoRelease release success'); + } else { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoRelease release filed, code is ${err.code}, message is ${err.message}`); + } + }); + } + + getDurationTime(): number { + return this.durationTime; + } + + getCurrentTime(): number { + return this.currentTime; + } + + // [Start window_scale_fun] + /** + * Set window scale mode + */ + videoScaleFit(): void { + if (this.avPlayer) { + try { + this.avPlayer.videoScaleType = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `videoScaleType_0`); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoScaleType_0 failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + videoScaleFitCrop(): void { + if (this.avPlayer) { + try { + this.avPlayer.videoScaleType = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT_CROP + hilog.info(CommonConstants.LOG_DOMAIN, TAG, `videoScaleType_1`); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `videoScaleType_1 failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // [End window_scale_fun] + subtitleUpdateFunction(): void { + try { + if (this.avPlayer) { + // [Start RegisterCaptionCallBack] + this.avPlayer.on('subtitleUpdate', (info: media.SubtitleInfo) => { + if (info) { + let text = (!info.text) ? '' : info.text; + let startTime = (!info.startTime) ? 0 : info.startTime; + let duration = (!info.duration) ? 0 : info.duration; + this.currentCaption = text; //update current caption content + hilog.info(CommonConstants.LOG_DOMAIN, TAG, + `subtitleUpdate info: text:${text}, startTime:${startTime}, duration:${duration}`); + } else { + this.currentCaption = ''; + hilog.error(CommonConstants.LOG_DOMAIN, TAG, 'subtitleUpdate info is null'); + } + }); + // [End RegisterCaptionCallBack] + } + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `subtitleUpdateFunction failed, code is ${err.code}, message is ${err.message}`); + } + } + + // [Start languageSwitch] + async languageChange(languageSelect: number = 0): Promise { + if (this.avPlayer) { + try { + if (this.curSource && this.curSource.caption) { + this.curSource.caption = languageSelect === 0 ? 'captions.srt' : 'en_captions.srt' + this.curSource.seekTime = this.avPlayer.currentTime; + await this.avPlayer.reset(); + this.initAVPlayer(this.curSource, this.surfaceID, this.avPlayer); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'language change'); + } + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `languageChange failed, code is ${err.code}, message is ${err.message}`); + } + } + } + + // [End languageSwitch] +} \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..9d939aec0e89269e2237344f3169a51914e37155 --- /dev/null +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 Hunan OpenValley Digital Industry Development 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 { UIAbility, Want } from '@kit.AbilityKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { window } from '@kit.ArkUI'; +import { emitter } from '@kit.BasicServicesKit'; +import { GlobalContext } from '../common/utils/GlobalContext'; +import { CommonConstants } from '../common/constants/CommonConstants'; + +const TAG = '[EntryAbility]'; + +export default class EntryAbility extends UIAbility { + onCreate(want: Want) { + GlobalContext.getContext().setObject('abilityWant', want) + GlobalContext.getContext().setObject('context', this.context) + AppStorage.setOrCreate('context', this.context); + if (want.parameters) { + if (want.parameters.currentTime) { + GlobalContext.getContext().setObject('currentTime', want.parameters.currentTime); + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'time: ' + want.parameters.currentTime); + } + } + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage): void { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onWindowStageCreate'); + try { + windowStage.getMainWindow().then((win: window.Window) => { + win.setWindowKeepScreenOn(true); + win.setWindowSystemBarProperties({ + statusBarColor: '#000000', + statusBarContentColor: '#FFFFFF' + }); + win.setWindowLayoutFullScreen(true); + win.on('windowSizeChange', (newSize: window.Size) => { + let eventWHData: emitter.EventData = { + data: { + 'width': newSize.width, + 'height': newSize.height + } + }; + emitter.emit(CommonConstants.innerEventWH, eventWHData); + }); + }); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `getMainWindow failed, code is ${err.code}, message is ${err.message}`); + } + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, 'Failed to load the content. Cause: %{public}s', + JSON.stringify(err) ?? ''); + return; + } + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'Succeeded in loading the content. Data: %{public}s', + JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onForeground'); + } + + onBackground() { + hilog.info(CommonConstants.LOG_DOMAIN, TAG, '%{public}s', 'Ability onBackground'); + } +} diff --git a/entry/src/main/ets/model/VideoData.ets b/entry/src/main/ets/model/VideoData.ets new file mode 100644 index 0000000000000000000000000000000000000000..3e0013f91cdd97f70738c363c818ae41425bfc8d --- /dev/null +++ b/entry/src/main/ets/model/VideoData.ets @@ -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. + */ + +import { VideoDataType } from '../common/constants/CommonConstants'; + +export interface VideoData { + type: VideoDataType; + videoSrc: string; + name?: string | Resource; + description?: ResourceStr; + head?: Resource; + caption?: string; + index?: number; + seekTime?:number; + isMuted?:boolean; +} \ No newline at end of file diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb581110dfbb861f8b94718ebcbb5635aa1d36ac --- /dev/null +++ b/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,349 @@ +/* + * 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 { connection } from '@kit.NetworkKit'; +import { display } from '@kit.ArkUI'; +import { emitter } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; +import { media } from '@kit.MediaKit'; +import { AvPlayerController } from '../controller/AvPlayerController'; +import { VideoOperate } from '../views/VideoOperate'; +import { SetVolume } from '../views/SetVolume' +import { timeConvert } from '../common/utils/TimeUtils'; +import { GlobalContext } from '../common/utils/GlobalContext'; +import { VideoDataType, CommonConstants } from '../common/constants/CommonConstants'; +import { VideoData } from '../model/VideoData'; + +const PROPORTION = 0.99; // Screen Percentage +const SURFACE_WIDTH = 0.9; // Surface width ratio +const SURFACE_HEIGHT = 1.78; // Surface height ratio +const TIMEOUT = 0; // Timer ID +const SET_TIME_OUT = 8000; // Interval: 8s +const SET_INTERVAL = 100; +const SET_VOLUME_TIME_OUT = 5000 // VolumeTimer: 5s +const TAG = '[Index]'; +const CASE_ZERO = 0; +const CASE_THREE = 3; + +@Entry +@Component +struct Index { + @State avPlayerController: AvPlayerController = new AvPlayerController() + @State isSwiping: boolean = false; + @State isClickScreen: boolean = false; + @State flag: boolean = true; // Pause Playback + @State XComponentFlag: boolean = false; + @State speedList: Resource[] = + [$r('app.string.video_speed_1_0X'), $r('app.string.video_speed_1_25X'), $r('app.string.video_speed_1_75X'), + $r('app.string.video_speed_2_0X')]; + @State @Watch('onSpeedSelectUpdate') speedSelect: number = 0; + @State durationTime: number = 0; + @State currentTime: number = 0; + @State surfaceW: number = 0; + @State surfaceH: number = 0; + @State @Watch('onVolumeUpdate') volume: number = 5; + @State volumeVisible: boolean = false + @State show: boolean = false; // Indicates whether the videoPanel component is displayed. + @State percent: number = 0; + @State windowWidth: number = 300; + @State windowHeight: number = 300; + @State isCalcWHFinished: boolean = false; + @StorageLink('videoName') videoName: Resource = $r('app.string.video_res_1'); + @StorageLink('videoIndex') videoIndex: number = 0; + @StorageLink('videoScaleType') videoScaleType: number = 0; + private surfaceId: string = ''; + private timeout: number = 0; // Timer ID + private volumeTimeout: number = 0; // VolumeTimer ID + private xComponentController: XComponentController = new XComponentController(); + + setTimer(): void { + let that = this; + this.timeout = setTimeout(() => { + that.isClickScreen = false; // Hide the operation panel + }, SET_TIME_OUT); // Hide in 8 seconds + } + + clearTimer(): void { + if (this.timeout !== TIMEOUT) { + clearTimeout(this.timeout); + this.timeout = TIMEOUT; + } + } + + setVolumeTimer(): void { + this.volumeTimeout = setTimeout(() => { + this.volumeVisible = false + }, SET_VOLUME_TIME_OUT) + } + + clearVolumeTimer(): void { + if (this.volumeTimeout !== TIMEOUT) { + clearTimeout(this.volumeTimeout); + this.volumeTimeout = TIMEOUT; + } + } + + aboutToAppear() { + try { + this.windowWidth = display.getDefaultDisplaySync().width; + this.windowHeight = display.getDefaultDisplaySync().height; + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `getDefaultDisplaySync failed, code is ${err.code}, message is ${err.message}`); + } + this.surfaceW = (GlobalContext.getContext().getObject('windowWidth') as number) * SURFACE_WIDTH; + this.surfaceH = this.surfaceW / SURFACE_HEIGHT; + this.flag = true; + AppStorage.setOrCreate('avPlayerController', this.avPlayerController); + emitter.on(CommonConstants.AVPLAYER_PREPARED, (res) => { + if (res.data) { + this.percent = res.data.percent; + this.setVideoWH(); + this.isCalcWHFinished = true; + this.durationTime = this.avPlayerController.durationTime; + setInterval(() => { // Update the current time. + if (!this.isSwiping) { + this.currentTime = this.avPlayerController.currentTime; + } + }, SET_INTERVAL); + } + }); + } + + aboutToDisappear() { + this.avPlayerController.videoRelease(); + emitter.off(CommonConstants.innerEventFalse.eventId); + } + + onPageHide() { + this.avPlayerController.videoPause(); + this.flag = false; + } + + onPageShow() { + emitter.on(CommonConstants.innerEventTrue, (res) => { + if (res.data) { + this.flag = res.data.flag; + this.XComponentFlag = res.data.flag; + } + }); + emitter.on(CommonConstants.innerEventFalse, (res) => { + if (res.data) { + this.flag = res.data.flag; + } + }); + emitter.on(CommonConstants.innerEventWH, (res) => { + if (res.data) { + this.windowWidth = res.data.width; + this.windowHeight = res.data.height; + this.setVideoWH(); + } + }); + if (this.flag === false) { + this.clearTimer(); + } + } + + setVideoWH(): void { + if (this.percent >= 1) { // Horizontal video + this.surfaceW = Math.round(this.windowWidth * PROPORTION); + this.surfaceH = Math.round(this.surfaceW / this.percent); + } else { // Vertical video + this.surfaceH = Math.round(this.windowHeight * PROPORTION); + this.surfaceW = Math.round(this.surfaceH * this.percent); + } + } + + onSpeedSelectUpdate() { + AppStorage.setOrCreate('speedName', this.speedList[this.speedSelect]); + AppStorage.setOrCreate('speedIndex', this.speedSelect); + } + + onVolumeUpdate() { + AppStorage.setOrCreate('isMuted', this.volume <= 0.0); + this.avPlayerController.videoMuted(this.volume <= 0.0); + } + + async isInternet(): Promise { + try { + if (connection.getAllNetsSync().length <= 0) { + this.toast(); + return false + } + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `getAllNetsSync failed, code is ${err.code}, message is ${err.message}`); + } + return true; + } + + async toast() { + try { + this.getUIContext().getPromptAction().showToast({ + message: $r('app.string.video_warn'), + duration: 2000, + }); + } catch (err) { + hilog.error(CommonConstants.LOG_DOMAIN, TAG, + `showToast failed, code is ${err.code}, message is ${err.message}`); + } + } + + @Builder + CoverXComponent() { + XComponent({ + // Loading the video container + id: 'xComponent', + type: XComponentType.SURFACE, + controller: this.xComponentController + }) + .onLoad(() => { + this.surfaceId = this.xComponentController.getXComponentSurfaceId(); + let source: VideoData = { + type: VideoDataType.RAW_FILE, + videoSrc: 'test1.mp4', + name: $r('app.string.local_video'), + description: '', + caption: 'captions.srt', + index: 0 + } + this.avPlayerController.initAVPlayer(source, this.surfaceId); + }) + .height(this.videoScaleType === 0 ? (this.isCalcWHFinished ? `${this.surfaceH}px` : '100%') : null) + .width(this.videoScaleType === 0 ? (this.isCalcWHFinished ? `${this.surfaceW}px` : '100%') : null) + } + + build() { + Stack() { + SetVolume({ volume: this.volume, volumeVisible: this.volumeVisible }) + + Column() { + // [Start currentCaptionText] + Stack({ alignContent: Alignment.Center }) { + Text(this.avPlayerController.currentCaption) + .fontColor(Color.White) + .fontSize($r('app.float.size_20')) + .fontFamily('Sans') + } + .width('100%') + .position({ x: $r('app.float.size_zero'), y: $r('app.float.size_210') }) + .zIndex(1) + + // [End currentCaptionText] + + this.CoverXComponent() + } + // [Start pan_gesture] + .gesture( + PanGesture({ direction: PanDirection.Vertical }) + .onActionStart(() => { + }) + .onActionUpdate((event: GestureEvent) => { + this.volumeVisible = true; + let curVolume = this.volume - this.getUIContext().vp2px(event.offsetY) / this.windowHeight; + curVolume = curVolume >= 15.0 ? 15.0 : curVolume; + curVolume = curVolume <= 0.0 ? 0.0 : curVolume; + this.volume = curVolume; + hilog.info(CommonConstants.LOG_DOMAIN, TAG, 'AVPlayManage', 'AVPlayer', `this volumn is: ` + this.volume); + }) + .onActionEnd(() => { + this.setVolumeTimer(); + }) + ) + // [End pan_gesture] + .align(Alignment.TopStart) + .margin({ top: $r('app.float.size_80') }) + .id('Video') + .justifyContent(FlexAlign.Center) + + Text() + .height(`${this.surfaceH}px`) + .width(`${this.surfaceW}px`) + .margin({ top: $r('app.float.size_80') }) + .backgroundColor(Color.Black) + .opacity($r('app.float.size_zero_five')) + .visibility(this.isSwiping ? Visibility.Visible : Visibility.Hidden) + + Row() { + Text(timeConvert(this.currentTime)) + .fontSize($r('app.float.size_24')) + .opacity($r('app.float.size_1')) + .fontColor($r('app.color.slider_selected')) + Text('/' + timeConvert(this.durationTime)) + .fontSize($r('app.float.size_24')) + .opacity($r('app.float.size_1')) + .fontColor(Color.White) + } + .margin({ top: $r('app.float.size_80') }) + .visibility(this.isSwiping ? Visibility.Visible : Visibility.Hidden) + + Column() { + Blank() + Column() { + // Progress bar + VideoOperate({ + flag: this.flag, + avPlayerController: this.avPlayerController, + currentTime: this.currentTime, + durationTime: this.durationTime, + isSwiping: this.isSwiping, + XComponentFlag: this.XComponentFlag + }) + .width('100%') + } + .justifyContent(FlexAlign.Center) + } + .onTouch((event: TouchEvent) => { + if (event.type === TouchType.Down) { + this.isClickScreen = true; + this.clearTimer(); + } else if (event.type === TouchType.Up) { + this.setTimer(); + } else if (event.type === TouchType.Move) { + this.isClickScreen = true; + this.clearTimer(); + } + }) + .visibility(this.isClickScreen ? Visibility.Visible : Visibility.Hidden) + .width('100%') + .height('100%') + } + .onClick(() => { + this.isClickScreen = !this.isClickScreen; + if (this.isClickScreen) { + this.setTimer(); + } else { + this.clearTimer(); + } + }) + // [Start long_press_gesture] + .gesture( + LongPressGesture({ repeat: true }) + .onAction(() => { + this.speedSelect = CASE_THREE + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X); + }) + .onActionEnd(() => { + this.speedSelect = CASE_ZERO + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X); + }) + ) + // [End long_press_gesture] + .backgroundColor(Color.Black) + .height('100%') + .width('100%') + .padding({ top: '36vp', bottom: '28vp' }) + } +} \ No newline at end of file diff --git a/entry/src/main/ets/views/LanguageDialog.ets b/entry/src/main/ets/views/LanguageDialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa88125a948a74229799fbead0fd09660baff316 --- /dev/null +++ b/entry/src/main/ets/views/LanguageDialog.ets @@ -0,0 +1,124 @@ +/* + * 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 { AvPlayerController } from '../controller/AvPlayerController'; + +// Index of the playback rate list. +const ONE = 1; + +// [Start video_language_dialog] +/** + * Set language dialog + */ +@CustomDialog +export struct LanguageDialog { + @State languageList: Resource[] = + [$r('app.string.Chinese'), $r('app.string.English')]; + @Link languageSelect: number; // Index of the current selection + @StorageLink('avPlayerController') avPlayerController: AvPlayerController = new AvPlayerController(); + private controller: CustomDialogController; + + build() { + Column() { + Text($r('app.string.language_switch'))// [StartExclude text_style1] + .fontSize($r('app.float.size_20')) + .fontWeight(FontWeight.Bold) + .width('90%') + .fontColor(Color.Black) + .textAlign(TextAlign.Center) + .margin({ top: $r('app.float.size_20'), bottom: $r('app.float.size_12') }) + // [EndExclude text_style1] + + List() { + ForEach(this.languageList, (item: Resource, index) => { + ListItem() { + Column() { + Row() { + Text(item)// [StartExclude text_style2] + .fontSize($r('app.float.size_16')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Medium) + .textAlign(TextAlign.Center) + // [EndExclude text_style2] + Blank() + Image(this.languageSelect === index ? $r('app.media.ic_radio_selected') : + $r('app.media.ic_radio'))// [StartExclude text_style3] + .width($r('app.float.size_24')) + .height($r('app.float.size_24')) + .objectFit(ImageFit.Contain) + // [EndExclude text_style3] + } + // [StartExclude text_style4] + .width('100%') + + if (index != this.languageList.length - ONE) { + Divider() + .vertical(false) + .strokeWidth(1) + .margin({ top: $r('app.float.size_10') }) + .color($r('app.color.speed_dialog')) + .width('100%') + } + // [EndExclude text_style4] + } + .width('90%') + } + .width('100%') + .height($r('app.float.size_48')) + .onClick(() => { + this.languageSelect = index; + AppStorage.setOrCreate('currentLanguageType', this.languageSelect); + this.avPlayerController.languageChange(this.languageSelect); + this.controller.close(); + }) + }, (item: Resource, index) => index + '_' + JSON.stringify(item)) + } + // [StartExclude cancel] + .width('100%') + .height('192vp') + .margin({ + top: $r('app.float.size_12') + }) + + Row() { + Text($r('app.string.dialog_cancel')) + .fontSize($r('app.float.size_16')) + .fontColor('#0A59F7') + .fontWeight(FontWeight.Medium) + .layoutWeight(1) + .textAlign(TextAlign.Center) + .onClick(() => { + this.controller.close(); + }) + } + .alignItems(VerticalAlign.Center) + .height($r('app.float.size_50')) + .padding({ bottom: $r('app.float.size_5') }) + .width('100%') + + // [EndExclude cancel] + } + // [StartExclude box_style] + .alignItems(HorizontalAlign.Center) + .width('100%') + .margin({ left: $r('app.float.size_16'), right: $r('app.float.size_16') }) + .borderRadius($r('app.float.size_24')) + .backgroundColor(Color.White) + + // [EndExclude box_style] + } +} + +// [End video_language_dialog] \ No newline at end of file diff --git a/entry/src/main/ets/views/ScaleDialog.ets b/entry/src/main/ets/views/ScaleDialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..082f4aa427beda9c184b5c3345b80cef5f6f5bb0 --- /dev/null +++ b/entry/src/main/ets/views/ScaleDialog.ets @@ -0,0 +1,129 @@ +/* + * 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 { AvPlayerController } from '../controller/AvPlayerController'; + +// Index of the playback rate list. +const ZERO = 0; +const ONE = 1; + +/** + * Window scale dialog + */ +@CustomDialog +export struct ScaleDialog { + @State scaleList: Resource[] = + [$r('app.string.video_scale_fit'), $r('app.string.video_scale_fit_crop')]; + @Link @Watch('onWindowScaleSelectUpdate') windowScaleSelect: number; // Index of the current selection + @StorageLink('avPlayerController') avPlayerController: AvPlayerController = new AvPlayerController(); + private controller: CustomDialogController; + + onWindowScaleSelectUpdate() { + AppStorage.setOrCreate('videoScaleType', this.windowScaleSelect); + } + + build() { + Column() { + Text($r('app.string.dialog_play_scale')) + .fontSize($r('app.float.size_20')) + .fontWeight(FontWeight.Bold) + .width('90%') + .fontColor(Color.Black) + .textAlign(TextAlign.Center) + .margin({ top: $r('app.float.size_20'), bottom: $r('app.float.size_12') }) + // [Start window_scale_dialog] + List() { + ForEach(this.scaleList, (item: Resource, index) => { + ListItem() { + Column() { + Row() { + Text(item)// [StartExclude text_style2] + .fontSize($r('app.float.size_16')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Medium) + .textAlign(TextAlign.Center) + // [EndExclude text_style2] + Blank() + Image(this.windowScaleSelect === index ? $r('app.media.ic_radio_selected') : + $r('app.media.ic_radio'))// [StartExclude text_style3] + .width($r('app.float.size_24')) + .height($r('app.float.size_24')) + .objectFit(ImageFit.Contain) + // [EndExclude text_style3] + } + // [StartExclude text_style4] + .width('100%') + + if (index != this.scaleList.length - ONE) { + Divider() + .vertical(false) + .strokeWidth(1) + .margin({ top: $r('app.float.size_10') }) + .color($r('app.color.speed_dialog')) + .width('100%') + } + // [EndExclude text_style4] + } + .width('90%') + } + .width('100%') + .height($r('app.float.size_48')) + .onClick(() => { + this.windowScaleSelect = index; + switch (this.windowScaleSelect) { + case ZERO: + this.avPlayerController.videoScaleFit(); + break; + case ONE: + this.avPlayerController.videoScaleFitCrop(); + break; + default: + break; + } + this.controller.close(); + }) + }) + } + // [End window_scale_dialog] + .width('100%') + .height('192vp') + .margin({ + top: $r('app.float.size_12') + }) + + Row() { + Text($r('app.string.dialog_cancel')) + .fontSize($r('app.float.size_16')) + .fontColor($r('app.color.scale_font_color')) + .fontWeight(FontWeight.Medium) + .layoutWeight(1) + .textAlign(TextAlign.Center) + .onClick(() => { + this.controller.close() + }) + } + .alignItems(VerticalAlign.Center) + .height($r('app.float.size_50')) + .padding({ bottom: $r('app.float.size_5') }) + .width('100%') + } + .alignItems(HorizontalAlign.Center) + .width('100%') + .margin({ left: $r('app.float.size_16'), right: $r('app.float.size_16') }) + .borderRadius($r('app.float.size_24')) + .backgroundColor(Color.White) + + } +} \ No newline at end of file diff --git a/entry/src/main/ets/views/SetVolume.ets b/entry/src/main/ets/views/SetVolume.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d779ab719bbe8c176aed6a750f8e0533607537c --- /dev/null +++ b/entry/src/main/ets/views/SetVolume.ets @@ -0,0 +1,41 @@ +/* + * 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. + */ + +// [Start set_volume_component] +import { AVVolumePanel } from '@kit.AudioKit'; + +@Component +export struct SetVolume { + @Prop volume: number = 5 + @Prop volumeVisible: boolean = false + + build() { + Column() { + AVVolumePanel({ + volumeLevel: this.volume, + volumeParameter: { + position: { + x: 50, + y: 900 + } + } + }) + .width(10) + } + .visibility(this.volumeVisible ? Visibility.Visible : Visibility.Hidden) + .height('50%') + } +} +// [End set_volume_component] \ No newline at end of file diff --git a/entry/src/main/ets/views/SpeedDialog.ets b/entry/src/main/ets/views/SpeedDialog.ets new file mode 100644 index 0000000000000000000000000000000000000000..a7ba007ce31c68c9b5194ae52edc0b24edd62806 --- /dev/null +++ b/entry/src/main/ets/views/SpeedDialog.ets @@ -0,0 +1,140 @@ +/* + * 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 { AvPlayerController } from '../controller/AvPlayerController'; + +// Index of the playback rate list. +const ZERO = 0; +const ONE = 1; +const TWO = 2; +const THREE = 3; + +/** + * Set speed dialog + */ +@CustomDialog +export struct SpeedDialog { + @State speedList: Resource[] = + [$r('app.string.video_speed_1_0X'), $r('app.string.video_speed_1_25X'), $r('app.string.video_speed_1_75X'), + $r('app.string.video_speed_2_0X')]; + @Link @Watch('onSpeedSelectUpdate') speedSelect: number; // Index of the current selection + @StorageLink('avPlayerController') avPlayerController: AvPlayerController = new AvPlayerController(); + private controller: CustomDialogController; + + onSpeedSelectUpdate() { + AppStorage.setOrCreate('speedName', this.speedList[this.speedSelect]); + AppStorage.setOrCreate('speedIndex', this.speedSelect); + } + + build() { + Column() { + Text($r('app.string.dialog_play_speed')) + .fontSize($r('app.float.size_20')) + .fontWeight(FontWeight.Bold) + .width('90%') + .fontColor(Color.Black) + .textAlign(TextAlign.Center) + .margin({ top: $r('app.float.size_20'), bottom: $r('app.float.size_12') }) + + List() { + // [Start video_speed_dialog] + ForEach(this.speedList, (item: Resource, index) => { + ListItem() { + Column() { + Row() { + Text(item)// [StartExclude text_style2] + .fontSize($r('app.float.size_16')) + .fontColor(Color.Black) + .fontWeight(FontWeight.Medium) + .textAlign(TextAlign.Center) + // [EndExclude text_style2] + Blank() + Image(this.speedSelect === index ? $r('app.media.ic_radio_selected') : + $r('app.media.ic_radio'))// [StartExclude text_style3] + .width($r('app.float.size_24')) + .height($r('app.float.size_24')) + .objectFit(ImageFit.Contain) + // [EndExclude text_style3] + } + // [StartExclude text_style4] + .width('100%') + + if (index != this.speedList.length - ONE) { + Divider() + .vertical(false) + .strokeWidth(1) + .margin({ top: $r('app.float.size_10') }) + .color($r('app.color.speed_dialog')) + .width('100%') + } + // [EndExclude text_style4] + } + .width('90%') + } + .width('100%') + .height($r('app.float.size_48')) + .onClick(() => { + this.speedSelect = index; + switch (this.speedSelect) { + case ZERO: + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_00_X); + break; + case ONE: + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_25_X); + break; + case TWO: + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_1_75_X); + break; + case THREE: + this.avPlayerController.videoSpeed(media.PlaybackSpeed.SPEED_FORWARD_2_00_X); + break; + default: + break; + } + this.controller.close(); + }) + }, (item: Resource, index) => index + '_' + JSON.stringify(item)) + } + // [End video_speed_dialog] + .width('100%') + .height('192vp') + .margin({ + top: $r('app.float.size_12') + }) + + Row() { + Text($r('app.string.dialog_cancel')) + .fontSize($r('app.float.size_16')) + .fontColor('#0A59F7') + .fontWeight(FontWeight.Medium) + .layoutWeight(1) + .textAlign(TextAlign.Center) + .onClick(() => { + this.controller.close(); + }) + } + .alignItems(VerticalAlign.Center) + .height($r('app.float.size_50')) + .padding({ bottom: $r('app.float.size_5') }) + .width('100%') + } + .alignItems(HorizontalAlign.Center) + .width('100%') + .margin({ left: $r('app.float.size_16'), right: $r('app.float.size_16') }) + .borderRadius($r('app.float.size_24')) + .backgroundColor(Color.White) + + } +} \ No newline at end of file diff --git a/entry/src/main/ets/views/VideoOperate.ets b/entry/src/main/ets/views/VideoOperate.ets new file mode 100644 index 0000000000000000000000000000000000000000..715b82198bb968ae0366c0379d6be591b70775c4 --- /dev/null +++ b/entry/src/main/ets/views/VideoOperate.ets @@ -0,0 +1,213 @@ +/* + * 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 { timeConvert } from '../common/utils/TimeUtils'; +import { AvPlayerController } from '../controller/AvPlayerController'; +import { SpeedDialog } from './SpeedDialog'; +import { ScaleDialog } from './ScaleDialog'; +import { LanguageDialog } from './LanguageDialog'; + +@Component +export struct VideoOperate { + @State speedSelect: number = 0; // Speed Magnification Selection + @State windowScaleSelect: number = 0 + @State languageSelect: number = 0 + @Link currentTime: number; + @Link durationTime: number; + @Link isSwiping: boolean; + @Link avPlayerController: AvPlayerController + @Link flag: boolean; // Play/Pause + @Link XComponentFlag: boolean; + @StorageLink('speedIndex') speedIndex: number = 0; // Index of the playback rate list. + @StorageLink('sliderWidth') sliderWidth: string = ''; + @StorageLink('speedName') speedName: Resource = $r('app.string.video_speed_1_0X'); + @StorageLink('isMuted') isMuted: boolean = false; + @StorageLink('videoScaleType') videoScaleType: number = media.VideoScaleType.VIDEO_SCALE_TYPE_FIT; + @StorageLink('currentLanguageType') currentLanguageType: number = 0; + private dialogController: CustomDialogController = new CustomDialogController({ + builder: SpeedDialog({ speedSelect: $speedSelect }), + alignment: DialogAlignment.Center, + offset: { dx: $r('app.float.size_zero'), dy: $r('app.float.size_down_20') } + }); + private scaleDialogController: CustomDialogController = new CustomDialogController({ + builder: ScaleDialog({ windowScaleSelect: $windowScaleSelect }), + alignment: DialogAlignment.Center, + offset: { dx: $r('app.float.size_zero'), dy: $r('app.float.size_down_20') } + }); + private languageDialogController: CustomDialogController = new CustomDialogController({ + builder: LanguageDialog({ languageSelect: $languageSelect }), + alignment: DialogAlignment.Center, + offset: { dx: $r('app.float.size_zero'), dy: $r('app.float.size_down_20') } + }); + + build() { + Column(){ + Row() { + // [Start video_language_switch_button] + /** + * Video Language switch + */ + Button() { + Image($r('app.media.ic_video_translate')) + .width($r('app.float.size_25')) + .height($r('app.float.size_25')) + } + .type(ButtonType.Normal) + .width($r('app.float.size_25')) + .height($r('app.float.size_25')) + .backgroundColor('rgba(0, 0, 0, 0)') + .margin({ left: $r('app.float.size_5') }) + .fontColor(Color.White) + .onClick(() => { + this.languageSelect = this.currentLanguageType; + this.languageDialogController.open(); + }) + + // [End video_language_switch_button] + } + .width('100%') + .padding({ left: $r('app.float.size_12'), right: $r('app.float.size_20') }) + .justifyContent(FlexAlign.End) + + + Row() { + Row() { + Image(this.flag ? $r('app.media.ic_video_play') : $r('app.media.ic_video_pause'))// Play/Pause + .id('play') + .width($r('app.float.size_30')) + .height($r('app.float.size_30')) + .onClick(() => { + this.flag ? this.avPlayerController.videoPause() : this.avPlayerController.videoPlay(); + this.flag = !this.flag; + }) + + // Left side time + Text(timeConvert(this.currentTime)) + .fontColor(Color.White) + .textAlign(TextAlign.End) + .fontWeight(FontWeight.Regular) + .margin({ left: $r('app.float.size_5') }) + } + + Row() { + // [Start progress_slider] + /** + * Progress slider + */ + Slider({ + value: this.currentTime, + min: 0, + max: this.durationTime, + style: SliderStyle.OutSet + }) + .id('Slider') + .blockColor(Color.White) + .trackColor(Color.Gray) + .selectedColor($r('app.color.slider_selected')) + .showTips(false) + .onChange((value: number, mode: SliderChangeMode) => { + if (mode === SliderChangeMode.Begin) { + this.isSwiping = true; + this.avPlayerController.videoPause(); + } + this.avPlayerController.videoSeek(value); + this.currentTime = value; + if (mode === SliderChangeMode.End) { + this.isSwiping = false; + this.flag = true; + this.avPlayerController.videoPlay(); + } + }) + // [End progress_slider] + } + .layoutWeight(1) + Row() { + // Right side time + Text(timeConvert(this.durationTime)) + .fontColor(Color.White) + .fontWeight(FontWeight.Regular) + + // [Start video_speed_button] + Button(this.speedName, { type: ButtonType.Normal }) + .border({ width: $r('app.float.size_1'), color: Color.White }) + .width($r('app.float.size_64')) + .height($r('app.float.size_30')) + .fontSize($r('app.float.size_15')) + .borderRadius($r('app.float.size_20')) + .fontColor(Color.White) + .backgroundColor('rgba(0, 0, 0, 0)') + .opacity($r('app.float.size_1')) + .padding({ left: $r('app.float.size_5'), right: $r('app.float.size_5') }) + .margin({ left: $r('app.float.size_8') }) + .id('Speed') + .onClick(() => { + this.speedSelect = this.speedIndex; + this.dialogController.open(); + }) + // [End video_speed_button] + + // [Start video_muted_button] + /** + * Video Muted Button + */ + Button() { + Image(this.isMuted ? $r('app.media.ic_video_speaker_slash') : $r('app.media.ic_video_speaker')) + .width($r('app.float.size_30')) + .height($r('app.float.size_30')) + } + .type(ButtonType.Normal) + .width($r('app.float.size_30')) + .height($r('app.float.size_30')) + .borderRadius($r('app.float.size_20')) + .backgroundColor('rgba(0, 0, 0, 0)') + .margin({ left: $r('app.float.size_5') }) + .fontColor(Color.White) + .onClick(() => { + this.isMuted = !this.isMuted; + this.avPlayerController.videoMuted(this.isMuted) + }) + + // [End video_muted_button] + + // [Start window_scale_button] + /** + * Window scale button + */ + Button() { + Image($r('app.media.ic_video_window_scale')) + .width($r('app.float.size_25')) + .height($r('app.float.size_25')) + } + .type(ButtonType.Normal) + .width($r('app.float.size_25')) + .height($r('app.float.size_25')) + .backgroundColor('rgba(0, 0, 0, 0)') + .margin({ left: $r('app.float.size_5') }) + .fontColor(Color.White) + .onClick(() => { + this.windowScaleSelect = this.videoScaleType; + this.scaleDialogController.open(); + }) + + // [End window_scale_button] + } + } + .justifyContent(FlexAlign.Center) + .padding({ left: $r('app.float.size_12'), right: $r('app.float.size_20') }) + .width('100%') + } + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..847fceb6c68f30a164b4f35acad31e4ec1733554 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023 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" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [ + { + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ets", + "description": "$string:entryAbility_desc", + "icon": "$media:icon", + "label": "$string:entryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "$string:reason_internet", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + }, + { + "name": "ohos.permission.GET_NETWORK_INFO", + "reason": "$string:reason_get_network_info", + "usedScene": { + "abilities": [ + "EntryAbility" + ], + "when": "always" + } + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..07787b20afa5a0d303a4bbf57b2311bdca980031 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,32 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + }, + { + "name": "slider_selected", + "value": "#007DFF" + }, + { + "name": "speed_dialog", + "value": "#33bab4b4" + }, + { + "name": "video_play", + "value": "#333333" + }, + { + "name": "video_play_selected", + "value": "#5c5c5c" + }, + { + "name": "back_button", + "value": "#4D505050" + }, + { + "name": "scale_font_color", + "value": "#0A59F7" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/float.json b/entry/src/main/resources/base/element/float.json new file mode 100644 index 0000000000000000000000000000000000000000..5006bd8c2403b0d94091f881fdf27e71e4624fd8 --- /dev/null +++ b/entry/src/main/resources/base/element/float.json @@ -0,0 +1,116 @@ +{ + "float": [ + { + "name": "size_zero_five", + "value": "0.5" + }, + { + "name": "size_zero_six", + "value": "0.6" + }, + { + "name": "size_zero", + "value": "0" + }, + { + "name": "size_1", + "value": "1" + }, + { + "name": "size_5", + "value": "5" + }, + { + "name": "size_8", + "value": "8" + }, + { + "name": "size_10", + "value": "10" + }, + { + "name": "size_12", + "value": "12" + }, + { + "name": "size_15", + "value": "15" + }, + { + "name": "size_16", + "value": "16" + }, + { + "name": "size_18", + "value": "18" + }, + { + "name": "size_20", + "value": "20" + }, + { + "name": "size_down_20", + "value": "-20" + }, + { + "name": "size_down_80", + "value": "-80" + }, + { + "name": "size_24", + "value": "24" + }, + { + "name": "size_25", + "value": "25" + }, + { + "name": "size_30", + "value": "30" + }, + { + "name": "size_32", + "value": "32" + }, + { + "name": "size_35", + "value": "35" + }, + { + "name": "size_40", + "value": "40" + }, + { + "name": "size_45", + "value": "45" + }, + { + "name": "size_48", + "value": "48" + }, + { + "name": "size_50", + "value": "50" + }, + { + "name": "size_64", + "value": "64" + }, + { + "name": "size_75", + "value": "75" + }, + { + "name": "size_80", + "value": "-80" + }, + { + "name": "size_210", + "value": "210" + }, + { + "name": "size_254", + "value": "254" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..83059752bdd5f7c8799c8d9994c2d3cf04c36221 --- /dev/null +++ b/entry/src/main/resources/base/element/string.json @@ -0,0 +1,96 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "entryAbility_desc", + "value": "description" + }, + { + "name": "entryAbility_label", + "value": "AVPlayer Basic Control" + }, + { + "name": "video_res_1", + "value": "test1.mp4" + }, + { + "name": "video_res_2", + "value": "test2.mp4" + }, + { + "name": "video_res_3", + "value": "network.mp4" + }, + { + "name": "video_speed_1_0X", + "value": "1.0X" + }, + { + "name": "video_speed_1_25X", + "value": "1.25X" + }, + { + "name": "video_speed_1_75X", + "value": "1.75X" + }, + { + "name": "video_speed_2_0X", + "value": "2.0X" + }, + { + "name": "video_warn", + "value": "Please check if the network is connected or available!" + }, + { + "name": "dialog_cancel", + "value": "Cancel" + }, + { + "name": "dialog_play_speed", + "value": "Playback speed" + }, + { + "name": "playing", + "value": "Playing" + }, + { + "name": "reason_internet", + "value": "Used for accessing the Internet during video playback" + }, + { + "name": "reason_get_network_info", + "value": "Used for retrieving network information during video playback" + }, + { + "name": "video_scale_fit", + "value": "FIT" + }, + { + "name": "video_scale_fit_crop", + "value": "FIT_CROP" + }, + { + "name": "dialog_play_scale", + "value": "window scale mode" + }, + { + "name": "local_video", + "value": "Local video" + }, + { + "name": "Chinese", + "value": "Chinese" + }, + { + "name": "English", + "value": "English" + }, + { + "name": "language_switch", + "value": "Language switch" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/media/background.png b/entry/src/main/resources/base/media/background.png new file mode 100644 index 0000000000000000000000000000000000000000..923f2b3f27e915d6871871deea0420eb45ce102f Binary files /dev/null and b/entry/src/main/resources/base/media/background.png differ diff --git a/entry/src/main/resources/base/media/foreground.png b/entry/src/main/resources/base/media/foreground.png new file mode 100644 index 0000000000000000000000000000000000000000..97014d3e10e5ff511409c378cd4255713aecd85f Binary files /dev/null and b/entry/src/main/resources/base/media/foreground.png differ diff --git a/entry/src/main/resources/base/media/ic_radio.png b/entry/src/main/resources/base/media/ic_radio.png new file mode 100644 index 0000000000000000000000000000000000000000..9c5f71f9c655cca2f4b3d05606e3841a372e813c Binary files /dev/null and b/entry/src/main/resources/base/media/ic_radio.png differ diff --git a/entry/src/main/resources/base/media/ic_radio_selected.svg b/entry/src/main/resources/base/media/ic_radio_selected.svg new file mode 100644 index 0000000000000000000000000000000000000000..f115d62baa097b60a6b7764edd5ea81295cb12d4 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_radio_selected.svg @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/entry/src/main/resources/base/media/ic_screen_switch.svg b/entry/src/main/resources/base/media/ic_screen_switch.svg new file mode 100644 index 0000000000000000000000000000000000000000..64bda6d74d09bbae5c3a96d593852fb279c7e20a --- /dev/null +++ b/entry/src/main/resources/base/media/ic_screen_switch.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_shuffle + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_back.svg b/entry/src/main/resources/base/media/ic_video_back.svg new file mode 100644 index 0000000000000000000000000000000000000000..77922e7aa4e50117c777aaf92f9db759b399d9f2 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_back.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_list.svg b/entry/src/main/resources/base/media/ic_video_list.svg new file mode 100644 index 0000000000000000000000000000000000000000..f56a83eff6b0680fc6ddd8f5cd5654f50b14125b --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_list.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_view_list + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_list_down.svg b/entry/src/main/resources/base/media/ic_video_list_down.svg new file mode 100644 index 0000000000000000000000000000000000000000..c74821d7a7b0b888d0de4c76e532a34531bf7670 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_list_down.svg @@ -0,0 +1,15 @@ + + + + 画板 + Created with Sketch. + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_list_up.svg b/entry/src/main/resources/base/media/ic_video_list_up.svg new file mode 100644 index 0000000000000000000000000000000000000000..b56a7c5aef39d028bb6cd16e1cf159a2bba1647f --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_list_up.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_arrow_up_0 + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_pause.svg b/entry/src/main/resources/base/media/ic_video_pause.svg new file mode 100644 index 0000000000000000000000000000000000000000..b18a4a3d00cf2f80fe90c55faef56b39ed485a1b --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_pause.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_play + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_play.svg b/entry/src/main/resources/base/media/ic_video_play.svg new file mode 100644 index 0000000000000000000000000000000000000000..675bf7f87b66ed5011191b77c1f3f678625be68a --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_play.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_pause + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_speaker.svg b/entry/src/main/resources/base/media/ic_video_speaker.svg new file mode 100644 index 0000000000000000000000000000000000000000..de631ac6ce93399e6671e4f781db8f1a6dae5cfb --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_speaker.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_speaker_slash.svg b/entry/src/main/resources/base/media/ic_video_speaker_slash.svg new file mode 100644 index 0000000000000000000000000000000000000000..fb345f0771d5363ef99d4bb19d58a801e6d38aa1 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_speaker_slash.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_translate.svg b/entry/src/main/resources/base/media/ic_video_translate.svg new file mode 100644 index 0000000000000000000000000000000000000000..907ba2997bc6abcf55a3303a3e3a23d1bf42c4d8 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_translate.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_view_list.svg b/entry/src/main/resources/base/media/ic_video_view_list.svg new file mode 100644 index 0000000000000000000000000000000000000000..3a7c8392a5ce10f74a34578415041614a8bce1d8 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_view_list.svg @@ -0,0 +1,13 @@ + + + Public/ic_public_view_list_filled + + + + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/ic_video_window_scale.svg b/entry/src/main/resources/base/media/ic_video_window_scale.svg new file mode 100644 index 0000000000000000000000000000000000000000..67eef9e155a46b5541a1fbced2ed9084cc55c257 --- /dev/null +++ b/entry/src/main/resources/base/media/ic_video_window_scale.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/entry/src/main/resources/base/media/icon.png b/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/entry/src/main/resources/base/media/icon.png differ diff --git a/entry/src/main/resources/base/media/layered_image.json b/entry/src/main/resources/base/media/layered_image.json new file mode 100644 index 0000000000000000000000000000000000000000..fb49920440fb4d246c82f9ada275e26123a2136a --- /dev/null +++ b/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/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/entry/src/main/resources/en_US/element/string.json b/entry/src/main/resources/en_US/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..8d5ec0fa074d19cbf56be3471ba6f2eff251022c --- /dev/null +++ b/entry/src/main/resources/en_US/element/string.json @@ -0,0 +1,96 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "entryAbility_desc", + "value": "description" + }, + { + "name": "entryAbility_label", + "value": "AVPlayerBasicControl" + }, + { + "name": "video_res_1", + "value": "test1.mp4" + }, + { + "name": "video_res_2", + "value": "test2.mp4" + }, + { + "name": "video_res_3", + "value": "network.mp4" + }, + { + "name": "video_speed_1_0X", + "value": "1.0X" + }, + { + "name": "video_speed_1_25X", + "value": "1.25X" + }, + { + "name": "video_speed_1_75X", + "value": "1.75X" + }, + { + "name": "video_speed_2_0X", + "value": "2.0X" + }, + { + "name": "video_warn", + "value": "Please check if the network is connected or available!" + }, + { + "name": "dialog_cancel", + "value": "Cancel" + }, + { + "name": "dialog_play_speed", + "value": "Playback speed" + }, + { + "name": "playing", + "value": "playing" + }, + { + "name": "reason_internet", + "value": "Used for accessing the Internet during video playback" + }, + { + "name": "reason_get_network_info", + "value": "Used for retrieving network information during video playback" + }, + { + "name": "video_scale_fit", + "value": "FIT" + }, + { + "name": "video_scale_fit_crop", + "value": "FIT_CROP" + }, + { + "name": "dialog_play_scale", + "value": "window scale mode" + }, + { + "name": "local_video", + "value": "Local video" + }, + { + "name": "Chinese", + "value": "Chinese" + }, + { + "name": "English", + "value": "English" + }, + { + "name": "language_switch", + "value": "Language switch" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/captions.srt b/entry/src/main/resources/rawfile/captions.srt new file mode 100644 index 0000000000000000000000000000000000000000..9a17e648059285d09261cd86c36e1dcfbcc18629 --- /dev/null +++ b/entry/src/main/resources/rawfile/captions.srt @@ -0,0 +1,47 @@ +1 +00:00:00,000 --> 00:00:01,000 +360°立体天气动态展示 + +2 +00:00:01,000 --> 00:00:02,000 +实时同步窗外真实气象 + +3 +00:00:02,000 --> 00:00:03,000 +雷暴预警闪电特效提示 + +4 +00:00:03,000 --> 00:00:04,000 +晨曦极光自动色调变换 + +5 +00:00:04,000 --> 00:00:05,000 +指尖轻触触发季节音效 + +6 +00:00:05,000 --> 00:00:06,000 +这是第一段比较长的字幕测试内容 + +7 +00:00:06,000 --> 00:00:07,000 +这是第二段比较长的字幕测试内容 + +8 +00:00:07,000 --> 00:00:08,000 +这是第三段比较长的字幕测试内容 + +9 +00:00:08,000 --> 00:00:09,000 +这是第四段比较长的字幕测试内容 + +10 +00:00:09,000 --> 00:00:10,000 +这是第五段比较长的字幕测试内容 + +11 +00:00:10,000 --> 00:00:11,000 +这是第六段比较长的字幕测试内容 + +12 +00:00:11,000 --> 00:00:12,000 +这是第七段比较长的字幕测试内容 \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/en_captions.srt b/entry/src/main/resources/rawfile/en_captions.srt new file mode 100644 index 0000000000000000000000000000000000000000..0de4e872eb7f99848907ed59113fca1a5a8d1ce4 --- /dev/null +++ b/entry/src/main/resources/rawfile/en_captions.srt @@ -0,0 +1,47 @@ +1 +00:00:00,000 --> 00:00:01,000 +360° dynamic display of three-dimensional weather + +2 +00:00:01,000 --> 00:00:02,000 +Synchronize the real-time meteorological conditions outside the window + +3 +00:00:02,000 --> 00:00:03,000 +Thunderstorm warning: lightning effect prompt + +4 +00:00:03,000 --> 00:00:04,000 +Dawn Aurora Automatic Color Tone Transition + +5 +00:00:04,000 --> 00:00:05,000 +A light touch on the fingertip triggers seasonal sound effects + +6 +00:00:05,000 --> 00:00:06,000 +This is the first relatively long subtitle test content + +7 +00:00:06,000 --> 00:00:07,000 +This is the second relatively long subtitle test content + +8 +00:00:07,000 --> 00:00:08,000 +This is the third relatively long subtitle test content + +9 +00:00:08,000 --> 00:00:09,000 +This is the fourth relatively long subtitle test content + +10 +00:00:09,000 --> 00:00:10,000 +This is the fifth relatively long subtitle test content + +11 +00:00:10,000 --> 00:00:11,000 +This is the sixth relatively long subtitle test content + +12 +00:00:11,000 --> 00:00:12,000 +This is the seventh relatively long subtitle test content \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/test1.mp4 b/entry/src/main/resources/rawfile/test1.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..e89bdff923a22a778a39edce405bb1092a14449d Binary files /dev/null and b/entry/src/main/resources/rawfile/test1.mp4 differ diff --git a/entry/src/main/resources/zh_CN/element/string.json b/entry/src/main/resources/zh_CN/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b074e3c1f8485a02902532389c4f119f719268b6 --- /dev/null +++ b/entry/src/main/resources/zh_CN/element/string.json @@ -0,0 +1,96 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "模块描述" + }, + { + "name": "entryAbility_desc", + "value": "description" + }, + { + "name": "entryAbility_label", + "value": "AVPlayer基础播控" + }, + { + "name": "video_warn", + "value": "请检查网络是否连接或可用!" + }, + { + "name": "video_speed_1_0X", + "value": "1.0X" + }, + { + "name": "video_speed_1_25X", + "value": "1.25X" + }, + { + "name": "video_speed_1_75X", + "value": "1.75X" + }, + { + "name": "video_res_1", + "value": "test1.mp4" + }, + { + "name": "video_res_2", + "value": "test2.mp4" + }, + { + "name": "video_res_3", + "value": "network.mp4" + }, + { + "name": "video_speed_2_0X", + "value": "2.0X" + }, + { + "name": "dialog_cancel", + "value": "取消" + }, + { + "name": "dialog_play_speed", + "value": "播放倍速" + }, + { + "name": "playing", + "value": "当前播放" + }, + { + "name": "reason_internet", + "value": "用于视频播放场景使用Internet网络" + }, + { + "name": "reason_get_network_info", + "value": "用于视频播放场景获取网络信息" + }, + { + "name": "video_scale_fit", + "value": "拉伸至与窗口等大" + }, + { + "name": "video_scale_fit_crop", + "value": "缩放至最短边填满窗口" + }, + { + "name": "dialog_play_scale", + "value": "窗口缩放模式" + }, + { + "name": "local_video", + "value": "本地视频" + }, + { + "name": "Chinese", + "value": "中文" + }, + { + "name": "English", + "value": "英文" + }, + { + "name": "language_switch", + "value": "语言切换" + } + ] +} \ No newline at end of file diff --git a/hvigor/hvigor-config.json5 b/hvigor/hvigor-config.json5 new file mode 100644 index 0000000000000000000000000000000000000000..5bebc9755447385d82ce4138f54d991b1f85f348 --- /dev/null +++ b/hvigor/hvigor-config.json5 @@ -0,0 +1,22 @@ +{ + "modelVersion": "5.0.5", + "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/hvigorfile.ts b/hvigorfile.ts new file mode 100644 index 0000000000000000000000000000000000000000..47113e2e36ecefde41c136272a0bd6ff745cffe4 --- /dev/null +++ b/hvigorfile.ts @@ -0,0 +1,6 @@ +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. */ +} \ No newline at end of file diff --git a/oh-package.json5 b/oh-package.json5 new file mode 100644 index 0000000000000000000000000000000000000000..2d9c74ff34f1383ec920815a40399dd0fe46a6c5 --- /dev/null +++ b/oh-package.json5 @@ -0,0 +1,8 @@ +{ + "modelVersion": "5.0.5", + "description": "Please describe the basic information.", + "dependencies": { + }, + "devDependencies": { + } +} diff --git a/screenshots/devices/pause.png b/screenshots/devices/pause.png new file mode 100644 index 0000000000000000000000000000000000000000..86813701956bc38e2c419b398fb3b7ee6a4d2703 Binary files /dev/null and b/screenshots/devices/pause.png differ diff --git a/screenshots/devices/playing.png b/screenshots/devices/playing.png new file mode 100644 index 0000000000000000000000000000000000000000..ed81fd38eb1d70d89c46ab5949cb6404f596aa03 Binary files /dev/null and b/screenshots/devices/playing.png differ diff --git a/screenshots/devices/scale_fit.png b/screenshots/devices/scale_fit.png new file mode 100644 index 0000000000000000000000000000000000000000..67b8a911244de0e2344b2ac587dffe03466fa275 Binary files /dev/null and b/screenshots/devices/scale_fit.png differ diff --git a/screenshots/devices/set_media_muted.png b/screenshots/devices/set_media_muted.png new file mode 100644 index 0000000000000000000000000000000000000000..a4a94bc62cbe343948dd686d73e937525a004821 Binary files /dev/null and b/screenshots/devices/set_media_muted.png differ diff --git a/screenshots/devices/set_volume.png b/screenshots/devices/set_volume.png new file mode 100644 index 0000000000000000000000000000000000000000..c11e3f332a78c94df518552da031d975d406fa2b Binary files /dev/null and b/screenshots/devices/set_volume.png differ diff --git a/screenshots/devices/speed_dialog.png b/screenshots/devices/speed_dialog.png new file mode 100644 index 0000000000000000000000000000000000000000..9845b501bcd6b66f3013b14438666e66a085b6ac Binary files /dev/null and b/screenshots/devices/speed_dialog.png differ