diff --git a/en/application-dev/reference/apis/js-apis-medialibrary.md b/en/application-dev/reference/apis/js-apis-medialibrary.md index 6b1b11f9e17627eea877edf5b34b25551f25ce24..46ad60a5fe4baee84f673dee354d688e1be4b2a2 100644 --- a/en/application-dev/reference/apis/js-apis-medialibrary.md +++ b/en/application-dev/reference/apis/js-apis-medialibrary.md @@ -28,7 +28,13 @@ Obtains a **MediaLibrary** instance, which is used to access and modify personal | ----------------------------- | :---- | | [MediaLibrary](#medialibrary) | **MediaLibrary** instance.| -**Example** +**Example (from API version 9)** + +``` +var media = mediaLibrary.getMediaLibrary(this.context); +``` + +**Example (API version 8)** ``` import featureAbility from '@ohos.ability.featureAbility'; @@ -246,7 +252,7 @@ Creates a media asset. This API uses a promise to return the result. ``` async function example() { - // Create an image file in promise mode + // Create an image file in promise mode. let mediaType = mediaLibrary.MediaType.IMAGE; let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE; const path = await media.getPublicDirectory(DIR_IMAGE); @@ -437,13 +443,13 @@ var media = mediaLibrary.getMediaLibrary(context); media.release() ``` -### storeMediaAsset +### storeMediaAsset(deprecated) storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>): void Stores a media asset. This API uses an asynchronous callback to return the URI that stores the media asset. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -467,19 +473,19 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => { console.log("An error occurred when storing the media asset."); return; } - console.log("Media asset stored. "); + console.log("Media asset stored."); // Obtain the URI that stores the media asset. }); ``` -### storeMediaAsset +### storeMediaAsset(deprecated) storeMediaAsset(option: MediaAssetOption): Promise<string> Stores a media asset. This API uses a promise to return the URI that stores the media asset. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -512,13 +518,13 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => { ``` -### startImagePreview +### startImagePreview(deprecated) startImagePreview(images: Array<string>, index: number, callback: AsyncCallback<void>): void Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -526,7 +532,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a | Name | Type | Mandatory | Description | | -------- | ------------------------- | ---- | ---------------------------------------- | -| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **https://** or **dataability://**.| +| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **dataability://** or **https://**.| | index | number | Yes | Index of the first image to preview. | | callback | AsyncCallback<void> | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. | @@ -537,7 +543,7 @@ let images = [ "dataability:///media/xxxx/2", "dataability:///media/xxxx/3" ]; -/* Online image usage mode +/* Preview online images. let images = [ "https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image2.jpg" @@ -554,13 +560,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => { ``` -### startImagePreview +### startImagePreview(deprecated) startImagePreview(images: Array<string>, callback: AsyncCallback<void>): void Starts image preview. This API can be used to preview local images whose URIs start with **dataability://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -578,7 +584,7 @@ let images = [ "dataability:///media/xxxx/2", "dataability:///media/xxxx/3" ]; -/* Online image usage mode +/* Preview online images. let images = [ "https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image2.jpg" @@ -594,13 +600,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => { ``` -### startImagePreview +### startImagePreview(deprecated) startImagePreview(images: Array<string>, index?: number): Promise<void> Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with dataability:// or online images whose URIs start with https://. It uses a promise to return the execution result. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -608,7 +614,7 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a | Name | Type | Mandatory | Description | | ------ | ------------------- | ---- | ---------------------------------------- | -| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **https://** or **dataability://**.| +| images | Array<string> | Yes | URIs of the images to preview. The value can start with either **dataability://** or **https://**.| | index | number | No | Index of the first image to preview. If this parameter is not specified, the default value **0** is used. | **Return value** @@ -624,7 +630,7 @@ let images = [ "dataability:///media/xxxx/2", "dataability:///media/xxxx/3" ]; -/* Online image usage mode +/* Preview online images. let images = [ "https://media.xxxx.com/image1.jpg", "https://media.xxxx.com/image2.jpg" @@ -639,13 +645,13 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => { ``` -### startMediaSelect +### startMediaSelect(deprecated) startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<string>>): void Starts media selection. This API uses an asynchronous callback to return the list of URIs that store the selected media assets. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -674,13 +680,13 @@ mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => { ``` -### startMediaSelect +### startMediaSelect(deprecated) startMediaSelect(option: MediaSelectOption): Promise<Array<string>> Starts media selection. This API uses a promise to return the list of URIs that store the selected media assets. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -723,7 +729,7 @@ Provides APIs for encapsulating file asset attributes. | Name | Type | Readable| Writable| Description | | ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | | id | number | Yes | No | File asset ID. | -| uri | string | Yes | No | File asset URI, for example, dataability:///media/image/2. | +| uri | string | Yes | No | File asset URI, for example, **dataability:///media/image/2**. | | mimeType | string | Yes | No | Extended file attributes. | | mediaType8+ | [MediaType](#mediatype8) | Yes | No | Media type. | | displayName | string | Yes | Yes | Display file name, including the file name extension. | @@ -821,7 +827,7 @@ async function example() { commitModify(callback: AsyncCallback<void>): void -Commits the modification of this file asset to the database. This API uses an asynchronous callback to return the result. +Commits the modification in this file asset to the database. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA @@ -857,7 +863,7 @@ async function example() { commitModify(): Promise<void> -Commits the modification of this file asset to the database. This API uses a promise to return the result. +Commits the modification in this file asset to the database. This API uses a promise to return the result. **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA @@ -893,6 +899,8 @@ open(mode: string, callback: AsyncCallback<number>): void Opens this file asset. This API uses an asynchronous callback to return the result. +Note: Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource. + **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -901,7 +909,7 @@ Opens this file asset. This API uses an asynchronous callback to return the resu | Name | Type | Mandatory | Description | | -------- | --------------------------- | ---- | ----------------------------------- | -| mode | string | Yes | Mode of opening the file, for example, **r** (read-only), **w** (write-only), and **rw** (read-write).| +| mode | string | Yes | Mode of opening the file, for example, **'r'** (read-only), **'w'** (write-only), and **'rw'** (read-write).| | callback | AsyncCallback<number> | Yes | Callback used to return the file handle. | **Example** @@ -928,6 +936,8 @@ open(mode: string): Promise<number> Opens this file asset. This API uses a promise to return the result. +Note: Currently, the write operations are mutually exclusive. After the write operation is complete, you must call **close** to release the resource. + **Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -1009,7 +1019,7 @@ close(fd: number): Promise<void> Closes this file asset. This API uses a promise to return the result. -**Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **r**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **w**) +**Required permissions**: ohos.permission.READ_MEDIA (when **mode** is set to **'r'**) and ohos.permission.WRITE_MEDIA (when **mode** is set to **'w'**) **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -1531,7 +1541,7 @@ Checks whether the cursor is in the last row of the result set. | Type | Description | | ------- | ---------------------------------- | -| boolean | Returns **true** if the cursor is in the last row of the result set; returns *false** otherwise.| +| boolean | Returns **true** if the cursor is in the last row of the result set; returns *false* otherwise.| **Example** @@ -1566,7 +1576,7 @@ async function example() { close(): void -Releases and invalidates this **FetchFileResult** instance. Other APIs cannot be invoked after the instance is released. +Releases and invalidates this **FetchFileResult** instance. Other APIs in this instance cannot be invoked after it is released. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core @@ -1965,7 +1975,7 @@ Provides APIs to implement a physical album. commitModify(callback: AsyncCallback<void>): void -Commits the modification of the album attributes to the database. This API uses an asynchronous callback to return the result. +Commits the modification in the album attributes to the database. This API uses an asynchronous callback to return the result. **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA @@ -2002,7 +2012,7 @@ async function example() { commitModify(): Promise<void> -Commits the modification of the album attributes to the database. This API uses a promise to return the result. +Commits the modification in the album attributes to the database. This API uses a promise to return the result. **Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA @@ -2204,7 +2214,7 @@ Describes options for fetching media files. | ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ | | selections | string | Yes | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?',| | selectionArgs | Array<string> | Yes | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.
Example:
selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], | -| order8+ | string | Yes | Yes | No | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:
Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " AESC"
Descending: order: mediaLibrary.FileKey.DATE_ADDED + " DESC"| +| order | string | Yes | Yes | No | Sorting mode of the search results, which can be ascending or descending. The enumerated values in [FileKey](#filekey8) are used as the columns for sorting the search results. Example:
Ascending: order: mediaLibrary.FileKey.DATE_ADDED + " AESC"
Descending: order: mediaLibrary.FileKey.DATE_ADDED + " DESC"| | uri8+ | string | Yes | Yes | No | File URI. | | networkId8+ | string | Yes | Yes | No | Network ID of the registered device. | | extendArgs8+ | string | Yes | Yes | No | Extended parameters for fetching the files. Currently, no extended parameters are available. | @@ -2218,30 +2228,30 @@ Describes the image size. | width | number | Yes | Yes | Image width, in pixels.| | height | number | Yes | Yes | Image height, in pixels.| -## MediaAssetOption +## MediaAssetOption(deprecated) Implements the media asset option. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core -| Name | Type | Mandatory | Description | -| ------------ | ------ | ---- | ---------------------------------------- | -| src | string | Yes | Absolute path of the local file of the application. | -| mimeType | string | Yes | Multipurpose Internet Mail Extensions (MIME) type of the media.
The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.| -| relativePath | string | No | Custom path for storing media assets, for example, 'Pictures/'. If this parameter is unspecified, media assets are stored in the default path.
Default path of images: 'Pictures/'
Default path of videos: 'Videos/'
Default path of audios: 'Audios/'
Default path of files: 'Documents/'| +| Name | Type | Mandatory| Description | +| ------------ | ------ | ---- | ------------------------------------------------------------ | +| src | string | Yes | Application sandbox oath of the local file. | +| mimeType | string | Yes | Multipurpose Internet Mail Extensions (MIME) type of the media.
The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.| +| relativePath | string | No | Custom path for storing media assets, for example, 'Pictures/'. If this parameter is unspecified, media assets are stored in the default path.
Default path of images: 'Pictures/'
Default path of videos: 'Videos/'
Default path of audios: 'Audios/'
Default path of files: 'Documents/'| -## MediaSelectOption +## MediaSelectOption(deprecated) Describes media selection option. -This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR. +> **NOTE**
This API is deprecated since API version 9. **System capability**: SystemCapability.Multimedia.MediaLibrary.Core | Name | Type | Mandatory | Description | | ----- | ------ | ---- | -------------------- | | type | string | Yes | Media type, which can be **image**, **media**, or **video**. Currently, only **media** is supported.| -| count | number | Yes | Number of media assets selected. If **count** is set to **1**, one media asset can be selected. If **count** is greater than **1**, multiple media assets can be selected. | +| count | number | Yes | Number of media assets selected. The value starts from 1, which indicates that one media asset can be selected. |