livephoto2-bugfix1
Created-by: zhixiang_song
Commit-by: zhixiang_song
Merged-by: openharmony_ci
Description: ### 一、内容说明(相关的Issue)
livephoto2-bugfix1
### 二、建议测试周期和提测地址
建议测试完成时间:xxxx.xx.xx
投产上线时间:xxxx.xx.xx
提测地址:CI环境/压测环境
测试账号:
### 三、变更内容
* 3.1 关联PR列表
* 3.2 数据库和部署说明
1. 常规更新
2. 重启unicorn
3. 重启sidekiq
4. 迁移任务:是否有迁移任务,没有写 "无"
5. rake脚本:`bundle exec xxx RAILS_ENV = production`;没有写 "无"
* 3.4 其他技术优化内容(做了什么,变更了什么)
- 重构了 xxxx 代码
- xxxx 算法优化
* 3.5 废弃通知(什么字段、方法弃用?)
* 3.6 后向不兼容变更(是否有无法向后兼容的变更?)
### 四、研发自测点(自测哪些?冒烟用例全部自测?)
自测测试结论:
### 五、测试关注点(需要提醒QA重点关注的、可能会忽略的地方)
检查点:
| 需求名称 | 是否影响xx公共模块 | 是否需要xx功能 | 需求升级是否依赖其他子产品 |
|------|------------|----------|---------------|
| xxx | 否 | 需要 | 不需要 |
| | | | |
接口测试:
性能测试:
并发测试:
其他:
See merge request: openharmony/multimedia_media_library!12759
MediaLibrary
Introduction
Figure 1 medialibrary architecture

The medialibrary_standard repository provides a set of easy-to-use APIs for getting media file metadata information. MediaLibrary APIs can only be used internally, not exposed to public application currently.
The various capabilities can be categorized as below:
- Query for audio, video and image files metadata information
- Query for image and video albums
- File operations like create, rename, copy and delete media file
- Album operations like create, rename and delete album
Directory Structure
The structure of the repository directory is as follows:
/foundation/multimedia/medialibrary_standard # Medialibrary code
├── frameworks # Framework code
│ ├── innerkitsimpl # Internal Native API implementation
│ │ └── media_library # Native MediaLibrary implementation
│ └── kitsimpl # External JS API implementation
│ └── medialibrary # External MediaLibrary NAPI implementation
├── interfaces # Interfaces
│ ├── innerkits # Internal Native APIs
│ └── kits # External JS APIs
├── LICENSE # License file
├── ohos.build # Build file
├── sa_profile # Service configuration profile
└── services # Service implementation
Usage Guidelines
Query AudioAsset
We can use APIs like GetMediaAssets, GetAudioAssets, GetVideoAssets and GetImageAssets to query for different file metadata information. The following steps describe how to use the GetAudioAssets API to obtain audio related metadata.
- Use GetMediaLibraryClientInstance API to obtain the Medialibrary instance
IMediaLibraryClient* mediaLibClientInstance = IMediaLibraryClient::GetMediaLibraryClientInstance(); - Set the scanning directory for audio files in selection string. The selection value will be a relative path to a media root directory i.e. "/storage/media/local/files". It will check for audio files recursively in the given directory.
string selection = "audios/audio1"; - Use the GetAudioAssets API to query for audio files. The input argument selectionArgs does not have any use case currently. The API returns a list of AudioAsset.
vector<string> selectionArgs; vector<unique_ptr<AudioAsset>> audioAssets = mediaLibClientInstance->GetAudioAssets(selection, selectionArgs); - We can obtain audio metadata for each file from the list.
for (size_t i = 0; i < audioAssets.size(); i++) { cout << audioAssets[i]->uri_ << endl; cout << audioAssets[i]->size_ << endl; cout << audioAssets[i]->dateAdded_ << endl; cout << audioAssets[i]->dateModified_ << endl; cout << audioAssets[i]->albumName_ << endl; cout << audioAssets[i]->duration_ << endl; cout << audioAssets[i]->artist_ << endl; }
Create Album
MediaLibrary offers APIs for application to perform album operations like create, modify and delete. Below are the steps on how to create a new album.
- Use GetMediaLibraryInstance API to obtain the Medialibrary instance
IMediaLibraryClient* mediaLibClientInstance = IMediaLibraryClient::GetMediaLibraryClientInstance(); - Specify the album type. It can be either ASSET_GENERIC_ALBUM, ASSET_IMAGEALBUM or ASSET_VIDEOALBUM.
AssetType assetType = ASSET_VIDEOALBUM; - Create a new AlbumAsset object and provide a new album name. Below album "new_video" will get created in the path "/storage/media/local/files/videos".
AlbumAsset albumAsset; albumAsset.albumName_ = "videos/new_video"; - Use CreateMediaAlbumAsset API to create the new album in the device. The return value will be boolean, which states whether the album creation succeeded or failed.
bool errCode = mediaLibClientInstance->CreateMediaAlbumAsset(assetType, albumAsset);
Copy ImageAsset
File operations are supported via APIs like CreateMediaAsset, ModifyMediaAsset, CopyMediaAsset, DeleteMediaAsset. The example below explains the usage of CopyMediaAsset API.
- Use GetMediaLibraryInstance API to obtain the Medialibrary instance
IMediaLibraryClient* mediaLibClientInstance = IMediaLibraryClient::GetMediaLibraryClientInstance(); - Specify the asset type. It can be either ASSET_MEDIA, ASSET_IMAGE, ASSET_AUDIO or ASSET_VIDEO.
AssetType assetType = ASSET_IMAGE; - Define the source and target ImageAsset. The target asset must specify the new album name where the source asset will be copied.
MediaAsset srcMediaAsset; MediaAsset dstMediaAsset; srcMediaAsset.name_ = "image1.jpg"; srcMediaAsset.uri_ = "/storage/media/local/files/images/001/image1.jpg"; dstMediaAsset.albumName_ = "images/new_image"; - Use CopyMediaAsset API to copy the source asset to target asset's album name location. The boolean return value denotes the status of the file operation. The source file "image1.jpg" will get copied to "/storage/media/local/files/images/new_image".
bool errCode = mediaLibClientInstance->CopyMediaAsset(assetType, srcMediaAsset, dstMediaAsset);