| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 36 | 33 | ||
| entry/ | 06-May-2025 | - | 3,303 | 2,902 | ||
| hvigor/ | 06-May-2025 | - | 21 | 21 | ||
| lib/ | 06-May-2025 | - | ||||
| screenshots/devices/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 79 | 6 | 6 | |
| README.md | D | 06-May-2025 | 1.8 KiB | 24 | 12 | |
| README_zh.md | D | 06-May-2025 | 7.6 KiB | 116 | 76 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 43 | 41 | |
| hvigorfile.js | D | 06-May-2025 | 168 | 2 | 1 | |
| hvigorw | D | 06-May-2025 | 2 KiB | 62 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 820 | 26 | 25 | |
| ohosTest.md | D | 06-May-2025 | 2.4 KiB | 27 | 24 |
README.md
1# Multimedia - Camera and Media Library 2 3### Introduction 4 5 This demo shows how to invoke the camera to take photos and record videos in eTS and how to use the **MediaLibrary** APIs to add, delete, modify, and query media files. 6 7### Usage 8 91. Start the demo app. After the user grants the permission, the home screen of the app displays the album information of the current device. It also listens for the album changes and updates the album information. 10 112. Touch **+** to display the camera, record, and text icons. 12 133. Touch the camera icon to enter the camera screen. By default, the camera mode is used. Touch the capture button at the bottom to take a photo. After the photo is taken, the preview image is displayed on the left at the bottom. Touch the video icon to switch to the video recording mode. Touch the button at the bottom to start video recording and touch the end button to stop recording. After the recording is complete, the video icon is displayed on the left at the bottom. Touch the system **Back** button or **Back** on the top of the page to return to the home screen. 14 15 164. Touch the record icon to enter the recording screen. Touch the **Start** button on the right to start recording. The button changes to the **Pause** button. Touch the button to pause or resume recording. Touch the **End** button on the left to stop recording and return to the home screen. 17 185. Touch the text icon to enter the text editing page. Enter the text content and touch **Save**. A text file is created, and then the home screen is displayed. 19 206. Touch the album to access the file list screen. The files in the album are displayed. The list contains the **Delete** and **Rename** buttons. You can touch a file to delete or rename it. 21### Constraints 22 23This sample can only be run on standard-system devices. 24
README_zh.md
1# 相机和媒体库 2 3### 介绍 4 5此Demo展示如何在ArkTS中调用相机拍照和录像,以及如何使用媒体库接口进行媒体文件的增、删、改、查操作。 6 7本示例用到了权限管理能力[@ohos.abilityAccessCtrl](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-ability-kit/js-apis-abilityAccessCtrl.md ) 8 9相机模块能力接口[@ohos.multimedia.camera](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-camera-kit/js-apis-camera.md ) 10 11图片处理接口[@ohos.multimedia.image](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-image-kit/js-apis-image.md ) 12 13音视频相关媒体业务能力接口[@ohos.multimedia.media](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-media-kit/js-apis-media.md ) 14 15用户数据管理接口[@ohos.filemanagement.userFileManager](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-userFileManager-sys.md ) 16 17公共文件访问与管理[@ohos.file.fileAccess](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-fileAccess-sys.md ) 18 19设备信息能力接口[@ohos.deviceInfo](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-basic-services-kit/js-apis-device-info.md ) 20 21弹窗能力接口[@ohos.promptAction](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-promptAction.md) 22 23### 效果预览 24|首页| 25|-------| 26|| 27 28使用说明 29 301.启动应用,在权限弹窗中授权后返回应用,首页显示当前设备的相册信息,首页监听相册变化会刷新相册列表。 31 322.点击 **+** 按钮,弹出相机、录音、文本文件三个图标。 33 343.安装相机应用[Camera](lib/CameraPage-1.0.0.hap)应用后,点击**相机**图标,进入相机界面,默认是拍照模式,点击底部拍照按钮可以拍照,拍照完成会在底部左侧显示照片预览图。点击**录像**切换到录像模式,点击底部按钮开始录像,点击结束按钮结束录像,结束录像后底部左侧显示视频图标。点击系统**Back**键或界面顶部**返回**按钮返回首页。 35 364.点击**录音**图标进入录音界面,点击右侧**开始**按钮开始录音,按钮变为暂停按钮,点击可以暂停和继续录音,点击左侧**结束**按钮结束录音返回首页。 37 385.点击**文本**图标进入文本编辑界面,输入文本内容后点击**Save**按钮,会创建并写入文本文件,完成后返回首页。 39 406.点击相册进入文件列表界面,展示相册内的文件,列表中有**删除**和**重命名**按钮,点击可以删除文件和重命名文件。 41 427.安装视频播放[VideoPlayer](lib/VideoPlayer.hap)应用后,点击视频文件可以调起视频播放界面播放该视频。 43 44### 工程目录 45``` 46entry/src/main/ets/ 47|---MainAbility 48| |---MainAbility.ts // 主程序入口,应用启动时获取相应权限 49|---pages 50| |---index.ets // 首页 51| |---AlbumPage.ets // 相册页面 52| |---CameraPage.ets // 相机页面 53| |---RecordPage.ets // 录音页面 54| |---DocumentPage.ets // 存储文件页面 55|---model 56| |---CameraService.ts // 相机模块(拍照录像模式) 57| |---DateTimeUtil.ts // 日期工具包 58| |---MediaUtils.ts // 媒体工具模块 59| |---RecordModel.ts // 录音模块(底层能力实现) 60| |---TimeUtils.ts // 时间工具包 61|---view 62| |---BasicDataSource.ets // 初始化媒体服务数组 63| |---MediaItem.ets // 定义具体的某一媒体模块页面 64| |---MediaView.ets // 媒体模块的前置模块(判断是否有展示的媒体内容) 65| |---RenameDialog.ets // 重命名文件模块 66| |---TitleBar.ets // 标题栏 67``` 68 69### 具体实现 70 71* 布局原理:定义@ObjectLink 装饰的数组变量album存放资源文件,使用list()组件中ListItem()循环数组展示,加号Button(),点击后触发 animateTo({ duration: 500, curve: Curve.Ease })控制动画展示,[源码参考](entry/src/main/ets/pages/Index.ets )。 72* 获取资源文件:通过引入用户数据管理接口@ohos.filemanagement.userFileManager,获取图片与视频音频类型的文件资源,并通过albums.push()添加至album数组中。 73* 展示系统资源文件:当album内的值被修改时,只会让用 @ObjectLink 装饰的变量album所在的组件被刷新,当前组件不会刷新。 74* 录音功能:通过引入音视频接口@ohos.multimedia.media,例如通过media.createAudioRecorder()创建音频录制的实例来控制音频的录制,通过this.audioRecorder.on('prepare', () => {this.audioRecorder.start()})异步方式开始音频录制,[源码参考](entry/src/main/ets/model/RecordModel.ts )。 75* 拍照录像功能:通过引入相机模块接口@ohos.multimedia.camera,例如通过this.cameraManager.createCaptureSession()创建相机入口的实例来控制拍照和录像,通过this.captureSession.start()开始会话工作,[源码参考](entry/src/main/ets/model/CameraService.ts )。 76 77 78### 相关权限 79相机权限:[ohos.permission.CAMERA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissioncamera ) 80 81麦克风权限:[ohos.permission.MICROPHONE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmicrophone ) 82 83访问媒体文件地理位置信息权限:[ohos.permission.MEDIA_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionmedia_location ) 84 85访问公共目录的图片或视频权限:[ohos.permission.READ_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_imagevideo ) 86 87修改公共目录的图片或视频权限:[ohos.permission.WRITE_IMAGEVIDEO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionwrite_imagevideo ) 88 89访问公共目录的音频权限:[ohos.permission.READ_AUDIO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionread_audio ) 90 91修改公共目录的音频权限:[ohos.permission.WRITE_AUDIO](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-system-apps.md#ohospermissionwrite_audio ) 92 93 94### 依赖 95 96不涉及 97 98### 约束与限制 99 1001.本示例仅支持标准系统上运行。 101 1022.本示例为Stage模型,已适配API version 10版本SDK,版本号:4.0.10.15。 103 1043.本示例需要使用DevEco Studio NEXT Developer Preview1 (Build Version: 4.1.3.500, built on January 20, 2024)及以上版本才可编译运行。 105 106### 下载 107 108如需单独下载本工程,执行如下命令: 109 110```` 111git init 112git config core.sparsecheckout true 113echo code/Solutions/Media/MultiMedia/ > .git/info/sparse-checkout 114git remote add origin https://gitee.com/openharmony/applications_app_samples.git 115git pull origin master 116````