• Home
Name Date Size #Lines LOC

..--

AppScope/12-May-2024-3634

entry/12-May-2024-2,9432,682

hvigor/12-May-2024-98

screenshots/12-May-2024-

.gitignoreD12-May-2024119 1111

README.mdD12-May-20247.2 KiB12284

build-profile.json5D12-May-20241 KiB4343

hvigorfile.tsD12-May-2024159 21

hvigorwD12-May-20241.4 KiB4928

hvigorw.batD12-May-20241.5 KiB6547

oh-package.json5D12-May-2024245 1312

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路径下并重启;
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.ets                          // 日志工具
51|   |---KvStoreModel.ets                    // kvstore对象操作类
52|   |---RemoteDeviceModel.ets               // 远程设备操作类
53|---common
54|   |---BasicDataSource.ets                 // 懒加载数据
55|   |---DeviceDialog.ets                    // 分布式设备列表弹窗
56|   |---ScreenshotDialog.ets                // 屏幕截图弹窗
57|   |---TitleBar.ets                        // 菜单栏模块(包含远端设备拉起)
58|---utils
59|   |---AVPlayerUtils.ts                    // 封装AVPlayer工具类
60|   |---DateTimeUtil.ets                    // 日期时间工具类
61|   |---MediaUtils.ts                       // 媒体库工具类
62|   |---utils.ets                           // 自定义工具类
63```
64
65### 具体实现
66
67在分布式视频播放器应用中,分布式设备管理包含了分布式设备搜索、分布式设备列表弹窗、远端设备拉起三部分。
68首先在分布式组网内搜索设备,然后把设备展示到分布式设备列表弹窗中,最后根据用户的选择拉起远端设备。
69
70#### 分布式设备搜索
71
72通过SUBSCRIBE_ID搜索分布式组网内的远端设备,详见startDeviceDiscovery(){}模块[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/model/RemoteDeviceModel.ets)73
74#### 分布式设备列表弹窗
75
76使用@CustomDialog装饰器来装饰分布式设备列表弹窗,[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/common/DeviceDialog.ets)77
78#### 远端设备拉起
79
80通过startAbility(deviceId)方法拉起远端设备的包,[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/common/TitleBar.ets)81
82#### 分布式数据管理
83
84(1) 管理分布式数据库
85创建一个KVManager对象实例,用于管理分布式数据库对象。通过distributedKVStore.createKVManager(config),并通过指定Options和storeId,创建并获取KVStore数据库,并通过Promise方式返回,此方法为异步方法,例如this.kvManager.getKVStore(STORE_ID, options).then((store) => {})
86
87(2) 订阅分布式数据变化
88通过订阅分布式数据库所有(本地及远端)数据变化实现数据协同[源码参考](https://gitee.com/openharmony/vendor_unionman/blob/master/unionpi_tiger/sample/app/DistributedVideoPlayer/entry/src/main/ets/model/KvStoreModel.ets)89
90### 相关权限
91
92[ohos.permission.DISTRIBUTED_DATASYNC](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissiondistributed_datasync)
93
94[ohos.permission.CAPTURE_SCREEN](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissioncapture_screen)
95
96[ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionread_media)
97
98[ohos.permission.WRITE_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/permission-list.md#ohospermissionwrite_media)
99
100### 依赖
101
102不涉及。
103
104### 约束与限制
105
1061. 本示例仅支持标准系统上运行;
1072. 本示例仅支持API9版本SDK,SDK版本号(API Version 9 Release),镜像版本号(3.2 Release);
1083. 本示例需要使用DevEco Studio 版本号(3.1 Release)才可编译运行;
1094. 本示例涉及使用系统接口:@ohos.distributedHardware.deviceManager,需要手动替换Full SDK才能编译通过,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)1105. 本示例涉及系统接口,需要配置系统应用签名,可以参考[特殊权限配置方法](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/app-provision-structure.md#修改harmonyappprovision配置文件),把配置文件中的“app-feature”字段信息改为“hos_system_app”。
111
112### 下载
113
114如需单独下载本工程,执行如下命令:
115
116```
117git init
118git config core.sparsecheckout true
119echo unionpi_tiger/sample/app/DistributedVideoPlayer/ > .git/info/sparse-checkout
120git remote add origin https://gitee.com/openharmony/vendor_unionman.git
121git pull origin master
122```