• Home
Name Date Size #Lines LOC

..--

AppScope/06-May-2025-3633

entry/06-May-2025-1,3431,160

hvigor/06-May-2025-2221

screenshots/device/06-May-2025-

.gitignoreD06-May-202595 77

README.mdD06-May-20251 KiB1710

README_zh.mdD06-May-20255.6 KiB8755

build-profile.json5D06-May-20251.1 KiB4342

hvigorfile.jsD06-May-2025168 21

hvigorwD06-May-20252 KiB6228

hvigorw.batD06-May-20252 KiB7356

oh-package.json5D06-May-2025820 2725

ohosTest.mdD06-May-2025705 119

README.md

1# Screen Recorder
2
3### Introduction
4
5 This sample shows how to use graphic and multi-media APIs to record the device screen
6
7### Usage
8
91. Start the sample Application, touch the **Start** button to start recording. During the recording, you can touch the **float window** button on the top with small red rectangle and recording timer, the recording file will be saved and it can be found in the Gallery Application.
10
11### Constraints
12
131. This sample can only be run on standard-system devices.
142. Please use the "DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)" or later IDE version
153. Use the Full SDK is necessary for this sample, please refer the [guide](https://docs.openharmony.cn/pages/v3.2/en/application-dev/quick-start/full-sdk-switch-guide.md/).
164. How to configure the auto signing with system permission, please refer DevEco Studio: File -> Project Structure -> Project -> Signing Configs(TAB page) , on the bottom of this page, please click the hyperlink of "**View the operation guide**".
17

README_zh.md

1# 录屏示例(仅对系统应用开放)
2
3### 介绍
4
5 该示例展示设备屏幕(含音频)录制功能。屏幕录制的主要工作是通过创建一个虚拟屏,捕获屏幕显示图形帧,完成视频编码并保存到文件中,帮助OEM设备厂家系统应用实现屏幕录制功能,也可以通过此应用抓取屏幕帧用于问题复现录制。
6
7### 效果预览
8
9|获取媒体权限|获取录音权限|应用主界面|录制过程界面|
10|--------------------------------|--------------------------------|--------------------------------|--------------------------------|
11|![image](screenshots/device/user_grant1.png)|![image](screenshots/device/user_grant2.png)|![image](screenshots/device/main.png)|![image](screenshots/device/recording.png)|
12
13使用说明
14
151.启动应用,首次启动需要用户授予“**访问媒体和文件**”和“**麦克风**”的权限
16
172.点击**启动**按钮,启动屏幕录制。
18
193.启动录制后会弹出一个透明录制悬浮控件,并显示录制时间计时,此时可以操作屏幕,操作过程屏幕显示会被录制下来。
20
214.需要停止录屏时,点击悬浮半透明的红色按钮,屏幕录制停止。
22
235.打开图库应用,在图库中可以看到最新录屏的媒体文件,点击后可支持录屏回放。
24
25### 工程目录
26```
27entry/src/main/ets/
28|---common
29|   |---Constants.ts                // 数据初始化
30|   |---Logger.ts                   // 日志工具
31|---MainAbility
32|   |---MainAbility.ts
33|---pages
34|   |---index.ets                   // 首页
35|   |---ScreenRecordre.ets          // 屏幕录制
36```
37### 具体实现
38
39* 该示例通过Screen方法获取屏幕实例,createVirtualScreen方法创建一个虚拟屏,getAllScreens方法获取获取所有的屏幕,makeMirror方法将屏幕设置为镜像模式,setVirtualScreenSurface方法设置虚拟屏幕的surface,display接口捕获屏幕显示图形帧,media,mediaLibrary接口完成视频编码并保存到文件中,帮助OEM设备厂家系统应用实现屏幕录制功能。
40* 源码链接:[ScreenRecorder.ets](entry/src/main/ets/pages/ScreenRecorder.ets)
41* 接口参考:[@ohos.screen](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-screen-sys.md),[@ohos.multimedia.media](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-media-kit/js-apis-media.md),[@ohos.file.photoAccessHelper](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-media-library-kit/js-apis-photoAccessHelper.md),[@ohos.display](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-display.md)
42
43### 相关权限
44
451.允许应用访问用户媒体文件中的地理位置信息权限:[ohos.permission.MEDIA_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmedia_location)
46
472.允许应用修改用户公共目录的图片或视频文件权限:[ohos.permission.WRITE_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionwrite_imagevideo)
48
493.允许应用读取用户公共目录的图片或视频文件权限:[ohos.permission.READ_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_imagevideo)
50
514.允许应用使用麦克风权限:[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmicrophone)
52
535.允许应用使用悬浮窗的能力权限,需要配置为system_basic类型系统应用:[ohos.permission.SYSTEM_FLOAT_WINDOW](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionsystem_float_window)
54
556.允许应用截取屏幕图像权限,需要配置为system_core类型系统应用:[ohos.permission.CAPTURE_SCREEN](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissioncapture_screen)
56
57### 依赖
58
59不涉及。
60
61### 约束与限制
62
631.本示例仅支持标准系统上安装运行。
64
652.本示例已适配API version 10版本SDK,版本号:4.0.10.15。
66
673.本示例需要使用DevEco Studio 4.0 Release (Build Version: 4.0.0.600)及以上版本才可编译运行。
68
694.本示例需要使用@ohos.screen系统权限的系统接口,使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/faqs/full-sdk-switch-guide.md)70
715.系统权限的自动化签名指南,可通过打开DevEco Studio中菜单,File -> Project Structure -> Project -> Signing Configs(TAB页最下方蓝色字体) -> “**View the operation guide**” 跳转链接,可支持系统权限的自动签名生成。
72
736.rk设备由于芯片限制,应用中videoFrameWidth,videoFrameHeight,videoFrameRate需同比缩小3/5, 才能实现rk上的播放效果。
74
757.库上代码为rk设备所适用代码,其他设备需要修改完应用代码后(应用代码中缩小3/5的地方,在其他设备不需要缩小),单独打包。
76
77### 下载
78
79如需单独下载本工程,执行如下命令:
80```
81git init
82git config core.sparsecheckout true
83echo code/SystemFeature/Media/ScreenRecorder/ > .git/info/sparse-checkout
84git remote add origin https://gitee.com/openharmony/applications_app_samples.git
85git pull origin master
86
87```