提交 dbea77a9 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 f8e684f9
......@@ -3,11 +3,12 @@
> **NOTE**
>
> - The APIs of this module are supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
> - This API is deprecated since API version 9 and will be retained until API version 13.
> - Certain functionalities are changed as system APIs and can be used only by system applications. To use these functionalities, call [@ohos.filemanagement.userFileManager](js-apis-userFileManager.md).
> - The functionalities for selecting and storing media assets are still open to common applications. To use these functionalities, call [@ohos.file.picker](js-apis-file-picker.md).
> - The APIs of this module are deprecated since API version 9 and will be retained until API version 13.
> - Some APIs are changed as system APIs and can be used only by system applications. Use [@ohos.filemanagement.userFileManager](js-apis-userFileManager.md) instead.
> - The APIs for selecting and storing media assets are still open to common applications. Use [@ohos.file.picker](js-apis-file-picker.md) instead.
## Modules to Import
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
```
......@@ -81,6 +82,9 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileRe
Obtains file assets (also called files). This API uses an asynchronous callback to return the result.
> **NOTE**
> From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -90,56 +94,56 @@ Obtains file assets (also called files). This API uses an asynchronous callback
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | --------------------------------- |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes | Options for fetching the files. |
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Asynchronous callback of **FetchFileResult**.|
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback invoked to return the file retrieval result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
// Create options for fetching the files. The options are used to obtain files of the image type.
let imagesFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
// Obtain the files in asynchronous callback mode.
media.getFileAssets(imagesFetchOp, async (error, fetchFileResult) => {
// Check whether the result set of the obtained files is undefined. If yes, the API call fails.
if (fetchFileResult == undefined) {
console.error('get fetchFileResult failed with error: ' + error);
return;
}
// Obtain the total number of files in the result set.
const count = fetchFileResult.getCount();
// Check whether the number is less than 0. If yes, the API call fails.
if (count < 0) {
console.error('get count from fetchFileResult failed, count: ' + count);
return;
}
// Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
if (count == 0) {
console.info('The count of fetchFileResult is zero');
return;
}
console.info('Get fetchFileResult successfully, count: ' + count);
// Obtain the first file in the result set in asynchronous callback mode. If there are a large number of files, use getAllObject instead.
fetchFileResult.getFirstObject(async (error, fileAsset) => {
// Check whether the first file is undefined. If yes, the API call fails.
if (fileAsset == undefined) {
console.error('get first object failed with error: ' + error);
return;
}
console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
// Call getNextObject to obtain the next file until the last one.
for (let i = 1; i < count; i++) {
let fileAsset = await fetchFileResult.getNextObject();
console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
}
// Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
fetchFileResult.close();
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
// Create options for fetching the files of the image type.
let imagesFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
// Obtain the files in asynchronous callback mode.
media.getFileAssets(imagesFetchOp, async (error, fetchFileResult) => {
// Check whether the result set of the obtained files is undefined. If yes, the API call fails.
if (fetchFileResult == undefined) {
console.error('get fetchFileResult failed with error: ' + error);
return;
}
// Obtain the total number of files in the result set.
const count = fetchFileResult.getCount();
// Check whether the number is less than 0. If yes, the API call fails.
if (count < 0) {
console.error('get count from fetchFileResult failed, count: ' + count);
return;
}
// Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
if (count == 0) {
console.info('The count of fetchFileResult is zero');
return;
}
console.info('Get fetchFileResult successfully, count: ' + count);
// Obtain the first file in the result set in asynchronous callback mode. If there are a large number of files, use getAllObject() instead.
fetchFileResult.getFirstObject(async (error, fileAsset) => {
// Check whether the first file is undefined. If yes, the API call fails.
if (fileAsset == undefined) {
console.error('get first object failed with error: ' + error);
return;
}
console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
// Call getNextObject to obtain the next file until the last one.
for (let i = 1; i < count; i++) {
let fileAsset = await fetchFileResult.getNextObject();
console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
}
// Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
fetchFileResult.close();
});
});
}
```
......@@ -149,6 +153,9 @@ getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt;
Obtains file assets. This API uses a promise to return the result.
> **NOTE**
> From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -163,52 +170,52 @@ Obtains file assets. This API uses a promise to return the result.
| Type | Description |
| ------------------------------------ | -------------- |
| [FetchFileResult](#fetchfileresult7) | Result set of the file retrieval operation.|
| Promise&lt;[FetchFileResult](#fetchfileresult7)&gt; | Promise used to return the file retrieval result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
// Create options for fetching the files. The options are used to obtain files of the image type.
let imagesFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
// Obtain the files in promise mode.
media.getFileAssets(imagesFetchOp).then(async (fetchFileResult) => {
// Obtain the total number of files in the result set.
const count = fetchFileResult.getCount();
// Check whether the number is less than 0. If yes, the API call fails.
if (count < 0) {
console.error('get count from fetchFileResult failed, count: ' + count);
return;
}
// Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
if (count == 0) {
console.info('The count of fetchFileResult is zero');
return;
}
console.info('Get fetchFileResult successfully, count: ' + count);
// Obtain the first file in the result set in promise mode. If there are a large number of files, use getAllObject instead.
fetchFileResult.getFirstObject().then(async (fileAsset) => {
console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
// Call getNextObject to obtain the next file until the last one.
for (let i = 1; i < count; i++) {
let fileAsset = await fetchFileResult.getNextObject();
console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
}
// Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
fetchFileResult.close();
}).catch((error) => {
// Calling getFirstObject fails.
console.error('get first object failed with error: ' + error);
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
// Create options for fetching the files of the image type.
let imagesFetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
// Obtain the files in promise mode.
media.getFileAssets(imagesFetchOp).then(async (fetchFileResult) => {
// Obtain the total number of files in the result set.
const count = fetchFileResult.getCount();
// Check whether the number is less than 0. If yes, the API call fails.
if (count < 0) {
console.error('get count from fetchFileResult failed, count: ' + count);
return;
}
// Check whether the number is 0. If yes, the API call is successful, but the result set is empty. Check whether the options for fetching the files are correctly set and whether the corresponding files exist on the device.
if (count == 0) {
console.info('The count of fetchFileResult is zero');
return;
}
console.info('Get fetchFileResult successfully, count: ' + count);
// Obtain the first file in the result set in promise mode. If there are a large number of files, use getAllObject instead.
fetchFileResult.getFirstObject().then(async (fileAsset) => {
console.info('fileAsset.displayName ' + '0 : ' + fileAsset.displayName);
// Call getNextObject to obtain the next file until the last one.
for (let i = 1; i < count; i++) {
let fileAsset = await fetchFileResult.getNextObject();
console.info('fileAsset.displayName ' + i + ': ' + fileAsset.displayName);
}
// Release the FetchFileResult instance and invalidate it. Other APIs can no longer be called.
fetchFileResult.close();
}).catch((error) => {
// Calling getFileAssets fails.
console.error('get file assets failed with error: ' + error);
// Calling getFirstObject fails.
console.error('get first object failed with error: ' + error);
});
}).catch((error) => {
// Calling getFileAssets fails.
console.error('get file assets failed with error: ' + error);
});
}
```
......@@ -216,7 +223,7 @@ async function example() {
on(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback: Callback&lt;void&gt;): void
Subscribes to the media library changes. This API uses an asynchronous callback to return the result.
Subscribes to the media library changes. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -224,21 +231,22 @@ Subscribes to the media library changes. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------------------------------- |
| type | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange' | Yes | Media type.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | Yes | Void callback. |
| type | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange' | Yes | Type of the event to subscribe to.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```js
media.on('imageChange', () => {
// image file had changed, do something
})
// image file had changed, do something.
});
```
### off<sup>8+</sup>
off(type: 'deviceChange'&#124;'albumChange'&#124;'imageChange'&#124;'audioChange'&#124;'videoChange'&#124;'fileChange'&#124;'remoteFileChange', callback?: Callback&lt;void&gt;): void
Unsubscribes from the media library changes. This API uses an asynchronous callback to return the result.
Unsubscribes from the media library changes. This API uses a callback to return the result.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -246,15 +254,15 @@ Unsubscribes from the media library changes. This API uses an asynchronous callb
| Name | Type | Mandatory | Description |
| -------- | -------------------- | ---- | ---------------------------------------- |
| type | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange' | Yes | Media type.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | No | Void callback. |
| type | 'deviceChange'&#124;<br>'albumChange'&#124;<br>'imageChange'&#124;<br>'audioChange'&#124;<br>'videoChange'&#124;<br>'fileChange'&#124;<br>'remoteFileChange' | Yes | Type of the event to unsubscribe from.<br>'deviceChange': registered device change<br>'albumChange': album change<br>'imageChange': image file change<br>'audioChange': audio file change<br>'videoChange': video file change<br>'fileChange': file change<br>'remoteFileChange': file change on the registered device|
| callback | Callback&lt;void&gt; | No | Callback that returns no value. |
**Example**
```js
media.off('imageChange', () => {
// Stop listening successfully.
})
// stop listening successfully.
});
```
### createAsset<sup>8+</sup>
......@@ -263,6 +271,9 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
Creates a media asset. This API uses an asynchronous callback to return the result.
> **NOTE**
> From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -272,25 +283,25 @@ Creates a media asset. This API uses an asynchronous callback to return the resu
| Name | Type | Mandatory| Description |
| ------------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
| mediaType | [MediaType](#mediatype8) | Yes | Media type. |
| displayName | string | Yes | Display file name. |
| relativePath | string | Yes | Path for storing the file. You can use [getPublicDirectory](#getpublicdirectory8) to obtain the paths for storing different types of files.|
| callback | AsyncCallback<[FileAsset](#fileasset7)> | Yes | Asynchronous callback for **FileAsset**. |
| displayName | string | Yes | File name to display. |
| relativePath | string | Yes | Path of the file, which can be obtained by using [getPublicDirectory](#getpublicdirectory8).|
| callback | AsyncCallback<[FileAsset](#fileasset7)> | Yes | Callback invoked to return the **FileAsset** instance created. |
**Example**
```js
async function example() {
// Create an image file in callback mode.
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (error, fileAsset) => {
if (fileAsset != undefined) {
console.info('createAsset successfully, message');
} else {
console.error('createAsset failed with error: ' + error);
}
});
// Create an image file in callback mode.
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (error, fileAsset) => {
if (fileAsset != undefined) {
console.info('createAsset successfully, message');
} else {
console.error('createAsset failed with error: ' + error);
}
});
}
```
......@@ -300,6 +311,9 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
Creates a media asset. This API uses a promise to return the result.
> **NOTE**
> From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -309,28 +323,28 @@ Creates a media asset. This API uses a promise to return the result.
| Name | Type | Mandatory| Description |
| ------------ | ------------------------ | ---- | ------------------------------------------------------------ |
| mediaType | [MediaType](#mediatype8) | Yes | Media type. |
| displayName | string | Yes | Display file name. |
| relativePath | string | Yes | Relative path. You can use [getPublicDirectory](#getpublicdirectory8) to obtain the relative path of the level-1 directory of different types of media files.|
| displayName | string | Yes | File name to display. |
| relativePath | string | Yes | Relative path of the file, which can be obtained by [getPublicDirectory](#getpublicdirectory8).|
**Return value**
| Type | Description |
| ------------------------ | ----------------- |
| [FileAsset](#fileasset7) | Media data (FileAsset).|
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** instance created.|
**Example**
```js
async function example() {
// 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);
media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
}).catch((error) => {
console.error('createAsset failed with error: ' + error);
});
// 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);
media.createAsset(mediaType, 'imagePromise.jpg', path + 'myPicture/').then((fileAsset) => {
console.info('createAsset successfully, message = ' + JSON.stringify(fileAsset));
}).catch((error) => {
console.error('createAsset failed with error: ' + error);
});
}
```
......@@ -353,6 +367,7 @@ Deletes a file asset. This API uses a promise to return the result.
| uri | string | Yes | URI of the file asset to delete.|
**Return value**
| Type | Description |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise used to return the result.|
......@@ -361,28 +376,29 @@ Deletes a file asset. This API uses a promise to return the result.
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let option = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
console.error('asset not exist');
return;
}
media.deleteAsset(asset.uri).then(() => {
console.info('deleteAsset successfully');
}).catch((error) => {
console.error('deleteAsset failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let option = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
console.error('asset not exist');
return;
}
media.deleteAsset(asset.uri).then(() => {
console.info('deleteAsset successfully');
}).catch((error) => {
console.error('deleteAsset failed with error: ' + error);
});
fetchFileResult.close();
}
```
### deleteAsset<sup>8+</sup>
deleteAsset(uri: string, callback: AsyncCallback\<void>): void
Deletes a file asset. This API uses an asynchronous callback to return the result.
......@@ -398,32 +414,32 @@ Deletes a file asset. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | Yes | URI of the file asset to delete.|
|callback |AsyncCallback\<void>| Yes |Callback used to return the result.|
|callback |AsyncCallback\<void>| Yes |Callback that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let option = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
console.error('asset not exist');
return;
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let option = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
};
const fetchFileResult = await media.getFileAssets(option);
let asset = await fetchFileResult.getFirstObject();
if (asset == undefined) {
console.error('asset not exist');
return;
}
media.deleteAsset(asset.uri, (error) => {
if (error != undefined) {
console.error('deleteAsset failed with error: ' + error);
} else {
console.info('deleteAsset successfully');
}
media.deleteAsset(asset.uri, (error) => {
if (error != undefined) {
console.error('deleteAsset failed with error: ' + error);
} else {
console.info('deleteAsset successfully');
}
});
fetchFileResult.close();
});
fetchFileResult.close();
}
```
......@@ -431,7 +447,7 @@ async function example() {
getPublicDirectory(type: DirectoryType, callback: AsyncCallback&lt;string&gt;): void
Obtains a public directory. This API uses an asynchronous callback to return the result.
Obtains a user directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -439,19 +455,19 @@ Obtains a public directory. This API uses an asynchronous callback to return the
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------- |
| type | [DirectoryType](#directorytype8) | Yes | Type of the public directory. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the public directory.|
| type | [DirectoryType](#directorytype8) | Yes | Type of the user directory. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the user directory obtained.|
**Example**
```js
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
if (dicResult == 'Camera/') {
console.info('getPublicDirectory DIR_CAMERA successfully');
} else {
console.error('getPublicDirectory DIR_CAMERA failed with error: ' + error);
}
if (dicResult == 'Camera/') {
console.info('getPublicDirectory DIR_CAMERA successfully');
} else {
console.error('getPublicDirectory DIR_CAMERA failed with error: ' + error);
}
});
```
......@@ -459,7 +475,7 @@ media.getPublicDirectory(DIR_CAMERA, (error, dicResult) => {
getPublicDirectory(type: DirectoryType): Promise&lt;string&gt;
Obtains a public directory. This API uses a promise to return the result.
Obtains a user directory. This API uses a promise to return the result.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -467,28 +483,28 @@ Obtains a public directory. This API uses a promise to return the result.
| Name| Type | Mandatory| Description |
| ------ | -------------------------------- | ---- | ------------ |
| type | [DirectoryType](#directorytype8) | Yes | Type of the public directory.|
| type | [DirectoryType](#directorytype8) | Yes | Type of the user directory.|
**Return value**
| Type | Description |
| ---------------- | ---------------- |
| Promise\<string> | Promise used to return the public directory.|
| Promise\<string> | Promise used to return the user directory obtained.|
**Example**
```js
async function example() {
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
if (dicResult == 'Camera/') {
console.info('getPublicDirectory DIR_CAMERA successfully');
} else {
console.error('getPublicDirectory DIR_CAMERA failed');
}
}).catch((error) => {
console.error('getPublicDirectory failed with error: ' + error);
});
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA).then((dicResult) => {
if (dicResult == 'Camera/') {
console.info('getPublicDirectory DIR_CAMERA successfully');
} else {
console.error('getPublicDirectory DIR_CAMERA failed');
}
}).catch((error) => {
console.error('getPublicDirectory failed with error: ' + error);
});
}
```
......@@ -496,7 +512,10 @@ async function example() {
getAlbums(options: MediaFetchOptions, callback: AsyncCallback&lt;Array&lt;Album&gt;&gt;): void
Obtains the albums. This API uses an asynchronous callback to return the result.
Obtains albums. This API uses an asynchronous callback to return the result.
> **NOTE**
> From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**. Currently, only **Camera** and **ScreenShots** albums are supported. For more details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA
......@@ -506,17 +525,16 @@ Obtains the albums. This API uses an asynchronous callback to return the result.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | --------------------------- |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes | Options for fetching the albums. |
| callback | AsyncCallback&lt;Array<[Album](#album7)>&gt; | Yes | Callback used to return the albums.|
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes | Options for fetching albums. |
| callback | AsyncCallback&lt;Array<[Album](#album7)>&gt; | Yes | Callback invoked to return the albums.|
**Example**
```js
async function example() {
// To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
let AlbumNoArgsfetchOp = {
selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
selectionArgs:['New Album 1'],
selectionArgs: ['Camera'],
};
media.getAlbums(AlbumNoArgsfetchOp, (error, albumList) => {
if (albumList != undefined) {
......@@ -524,7 +542,7 @@ async function example() {
} else {
console.error('getAlbums failed with error: ' + error);
}
})
});
}
```
......@@ -532,7 +550,10 @@ async function example() {
getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt;
Obtains the albums. This API uses a promise to return the result.
Obtains albums. This API uses a promise to return the result.
> **NOTE**
> From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**. Currently, only **Camera** and **ScreenShots** albums are supported. For more details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA
......@@ -554,10 +575,9 @@ Obtains the albums. This API uses a promise to return the result.
```js
async function example() {
// To obtain the file assets in an album, you must preset the album and resources. The sample code below presets 'New Album 1'.
let AlbumNoArgsfetchOp = {
selections: mediaLibrary.FileKey.ALBUM_NAME + '= ?',
selectionArgs:['New Album 1'],
selectionArgs: ['Camera'],
};
media.getAlbums(AlbumNoArgsfetchOp).then((albumList) => {
console.info('getAlbums successfully: ' + JSON.stringify(albumList));
......@@ -586,7 +606,7 @@ Call this API when you no longer need to use the APIs in the **MediaLibrary** in
```js
media.release(() => {
// do something
// do something.
});
```
......@@ -603,23 +623,21 @@ Call this API when you no longer need to use the APIs in the **MediaLibrary** in
| Type | Description |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise used to return the execution result.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
media.release()
media.release();
```
### storeMediaAsset
storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void
Stores a media asset. This API uses an asynchronous callback to return the URI that stores the media asset.
Stores a media asset. This API uses an asynchronous callback to return the URI of the media asset.
> **NOTE**
>
> This API is supported since API version 6 and can be used only by the FA model.
> **NOTE**<br>This API is supported since API version 6 and can be used only in the FA model.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -628,36 +646,33 @@ Stores a media asset. This API uses an asynchronous callback to return the URI t
| Name | Type | Mandatory | Description |
| -------- | ------------------------------------- | ---- | ----------------------- |
| option | [MediaAssetOption](#mediaassetoption) | Yes | Media asset option. |
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the URI that stores the media asset.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked to return the URI of the media resource saved.|
**Example**
```js
let option = {
src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : 'image/*',
relativePath : 'Pictures/'
src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : 'image/*',
relativePath : 'Pictures/'
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option, (error, value) => {
if (error) {
console.error('storeMediaAsset failed with error: ' + error);
return;
}
console.info('Media resources stored. ');
// Obtain the URI that stores the media asset.
if (error) {
console.error('storeMediaAsset failed with error: ' + error);
return;
}
console.info('Media resources stored. ');
// Obtain the URI of the media asset.
});
```
### storeMediaAsset
storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt;
Stores a media asset. This API uses a promise to return the URI that stores the media asset.
Stores a media asset. This API uses a promise to return the URI of the media asset.
> **NOTE**
>
> This API is supported since API version 6 and can be used only by the FA model.
> **NOTE**<br>This API is supported since API version 6 and can be used only in the FA model.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -671,34 +686,33 @@ Stores a media asset. This API uses a promise to return the URI that stores the
| Type | Description |
| --------------------- | ---------------------------- |
| Promise&lt;string&gt; | Promise used to return the URI that stores the media asset.|
| Promise&lt;string&gt; | Promise used to return the URI of the media asset saved.|
**Example**
```js
let option = {
src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : 'image/*',
relativePath : 'Pictures/'
src : '/data/storage/el2/base/haps/entry/image.png',
mimeType : 'image/*',
relativePath : 'Pictures/'
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
console.info('Media resources stored.');
// Obtain the URI that stores the media asset.
console.info('Media resources stored.');
// Obtain the URI of the media asset.
}).catch((error) => {
console.error('storeMediaAsset failed with error: ' + error);
console.error('storeMediaAsset failed with error: ' + error);
});
```
### startImagePreview
startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result.
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the result.
> **NOTE**
> This API is supported since API version 6 and can be used only by the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **\<Image>** component can be used to render and display local and online images.
> This API is supported since API version 6 and can be used only in the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead.<br>The **\<Image>** component can be used to render and display local and online images.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -708,41 +722,40 @@ Starts image preview, with the first image to preview specified. This API can be
| -------- | ------------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| index | number | Yes | Index of the first image to preview. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```js
let images = [
'file://media/xxxx/2',
'file://media/xxxx/3'
'file://media/xxxx/2',
'file://media/xxxx/3'
];
/* Preview online images.
let images = [
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
];
*/
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index, (error) => {
if (error) {
console.error('startImagePreview failed with error: ' + error);
return;
}
console.info('Succeeded in previewing the images.');
if (error) {
console.error('startImagePreview failed with error: ' + error);
return;
}
console.info('Succeeded in previewing the images.');
});
```
### startImagePreview
startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void
Starts image preview. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the execution result.
Starts image preview. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses an asynchronous callback to return the result.
> **NOTE**
> This API is supported since API version 6 and can be used only by the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **\<Image>** component can be used to render and display local and online images.
> This API is supported since API version 6 and can be used only in the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead.<br>The **\<Image>** component can be used to render and display local and online images.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -751,31 +764,30 @@ Starts image preview. This API can be used to preview local images whose URIs st
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | Yes | URIs of the images to preview. The value can start with either **'https://'** or **'datashare://'**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the image preview result. If the preview fails, an error message is returned. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```js
let images = [
'file://media/xxxx/2',
'file://media/xxxx/3'
'file://media/xxxx/2',
'file://media/xxxx/3'
];
/* Preview online images.
let images = [
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
];
*/
mediaLibrary.getMediaLibrary().startImagePreview(images, (error) => {
if (error) {
console.error('startImagePreview failed with error: ' + error);
return;
}
console.info('Succeeded in previewing the images.');
if (error) {
console.error('startImagePreview failed with error: ' + error);
return;
}
console.info('Succeeded in previewing the images.');
});
```
### startImagePreview
startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt;
......@@ -783,8 +795,8 @@ startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&
Starts image preview, with the first image to preview specified. This API can be used to preview local images whose URIs start with **datashare://** or online images whose URIs start with **https://**. It uses a promise to return the execution result.
> **NOTE**
> This API is supported since API version 6 and can be used only by the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead. The **\<Image>** component can be used to render and display local and online images.
> This API is supported since API version 6 and can be used only in the FA model.
> You are advised to use the **\<[Image](../arkui-ts/ts-basic-components-image.md)>** component instead.<br>The **\<Image>** component can be used to render and display local and online images.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -799,39 +811,38 @@ Starts image preview, with the first image to preview specified. This API can be
| Type | Description |
| ------------------- | ------------------------------- |
| Promise&lt;void&gt; | Promise used to return the image preview result. If the preview fails, an error message is returned.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
let images = [
'file://media/xxxx/2',
'file://media/xxxx/3'
'file://media/xxxx/2',
'file://media/xxxx/3'
];
/* Preview online images.
let images = [
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
'https://media.xxxx.com/image1.jpg',
'https://media.xxxx.com/image2.jpg'
];
*/
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
console.info('Succeeded in previewing the images.');
console.info('Succeeded in previewing the images.');
}).catch((error) => {
console.error('startImagePreview failed with error: ' + error);
console.error('startImagePreview failed with error: ' + error);
});
```
### startMediaSelect
startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Starts media selection. This API uses an asynchronous callback to return the list of URIs that store the selected media assets.
Starts media selection. This API uses an asynchronous callback to return the URIs of the selected media assets.
> **NOTE**
> This API is supported since API version 6 and can be used only by the FA model.
> You are advised to use the system app Gallery instead. Gallery is a built-in visual resource access application that provides features such as image and video management and browsing. For details about how to use Gallery, visit [OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos).
> This API is supported since API version 6 and can be used only in the FA model.
> You are advised to use the system app Gallery instead. Gallery is a built-in visual resource access application that provides features such as image and video management and browsing. For details about how to use Gallery, see [OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos).
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -840,35 +851,34 @@ Starts media selection. This API uses an asynchronous callback to return the lis
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| option | [MediaSelectOption](#mediaselectoption) | Yes | Media selection option. |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback used to return the list of URIs (starting with **datashare://**) that store the selected media assets.|
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the URIs of the selected media assets.|
**Example**
```js
let option : mediaLibrary.MediaSelectOption = {
type : 'media',
count : 2
type : 'media',
count : 2
};
mediaLibrary.getMediaLibrary().startMediaSelect(option, (error, value) => {
if (error) {
console.error('startMediaSelect failed with error: ' + error);
return;
}
console.info('Media resources selected.');
// Obtain the media selection value.
if (error) {
console.error('startMediaSelect failed with error: ' + error);
return;
}
console.info('Media resources selected.');
// Obtain the media selection value.
});
```
### startMediaSelect
startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt;
Starts media selection. This API uses a promise to return the list of URIs that store the selected media assets.
Starts media selection. This API uses a promise to return the URIs of the selected media assets.
> **NOTE**
> This API is supported since API version 6 and can be used only by the FA model.
> You are advised to use the system app Gallery instead. Gallery is a built-in visual resource access application that provides features such as image and video management and browsing. For details about how to use Gallery, visit [OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos).
> This API is supported since API version 6 and can be used only in the FA model.
> You are advised to use the system app Gallery instead. Gallery is a built-in visual resource access application that provides features such as image and video management and browsing. For details about how to use Gallery, see [OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos).
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -882,23 +892,23 @@ Starts media selection. This API uses a promise to return the list of URIs that
| Type | Description |
| ---------------------------------- | ---------------------------------------- |
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the list of URIs (starting with **datashare://**) that store the selected media assets.|
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the URIs of the selected media assets.|
**Example**
```js
let option : mediaLibrary.MediaSelectOption = {
type : 'media',
count : 2
type : 'media',
count : 2
};
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
console.info('Media resources selected.');
// Obtain the media selection value.
console.info('Media resources selected.');
// Obtain the media selection value.
}).catch((error) => {
console.error('startMediaSelect failed with error: ' + error);
console.error('startMediaSelect failed with error: ' + error);
});
```
### getActivePeers<sup>8+</sup>
getActivePeers(): Promise\<Array\<PeerInfo>>;
......@@ -921,15 +931,15 @@ Obtains information about online peer devices. This API uses a promise to return
```js
async function example() {
media.getActivePeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.info('get distributed info is undefined!');
}
}).catch((error) => {
console.error('get distributed info failed with error: ' + error);
});
media.getActivePeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.info('get distributed info is undefined!');
}
}).catch((error) => {
console.error('get distributed info failed with error: ' + error);
});
}
```
......@@ -949,23 +959,22 @@ Obtains information about online peer devices. This API uses an asynchronous cal
| Type | Description |
| ------------------- | -------------------- |
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return the online peer devices, in an array of **PeerInfo** objects.|
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return the online peer devices, in an array of **PeerInfo** objects.|
**Example**
```js
async function example() {
media.getActivePeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.error('get distributed failed with error: ' + error);
}
});
media.getActivePeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.error('get distributed failed with error: ' + error);
}
});
}
```
### getAllPeers<sup>8+</sup>
getAllPeers(): Promise\<Array\<PeerInfo>>;
......@@ -988,15 +997,15 @@ Obtains information about all peer devices. This API uses a promise to return th
```js
async function example() {
media.getAllPeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.info('get distributed info is undefined!');
}
}).catch((error) => {
console.error('get distributed info failed with error: ' + error);
});
media.getAllPeers().then((devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.info('get distributed info is undefined!');
}
}).catch((error) => {
console.error('get distributed info failed with error: ' + error);
});
}
```
......@@ -1004,7 +1013,7 @@ async function example() {
getAllPeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;
Obtains information about online peer devices. This API uses an asynchronous callback to return the result.
Obtains information about all peer devices. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
......@@ -1016,19 +1025,19 @@ Obtains information about online peer devices. This API uses an asynchronous cal
| Type | Description |
| ------------------- | -------------------- |
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Promise used to return all peer devices, in an array of **PeerInfo** objects.|
| callback: AsyncCallback\<Array\<[PeerInfo](#peerinfo8)>> | Callback invoked to return all peer devices, in an array of **PeerInfo** objects.|
**Example**
```js
async function example() {
media.getAllPeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.error('get distributed failed with error: ' + error);
}
});
media.getAllPeers((error, devicesInfo) => {
if (devicesInfo != undefined) {
console.info('get distributed info ' + JSON.stringify(devicesInfo));
} else {
console.error('get distributed failed with error: ' + error);
}
});
}
```
......@@ -1037,6 +1046,7 @@ async function example() {
Provides APIs for encapsulating file asset attributes.
> **NOTE**
>
> 1. The system attempts to parse the file content if the file is an audio or video file. The actual field values will be restored from the passed values during scanning on some devices.
> 2. Some devices may not support the modification of **orientation**. You are advised to use [ModifyImageProperty](js-apis-image.md#modifyimageproperty9) of the **image** module.
......@@ -1050,10 +1060,10 @@ Provides APIs for encapsulating file asset attributes.
| uri | string | Yes | No | File asset URI, for example, **file://media/image/2**. |
| mimeType | string | Yes | No | Extended file attributes. |
| mediaType<sup>8+</sup> | [MediaType](#mediatype8) | Yes | No | Media type. |
| displayName | string | Yes | Yes | Display file name, including the file name extension. |
| title | string | Yes | Yes | Title in the file. By default, it carries the file name without extension. |
| relativePath<sup>8+</sup> | string | Yes | Yes | Relative public directory of the file. |
| parent<sup>8+</sup> | number | Yes | No | Parent directory ID. |
| displayName | string | Yes | Yes | File name, including the file name extension, to display. |
| title | string | Yes | Yes | Title in the file. |
| relativePath<sup>8+</sup> | string | Yes | Yes | Relative path of the user directory. |
| parent<sup>8+</sup> | number | Yes | No | Parent directory ID. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**. |
| size | number | Yes | No | File size, in bytes. |
| dateAdded | number | Yes | No | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. |
| dateModified | number | Yes | No | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
......@@ -1064,10 +1074,9 @@ Provides APIs for encapsulating file asset attributes.
| height | number | Yes | No | Image height, in pixels. |
| orientation | number | Yes | Yes | Image display direction (clockwise rotation angle, for example, 0, 90, or 180, in degrees).|
| duration<sup>8+</sup> | number | Yes | No | Duration, in ms. |
| albumId | number | Yes | No | ID of the album to which the file belongs. |
| albumUri<sup>8+</sup> | string | Yes | No | URI of the album to which the file belongs. |
| albumName | string | Yes | No | Name of the album to which the file belongs. |
| albumId | number | Yes | No | ID of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always **0**. |
| albumUri<sup>8+</sup> | string | Yes | No | URI of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string. |
| albumName | string | Yes | No | Name of the album to which the file belongs. Since SDK of API version 10, an asset can exist in multiple albums. Therefore, this attribute is incompatible. The obtained value is always an empty string. |
### isDirectory<sup>8+</sup>
......@@ -1083,29 +1092,29 @@ Checks whether this file asset is a directory. This API uses an asynchronous cal
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | ------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return whether the file asset is a directory.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the file asset is a directory; the value false means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isDirectory((error, isDirectory) => {
if (error) {
console.error('isDirectory failed with error: ' + error);
} else {
console.info('isDirectory result:' + isDirectory);
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isDirectory((error, isDirectory) => {
if (error) {
console.error('isDirectory failed with error: ' + error);
} else {
console.info('isDirectory result:' + isDirectory);
}
});
fetchFileResult.close();
}
```
......@@ -1123,27 +1132,27 @@ Checks whether this file asset is a directory. This API uses a promise to return
| Type | Description |
| ---------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return whether the file asset is a directory.|
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is a directory; the value **false** means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isDirectory().then((isDirectory) => {
console.info('isDirectory result:' + isDirectory);
}).catch((error) => {
console.error('isDirectory failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isDirectory().then((isDirectory) => {
console.info('isDirectory result:' + isDirectory);
}).catch((error) => {
console.error('isDirectory failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1151,7 +1160,10 @@ async function example() {
commitModify(callback: AsyncCallback&lt;void&gt;): void
Commits the modification in this file asset to the database. This API uses an asynchronous callback to return the result.
Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result.
> **NOTE**
> Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
......@@ -1161,26 +1173,26 @@ Commits the modification in this file asset to the database. This API uses an as
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ----- |
| callback | AsyncCallback&lt;void&gt; | Yes | Void callback.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
asset.commitModify(() => {
console.info('commitModify successfully');
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
asset.commitModify(() => {
console.info('commitModify successfully');
});
fetchFileResult.close();
}
```
......@@ -1188,7 +1200,10 @@ async function example() {
commitModify(): Promise&lt;void&gt;
Commits the modification in this file asset to the database. This API uses a promise to return the result.
Commits the modification on the file asset to the database. This API uses a promise to return the result.
> **NOTE**
> Since the SDK of API version 10, **audio** does not have the **orientation** attribute. Therefore, the **orientation** attribute of the audio resource cannot be modified by **commitModify()**. For details, see [changelogs-mediaLibrary.md](../../../release-notes/changelogs/OpenHarmony_4.0.8.2/changelogs-mediaLibrary.md).
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
......@@ -1198,24 +1213,24 @@ Commits the modification in this file asset to the database. This API uses a pro
| Type | Description |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Void promise.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
await asset.commitModify();
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title = 'newtitle';
await asset.commitModify();
fetchFileResult.close();
}
```
......@@ -1225,7 +1240,7 @@ open(mode: string, callback: AsyncCallback&lt;number&gt;): void
Opens this file asset. This API uses an asynchronous callback to return the result.
**NOTE**: When a file is opened in 'w' mode, the returned FD cannot be read. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
**NOTE**<br>If a file is opened in 'w' mode, the returned file descriptor (FD) cannot be used to read the file. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to close the file.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
......@@ -1235,24 +1250,24 @@ 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).|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback used to return the file descriptor. |
| mode | string | Yes | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the FD of the file opened. |
**Example**
```js
async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw', (error, fd) => {
if (fd > 0) {
asset.close(fd);
} else {
console.error('File Open failed with error: ' + error);
}
});
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw', (error, fd) => {
if (fd > 0) {
asset.close(fd);
} else {
console.error('File Open failed with error: ' + error);
}
});
}
```
......@@ -1262,7 +1277,7 @@ open(mode: string): Promise&lt;number&gt;
Opens this file asset. This API uses a promise to return the result.
**NOTE**: When a file is opened in 'w' mode, the returned FD cannot be read. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to release the resource.
**NOTE**<br>If a file is opened in 'w' mode, the returned FD cannot be used to read the file. However, due to the implementation differences of file systems, some user-mode files opened in 'w' mode can be read by using FD. To perform the read or write operation on a file by using FD, you are advised to open the file in 'rw' mode. The write operations are mutually exclusive. After a write operation is complete, you must call **close** to close the file.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
......@@ -1272,27 +1287,27 @@ Opens this file asset. This API uses a promise to return the result.
| 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 | File open mode, which can be **r** (read-only), **w** (write-only), or **rw** (read-write).|
**Return value**
| Type | Description |
| --------------------- | ------------- |
| Promise&lt;number&gt; | Promise used to return the file descriptor.|
| Promise&lt;number&gt; | Promise used to return the FD of the file opened.|
**Example**
```js
async function example() {
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw').then((fd) => {
console.info('File open fd: ' + fd);
}).catch((error) => {
console.error('File open failed with error: ' + error);
});
let mediaType = mediaLibrary.MediaType.IMAGE;
let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
const path = await media.getPublicDirectory(DIR_IMAGE);
const asset = await media.createAsset(mediaType, 'image00003.jpg', path);
asset.open('rw').then((fd) => {
console.info('File open fd: ' + fd);
}).catch((error) => {
console.error('File open failed with error: ' + error);
});
}
```
......@@ -1300,7 +1315,7 @@ async function example() {
close(fd: number, callback: AsyncCallback&lt;void&gt;): void
Closes this file asset. This API uses an asynchronous callback to return the result.
Closes a file. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
......@@ -1310,35 +1325,35 @@ Closes this file asset. This API uses an asynchronous callback to return the res
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ----- |
| fd | number | Yes | File descriptor.|
| callback | AsyncCallback&lt;void&gt; | Yes | Void callback.|
| fd | number | Yes | FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
console.info('File open fd: ' + fd);
asset.close(fd, (error) => {
if (error) {
console.error('asset.close failed with error: ' + error);
} else {
console.info('asset.close successfully');
}
});
}).catch((error) => {
console.error('File open failed with error: ' + error);
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
console.info('File open fd: ' + fd);
asset.close(fd, (error) => {
if (error) {
console.error('asset.close failed with error: ' + error);
} else {
console.info('asset.close successfully');
}
});
fetchFileResult.close();
}).catch((error) => {
console.error('File open failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1346,7 +1361,7 @@ async function example() {
close(fd: number): Promise&lt;void&gt;
Closes this file asset. This API uses a promise to return the result.
Closes a file. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.WRITE_MEDIA
......@@ -1356,38 +1371,38 @@ Closes this file asset. This API uses a promise to return the result.
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| fd | number | Yes | File descriptor.|
| fd | number | Yes | FD of the file to close.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Void promise.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
console.info('File fd!' + fd);
asset.close(fd).then(() => {
console.info('asset.close successfully');
}).catch((closeErr) => {
console.error('asset.close fail, closeErr: ' + closeErr);
});
}).catch((error) => {
console.error('open File failed with error: ' + error);
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.open('rw').then((fd) => {
console.info('File fd!' + fd);
asset.close(fd).then(() => {
console.info('asset.close successfully');
}).catch((closeErr) => {
console.error('asset.close fail, closeErr: ' + closeErr);
});
fetchFileResult.close();
}).catch((error) => {
console.error('open File failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1405,29 +1420,29 @@ Obtains the thumbnail of this file asset. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return the pixel map of the thumbnail.|
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback invoked to return the PixelMap of the thumbnail.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail((error, pixelmap) => {
if (error) {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
} else {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail((error, pixelmap) => {
if (error) {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
} else {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}
});
fetchFileResult.close();
}
```
......@@ -1435,7 +1450,7 @@ async function example() {
getThumbnail(size: Size, callback: AsyncCallback&lt;image.PixelMap&gt;): void
Obtains the thumbnail of this file asset, with the thumbnail size passed. This API uses an asynchronous callback to return the result.
Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.READ_MEDIA
......@@ -1446,30 +1461,30 @@ Obtains the thumbnail of this file asset, with the thumbnail size passed. This A
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------- | ---- | ---------------- |
| size | [Size](#size8) | Yes | Size of the thumbnail. |
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback used to return the pixel map of the thumbnail.|
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes | Callback invoked to return the PixelMap of the thumbnail.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size, (error, pixelmap) => {
if (error) {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
} else {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size, (error, pixelmap) => {
if (error) {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
} else {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}
});
fetchFileResult.close();
}
```
......@@ -1477,7 +1492,7 @@ async function example() {
getThumbnail(size?: Size): Promise&lt;image.PixelMap&gt;
Obtains the thumbnail of this file asset, with the thumbnail size passed. This API uses a promise to return the result.
Obtains the file thumbnail of the given size. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_MEDIA
......@@ -1493,28 +1508,28 @@ Obtains the thumbnail of this file asset, with the thumbnail size passed. This A
| Type | Description |
| ----------------------------- | --------------------- |
| Promise&lt;image.PixelMap&gt; | Promise to return the pixel map of the thumbnail.|
| Promise&lt;image.PixelMap&gt; | Promise used to return the PixelMap of the thumbnail.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size).then((pixelmap) => {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}).catch((error) => {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let size = { width: 720, height: 720 };
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size).then((pixelmap) => {
console.info('mediaLibrary getThumbnail Successful, pixelmap ' + JSON.stringify(pixelmap));
}).catch((error) => {
console.error('mediaLibrary getThumbnail failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1532,30 +1547,30 @@ Favorites or unfavorites this file asset. This API uses an asynchronous callback
| Name | Type | Mandatory | Description |
| ---------- | ------------------------- | ---- | ---------------------------------- |
| isFavorite | boolean | Yes | Whether to favorite or unfavorite the file. The value **true** means to favorite the file, and **false** means to unfavorite the file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Void callback. |
| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.favorite(true,(error) => {
if (error) {
console.error('mediaLibrary favorite failed with error: ' + error);
} else {
console.info('mediaLibrary favorite Successful');
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.favorite(true,(error) => {
if (error) {
console.error('mediaLibrary favorite failed with error: ' + error);
} else {
console.info('mediaLibrary favorite Successful');
}
});
fetchFileResult.close();
}
```
......@@ -1573,33 +1588,33 @@ Favorites or unfavorites this file asset. This API uses a promise to return the
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| isFavorite | boolean | Yes | Whether to favorite or unfavorite the file. The value **true** means to favorite the file, and **false** means to unfavorite the file.|
| isFavorite | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Void promise.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.favorite(true).then(() => {
console.info('mediaLibrary favorite Successful');
}).catch((error) => {
console.error('mediaLibrary favorite failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.favorite(true).then(() => {
console.info('mediaLibrary favorite Successful');
}).catch((error) => {
console.error('mediaLibrary favorite failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1617,29 +1632,29 @@ Checks whether this file asset is favorited. This API uses an asynchronous callb
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | ----------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return whether the file asset is favorited.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isFavorite((error, isFavorite) => {
if (error) {
console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
} else {
console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isFavorite((error, isFavorite) => {
if (error) {
console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
} else {
console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}
});
fetchFileResult.close();
}
```
......@@ -1657,27 +1672,27 @@ Checks whether this file asset is favorited. This API uses a promise to return t
| Type | Description |
| ---------------------- | ------------------ |
| Promise&lt;boolean&gt; | Promise used to return whether the file asset is favorited.|
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means the file asset is favorited; the value **false** means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isFavorite().then((isFavorite) => {
console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}).catch((error) => {
console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isFavorite().then((isFavorite) => {
console.info('mediaLibrary isFavorite Successful, isFavorite result: ' + isFavorite);
}).catch((error) => {
console.error('mediaLibrary favoriisFavoritete failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1697,30 +1712,30 @@ Files in the trash are not actually deleted. You can set **isTrash** to **false*
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------- |
| isTrash | boolean | Yes | Whether to move the file asset to the trash. The value **true** means to move the file asset to the trash, and **false** means the opposite.|
| callback | AsyncCallback&lt;void&gt; | Yes | Void callback. |
| isTrash | boolean | Yes | Whether to move the file asset to the trash.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value. |
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.trash(true, (error) => {
if (error) {
console.error('mediaLibrary trash failed with error: ' + error);
} else {
console.info('mediaLibrary trash Successful');
}
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.trash(true, (error) => {
if (error) {
console.error('mediaLibrary trash failed with error: ' + error);
} else {
console.info('mediaLibrary trash Successful');
}
});
fetchFileResult.close();
}
```
......@@ -1740,33 +1755,33 @@ Files in the trash are not actually deleted. You can set **isTrash** to **false*
| Name | Type | Mandatory | Description |
| ------- | ------- | ---- | --------- |
| isTrash | boolean | Yes | Whether to move the file asset to the trash. The value **true** means to move the file asset to the trash, and **false** means the opposite.|
| isTrash | boolean | Yes | Whether to move the file asset to the trash.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise&lt;void&gt; | Void promise.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.trash(true).then(() => {
console.info('trash successfully');
}).catch((error) => {
console.error('trash failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.trash(true).then(() => {
console.info('trash successfully');
}).catch((error) => {
console.error('trash failed with error: ' + error);
});
fetchFileResult.close();
}
```
......@@ -1784,29 +1799,29 @@ Checks whether this file asset is in the trash. This API uses an asynchronous ca
| Name | Type | Mandatory | Description |
| -------- | ---------------------------- | ---- | --------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return whether the file asset is in the trash. If the file asset is in the trash, **true** will be returned; otherwise, **false** will be returned.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isTrash((error, isTrash) => {
if (error) {
console.error('Failed to get trash state failed with error: ' + error);
return;
}
console.info('Get trash state successfully, isTrash result: ' + isTrash);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isTrash((error, isTrash) => {
if (error) {
console.error('Failed to get trash state failed with error: ' + error);
return;
}
console.info('Get trash state successfully, isTrash result: ' + isTrash);
});
fetchFileResult.close();
}
```
......@@ -1824,33 +1839,33 @@ Checks whether this file asset is in the trash. This API uses a promise to retur
| Type | Description |
| ------------------- | -------------------- |
| Promise&lt;void&gt; | Promise used to return whether the file asset is in the trash. If the file asset is in the trash, **true** will be returned; otherwise, **false** will be returned.|
| Promise&lt;void&gt; | Promise used to return the result. The value **true** means the file is in the trash; the value **false** means the opposite.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isTrash().then((isTrash) => {
console.info('isTrash result: ' + isTrash);
}).catch((error) => {
console.error('isTrash failed with error: ' + error);
});
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.isTrash().then((isTrash) => {
console.info('isTrash result: ' + isTrash);
}).catch((error) => {
console.error('isTrash failed with error: ' + error);
});
fetchFileResult.close();
}
```
## FetchFileResult<sup>7+</sup>
Implements the result set of the file retrieval operation.
Provides APIs to manage the file retrieval result.
### getCount<sup>7+</sup>
......@@ -1864,23 +1879,23 @@ Obtains the total number of files in the result set.
| Type | Description |
| ------ | -------- |
| number | Total number of files.|
| number | Returns the total number of files obtained.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let getFileCountOneOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
const fetchCount = fetchFileResult.getCount();
console.info('fetchCount result: ' + fetchCount);
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let fileType = mediaLibrary.MediaType.FILE;
let getFileCountOneOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [fileType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
const fetchCount = fetchFileResult.getCount();
console.info('fetchCount result: ' + fetchCount);
fetchFileResult.close();
}
```
......@@ -1896,31 +1911,31 @@ 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**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount();
console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
let fileAsset = await fetchFileResult.getFirstObject();
for (var i = 1; i < fetchCount; i++) {
fileAsset = await fetchFileResult.getNextObject();
if(i == fetchCount - 1) {
var result = fetchFileResult.isAfterLast();
console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
fetchFileResult.close();
}
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount();
console.info('mediaLibrary fetchFileResult.getCount, count:' + fetchCount);
let fileAsset = await fetchFileResult.getFirstObject();
for (var i = 1; i < fetchCount; i++) {
fileAsset = await fetchFileResult.getNextObject();
if(i == fetchCount - 1) {
var result = fetchFileResult.isAfterLast();
console.info('mediaLibrary fileAsset isAfterLast result: ' + result);
fetchFileResult.close();
}
}
}
```
......@@ -1928,7 +1943,7 @@ async function example() {
close(): void
Releases and invalidates this **FetchFileResult** instance. Other APIs in this instance cannot be invoked after it is released.
Releases and invalidates this **FetchFileResult** instance. After this instance is released, the APIs in this instance cannot be invoked.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -1936,15 +1951,15 @@ Releases and invalidates this **FetchFileResult** instance. Other APIs in this i
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.close();
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.close();
}
```
......@@ -1960,28 +1975,28 @@ Obtains the first file asset in the result set. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the first file asset.|
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback invoked to return the first **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject((error, fileAsset) => {
if (error) {
console.error('fetchFileResult getFirstObject failed with error: ' + error);
return;
}
console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
fetchFileResult.close();
})
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject((error, fileAsset) => {
if (error) {
console.error('fetchFileResult getFirstObject failed with error: ' + error);
return;
}
console.info('getFirstObject successfully, displayName : ' + fileAsset.displayName);
fetchFileResult.close();
})
}
```
......@@ -1997,26 +2012,26 @@ Obtains the first file asset in the result set. This API uses a promise to retur
| Type | Description |
| --------------------------------------- | -------------------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the file asset.|
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the first **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject().then((fileAsset) => {
console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getFirstObject failed with error: ' + error);
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getFirstObject().then((fileAsset) => {
console.info('getFirstObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getFirstObject failed with error: ' + error);
});
}
```
......@@ -2025,9 +2040,8 @@ async function example() {
getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void
Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
> **NOTE**<br>Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -2035,32 +2049,32 @@ Obtains the next file asset in the result set. This API uses an asynchronous cal
| Name | Type | Mandatory| Description |
| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
| callback| AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the next file asset.|
| callbacke | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback invoked to return the next **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
let fileAsset = await fetchFileResult.getFirstObject();
console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
if (!fetchFileResult.isAfterLast()) {
fetchFileResult.getNextObject((error, fileAsset) => {
if (error) {
console.error('fetchFileResult getNextObject failed with error: ' + error);
return;
}
console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
}
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
let fileAsset = await fetchFileResult.getFirstObject();
console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
if (!fetchFileResult.isAfterLast()) {
fetchFileResult.getNextObject((error, fileAsset) => {
if (error) {
console.error('fetchFileResult getNextObject failed with error: ' + error);
return;
}
console.log('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
}
}
```
......@@ -2070,9 +2084,8 @@ async function example() {
getNextObject(): Promise&lt;FileAsset&gt;
Obtains the next file asset in the result set. This API uses a promise to return the result.
> **NOTE**
>
> Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
> **NOTE**<br>Before using this API, you must use [getFirstObject](#getfirstobject7) to obtain the first file asset and then use [isAfterLast](#isafterlast7) to ensure that the cursor does not point to the last file asset in the result set.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -2080,30 +2093,30 @@ Obtains the next file asset in the result set. This API uses a promise to return
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next file asset.|
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
let fileAsset = await fetchFileResult.getFirstObject();
console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
if (!fetchFileResult.isAfterLast()) {
fetchFileResult.getNextObject().then((fileAsset) => {
console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('fetchFileResult getNextObject failed with error: ' + error);
})
}
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
let fileAsset = await fetchFileResult.getFirstObject();
console.log('fetchFileResult getFirstObject successfully, displayName: ' + fileAsset.displayName);
if (!fetchFileResult.isAfterLast()) {
fetchFileResult.getNextObject().then((fileAsset) => {
console.info('fetchFileResult getNextObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('fetchFileResult getNextObject failed with error: ' + error);
})
}
}
```
......@@ -2119,28 +2132,28 @@ Obtains the last file asset in the result set. This API uses an asynchronous cal
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------- | ---- | --------------------------- |
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the last file asset.|
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback invoked to return the last **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getLastObject((error, fileAsset) => {
if (error) {
console.error('getLastObject failed with error: ' + error);
return;
}
console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getLastObject((error, fileAsset) => {
if (error) {
console.error('getLastObject failed with error: ' + error);
return;
}
console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
}
```
......@@ -2156,26 +2169,26 @@ Obtains the last file asset in the result set. This API uses a promise to return
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next file asset.|
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the last **FileAsset** object in the result set.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getLastObject().then((fileAsset) => {
console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getLastObject failed with error: ' + error);
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getLastObject().then((fileAsset) => {
console.info('getLastObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getLastObject failed with error: ' + error);
});
}
```
......@@ -2192,28 +2205,28 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ------------------ |
| index | number | Yes | Index of the file to obtain. The value starts from 0 and must be smaller than the **count** value of the result set. |
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback used to return the last file asset.|
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | Yes | Callback invoked to return the **FileAsset** object with the specified index obtained.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(0, (error, fileAsset) => {
if (error) {
console.error('getPositionObject failed with error: ' + error);
return;
}
console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(0, (error, fileAsset) => {
if (error) {
console.error('getPositionObject failed with error: ' + error);
return;
}
console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
})
}
```
......@@ -2235,26 +2248,26 @@ Obtains a file asset with the specified index in the result set. This API uses a
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the next file asset.|
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise used to return the **FileAsset** object with the specified index obtained.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(0).then((fileAsset) => {
console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getPositionObject failed with error: ' + error);
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(0).then((fileAsset) => {
console.info('getPositionObject successfully, displayName: ' + fileAsset.displayName);
fetchFileResult.close();
}).catch((error) => {
console.error('getPositionObject failed with error: ' + error);
});
}
```
......@@ -2270,30 +2283,30 @@ Obtains all the file assets in the result set. This API uses an asynchronous cal
| Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | -------------------- |
| callback | AsyncCallback&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Yes | Callback used to return the file assets.|
| callback | AsyncCallback&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Yes | Callback invoked to return all the **FileAsset** objects in the result reset.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getAllObject((error, fileAssetList) => {
if (error) {
console.error('getAllObject failed with error: ' + error);
return;
}
for (let i = 0; i < fetchFileResult.getCount(); i++) {
console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
}
fetchFileResult.close();
})
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getAllObject((error, fileAssetList) => {
if (error) {
console.error('getAllObject failed with error: ' + error);
return;
}
for (let i = 0; i < fetchFileResult.getCount(); i++) {
console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
}
fetchFileResult.close();
})
}
```
......@@ -2309,34 +2322,34 @@ Obtains all the file assets in the result set. This API uses a promise to return
| Type | Description |
| ---------------------------------------- | --------------------- |
| Promise&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Promise used to return the file assets.|
| Promise&lt;Array&lt;[FileAsset](#fileasset7)&gt;&gt; | Promise used to return all the **FileAsset** objects in the result reset.|
**Example**
```js
async function example() {
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getAllObject().then((fileAssetList) => {
for (let i = 0; i < fetchFileResult.getCount(); i++) {
console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
}
fetchFileResult.close();
}).catch((error) => {
console.error('getAllObject failed with error: ' + error);
});
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
order: fileKeyObj.DATE_ADDED + ' DESC',
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getAllObject().then((fileAssetList) => {
for (let i = 0; i < fetchFileResult.getCount(); i++) {
console.info('getAllObject fileAssetList ' + i + ' displayName: ' + fileAssetList[i].displayName);
}
fetchFileResult.close();
}).catch((error) => {
console.error('getAllObject failed with error: ' + error);
});
}
```
## Album<sup>7+</sup>
Provides APIs to implement a physical album.
Provides APIs to manage albums.
### Attributes
......@@ -2345,9 +2358,9 @@ Provides APIs to implement a physical album.
| Name | Type | Readable | Writable | Description |
| ------------ | ------ | ---- | ---- | ------- |
| albumId | number | Yes | No | Album ID. |
| albumName | string | Yes | Yes | Album name. |
| albumUri<sup>8+</sup> | string | Yes | No | Album URI. |
| dateModified | number | Yes | No | Date when the album was modified. |
| albumName | string | Yes | Yes | Name of the album. |
| albumUri<sup>8+</sup> | string | Yes | No | URI of the album. |
| dateModified | number | Yes | No | Date when the album was last modified. |
| count<sup>8+</sup> | number | Yes | No | Number of files in the album.|
| relativePath<sup>8+</sup> | string | Yes | No | Relative path of the album. |
| coverUri<sup>8+</sup> | string | Yes | No | URI of the cover file of the album.|
......@@ -2356,7 +2369,7 @@ Provides APIs to implement a physical album.
commitModify(callback: AsyncCallback&lt;void&gt;): void
Commits the modification in the album attributes to the database. This API uses an asynchronous callback to return the result.
Commits the modification on the album attributes to the database.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
......@@ -2366,7 +2379,7 @@ Commits the modification in the album attributes to the database. This API uses
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Void callback.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback that returns no value.|
**Example**
......@@ -2386,7 +2399,7 @@ async function example() {
return;
}
console.info('commitModify successful.');
})
});
}
```
......@@ -2394,7 +2407,7 @@ async function example() {
commitModify(): Promise&lt;void&gt;
Commits the modification in the album attributes to the database. This API uses a promise to return the result.
Commits the modification on the album attributes to the database.
**Required permissions**: ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
......@@ -2404,7 +2417,7 @@ Commits the modification in the album attributes to the database. This API uses
| Type | Description |
| ------------------- | ------------ |
| Promise&lt;void&gt; | Void promise.|
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
......@@ -2440,7 +2453,7 @@ Obtains the file assets in this album. This API uses an asynchronous callback to
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback used to return the file assets.|
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback invoked to return the file retrieval result set of the album.|
**Example**
......@@ -2482,7 +2495,7 @@ Obtains the file assets in this album. This API uses an asynchronous callback to
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
| options | [MediaFetchOptions](#mediafetchoptions7) | Yes | Options for fetching the files. |
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback used to return the file assets.|
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | Yes | Callback invoked to return the file retrieval result set of the album.|
**Example**
......@@ -2496,7 +2509,7 @@ async function example() {
let fileNoArgsfetchOp = {
selections: '',
selectionArgs: [],
}
};
// Obtain the albums that meet the retrieval options and return the album list.
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
......@@ -2533,7 +2546,7 @@ Obtains the file assets in this album. This API uses a promise to return the res
| Type | Description |
| --------------------------------------------- | ------------------------- |
| Promise<[FetchFileResult](#fetchfileresult7)> | Promise used to return the file assets.|
| Promise<[FetchFileResult](#fetchfileresult7)> | Promise used to return the file retrieval result set of the album.|
**Example**
......@@ -2564,7 +2577,7 @@ async function example() {
## PeerInfo<sup>8+</sup>
Describes information about a registered device.
Defines information about a registered device.
**System API**: This is a system API.
......@@ -2577,8 +2590,6 @@ Describes information about a registered device.
| deviceType | [DeviceType](#devicetype8) | Yes | No | Type of the registered device. |
| isOnline | boolean | Yes | No | Whether the registered device is online. |
## MediaType<sup>8+</sup>
Enumerates media types.
......@@ -2604,8 +2615,8 @@ Enumerates key file information.
| Name | Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- |
| ID | 'file_id' | File ID. |
| RELATIVE_PATH | 'relative_path' | Relative public directory of the file. |
| DISPLAY_NAME | 'display_name' | Display file name. |
| RELATIVE_PATH | 'relative_path' | Relative path of the user directory. |
| DISPLAY_NAME | 'display_name' | File name displayed. |
| PARENT | 'parent' | Parent directory ID. |
| MIME_TYPE | 'mime_type' | Extended file attributes, such as image/, video/, and file/*. |
| MEDIA_TYPE | 'media_type' | Media type. |
......@@ -2640,7 +2651,7 @@ Enumerates directory types.
## DeviceType<sup>8+</sup>
Enumerates device types.
Enumerates the device types.
**System API**: This is a system API.
......@@ -2658,22 +2669,22 @@ Enumerates device types.
## MediaFetchOptions<sup>7+</sup>
Describes options for fetching media files.
Defines the options for fetching media files.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Type | Readable| Writable| Description |
| ----------------------- | ------------------- | ---- | ---- | ------------------------------------------------------------ |
| selections | string | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names of the conditions. Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
| selectionArgs | Array&lt;string&gt; | Yes | Yes | Value of the condition, which corresponds to the value of the condition column in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
| selections | string | Yes | Yes | Conditions for fetching files. The enumerated values in [FileKey](#filekey8) are used as the column names when files are fetched. Example:<br>selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR ' + mediaLibrary.FileKey.MEDIA_TYPE + '= ?', |
| selectionArgs | Array&lt;string&gt; | Yes | Yes | Values of the conditions specified in **selections**.<br>Example:<br>selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
| order | string | Yes | Yes | 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:<br>Ascending: order: mediaLibrary.FileKey.DATE_ADDED + ' ASC'<br>Descending: order: mediaLibrary.FileKey.DATE_ADDED + ' DESC'|
| uri<sup>8+</sup> | string | Yes | Yes | File URI. |
| uri<sup>8+</sup> | string | Yes | Yes | URI of the file. |
| networkId<sup>8+</sup> | string | Yes | Yes | Network ID of the registered device. |
| extendArgs<sup>8+</sup> | string | Yes | Yes | Extended parameters for fetching the files. Currently, no extended parameters are available. |
## Size<sup>8+</sup>
Describes the image size.
Defines the image size.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......@@ -2684,20 +2695,19 @@ Describes the image size.
## MediaAssetOption
Implements the media asset option.
Defines the media asset option.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
| Name | Type | Readable| Writable| Description |
| ------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
| src | string | Yes | Yes | Application sandbox oath of the local file. |
| mimeType | string | Yes | Yes | Multipurpose Internet Mail Extensions (MIME) type of the media.<br>The value can be 'image/\*', 'video/\*', 'audio/\*' or 'file\*'.|
| relativePath | string | Yes | Yes | Custom path for storing media assets, for example, 'Pictures/'. If this parameter is unspecified, media assets are stored in the default path.<br> Default path of images: 'Pictures/'<br> Default path of videos: 'Videos/'<br> Default path of audios: 'Audios/'<br> Default path of files: 'Documents/'|
| relativePath | string | Yes | Yes | Custom path of media assets, for example, **Pictures/**. If this parameter is unspecified, media assets are stored in the default path.<br> Default path of images: **'Pictures/'**<br> Default path of videos: **'Videos/'**<br> Default path of audios: **'Audios/'**<br> Default path of documents: **'Documents/'**|
## MediaSelectOption
Describes media selection option.
Defines media selection option.
**System capability**: SystemCapability.Multimedia.MediaLibrary.Core
......
......@@ -903,7 +903,7 @@ async function example() {
deleteAssets(uriList: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Deletes media files. This API uses an asynchronous callback to return the result. The deleted files are moved to the recycle bin.
Deletes media files. This API uses an asynchronous callback to return the result. The deleted files are moved to the trash.
**System API**: This is a system API.
......@@ -964,7 +964,7 @@ async function example() {
deleteAssets(uriList: Array&lt;string&gt;): Promise&lt;void&gt;;
Deletes media files. This API uses a promise to return the result. The deleted files are moved to the recycle bin.
Deletes media files. This API uses a promise to return the result. The deleted files are moved to the trash.
**System API**: This is a system API.
......@@ -1159,7 +1159,7 @@ async function example() {
createDeleteRequest(uriList: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void;
Creates a dialog box for deleting photos. This API uses an asynchronous callback to return the result. The deleted photos are moved to the recycle bin.
Creates a dialog box for deleting photos. This API uses an asynchronous callback to return the result. The deleted photos are moved to the trash.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
......@@ -1217,7 +1217,7 @@ async function example() {
createDeleteRequest(uriList: Array&lt;string&gt;): Promise&lt;void&gt;;
Creates a dialog box for deleting photos. This API uses a promise to return the result. The deleted photos are moved to the recycle bin.
Creates a dialog box for deleting photos. This API uses a promise to return the result. The deleted photos are moved to the trash.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
......@@ -3258,7 +3258,7 @@ async function example() {
recoverAssets(assets: Array&lt;PhotoAsset&gt;, callback: AsyncCallback&lt;void&gt;): void;
Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result.
Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
......@@ -3316,7 +3316,7 @@ async function example() {
recoverAssets(assets: Array&lt;PhotoAsset&gt;): Promise&lt;void&gt;;
Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result.
Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses a promise to return the result.
**System API**: This is a system API.
......@@ -3377,7 +3377,7 @@ async function example() {
deleteAssets(assets: Array&lt;PhotoAsset&gt;, callback: AsyncCallback&lt;void&gt;): void;
Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result.
Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result.
**CAUTION**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
......@@ -3437,7 +3437,7 @@ async function example() {
deleteAssets(assets: Array&lt;PhotoAsset&gt;): Promise&lt;void&gt;;
Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result.
Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses a promise to return the result.
**CAUTION**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
......@@ -3568,7 +3568,7 @@ Enumerate the album subtypes.
| FAVORITE | 1025 | Favorites.|
| VIDEO | 1026 | Video album.|
| HIDDEN | 1027 | Hidden album. **System API**: This is a system API.|
| TRASH | 1028 | Recycle bin. **System API**: This is a system API.|
| TRASH | 1028 | Trash. **System API**: This is a system API.|
| SCREENSHOT | 1029 | Album for screenshots and screen recording files. **System API**: This is a system API.|
| CAMERA | 1030 | Album for photos and videos taken by the camera. **System API**: This is a system API.|
| ANY | 2147483647 | Any album.|
......
# File Subsystem Changelog
## cl.file.1 Change of the mediaLibrary Interface Compatibility
Changed the compatibility of some **mediaLibrary** APIs.
**Change Impact**
The compatibility of some [mediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md) APIs is changed.
For applications developed based on earlier versions, pay attention to the iterative update of deprecated APIs.
**Key API/Component Changes**
| Module | Method/Attribute/Enum/Constant | Change Type|
| ------------------------- | ------------------------------------------------------------ | -------- |
| medialibrary | **function** getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void | Interface compatibility changed |
| medialibrary | **function** getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt; | Interface compatibility changed |
| medialibrary | **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback&lt;FileAsset&gt;): void| Interface compatibility changed |
| medialibrary | **function** createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise&lt;FileAsset&gt;| Interface compatibility changed |
| medialibrary | **function** getAlbums(options: MediaFetchOptions, callback: AsyncCallback&lt;Array&lt;Album&gt;&gt;): void | Interface compatibility changed |
| medialibrary | **function** getAlbums(options: MediaFetchOptions): Promise&lt;Array&lt;Album&gt;&gt; | Interface compatibility changed |
| medialibrary | **function** FileAsset.commitModify(callback: AsyncCallback&lt;void&gt;): void | Interface compatibility changed |
| medialibrary | **function** FileAsset.commitModify(): Promise&lt;void&gt; | Interface compatibility changed |
**Adaptation Guide**
**getFileAssets**
From API version 10, the albums represented by physical directories are replaced by logical albums, which allows multiple files in an album and presence of a file in multiple albums. This design, however, makes **parent**, **albumId**, **albumUri**, and **albumName** incompatible. They cannot be used as parameters of **MediaFetchOptions** in **getFileAssets()**. See the following example:
1. Use [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance.
2. Use [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the file fetching options.
3. Use [getFileAssets](../../../application-dev/reference/apis/js-apis-medialibrary.md#getfileassets7) to obtain file assets.
**Incorrect code example**:
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
async function example() {
try {
let context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
let fileKeyObj = mediaLibrary.FileKey;
let albumId = 1;
let getImageOp = {
selections: fileKeyObj.ALBUM_ID + '= ?', // File assets cannot be obtained based on the parent, albumId, albumUri, and albumName attributes.
selectionArgs: [albumId.toString()],
};
const fetchFileResult = await media.getFileAssets(getImageOp); // The obtained fetchFileResult is empty.
const fileAsset = await fetchFileResult.getFirstObject();
console.info('mediaLibrary fileAsset displayName: ' + fileAsset.displayName);
} catch (err) {
console.error('mediaLibrary fail, err: ' + err);
}
}
```
Use **getFileAssets()** as follows:
**Correct code example**:
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
async function example() {
try {
let context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
let fileKeyObj = mediaLibrary.FileKey;
let imageType = mediaLibrary.MediaType.IMAGE;
let getImageOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()], // Query all files of the image type.
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const fileAsset = await fetchFileResult.getFirstObject();
console.info('mediaLibrary fileAsset displayName: ' + fileAsset.displayName);
} catch (err) {
console.error('mediaLibrary fail, err: ' + err);
}
}
```
**createAsset**
From the SDK of API version 10, **relativePath** is no longer associated with an album. After a file is created, the last-level directory of **relativePath** is not displayed as an album.
**getAlbums**
From the SDK of API version 10, **relativePath** is no longer associated with an album. Therefore, **relativePath** cannot be used as a search criterion in **getAlbums**, and the values of **ALBUM_NAME** can be **Camera** and **Screenshots** only. See the following example:
1. Use [getMediaLibrary](../../../application-dev/reference/apis/js-apis-medialibrary.md#medialibrarygetmedialibrary) to obtain a **MediaLibrary** instance.
2. Use [MediaFetchOptions](../../../application-dev/reference/apis/js-apis-medialibrary.md#mediafetchoptions7) to create the album fetching options.
3. Use [getAlbums](../../../application-dev/reference/apis/js-apis-medialibrary.md#getalbums7) to obtain albums.
**Incorrect code example**:
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
async function example() {
try {
let context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
let AlbumNoArgsfetchOp = {
selections: mediaLibrary.FileKey.ALBUM_NAME + ' = ?',
selectionArgs:['New album 1'], //Obtain the album named New album 1.
};
const albumList = await media.getAlbums(AlbumNoArgsfetchOp); // The fetchFileResult returned is empty.
for (let i = 0; i < albumList.length; i++) {
console.info('mediaLibrary album albumName: ' + albumList[i].albumName);
}
} catch (err) {
console.error('mediaLibrary fail, err: ' + err);
}
}
```
The following example shows how to obtain **Camera** and **Screenshots** albums:
**Correct code example**:
```js
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
async function example() {
try {
let context = getContext(this);
let media = mediaLibrary.getMediaLibrary(context);
let AlbumNoArgsfetchOp = {
selections: mediaLibrary.FileKey.ALBUM_NAME + ' = ? OR ' + mediaLibrary.FileKey.ALBUM_NAME + ' = ?',
selectionArgs: ['Camera', 'Screenshots'], // Obtain the camera and screenshot albums.
};
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
for (let i = 0; i < albumList.length; i++) {
console.info('mediaLibrary album albumName: ' + albumList[i].albumName);
}
} catch (err) {
console.error('mediaLibrary fail, err: ' + err);
}
}
```
**FileAsset.commitModify**
The **orientation** attribute for audio is deleted from the SDK of API version 10. When **commitModify** is used, the **orientation** attribute of audio resources cannot be modified.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册