1# 自定义振动 2 3### 介绍 4 5本示例使用[Vibrator模块](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md)展示了振感定制化的基本功能,包括振感与音效、视频协同振动等。 6 7### 效果预览 8| 首页 | 我的 | 视频 | 9|----------------------------------------|---------------------------------------|------------------------------------------| 10|  |  |  | 11 12使用说明: 131. 在"我的"界面中包含开发信息及基本设置,点击振动强度设置,可选择振动强度等级,本步骤可选,默认为低强度模式; 142. 在"发现"界面,振效库中罗列了不同体验场景,可点击各条目享受音效与振动的协同感受; 153. 在"发现"界面,触感效果视频可体验视频与振动的协同,点击视频预览图片进入全屏播放界面; 164. "显示更多"中罗列了当前的振感视频列表。 17 18### 目录结构 19``` 20entry/src/main/ets/ 21|---component 22| |---Common.ets // 振效库场景公共组件 23| |---Battle.ets // 振效库"战斗"场景 24| |---Environment.ets // 振效库"环境"场景 25| |---Exercise.ets // 振效库"运动"场景 26| |---Footstep.ets // 振效库"脚步"场景 27| |---Instrument.ets // 振效库"乐器"场景 28| |---Interaction.ets // 振效库"互动"场景 29| |---Racing.ets // 振效库"竞速"场景 30| |---Realistic.ets // 振效库"拟真"场景 31| |---Shooting.ets // 振效库"射击"场景 32| |---VideoPreview.ets // 视频频预览界面 33|---module 34| |---AudioPlayer.ets // 音频播放模块 35| |---DisplayModule.ets // "发现"界面,主界面 36| |---ImageData.ets // 资源数据结构 37| |---Logger.ets // 封装的日志 38| |---MyInfoModule.ets // "我的"界面 39| |---TabBar.ets // 振效库场景类别滑动栏 40| |---Util.ets // 工具函数 41| |---VideoListModule.ets // 视频列表模块 42| |---VideoPlayModule.ets // 视频播放模块 43|---pages 44| |---Index.ets // 首页 45``` 46### 具体实现 47+ 振动强度设置:可以选择振动的强度等级,源码参考[MyInfoMoModule.ets](entry/src/main/ets/module/MyInfoModule.ets); 48+ 振效库:点击振效库中各项,会调用媒体库AVPlayer播放音效,并同时调用vibrator模块startVibration接口启动振动,源码参考[DisplayModule.ets](entry/src/main/ets/module/DisplayModule.ets)以及component目录下振效库场景,比如[Battle.ets](entry/src/main/ets/component/Battle.ets)等; 49+ 振感视频:使用Video控件全屏播放视频,在开始播放同时调用vibrator模块startVibration接口启动振动,源码参考[VideoPlayModule.ets](entry/src/main/ets//module/VideoPlayModule.ets); 50+ 自定义振动:使用[Vibrator模块](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md)的startVibration方法播放应用内置的振动资源文件,代码参考[Util.ets](entry/src/main/ets/module/Util.ets); 51 52### 相关权限 53 54[ohos.permission.VIBRATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionvibrate) 55 56### 依赖 57不涉及 58 59### 约束与限制 60 611.本示例仅可在支持自定义振动的标准系统上运行。 62 632.本示例为Stage模型,仅适配API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release) 64 653.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。 66 67### 下载 68如需单独下载本工程,执行如下命令: 69``` 70git init 71git config core.sparsecheckout true 72echo code/BasicFeature/DeviceManagement/Vibrator/CustomHaptic/ > .git/info/sparse-checkout 73git remote add origin https://gitee.com/openharmony/applications_app_samples.git 74git pull origin master 75``` 76