1.Introduction to MediaLibrary
OpenAtom OpenHarmony (hereinafter referred to as "OpenHarmony") MediaLibrary provides a series of easy-to-use interfaces for obtaining metadata information of media files. The MediaLibrary interface is an interface used internally by the OpenHarmony system, not an interface used by external third-party applications.
The function of MediaLibrary supports the ability to scan all media files in the device, and provides a unified media metadata information operation interface for applications such as photo albums, audio and video players, and file managers. The specific capabilities that can be implemented are as follows:
● Query audio, video and picture file metadata information ● Query picture and video albums ● Media file operations such as create, rename, copy and delete ● Album operations such as create, rename and delete
The location of the MediaLibrary code warehouse: foundation/multimedia/media_library

2. Code structure

图片
The framework of the code is mainly divided into two parts: Napi and Native.
The NAPI part implements the query of media resources, the realization of the addition, deletion and modification of albums and the JS interface.
Native part:
(1) media_library_helper:
It mainly provides resource setting and creation functions, such as album operation, thumbnail operation, etc., mainly involving the creation of resource files or folders.
(2) media_library_manager:
Mainly operate on the relevant database of the media library.
(3) media_scanner:
The code in media_library/frameworks/innerkitsimpl/media_scanner is not added to the build system, the scan code of OpenHarmony 3.2 Beta version is mainly placed in the media_library/frameworks/services/media_scanner directory.
(4) medialibrary_data_extension:
This directory involves some C++ source code and application code of the Hap package. The current scanning, screenshot and other processes do not involve the content of this directory.

3. External interface

getPublicDirectory View the public directory <br>Returns the relative directory of different types of media libraries according to the directory type passed by the parameter. For example: "Cameras/", "Videos/", "Pictures/", "Audios/", "Documents/" and "Downloads/".
getFileAssets Get file resources <br>Call the Query interface of DataShareHelper to get file resources, and finally call back the implementation of the Query interface of JsDataShareExtAbility.
getAlbums Get albums <br>Query the album directory information in the media.
createAsset creates a resource <br>Call the Insert() interface provided by DataShareHelper to insert into the database, and the incoming uri indicates the creation of a data resource through the "create_asset" character.
deleteAsset deletes resources <br>Call the Insert() interface provided by DataShareHelper to insert into the database, and the incoming uri indicates the deletion of data resources through the "delete_asset" character.

4. Media library related services

The directory structure of the OpenHarmony 3.2 Beta version has been greatly adjusted, the Services directory is placed under the frameworks path, and the IPC calling mechanism is removed compared to the 3.1 Release version. At present, the contents of the files in media_library_data_share and media_thumbnail in the Services directory are empty, which will be improved in the future.
图片

5. Media library related database

The data for media library operations is in the /data/app/el2/100/database/com.ohos.medialibrary.medialibrarydata/media_library.db directory. This is the file of the SQLite3 database, which can be opened with the SqliteManager software. It mainly looks at two parts of the database: the first part, the Files table data
图片
Files table fields:
图片
The second part is several tables in VIEWS, such as album query, picture query, video query.
图片

6. Code process screenshot process

图片
The screenshot app saves the screenshot by calling the saveImage method. This method obtains the MediaLibrary through the getMediaLibrary interface of @ohos.multimedia.mediaLibrary. The interface that calls it will call the interface provided by MediaLibraryNapi. This object is the bridge connecting JS and Native. . First, get the relative path through getPublicDirectory, then create a resource through createAsset and return to fileAsset, then operate the file through fileAsset (write jpegData data to the file), and finally close the file to save the screenshot.
Start the gallery process
图片
The library obtains file resources through the getFileAssets interface of MediaLibraryNapi, and finally returns pixelMap for the application to use.
Media file scanning process
图片
The InitMediaLibraryMgr interface of MediaLibraryDataManager will eventually call ScanDir to scan media files. This interface calls the corresponding implementation in the frameworks/services/media_scanner directory.

7. Summary

This paper mainly introduces the media library module of the OpenHarmony 3.2 Beta multimedia subsystem. The interface of this module does not provide external third-party applications for the time being, but only provides the internal use of the OpenHarmony system. Compared with the OpenHarmony 3.1 Release version, the directory structure of the OpenHarmony 3.2 Beta version has been greatly adjusted, and the related functions are expected to be added and improved by developers.
图片


OpenHarmony开发者
160 声望1.1k 粉丝

OpenHarmony是由开放原子开源基金会(OpenAtom Foundation)孵化及运营的开源项目,


引用和评论

0 条评论