• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3634

entry/12-May-2024-3,1372,691

hvigor/12-May-2024-2019

screenshots/12-May-2024-

.gitignoreD12-May-2024119 1111

README.mdD12-May-20247.3 KiB12385

build-profile.json5D12-May-20241.2 KiB5252

hvigorfile.tsD12-May-2024234 75

hvigorwD12-May-20241.4 KiB4928

hvigorw.batD12-May-20241.5 KiB6547

oh-package.json5D12-May-2024249 1413

ohosTest.mdD12-May-20242.8 KiB1917

README.md

1# 分布式视频播放器
2
3### 介绍
4
5本示例使用medialibrary获取本地视频文件资源,并通过AVPlayer完成了视频的播放、暂停、跳转、倍速等功能;并使用DeviceManager完成了分布式设备列表的显示和分布式能力完成了视频播放状态的跨设备协同。
6
7本示例用到了文件存储管理能力接口[@ohos.fileio](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-fileio.md)
8
9媒体查询接口[@ohos.mediaquery](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-mediaquery.md)
10
11分布式键值数据库接口[@ohos.data.distributedKVStore](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-distributed-data.md)
12
13音视频相关媒体业务能力接口[@ohos.multimedia.media](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-media.md)
14
15分布式设备管理能力接口(设备管理),实现设备之间的kvStore对象的数据传输交互[@ohos.distributedHardware.deviceManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-device-manager.md)
16
17应用持久化轻量级数据接口[@ohos.data.preferences](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-data-preferences.md)
18
19屏幕截图接口[@ohos.screenshot](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-screenshot.md)
20
21### 效果预览
22
23| 首页                                 | 视频列表                           |
24| ------------------------------------ | ---------------------------------- |
25| ![](screenshots/Index.jpeg)        | ![](screenshots/VideoList.jpeg) |
26| **设备弹窗**                          | **设置**                           |
27| ![](screenshots/DeviceDialog.jpeg) | ![](screenshots/Settings.jpeg)     |
28
29使用说明
30
311. 首次进入应用会弹出权限弹窗,需要进行授权;
321. 播放视频源可使用hdc命令将视频推到`storage/media/100/local/files/Videos`路径下并重启或使用`scanner`命令刷新;
331. **单击**播放键/暂停键或**双击**界面控制**播放/暂停**;
342. 点击进度条或左右滑动**操控进度**;
353. 点击右上角流转按钮,即可弹出设备选择框;
363. 在设备选择框中点击对端设备名称,拉起对端应用;
373. 对端应用启动后,可在任意一端中操作应用,两端应用可实现数据实时同步;
383. 在设备选择框中选中本机即可关闭对端应用;
393. 点击右上角设置按钮,可对流转模式及分布式认证设备进行设置管理;
40
41### 工程目录
42
43```
44entry/src/main/ets/
45|---pages
46|   |---Index.ets                           // 首页
47|   |---Settings.ets                        // 设置页
48|---model
49|   |---DistributedDataModel.ts             // 封装分布式数据类
50|   |---Logger.ts                          // 日志工具
51|   |---KvStoreModel.ts                    // kvstore对象操作类
52|   |---RemoteDeviceModel.ts               // 远程设备操作类
53|---common
54|   |---BasicDataSource.ets                 // 懒加载数据
55|   |---DeviceDialog.ets                    // 分布式设备列表弹窗
56|   |---ScreenshotDialog.ets                // 屏幕截图弹窗
57|   |---TitleBar.ets                        // 菜单栏模块(包含远端设备拉起)
58|---utils
59|   |---AVPlayerUtils.ts                    // 封装AVPlayer工具类
60|   |---DateTimeUtil.ts                    // 日期时间工具类
61|   |---globalThis.ts
62|   |---MediaUtils.ts                       // 媒体库工具类
63|   |---utils.ts                           // 自定义工具类
64```
65
66### 具体实现
67
68在分布式视频播放器应用中,分布式设备管理包含了分布式设备搜索、分布式设备列表弹窗、远端设备拉起三部分。
69首先在分布式组网内搜索设备,然后把设备展示到分布式设备列表弹窗中,最后根据用户的选择拉起远端设备。
70
71#### 分布式设备搜索
72
73通过SUBSCRIBE_ID搜索分布式组网内的远端设备,详见startDeviceDiscovery(){}模块[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/model/RemoteDeviceModel.ets)74
75#### 分布式设备列表弹窗
76
77使用@CustomDialog装饰器来装饰分布式设备列表弹窗,[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/common/DeviceDialog.ets)78
79#### 远端设备拉起
80
81通过startAbility(deviceId)方法拉起远端设备的包,[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/common/TitleBar.ets)82
83#### 分布式数据管理
84
85(1) 管理分布式数据库
86创建一个KVManager对象实例,用于管理分布式数据库对象。通过distributedKVStore.createKVManager(config),并通过指定Options和storeId,创建并获取KVStore数据库,并通过Promise方式返回,此方法为异步方法,例如this.kvManager.getKVStore(STORE_ID, options).then((store) => {})
87
88(2) 订阅分布式数据变化
89通过订阅分布式数据库所有(本地及远端)数据变化实现数据协同[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/model/KvStoreModel.ets)90
91### 相关权限
92
93[ohos.permission.DISTRIBUTED_DATASYNC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissiondistributed_datasync)
94
95[ohos.permission.CAPTURE_SCREEN](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissioncapture_screen)
96
97[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionread_media)
98
99[ohos.permission.WRITE_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionwrite_media)
100
101### 依赖
102
103不涉及。
104
105### 约束与限制
106
1071. 本示例仅支持标准系统上运行;
1082. 本示例仅支持API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release);
1093. 本示例需要使用DevEco Studio 版本号(4.0 Release)才可编译运行;
1104. 本示例涉及使用系统接口:@ohos.distributedHardware.deviceManager,需要手动替换Full SDK才能编译通过,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)1115. 本示例涉及系统接口,需要配置系统应用签名,可以参考[特殊权限配置方法](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/app-provision-structure.md#修改harmonyappprovision配置文件),把配置文件中的“app-feature”字段信息改为“hos_system_app”。
112
113### 下载
114
115如需单独下载本工程,执行如下命令:
116
117```
118git init
119git config core.sparsecheckout true
120echo unionpi_tiger/sample_api10/app/DistributedVideoPlayer/ > .git/info/sparse-checkout
121git remote add origin https://gitee.com/openharmony/vendor_unionman.git
122git pull origin master
123```