js-apis-medialibrary.md 80.0 KB
Newer Older
Z
zengyawen 已提交
1 2
# 媒体库管理

P
panqiangbiao 已提交
3 4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 该组件从API Version 6开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
P
panqiangbiao 已提交
5

Z
zengyawen 已提交
6
## 导入模块
P
panqiangbiao 已提交
7
```
8
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
P
panqiangbiao 已提交
9 10
```

Z
zengyawen 已提交
11
## mediaLibrary.getMediaLibrary<sup>8+</sup>
P
panqiangbiao 已提交
12

P
panqiangbiao 已提交
13
getMediaLibrary(context: Context): MediaLibrary
P
panqiangbiao 已提交
14

Z
zengyawen 已提交
15
获取媒体库的实例,用于访问和修改用户等个人媒体数据信息(如音频、视频、图片、文档等)。
P
panqiangbiao 已提交
16

P
panqiangbiao 已提交
17
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
18

P
panqiangbiao 已提交
19
**参数:** 
P
panqiangbiao 已提交
20

Z
zengyawen 已提交
21 22 23
| 参数名  | 类型    | 必填 | 说明                       |
| ------- | ------- | ---- | -------------------------- |
| context | Context | 是   | 传入Ability实例的Context。 |
P
panqiangbiao 已提交
24 25 26

**返回值:**

H
HelloCrease 已提交
27 28
| 类型                            | 说明    |
| ----------------------------- | :---- |
P
panqiangbiao 已提交
29
| [MediaLibrary](#medialibrary) | 媒体库实例 |
P
panqiangbiao 已提交
30

潘强标 已提交
31 32 33 34 35 36 37
**示例:(从API Version 9开始)**

```
var media = mediaLibrary.getMediaLibrary(this.context);
```

**示例:(API Version 8)**
P
panqiangbiao 已提交
38 39

```
P
panqiangbiao 已提交
40
import featureAbility from '@ohos.ability.featureAbility';
P
panqiangbiao 已提交
41

P
panqiangbiao 已提交
42
var context = featureAbility.getContext()
P
panqiangbiao 已提交
43
var media = mediaLibrary.getMediaLibrary(context);
P
panqiangbiao 已提交
44
```
Z
zengyawen 已提交
45 46 47 48 49 50
## mediaLibrary.getMediaLibrary

getMediaLibrary(): MediaLibrary

获取媒体库的实例,用于访问和修改用户等个人媒体数据信息(如音频、视频、图片、文档等)。

Z
zengyawen 已提交
51
> **说明**: 从API Version 8开始,该接口不再维护,推荐使用新接口[mediaLibrary.getMediaLibrary<sup>8+</sup>](#medialibrarygetmedialibrary8)。
Z
zengyawen 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**返回值:**

| 类型                          | 说明       |
| ----------------------------- | :--------- |
| [MediaLibrary](#medialibrary) | 媒体库实例 |

**示例:**

```js
var media = mediaLibrary.getMediaLibrary();
```

P
panqiangbiao 已提交
67
## MediaLibrary
P
panqiangbiao 已提交
68

Z
zengyawen 已提交
69
### getFileAssets<sup>7+</sup>
P
panqiangbiao 已提交
70 71


P
panqiangbiao 已提交
72
getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void 
P
panqiangbiao 已提交
73 74 75

获取文件资源,使用callback方式返回异步结果。

P
panqiangbiao 已提交
76
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
77

P
panqiangbiao 已提交
78
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
79

P
panqiangbiao 已提交
80 81
**参数:**

Z
zengyawen 已提交
82 83 84 85
| 参数名   | 类型                                                | 必填 | 说明                              |
| -------- | --------------------------------------------------- | ---- | --------------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)            | 是   | 文件获取选项                      |
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | 是   | 异步获取FetchFileResult之后的回调 |
P
panqiangbiao 已提交
86 87 88 89

**示例:**

```
P
panqiangbiao 已提交
90 91 92 93 94 95
let fileKeyObj = mediaLibrary.FileKey
let imageType = mediaLibrary.MediaType.IMAGE
let imagesfetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
};
潘强标 已提交
96
media.getFileAssets(imagesfetchOp, (error, fetchFileResult) => {
P
panqiangbiao 已提交
97
    if (fetchFileResult != undefined) {
P
panqiangbiao 已提交
98
        console.info('mediaLibraryTest : ASSET_CALLBACK fetchFileResult success');
P
panqiangbiao 已提交
99 100 101 102
        fetchFileResult.getAllObject((err, fileAssetList) => {
            if (fileAssetList != undefined) {
                fileAssetList.forEach(getAllObjectInfo);
            }
P
panqiangbiao 已提交
103 104
    	});
    }
P
panqiangbiao 已提交
105
});
P
panqiangbiao 已提交
106
```
Z
zengyawen 已提交
107
### getFileAssets<sup>7+</sup>
P
panqiangbiao 已提交
108

P
panqiangbiao 已提交
109
getFileAssets(options: MediaFetchOptions): Promise&lt;FetchFileResult&gt;
P
panqiangbiao 已提交
110 111 112

获取文件资源,使用Promise方式返回结果。

P
panqiangbiao 已提交
113
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
114

P
panqiangbiao 已提交
115
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
116

P
panqiangbiao 已提交
117 118
**参数:**

Z
zengyawen 已提交
119 120 121
| 参数名  | 类型                                     | 必填 | 说明         |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | 是   | 文件检索选项 |
P
panqiangbiao 已提交
122 123 124

**返回值**

Z
zengyawen 已提交
125 126 127
| 类型                                 | 说明           |
| ------------------------------------ | -------------- |
| [FetchFileResult](#fetchfileresult7) | 文件数据结果集 |
P
panqiangbiao 已提交
128 129 130 131

**示例:**

```
P
panqiangbiao 已提交
132 133 134 135 136 137
let fileKeyObj = mediaLibrary.FileKey
let imageType = mediaLibrary.MediaType.IMAGE
let imagesfetchOp = {
    selections: fileKeyObj.MEDIA_TYPE + '= ?',
    selectionArgs: [imageType.toString()],
};
潘强标 已提交
138
media.getFileAssets(imagesfetchOp).then(function(fetchFileResult){
P
panqiangbiao 已提交
139 140 141 142
    console.info("getFileAssets successfully:"+ JSON.stringify(dir));
}).catch(function(err){
    console.info("getFileAssets failed with error:"+ err);
});
P
panqiangbiao 已提交
143 144
```

P
panqiangbiao 已提交
145
### on<sup>8+</sup>
P
panqiangbiao 已提交
146

P
panqiangbiao 已提交
147
on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback&lt;void&gt;): void
P
panqiangbiao 已提交
148

149
打开媒体库变更通知,使用callback方式返回异步结果。
P
panqiangbiao 已提交
150

P
panqiangbiao 已提交
151
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
152

P
panqiangbiao 已提交
153 154
**参数:**

H
HelloCrease 已提交
155 156 157 158
| 参数名      | 类型                   | 必填   | 说明                                       |
| -------- | -------------------- | ---- | ---------------------------------------- |
| type     | string               | 是    | 媒体类型 <br/>'deviceChange':&nbsp;注册设备变更 <br/>'albumChange':&nbsp;相册变更<br/>'imageChange':&nbsp;图片文件变更<br/>'audioChange': &nbsp;音频文件变更<br/>'videoChange':  &nbsp;视频文件变更<br/>'fileChange':     &nbsp;文件变更<br/>'remoteFileChange':&nbsp;注册设备上文件变更 |
| callback | callback&lt;void&gt; | 是    | 回调返回空                                    |
P
panqiangbiao 已提交
159 160 161 162

**示例:**

```
P
panqiangbiao 已提交
163
mediaLibrary.on('imageChange', () => {
P
panqiangbiao 已提交
164
    // image file had changed, do something
P
panqiangbiao 已提交
165 166
})
```
P
panqiangbiao 已提交
167
### off<sup>8+</sup>
P
panqiangbiao 已提交
168

P
panqiangbiao 已提交
169
off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback&lt;void&gt;): void
P
panqiangbiao 已提交
170

171
关闭媒体库变更通知,使用callback方式返回异步结果。
P
panqiangbiao 已提交
172

P
panqiangbiao 已提交
173
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
174

P
panqiangbiao 已提交
175 176
**参数:**

H
HelloCrease 已提交
177 178 179 180
| 参数名      | 类型                   | 必填   | 说明                                       |
| -------- | -------------------- | ---- | ---------------------------------------- |
| type     | string               | 是    | 媒体类型 <br/>'deviceChange':&nbsp;注册设备变更 <br/>'albumChange':&nbsp;相册变更<br/>'imageChange':&nbsp;图片文件变更<br/>'audioChange': &nbsp;音频文件变更<br/>'videoChange':  &nbsp;视频文件变更<br/>'fileChange':     &nbsp;文件变更<br/>'remoteFileChange':&nbsp;注册设备上文件变更 |
| callback | callback&lt;void&gt; | 否    | 回调返回空                                    |
P
panqiangbiao 已提交
181 182 183 184

**示例:**

```
潘强标 已提交
185
media.off('imageChange', () => {
P
panqiangbiao 已提交
186
    // stop listening success
P
panqiangbiao 已提交
187 188 189
})
```

P
panqiangbiao 已提交
190
### createAsset <sup>8+</sup>
P
panqiangbiao 已提交
191

P
panqiangbiao 已提交
192
createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback&lt;FileAsset&gt;): void
P
panqiangbiao 已提交
193 194 195

创建媒体资源,使用callback方式返回结果。

P
panqiangbiao 已提交
196
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
197

P
panqiangbiao 已提交
198
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
199

P
panqiangbiao 已提交
200 201
**参数:**

Z
zengyawen 已提交
202 203 204 205 206 207
| 参数名       | 类型                                    | 必填 | 说明                                                         |
| ------------ | --------------------------------------- | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8)                | 是   | 媒体类型                                                     |
| displayName  | string                                  | 是   | 展示文件名                                                   |
| relativePath | string                                  | 是   | 文件保存路径,可以通过[getPublicDirectory](#getpublicdirectory8)获取不同类型文件的保存路径 |
| callback     | AsyncCallback<[FileAsset](#fileasset7)> | 是   | 异步获取媒体数据FileAsset之后的回调                          |
P
panqiangbiao 已提交
208 209 210 211

**示例:**

```
P
panqiangbiao 已提交
212 213 214 215 216
async function example() {
    // 使用Callback方式创建Image类型文件
    let mediaType = mediaLibrary.MediaType.IMAGE;
    let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
    const path = await media.getPublicDirectory(DIR_IMAGE);
潘强标 已提交
217
    media.createAsset(mediaType, 'imageCallBack.jpg', path + 'myPicture/', (err, fileAsset) => {
P
panqiangbiao 已提交
218 219 220 221 222 223 224
        if (fileAsset != undefined) {
            console.info('createAsset successfully, message = ' + err);
        } else {
            console.info('createAsset failed, message = ' + err);
        }
    });
}
P
panqiangbiao 已提交
225 226
```

P
panqiangbiao 已提交
227
### createAsset<sup>8+</sup>
P
panqiangbiao 已提交
228

P
panqiangbiao 已提交
229
createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise&lt;FileAsset&gt;
P
panqiangbiao 已提交
230 231 232

创建媒体资源,使用Promise方式返回结果。

P
panqiangbiao 已提交
233
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
234

P
panqiangbiao 已提交
235
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
236

P
panqiangbiao 已提交
237 238
**参数:**

Z
zengyawen 已提交
239 240 241 242 243
| 参数名       | 类型                     | 必填 | 说明                                                         |
| ------------ | ------------------------ | ---- | ------------------------------------------------------------ |
| mediaType    | [MediaType](#mediatype8) | 是   | 媒体类型                                                     |
| displayName  | string                   | 是   | 展示文件名                                                   |
| relativePath | string                   | 是   | 相对路径,可以通过getPublicDirectory获取不同类型媒体文件的一层目录的relative path |
P
panqiangbiao 已提交
244 245 246

**返回值**

Z
zengyawen 已提交
247 248 249
| 类型                     | 说明              |
| ------------------------ | ----------------- |
| [FileAsset](#fileasset7) | 媒体数据FileAsset |
P
panqiangbiao 已提交
250 251 252 253

**示例:**

```
P
panqiangbiao 已提交
254 255 256 257 258
async function example() {
    // 使用Promise方式创建Image类型文件
    let mediaType = mediaLibrary.MediaType.IMAGE;
    let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
    const path = await media.getPublicDirectory(DIR_IMAGE);
潘强标 已提交
259
    media.createAsset(mediaType, "image01.jpg", path + 'myPicture/').then (function (asset) {
P
panqiangbiao 已提交
260 261 262 263 264
        console.info("createAsset successfully:"+ JSON.stringify(asset));
    }).catch(function(err){
        console.info("createAsset failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
265 266
```

P
panqiangbiao 已提交
267
### getPublicDirectory<sup>8+</sup>
P
panqiangbiao 已提交
268

P
panqiangbiao 已提交
269
getPublicDirectory(type: DirectoryType, callback: AsyncCallback&lt;string&gt;): void
P
panqiangbiao 已提交
270

P
panqiangbiao 已提交
271
获取公共目录路径,使用callback方式返回结果。
P
panqiangbiao 已提交
272 273 274 275 276

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

Z
zengyawen 已提交
277 278 279 280
| 参数名   | 类型                             | 必填 | 说明                      |
| -------- | -------------------------------- | ---- | ------------------------- |
| type     | [DirectoryType](#directorytype8) | 是   | 公共目录类型              |
| callback | AsyncCallback&lt;string&gt;      | 是   | callback 返回公共目录路径 |
P
panqiangbiao 已提交
281 282 283 284 285

**示例:**

```
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
P
panqiangbiao 已提交
286
media.getPublicDirectory(DIR_CAMERA, (err, dicResult) => {
P
panqiangbiao 已提交
287
    if (dicResult == 'Camera/') {
P
panqiangbiao 已提交
288
        console.info('mediaLibraryTest : getPublicDirectory passed');
P
panqiangbiao 已提交
289
    } else {
P
panqiangbiao 已提交
290
        console.info('mediaLibraryTest : getPublicDirectory failed');
P
panqiangbiao 已提交
291 292 293 294
    }
});
```

P
panqiangbiao 已提交
295
### getPublicDirectory<sup>8+</sup>
P
panqiangbiao 已提交
296

P
panqiangbiao 已提交
297
getPublicDirectory(type: DirectoryType): Promise&lt;string&gt;
P
panqiangbiao 已提交
298

P
panqiangbiao 已提交
299
获取公共目录路径,使用Promise方式返回结果。
P
panqiangbiao 已提交
300 301 302 303 304

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

Z
zengyawen 已提交
305 306 307
| 参数名 | 类型                             | 必填 | 说明         |
| ------ | -------------------------------- | ---- | ------------ |
| type   | [DirectoryType](#directorytype8) | 是   | 公共目录类型 |
P
panqiangbiao 已提交
308 309 310

**返回值:**

Z
zengyawen 已提交
311 312 313
| 类型             | 说明             |
| ---------------- | ---------------- |
| Promise\<string> | 返回公共目录路径 |
P
panqiangbiao 已提交
314 315 316 317

**示例:**

```
P
panqiangbiao 已提交
318
async function example() {
P
panqiangbiao 已提交
319 320
    let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
    const dicResult = await media.getPublicDirectory(DIR_CAMERA);
P
panqiangbiao 已提交
321
    if (dicResult == 'Camera/') {
P
panqiangbiao 已提交
322 323 324 325
        console.info('MediaLibraryTest : getPublicDirectory');
    } else {
        console.info('MediaLibraryTest : getPublicDirectory failed');
    }
P
panqiangbiao 已提交
326 327 328
}
```

Z
zengyawen 已提交
329
### getAlbums<sup>7+</sup>
P
panqiangbiao 已提交
330

P
panqiangbiao 已提交
331
getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array&lt;Album&gt;>): void
P
panqiangbiao 已提交
332

P
panqiangbiao 已提交
333
获取相册列表,使用callback 方式返回结果。
P
panqiangbiao 已提交
334

P
panqiangbiao 已提交
335
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
336

P
panqiangbiao 已提交
337
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
338

P
panqiangbiao 已提交
339 340
**参数**

Z
zengyawen 已提交
341 342 343 344
| 参数名   | 类型                                         | 必填 | 说明                        |
| -------- | -------------------------------------------- | ---- | --------------------------- |
| options  | [MediaFetchOptions](#mediafetchoptions7)     | 是   | 相册获取条件                |
| callback | AsyncCallback&lt;Array<[Album](#album7)>&gt; | 是   | 异步获取Album列表之后的回调 |
P
panqiangbiao 已提交
345 346 347 348

**示例:**

```
P
panqiangbiao 已提交
349 350 351 352
let AlbumNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
};
潘强标 已提交
353
media.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => {
P
panqiangbiao 已提交
354 355 356 357 358 359 360
    if (albumList != undefined) {
        const album = albumList[0];
        console.info('album.albumName = ' + album.albumName);
        console.info('album.count = ' + album.count);
     } else {
        console.info('getAlbum fail, message = ' + err);
     }
P
panqiangbiao 已提交
361
})
P
panqiangbiao 已提交
362 363
```

Z
zengyawen 已提交
364
### getAlbums<sup>7+</sup>
P
panqiangbiao 已提交
365

P
panqiangbiao 已提交
366
getAlbums(options: MediaFetchOptions): Promise<Array&lt;Album&gt;>
P
panqiangbiao 已提交
367

P
panqiangbiao 已提交
368
获取相册列表,使用 promise 方式返回结果。
P
panqiangbiao 已提交
369

P
panqiangbiao 已提交
370
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
371

P
panqiangbiao 已提交
372
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
373

P
panqiangbiao 已提交
374 375
**参数:**

Z
zengyawen 已提交
376 377 378
| 参数名  | 类型                                     | 必填 | 说明         |
| ------- | ---------------------------------------- | ---- | ------------ |
| options | [MediaFetchOptions](#mediafetchoptions7) | 是   | 相册获取条件 |
P
panqiangbiao 已提交
379 380 381

**返回值:**

Z
zengyawen 已提交
382 383 384
| 类型                             | 说明          |
| -------------------------------- | ------------- |
| Promise<Array<[Album](#album7)>> | 返回Album列表 |
P
panqiangbiao 已提交
385 386 387 388

**示例:**

```
P
panqiangbiao 已提交
389 390 391 392
let AlbumNoArgsfetchOp = {
    selections: '',
    selectionArgs: [],
};
潘强标 已提交
393
media.getAlbums(AlbumNoArgsfetchOp).then(function(albumList){
P
panqiangbiao 已提交
394 395 396 397
    console.info("getAlbums successfully:"+ JSON.stringify(albumList));
}).catch(function(err){
    console.info("getAlbums failed with error:"+ err);
});
P
panqiangbiao 已提交
398 399
```

P
panqiangbiao 已提交
400
### release<sup>8+</sup>
P
panqiangbiao 已提交
401

P
panqiangbiao 已提交
402
release(callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
403

P
panqiangbiao 已提交
404 405
释放MediaLibrary实例。
当后续不需要使用MediaLibrary实例中的方法时调用。
P
panqiangbiao 已提交
406

P
panqiangbiao 已提交
407
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
408

P
panqiangbiao 已提交
409 410
**参数:**

H
HelloCrease 已提交
411 412 413
| 参数名      | 类型                        | 必填   | 说明         |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是    | 回调表示成功还是失败 |
P
panqiangbiao 已提交
414 415 416 417

**示例:**

```
P
panqiangbiao 已提交
418
var media = mediaLibrary.getMediaLibrary(context);
P
panqiangbiao 已提交
419
media.release((err) => {
P
panqiangbiao 已提交
420
    // do something
P
panqiangbiao 已提交
421
});
P
panqiangbiao 已提交
422 423
```

P
panqiangbiao 已提交
424
### release<sup>8+</sup>
P
panqiangbiao 已提交
425

P
panqiangbiao 已提交
426
release(): Promise&lt;void&gt;
P
panqiangbiao 已提交
427

P
panqiangbiao 已提交
428 429
释放MediaLibrary实例。
当后续不需要使用MediaLibrary实例中的方法时调用。
P
panqiangbiao 已提交
430

P
panqiangbiao 已提交
431
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
432

P
panqiangbiao 已提交
433 434
**返回值:**

H
HelloCrease 已提交
435 436
| 类型                  | 说明                   |
| ------------------- | -------------------- |
P
panqiangbiao 已提交
437
| Promise&lt;void&gt; | Promise实例,用于获取异步返回结果 |
P
panqiangbiao 已提交
438 439 440 441

**示例:**

```
P
panqiangbiao 已提交
442
media.release()
P
panqiangbiao 已提交
443 444
```

Z
update  
zengyawen 已提交
445
### storeMediaAsset<sup>(deprecated)</sup>
P
panqiangbiao 已提交
446 447 448 449 450

storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback&lt;string&gt;): void

保存媒体资源,以异步方法获取保存成功的URI,使用callback形式返回结果。

Z
update  
zengyawen 已提交
451
> **说明**: 从API Version 9开始废弃。
P
panqiangbiao 已提交
452 453 454 455 456

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
457 458 459 460
| 参数名      | 类型                                    | 必填   | 说明                      |
| -------- | ------------------------------------- | ---- | ----------------------- |
| option   | [MediaAssetOption](#mediaassetoption) | 是    | 媒体资源选项。                 |
| callback | AsyncCallback&lt;string&gt;           | 是    | 媒体资源保存回调,返回保存成功后得到的URI。 |
P
panqiangbiao 已提交
461 462 463 464 465

**示例:**

  ```
let option = {
潘强标 已提交
466 467 468
    src : "/data/storage/el2/base/haps/entry/image.png",
    mimeType : "image/*",
    relativePath : "Pictures/"
P
panqiangbiao 已提交
469 470 471 472 473 474 475 476 477 478 479 480
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => {
    if (err) {
        console.log("An error occurred when storing media resources.");
        return;
    }
    console.log("Media resources stored. ");
    // Obtain the URI that stores media resources.
});
  ```


Z
update  
zengyawen 已提交
481
### storeMediaAsset<sup>(deprecated)</sup>
P
panqiangbiao 已提交
482 483 484 485 486

storeMediaAsset(option: MediaAssetOption): Promise&lt;string&gt;

保存媒体资源,以异步方法获取保存成功的URI,使用Promise形式返回结果。

Z
update  
zengyawen 已提交
487
> **说明**: 从API Version 9开始废弃。
P
panqiangbiao 已提交
488 489 490 491 492

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
493 494 495
| 参数名    | 类型                                    | 必填   | 说明      |
| ------ | ------------------------------------- | ---- | ------- |
| option | [MediaAssetOption](#mediaassetoption) | 是    | 媒体资源选项。 |
P
panqiangbiao 已提交
496 497 498

**返回值:**

H
HelloCrease 已提交
499 500
| 类型                    | 说明                           |
| --------------------- | ---------------------------- |
P
panqiangbiao 已提交
501 502 503 504 505 506
| Promise&lt;string&gt; | Promise实例,用于异步获取保存成功后得到的URI。 |

**示例:**

  ```
let option = {
潘强标 已提交
507 508 509
    src : "/data/storage/el2/base/haps/entry/image.png",
    mimeType : "image/*",
    relativePath : "Pictures/"
P
panqiangbiao 已提交
510 511 512 513 514 515 516 517 518 519
};
mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
    console.log("Media resources stored.");
    // Obtain the URI that stores media resources.
}).catch((err) => {
    console.log("An error occurred when storing media resources.");
});
  ```


Z
update  
zengyawen 已提交
520
### startImagePreview<sup>(deprecated)</sup>
P
panqiangbiao 已提交
521 522 523 524 525

startImagePreview(images: Array&lt;string&gt;, index: number, callback: AsyncCallback&lt;void&gt;): void

启动图片预览界面并限定预览开始显示的图片。可以预览指定序号的单张本地图片(dataability://),也可以预览列表中的所有网络图片(https://)。使用callback方式进行异步回调。

526
> **说明**: <br/>从API Version 9开始废弃。建议使用[Image组件](../arkui-ts/ts-basic-components-image.md)替代。<br/>Image组件,可用于本地图片和网络图片的渲染展示。
P
panqiangbiao 已提交
527 528 529 530 531

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
532 533 534 535 536
| 参数名      | 类型                        | 必填   | 说明                                       |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| images   | Array&lt;string&gt;       | 是    | 预览的图片URI("https://","dataability://")列表。 |
| index    | number                    | 是    | 开始显示的图片序号。                               |
| callback | AsyncCallback&lt;void&gt; | 是    | 图片预览回调,失败时返回错误信息。                        |
P
panqiangbiao 已提交
537 538 539 540 541

**示例:**

  ```
let images = [
潘强标 已提交
542 543
    "dataability:///media/xxxx/2",
    "dataability:///media/xxxx/3"
P
panqiangbiao 已提交
544
];
H
HelloCrease 已提交
545
/* 网络图片使用方式
P
panqiangbiao 已提交
546 547 548 549
let images = [
    "https://media.xxxx.com/image1.jpg",
    "https://media.xxxx.com/image2.jpg"
];
H
HelloCrease 已提交
550
*/
P
panqiangbiao 已提交
551 552 553 554 555 556 557 558 559 560 561
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => {
    if (err) {
        console.log("An error occurred when previewing the images.");
        return;
    }
    console.log("Succeeded in previewing the images.");
});
  ```


Z
update  
zengyawen 已提交
562
### startImagePreview<sup>(deprecated)</sup>
P
panqiangbiao 已提交
563 564 565 566 567

startImagePreview(images: Array&lt;string&gt;, callback: AsyncCallback&lt;void&gt;): void

启动图片预览界面,可以预览列表中首张本地图片(dataability://),也可以预览列表中的所有网络图片(https://)。使用callback方式进行异步回调。

568
> **说明**: <br/>从API Version 9开始废弃。建议使用[Image组件](../arkui-ts/ts-basic-components-image.md)替代。<br/>Image组件,可用于本地图片和网络图片的渲染展示。
P
panqiangbiao 已提交
569 570 571 572 573

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
574 575 576 577
| 参数名      | 类型                        | 必填   | 说明                                       |
| -------- | ------------------------- | ---- | ---------------------------------------- |
| images   | Array&lt;string&gt;       | 是    | 预览的图片URI("https://","dataability://")列表。 |
| callback | AsyncCallback&lt;void&gt; | 是    | 图片预览回调,失败时返回错误信息。                        |
P
panqiangbiao 已提交
578 579 580 581 582

**示例:**

  ```
let images = [
潘强标 已提交
583 584
    "dataability:///media/xxxx/2",
    "dataability:///media/xxxx/3"
P
panqiangbiao 已提交
585
];
H
HelloCrease 已提交
586
/* 网络图片使用方式
P
panqiangbiao 已提交
587 588 589 590
let images = [
    "https://media.xxxx.com/image1.jpg",
    "https://media.xxxx.com/image2.jpg"
];
H
HelloCrease 已提交
591
*/
P
panqiangbiao 已提交
592 593 594 595 596 597 598 599 600 601
mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => {
    if (err) {
        console.log("An error occurred when previewing the images.");
        return;
    }
    console.log("Succeeded in previewing the images.");
});
  ```


Z
update  
zengyawen 已提交
602
### startImagePreview<sup>(deprecated)</sup>
P
panqiangbiao 已提交
603 604 605 606 607

startImagePreview(images: Array&lt;string&gt;, index?: number): Promise&lt;void&gt;

启动图片预览界面并限定预览开始显示的图片。可以预览指定序号的单张本地图片(dataability://),也可以预览列表中的所有网络图片(https://)。使用Promise方式进行异步回调。

608
> **说明**: <br/>从API Version 9开始废弃。建议使用[Image组件](../arkui-ts/ts-basic-components-image.md)替代。<br/>Image组件,可用于本地图片和网络图片的渲染展示。
P
panqiangbiao 已提交
609 610 611 612 613

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
614 615 616 617
| 参数名    | 类型                  | 必填   | 说明                                       |
| ------ | ------------------- | ---- | ---------------------------------------- |
| images | Array&lt;string&gt; | 是    | 预览的图片URI("https://","dataability://")列表。 |
| index  | number              | 否    | 开始显示的图片序号,不选择时默认为0。                      |
P
panqiangbiao 已提交
618 619 620

**返回值:**

H
HelloCrease 已提交
621 622
| 类型                  | 说明                              |
| ------------------- | ------------------------------- |
P
panqiangbiao 已提交
623 624 625 626 627 628
| Promise&lt;void&gt; | Promise实例,用于异步获取预览结果,失败时返回错误信息。 |

**示例:**

  ```
let images = [
潘强标 已提交
629 630
    "dataability:///media/xxxx/2",
    "dataability:///media/xxxx/3"
P
panqiangbiao 已提交
631
];
H
HelloCrease 已提交
632
/* 网络图片使用方式
P
panqiangbiao 已提交
633 634 635 636
let images = [
    "https://media.xxxx.com/image1.jpg",
    "https://media.xxxx.com/image2.jpg"
];
H
HelloCrease 已提交
637
*/
P
panqiangbiao 已提交
638 639 640 641 642 643 644 645 646
let index = 1;
mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
    console.log("Succeeded in previewing the images.");
}).catch((err) => {
    console.log("An error occurred when previewing the images.");
});
  ```


Z
update  
zengyawen 已提交
647
### startMediaSelect<sup>(deprecated)</sup>
P
panqiangbiao 已提交
648 649 650 651 652

startMediaSelect(option: MediaSelectOption, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void

启动媒体选择界面,以异步方法获取选择的媒体URI列表,使用callback形式返回结果。

653
> **说明**: <br/>从API Version 9开始废弃。建议使用系统应用图库替代。图库是系统内置的可视资源访问应用,提供图片和视频的管理、浏览等功能,使用方法请参考[OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos#4-%E5%85%B8%E5%9E%8B%E6%8E%A5%E5%8F%A3%E7%9A%84%E4%BD%BF%E7%94%A8)。
P
panqiangbiao 已提交
654 655 656 657 658

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
659 660 661 662
| 参数名      | 类型                                       | 必填   | 说明                                   |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| option   | [MediaSelectOption](#mediaselectoption)  | 是    | 媒体选择选项。                              |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 媒体选择回调,返回选择的媒体URI(dataability://)列表。 |
P
panqiangbiao 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681

**示例:**

  ```
let option = {
    type : "image",
    count : 2
};
mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => {
    if (err) {
        console.log("An error occurred when selecting media resources.");
        return;
    }
    console.log("Media resources selected.");
    // Obtain the media selection value.
});
  ```


Z
update  
zengyawen 已提交
682
### startMediaSelect<sup>(deprecated)</sup>
P
panqiangbiao 已提交
683 684 685 686 687

startMediaSelect(option: MediaSelectOption): Promise&lt;Array&lt;string&gt;&gt;

启动媒体选择界面,以异步方法获取选择的媒体URI列表,使用Promise形式返回结果。

688
> **说明**: <br/>从API Version 9开始废弃。建议使用系统应用图库替代。图库是系统内置的可视资源访问应用,提供图片和视频的管理、浏览等功能,使用方法请参考[OpenHarmony/applications_photos](https://gitee.com/openharmony/applications_photos#4-%E5%85%B8%E5%9E%8B%E6%8E%A5%E5%8F%A3%E7%9A%84%E4%BD%BF%E7%94%A8)。
P
panqiangbiao 已提交
689 690 691 692 693

**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core

**参数:**

H
HelloCrease 已提交
694 695 696
| 参数名    | 类型                                      | 必填   | 说明      |
| ------ | --------------------------------------- | ---- | ------- |
| option | [MediaSelectOption](#mediaselectoption) | 是    | 媒体选择选项。 |
P
panqiangbiao 已提交
697 698 699

**返回值:**

H
HelloCrease 已提交
700 701
| 类型                                 | 说明                                       |
| ---------------------------------- | ---------------------------------------- |
P
panqiangbiao 已提交
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
| Promise&lt;Array&lt;string&gt;&gt; | Promise实例,用于异步获取选择的媒体URI(dataability://)列表。 |

**示例:**

  ```
let option = {
    type : "image",
    count : 2
};
mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
    console.log("Media resources selected.");
    // Obtain the media selection value.
}).catch((err) => {
    console.log("An error occurred when selecting media resources.");
});

  ```

Z
zengyawen 已提交
720
## FileAsset<sup>7+</sup>
P
panqiangbiao 已提交
721 722 723

提供封装文件属性的方法。

Z
zengyawen 已提交
724 725 726
### 属性

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
727

Z
zengyawen 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
| 名称                      | 类型                     | 可读 | 可写 | 说明                                                   |
| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ |
| id                        | number                   | 是   | 否   | 文件资源编号                                           |
| uri                       | string                   | 是   | 否   | 文件资源uri(如:dataability:///media/image/2)         |
| mimeType                  | string                   | 是   | 否   | 文件扩展属性                                           |
| mediaType<sup>8+</sup>    | [MediaType](#mediatype8) | 是   | 否   | 媒体类型                                               |
| displayName               | string                   | 是   | 是   | 显示文件名,包含后缀名                                 |
| title                     | string                   | 是   | 是   | 文件标题                                               |
| relativePath<sup>8+</sup> | string                   | 是   | 是   | 相对公共目录路径                                       |
| parent<sup>8+</sup>       | number                   | 是   | 否   | 父目录id                                               |
| size                      | number                   | 是   | 否   | 文件大小(单位:字节)                                 |
| dateAdded                 | number                   | 是   | 否   | 添加日期(添加文件时间到1970年1月1日的秒数值)         |
| dateModified              | number                   | 是   | 否   | 修改日期(修改文件时间到1970年1月1日的秒数值)         |
| dateTaken                 | number                   | 是   | 否   | 拍摄日期(文件拍照时间到1970年1月1日的秒数值)         |
| artist<sup>8+</sup>       | string                   | 是   | 否   | 作者                                                   |
| audioAlbum<sup>8+</sup>   | string                   | 是   | 否   | 专辑                                                   |
| width                     | number                   | 是   | 否   | 图片宽度(单位:像素)                                 |
| height                    | number                   | 是   | 否   | 图片高度(单位:像素)                                 |
| orientation               | number                   | 是   | 是   | 图片显示方向(顺时针旋转角度,如0,90,180  单位:度) |
| duration<sup>8+</sup>     | number                   | 是   | 否   | 持续时间(单位:秒)                                   |
| albumId                   | number                   | 是   | 否   | 文件所归属的相册编号                                   |
| albumUri<sup>8+</sup>     | string                   | 是   | 否   | 文件所归属相册uri                                      |
| albumName                 | string                   | 是   | 否   | 文件所归属相册名称                                     |
P
panqiangbiao 已提交
751 752 753


### isDirectory<sup>8+</sup>
P
panqiangbiao 已提交
754

P
panqiangbiao 已提交
755
isDirectory(callback: AsyncCallback&lt;boolean&gt;): void
P
panqiangbiao 已提交
756 757 758

判断fileAsset是否为目录,使用callback方式返回异步结果。

P
panqiangbiao 已提交
759
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
760

P
panqiangbiao 已提交
761
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
762

P
panqiangbiao 已提交
763 764
**参数:**

H
HelloCrease 已提交
765 766 767
| 参数名      | 类型                           | 必填   | 说明                  |
| -------- | ---------------------------- | ---- | ------------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是    | 当前FileAsset是否是目录的回调 |
P
panqiangbiao 已提交
768 769 770 771

**示例:**

```
P
panqiangbiao 已提交
772
async function example() {
P
panqiangbiao 已提交
773 774 775 776
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
777 778
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
779 780 781 782 783 784 785
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isDirectory((err, isDirectory) => {
        // do something
    });
}
P
panqiangbiao 已提交
786 787
```

P
panqiangbiao 已提交
788
### isDirectory<sup>8+</sup>
P
panqiangbiao 已提交
789

P
panqiangbiao 已提交
790
isDirectory():Promise&lt;boolean&gt;
P
panqiangbiao 已提交
791 792 793

判断fileAsset是否为目录,使用Promise方式返回异步结果。

P
panqiangbiao 已提交
794
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
795

P
panqiangbiao 已提交
796
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
797

P
panqiangbiao 已提交
798 799
**返回值:**

H
HelloCrease 已提交
800 801
| 类型                     | 说明                           |
| ---------------------- | ---------------------------- |
P
panqiangbiao 已提交
802
| Promise&lt;boolean&gt; | Promise实例,返回当前FileAsset是否是目录 |
P
panqiangbiao 已提交
803 804 805 806

**示例:**

```
P
panqiangbiao 已提交
807
async function example() {
P
panqiangbiao 已提交
808 809 810 811
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
812 813
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
814 815 816 817 818 819 820 821 822
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isDirectory().then(function(isDirectory){
        console.info("isDirectory result:"+ isDirectory);
    }).catch(function(err){
        console.info("isDirectory failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
823 824
```

P
panqiangbiao 已提交
825
### commitModify<sup>8+</sup>
P
panqiangbiao 已提交
826

P
panqiangbiao 已提交
827
commitModify(callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
828 829 830

修改文件的元数据,使用callback方式返回异步结果。

P
panqiangbiao 已提交
831
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
832

P
panqiangbiao 已提交
833
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
834

P
panqiangbiao 已提交
835 836
**参数:**

H
HelloCrease 已提交
837 838 839
| 参数名      | 类型                        | 必填   | 说明    |
| -------- | ------------------------- | ---- | ----- |
| callback | AsyncCallback&lt;void&gt; | 是    | 回调返回空 |
P
panqiangbiao 已提交
840 841 842 843

**示例:**

```
P
panqiangbiao 已提交
844
async function example() {
P
panqiangbiao 已提交
845 846 847 848
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
849 850
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
851 852 853
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
P
panqiangbiao 已提交
854
    asset.title = 'newtitle';
P
panqiangbiao 已提交
855 856
    asset.commitModify(() => {
        console.info('commitModify success');   
P
panqiangbiao 已提交
857
    });
P
panqiangbiao 已提交
858
}
P
panqiangbiao 已提交
859 860
```

P
panqiangbiao 已提交
861
### commitModify<sup>8+</sup>
P
panqiangbiao 已提交
862

P
panqiangbiao 已提交
863
commitModify(): Promise&lt;void&gt;
P
panqiangbiao 已提交
864 865 866

修改文件的元数据,使用promise方式返回异步结果。

P
panqiangbiao 已提交
867
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
868

P
panqiangbiao 已提交
869
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
870

P
panqiangbiao 已提交
871 872
**返回值:**

H
HelloCrease 已提交
873 874
| 类型                  | 说明         |
| ------------------- | ---------- |
P
panqiangbiao 已提交
875
| Promise&lt;void&gt; | Promise返回空 |
P
panqiangbiao 已提交
876 877 878 879

**示例:**

```
P
panqiangbiao 已提交
880
async function example() {
P
panqiangbiao 已提交
881 882 883 884
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
885 886
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
887 888 889
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
P
panqiangbiao 已提交
890
    asset.title = 'newtitle';
P
panqiangbiao 已提交
891 892
    asset.commitModify();
}
P
panqiangbiao 已提交
893 894
```

P
panqiangbiao 已提交
895
### open<sup>8+</sup>
P
panqiangbiao 已提交
896

P
panqiangbiao 已提交
897
open(mode: string, callback: AsyncCallback&lt;number&gt;): void
P
panqiangbiao 已提交
898 899 900

打开当前文件,使用callback方式返回异步结果。

潘强标 已提交
901 902
**注意**:当前写操作是互斥的操作,写操作完成后需要调用close进行释放

P
panqiangbiao 已提交
903
**需要权限**:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA('w'模式打开)
P
panqiangbiao 已提交
904

P
panqiangbiao 已提交
905
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
906

P
panqiangbiao 已提交
907 908
**参数**

H
HelloCrease 已提交
909 910 911 912
| 参数名      | 类型                          | 必填   | 说明                                  |
| -------- | --------------------------- | ---- | ----------------------------------- |
| mode     | string                      | 是    | 打开文件方式,如:'r'(只读), 'w'(只写), 'rw'(读写) |
| callback | AsyncCallback&lt;number&gt; | 是    | 回调返回文件句柄                            |
P
panqiangbiao 已提交
913 914 915 916

**示例:**

```
P
panqiangbiao 已提交
917
async function example() {
P
panqiangbiao 已提交
918
    let mediaType = mediaLibrary.MediaType.IMAGE;
P
panqiangbiao 已提交
919 920
    let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
    const path = await media.getPublicDirectory(DIR_IMAGE);
P
panqiangbiao 已提交
921 922 923 924 925 926 927 928 929
    asset = await media.createAsset(mediaType, "image00003.jpg", path);
    asset.open('rw', (openError, fd) => {
            if(fd > 0){
                asset.close(fd);
            }else{
                console.info('File Open Failed!' + openError);
            }
    });
}
P
panqiangbiao 已提交
930 931
```

P
panqiangbiao 已提交
932
### open<sup>8+</sup>
P
panqiangbiao 已提交
933

P
panqiangbiao 已提交
934
open(mode: string): Promise&lt;number&gt;
P
panqiangbiao 已提交
935 936 937

打开当前文件,使用promise方式返回异步结果。

潘强标 已提交
938 939
**注意**:当前写操作是互斥的操作,写操作完成后需要调用close进行释放

P
panqiangbiao 已提交
940
**需要权限**:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA('w'模式打开)
P
panqiangbiao 已提交
941

P
panqiangbiao 已提交
942
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
943

P
panqiangbiao 已提交
944 945
**参数:**

H
HelloCrease 已提交
946 947 948
| 参数名  | 类型     | 必填   | 说明                                  |
| ---- | ------ | ---- | ----------------------------------- |
| mode | string | 是    | 打开文件方式,如:'r'(只读), 'w'(只写), 'rw'(读写) |
P
panqiangbiao 已提交
949 950 951

**返回值:**

H
HelloCrease 已提交
952 953
| 类型                    | 说明            |
| --------------------- | ------------- |
P
panqiangbiao 已提交
954
| Promise&lt;number&gt; | Promise返回文件句柄 |
P
panqiangbiao 已提交
955 956 957 958

**示例:**

```
P
panqiangbiao 已提交
959
async function example() {
P
panqiangbiao 已提交
960
    let mediaType = mediaLibrary.MediaType.IMAGE;
P
panqiangbiao 已提交
961 962
    let DIR_IMAGE = mediaLibrary.DirectoryType.DIR_IMAGE;
    const path = await media.getPublicDirectory(DIR_IMAGE);
P
panqiangbiao 已提交
963
    asset = await media.createAsset(mediaType, "image00003.jpg", path);
P
panqiangbiao 已提交
964 965 966 967 968 969 970
    asset.open('rw')
        .then((fd) => {
            console.info('File fd!' + fd);
        })
        .catch((err) => {
            console.info('File err!' + err);
        });
P
panqiangbiao 已提交
971
}
P
panqiangbiao 已提交
972 973
```

P
panqiangbiao 已提交
974
### close<sup>8+</sup>
P
panqiangbiao 已提交
975

P
panqiangbiao 已提交
976
close(fd: number, callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
977 978 979

关闭当前文件,使用callback方式返回异步结果。

P
panqiangbiao 已提交
980
**需要权限**:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA('w'模式打开)
P
panqiangbiao 已提交
981

P
panqiangbiao 已提交
982
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
983

P
panqiangbiao 已提交
984 985
**参数:**

H
HelloCrease 已提交
986 987 988 989
| 参数名      | 类型                        | 必填   | 说明    |
| -------- | ------------------------- | ---- | ----- |
| fd       | number                    | 是    | 文件描述符 |
| callback | AsyncCallback&lt;void&gt; | 是    | 回调返回空 |
P
panqiangbiao 已提交
990 991 992 993

**示例:**

```
P
panqiangbiao 已提交
994
async function example() {
P
panqiangbiao 已提交
995 996 997 998
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
999 1000
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1001 1002 1003 1004 1005
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.close(fd, (closeErr) => {
        if (closeErr != undefined) {
P
panqiangbiao 已提交
1006 1007
            console.info('mediaLibraryTest : close : FAIL ' + closeErr.message);
            console.info('mediaLibraryTest : ASSET_CALLBACK : FAIL');
P
panqiangbiao 已提交
1008 1009 1010 1011 1012
        } else {
            console.info("=======asset.close success====>");
        }
    });
}
P
panqiangbiao 已提交
1013 1014
```

P
panqiangbiao 已提交
1015
### close<sup>8+</sup>
P
panqiangbiao 已提交
1016

P
panqiangbiao 已提交
1017
close(fd: number): Promise&lt;void&gt;
P
panqiangbiao 已提交
1018 1019 1020

关闭当前文件,使用promise方式返回异步结果。

P
panqiangbiao 已提交
1021
**需要权限**:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA('w'模式打开)
P
panqiangbiao 已提交
1022

P
panqiangbiao 已提交
1023
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1024

P
panqiangbiao 已提交
1025 1026
**参数:**

H
HelloCrease 已提交
1027 1028 1029
| 参数名  | 类型     | 必填   | 说明    |
| ---- | ------ | ---- | ----- |
| fd   | number | 是    | 文件描述符 |
P
panqiangbiao 已提交
1030 1031 1032

**返回值:**

H
HelloCrease 已提交
1033 1034
| 类型                  | 说明         |
| ------------------- | ---------- |
P
panqiangbiao 已提交
1035
| Promise&lt;void&gt; | Promise返回空 |
P
panqiangbiao 已提交
1036 1037 1038 1039

**示例:**

```
P
panqiangbiao 已提交
1040
async function example() {
P
panqiangbiao 已提交
1041 1042 1043 1044
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1045 1046
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1047 1048 1049 1050 1051
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.close(fd).then((closeErr) => {
        if (closeErr != undefined) {
P
panqiangbiao 已提交
1052 1053
            console.info('mediaLibraryTest : close : FAIL ' + closeErr.message);
            console.info('mediaLibraryTest : ASSET_CALLBACK : FAIL');
P
panqiangbiao 已提交
1054 1055 1056 1057 1058 1059

        } else {
            console.info("=======asset.close success====>");
        }
    });
}
P
panqiangbiao 已提交
1060 1061
```

P
panqiangbiao 已提交
1062
### getThumbnail<sup>8+</sup>
P
panqiangbiao 已提交
1063

P
panqiangbiao 已提交
1064
getThumbnail(callback: AsyncCallback&lt;image.PixelMap&gt;): void
P
panqiangbiao 已提交
1065 1066 1067

获取文件的缩略图,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1068
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1069

P
panqiangbiao 已提交
1070
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1071

P
panqiangbiao 已提交
1072 1073
**参数:**

H
HelloCrease 已提交
1074 1075 1076
| 参数名      | 类型                                  | 必填   | 说明               |
| -------- | ----------------------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;image.PixelMap&gt; | 是    | 回调返回缩略图的PixelMap |
P
panqiangbiao 已提交
1077 1078 1079 1080

**示例:**

```
P
panqiangbiao 已提交
1081
async function example() {
P
panqiangbiao 已提交
1082 1083 1084 1085
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1086 1087
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1088 1089 1090 1091
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.getThumbnail((err, pixelmap) => {
P
panqiangbiao 已提交
1092
        console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap);
P
panqiangbiao 已提交
1093 1094
    });
}
P
panqiangbiao 已提交
1095 1096
```

P
panqiangbiao 已提交
1097
### getThumbnail<sup>8+</sup>
P
panqiangbiao 已提交
1098

P
panqiangbiao 已提交
1099
getThumbnail(size: Size, callback: AsyncCallback&lt;image.PixelMap&gt;): void
P
panqiangbiao 已提交
1100 1101 1102

获取文件的缩略图,传入缩略图尺寸,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1103
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1104

P
panqiangbiao 已提交
1105
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1106

P
panqiangbiao 已提交
1107 1108
**参数:**

H
HelloCrease 已提交
1109 1110 1111 1112
| 参数名      | 类型                                  | 必填   | 说明               |
| -------- | ----------------------------------- | ---- | ---------------- |
| size     | [Size](#size8)                      | 是    | 缩略图尺寸            |
| callback | AsyncCallback&lt;image.PixelMap&gt; | 是    | 回调返回缩略图的PixelMap |
P
panqiangbiao 已提交
1113 1114 1115 1116

**示例:**

```
P
panqiangbiao 已提交
1117
async function example() {
P
panqiangbiao 已提交
1118 1119 1120 1121
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1122 1123
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1124 1125 1126 1127
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.getThumbnail(size, (err, pixelmap) => {
P
panqiangbiao 已提交
1128
        console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap);
P
panqiangbiao 已提交
1129 1130
    });
}
P
panqiangbiao 已提交
1131 1132
```

P
panqiangbiao 已提交
1133
### getThumbnail<sup>8+</sup>
P
panqiangbiao 已提交
1134

P
panqiangbiao 已提交
1135
getThumbnail(size?: Size): Promise&lt;image.PixelMap&gt;
P
panqiangbiao 已提交
1136 1137 1138

获取文件的缩略图,传入缩略图尺寸,使用promise方式返回异步结果。

P
panqiangbiao 已提交
1139
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1140

P
panqiangbiao 已提交
1141
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1142

P
panqiangbiao 已提交
1143 1144
**参数:**

H
HelloCrease 已提交
1145 1146 1147
| 参数名  | 类型             | 必填   | 说明    |
| ---- | -------------- | ---- | ----- |
| size | [Size](#size8) | 否    | 缩略图尺寸 |
P
panqiangbiao 已提交
1148 1149 1150

**返回值:**

H
HelloCrease 已提交
1151 1152
| 类型                            | 说明                    |
| ----------------------------- | --------------------- |
P
panqiangbiao 已提交
1153
| Promise&lt;image.PixelMap&gt; | Promise返回缩略图的PixelMap |
P
panqiangbiao 已提交
1154 1155 1156 1157

**示例:**

```
P
panqiangbiao 已提交
1158
async function example() {
P
panqiangbiao 已提交
1159 1160
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
潘强标 已提交
1161 1162 1163 1164
        selections: fileKeyObj.MEDIA_TYPE + '= ?',
        selectionArgs: [imageType.toString()],
        order: fileKeyObj.DATE_ADDED + " DESC",
        extendArgs: "",
P
panqiangbiao 已提交
1165 1166 1167
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
潘强标 已提交
1168 1169
    asset.getThumbnail(size)
    .then((pixelmap) => {
P
panqiangbiao 已提交
1170
        console.info('mediaLibraryTest : getThumbnail Successfull '+ pixelmap);
潘强标 已提交
1171 1172 1173
    })
    .catch((err) => {
        console.info('mediaLibraryTest : getThumbnail fail'+ err);
P
panqiangbiao 已提交
1174 1175
    });
}
P
panqiangbiao 已提交
1176 1177
```

P
panqiangbiao 已提交
1178
### favorite<sup>8+</sup>
P
panqiangbiao 已提交
1179

P
panqiangbiao 已提交
1180
favorite(isFavorite: boolean, callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
1181 1182 1183

将文件设置为收藏文件,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1184
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
1185

P
panqiangbiao 已提交
1186
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1187

P
panqiangbiao 已提交
1188 1189
**参数:**

H
HelloCrease 已提交
1190 1191 1192 1193
| 参数名        | 类型                        | 必填   | 说明                                 |
| ---------- | ------------------------- | ---- | ---------------------------------- |
| isFavorite | boolean                   | 是    | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏 |
| callback   | AsyncCallback&lt;void&gt; | 是    | 回调返回空                              |
P
panqiangbiao 已提交
1194 1195 1196 1197

**示例:**

```
P
panqiangbiao 已提交
1198
async function example() {
P
panqiangbiao 已提交
1199 1200 1201 1202
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1203 1204
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1205 1206 1207 1208 1209 1210 1211
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.favorite(true,function(err){
        // do something
    });
}
P
panqiangbiao 已提交
1212 1213
```

P
panqiangbiao 已提交
1214
### favorite<sup>8+</sup>
P
panqiangbiao 已提交
1215

P
panqiangbiao 已提交
1216
favorite(isFavorite: boolean): Promise&lt;void&gt;
P
panqiangbiao 已提交
1217 1218 1219

将文件设置为收藏文件,使用promise方式返回异步结果。

P
panqiangbiao 已提交
1220
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
1221

P
panqiangbiao 已提交
1222
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1223

P
panqiangbiao 已提交
1224 1225
**参数:**

H
HelloCrease 已提交
1226 1227 1228
| 参数名        | 类型      | 必填   | 说明                                 |
| ---------- | ------- | ---- | ---------------------------------- |
| isFavorite | boolean | 是    | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏 |
P
panqiangbiao 已提交
1229 1230 1231

**返回值:**

H
HelloCrease 已提交
1232 1233
| 类型                  | 说明         |
| ------------------- | ---------- |
P
panqiangbiao 已提交
1234
| Promise&lt;void&gt; | Promise返回空 |
P
panqiangbiao 已提交
1235 1236 1237 1238

**示例:**

```
P
panqiangbiao 已提交
1239
async function example() {
P
panqiangbiao 已提交
1240 1241 1242 1243
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1244 1245
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1246 1247 1248 1249 1250 1251 1252 1253 1254
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.favorite(true).then(function() {
        console.info("favorite successfully");
    }).catch(function(err){
        console.info("favorite failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
1255 1256
```

P
panqiangbiao 已提交
1257
### isFavorite<sup>8+</sup>
P
panqiangbiao 已提交
1258

P
panqiangbiao 已提交
1259
isFavorite(callback: AsyncCallback&lt;boolean&gt;): void
P
panqiangbiao 已提交
1260 1261 1262

判断该文件是否为收藏文件,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1263
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1264

P
panqiangbiao 已提交
1265
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1266

P
panqiangbiao 已提交
1267 1268
**参数:**

H
HelloCrease 已提交
1269 1270 1271
| 参数名      | 类型                           | 必填   | 说明          |
| -------- | ---------------------------- | ---- | ----------- |
| callback | AsyncCallback&lt;boolean&gt; | 是    | 回调表示是否为收藏文件 |
P
panqiangbiao 已提交
1272 1273 1274 1275

**示例:**

```
P
panqiangbiao 已提交
1276
async function example() {
P
panqiangbiao 已提交
1277 1278 1279 1280
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1281 1282
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isFavorite((err, isFavorite) => {
        if (isFavorite) {
            console.info('FileAsset is favorite');
        }else{
            console.info('FileAsset is not favorite');
        }
    });
}
P
panqiangbiao 已提交
1294 1295
```

P
panqiangbiao 已提交
1296
### isFavorite<sup>8+</sup>
P
panqiangbiao 已提交
1297

P
panqiangbiao 已提交
1298
isFavorite():Promise&lt;boolean&gt;
P
panqiangbiao 已提交
1299 1300 1301

判断该文件是否为收藏文件,使用promise方式返回异步结果。

P
panqiangbiao 已提交
1302
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1303

P
panqiangbiao 已提交
1304
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1305

P
panqiangbiao 已提交
1306 1307
**返回值:**

H
HelloCrease 已提交
1308 1309
| 类型                     | 说明                 |
| ---------------------- | ------------------ |
P
panqiangbiao 已提交
1310
| Promise&lt;boolean&gt; | Promise回调表示是否是收藏文件 |
P
panqiangbiao 已提交
1311 1312 1313 1314

**示例:**

```
P
panqiangbiao 已提交
1315
async function example() {
P
panqiangbiao 已提交
1316 1317 1318 1319
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1320 1321
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isFavorite().then(function(isFavorite){
        console.info("isFavorite result:"+ isFavorite);
    }).catch(function(err){
        console.info("isFavorite failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
1331 1332
```

P
panqiangbiao 已提交
1333
### trash<sup>8+</sup>
P
panqiangbiao 已提交
1334

A
AOL 已提交
1335
trash(isTrash: boolean, callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
1336 1337 1338

当文件被定位时,将文件放到垃圾文件夹,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1339 1340
放入垃圾文件夹的文件不会被真正删除,可以通过isTrash = false参数恢复成正常文件。

P
panqiangbiao 已提交
1341
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
1342

P
panqiangbiao 已提交
1343
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1344

P
panqiangbiao 已提交
1345 1346
**参数:**

H
HelloCrease 已提交
1347 1348 1349 1350
| 参数名      | 类型                        | 必填   | 说明        |
| -------- | ------------------------- | ---- | --------- |
| isTrash  | boolean                   | 是    | 是否设置为垃圾文件 |
| callback | AsyncCallback&lt;void&gt; | 是    | 回调返回空     |
P
panqiangbiao 已提交
1351 1352 1353 1354

**示例:**

```
P
panqiangbiao 已提交
1355
async function example() {
P
panqiangbiao 已提交
1356 1357 1358 1359
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1360 1361
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1362 1363 1364 1365 1366
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.trash(true, trashCallBack);
    function trashCallBack(err, trash) {
P
panqiangbiao 已提交
1367
        console.info('mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash');
P
panqiangbiao 已提交
1368
    }
P
panqiangbiao 已提交
1369
}
P
panqiangbiao 已提交
1370 1371
```

P
panqiangbiao 已提交
1372
### trash<sup>8+</sup>
P
panqiangbiao 已提交
1373

A
AOL 已提交
1374
trash(isTrash: boolean): Promise&lt;void&gt;
P
panqiangbiao 已提交
1375 1376 1377

当文件被定位时,将文件放到垃圾文件夹,使用promise方式返回异步结果。

P
panqiangbiao 已提交
1378 1379
放入垃圾文件夹的文件不会被真正删除,可以通过isTrash = false参数恢复成正常文件。

P
panqiangbiao 已提交
1380
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
1381

P
panqiangbiao 已提交
1382
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1383

P
panqiangbiao 已提交
1384 1385
**参数:**

H
HelloCrease 已提交
1386 1387 1388
| 参数名     | 类型      | 必填   | 说明        |
| ------- | ------- | ---- | --------- |
| isTrash | boolean | 是    | 是否设置为垃圾文件 |
P
panqiangbiao 已提交
1389 1390 1391

**返回值:**

H
HelloCrease 已提交
1392 1393
| 类型                  | 说明         |
| ------------------- | ---------- |
P
panqiangbiao 已提交
1394
| Promise&lt;void&gt; | Promise返回空 |
P
panqiangbiao 已提交
1395 1396 1397 1398

**示例:**

```
P
panqiangbiao 已提交
1399
async function example() {
P
panqiangbiao 已提交
1400 1401 1402 1403
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1404 1405
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1406 1407 1408 1409 1410 1411 1412 1413 1414
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.trash(true).then(function() {
        console.info("trash successfully");
    }).catch(function(err){
        console.info("trash failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
1415 1416
```

P
panqiangbiao 已提交
1417
### isTrash<sup>8+</sup>
P
panqiangbiao 已提交
1418

P
panqiangbiao 已提交
1419
isTrash(callback: AsyncCallback&lt;boolean&gt;): void
P
panqiangbiao 已提交
1420 1421 1422

当文件被定位,判断文件是否为垃圾文件,使用callback方式返回异步结果。

P
panqiangbiao 已提交
1423
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1424

P
panqiangbiao 已提交
1425
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1426

P
panqiangbiao 已提交
1427 1428
**参数:**

H
HelloCrease 已提交
1429 1430 1431
| 参数名      | 类型                           | 必填   | 说明              |
| -------- | ---------------------------- | ---- | --------------- |
| callback | AsyncCallback&lt;boolean&gt; | 是    | 回调返回表示文件是否为垃圾文件 |
P
panqiangbiao 已提交
1432 1433 1434 1435

**示例:**

```
P
panqiangbiao 已提交
1436
async function example() {
P
panqiangbiao 已提交
1437 1438 1439 1440
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1441 1442
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1443 1444 1445 1446 1447 1448
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isTrash(isTrashCallBack);
    function isTrashCallBack(err, isTrash) {
            if (isTrash == true) {
P
panqiangbiao 已提交
1449
                console.info('mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isTrash = ' + isTrash);
P
panqiangbiao 已提交
1450 1451 1452
                asset.trash(true, trashCallBack);

            } else {
P
panqiangbiao 已提交
1453 1454
                console.info('mediaLibraryTest : ASSET_CALLBACK isTrash Unsuccessfull = ' + err);
                console.info('mediaLibraryTest : ASSET_CALLBACK isTrash : FAIL');
P
panqiangbiao 已提交
1455 1456

            }
P
panqiangbiao 已提交
1457
    }
P
panqiangbiao 已提交
1458
}
P
panqiangbiao 已提交
1459 1460
```

P
panqiangbiao 已提交
1461
### isTrash<sup>8+</sup>
P
panqiangbiao 已提交
1462

P
panqiangbiao 已提交
1463
isTrash():Promise&lt;boolean&gt;
P
panqiangbiao 已提交
1464

P
panqiangbiao 已提交
1465
当文件被定位,判断文件是否为垃圾文件,使用promise方式返回异步结果。
P
panqiangbiao 已提交
1466

P
panqiangbiao 已提交
1467
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1468

P
panqiangbiao 已提交
1469
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1470

P
panqiangbiao 已提交
1471 1472
**返回值:**

H
HelloCrease 已提交
1473 1474
| 类型                  | 说明                   |
| ------------------- | -------------------- |
P
panqiangbiao 已提交
1475
| Promise&lt;void&gt; | Promise回调表示文件是否为垃圾文件 |
P
panqiangbiao 已提交
1476 1477 1478 1479

**示例:**

```
P
panqiangbiao 已提交
1480
async function example() {
P
panqiangbiao 已提交
1481 1482 1483 1484
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1485 1486
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1487 1488 1489 1490 1491 1492 1493 1494 1495
    };
    const fetchFileResult = await media.getFileAssets(getImageOp);
    const asset = await fetchFileResult.getFirstObject();
    asset.isTrash().then(function(isTrash){
        console.info("isTrash result:"+ isTrash);
    }).catch(function(err){
        console.info("isTrash failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
1496 1497
```

Z
zengyawen 已提交
1498
## FetchFileResult<sup>7+</sup>
P
panqiangbiao 已提交
1499 1500 1501

文件检索结果集。

Z
zengyawen 已提交
1502
### getCount<sup>7+</sup>
P
panqiangbiao 已提交
1503

P
panqiangbiao 已提交
1504
getCount(): number
P
panqiangbiao 已提交
1505 1506 1507

获取文件检索结果中的文件总数。

P
panqiangbiao 已提交
1508
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1509

P
panqiangbiao 已提交
1510 1511
**返回值**

H
HelloCrease 已提交
1512 1513
| 类型     | 说明       |
| ------ | -------- |
P
panqiangbiao 已提交
1514
| number | 检索到的文件总数 |
P
panqiangbiao 已提交
1515 1516 1517 1518

**示例**

```
P
panqiangbiao 已提交
1519
async function example() {
P
panqiangbiao 已提交
1520 1521 1522
    let getFileCountOneOp = {
        selections: fileKeyObj.MEDIA_TYPE + '= ?',
        selectionArgs: [fileType.toString()],
P
panqiangbiao 已提交
1523 1524
        order: fileKeyObj.DATE_ADDED + " DESC",
        extendArgs: "",
P
panqiangbiao 已提交
1525 1526 1527 1528
    };
    let fetchFileResult = await media.getFileAssets(getFileCountOneOp);
    const fetchCount = fetchFileResult.getCount();
}
P
panqiangbiao 已提交
1529 1530
```

Z
zengyawen 已提交
1531
### isAfterLast<sup>7+</sup>
P
panqiangbiao 已提交
1532

P
panqiangbiao 已提交
1533
isAfterLast(): boolean
P
panqiangbiao 已提交
1534 1535 1536

检查结果集是否指向最后一行。

P
panqiangbiao 已提交
1537
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1538

P
panqiangbiao 已提交
1539 1540
**返回值**

H
HelloCrease 已提交
1541 1542
| 类型      | 说明                                 |
| ------- | ---------------------------------- |
P
panqiangbiao 已提交
1543
| boolean | 当读到最后一条记录后,后续没有记录返回true,否则返回false。 |
P
panqiangbiao 已提交
1544 1545 1546 1547

**示例**

```
P
panqiangbiao 已提交
1548
async function example() {
P
panqiangbiao 已提交
1549 1550 1551 1552
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1553 1554
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1555 1556 1557
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    const fetchCount = fetchFileResult.getCount();
P
panqiangbiao 已提交
1558
    console.info('mediaLibraryTest : count:' + fetchCount);
P
panqiangbiao 已提交
1559 1560 1561 1562
    let fileAsset = await fetchFileResult.getFirstObject();
    for (var i = 1; i < fetchCount; i++) {
            fileAsset = await fetchFileResult.getNextObject();
            if(i == fetchCount - 1) {
P
panqiangbiao 已提交
1563
              console.info('mediaLibraryTest : isLast');
P
panqiangbiao 已提交
1564
              var result = fetchFileResult.isAfterLast();
P
panqiangbiao 已提交
1565 1566
              console.info('mediaLibraryTest : isAfterLast:' + result);
              console.info('mediaLibraryTest : isAfterLast end');
P
panqiangbiao 已提交
1567
              fetchFileResult.close();
P
panqiangbiao 已提交
1568

P
panqiangbiao 已提交
1569 1570
            }
    }
P
panqiangbiao 已提交
1571
}
P
panqiangbiao 已提交
1572 1573
```

Z
zengyawen 已提交
1574
### close<sup>7+</sup>
P
panqiangbiao 已提交
1575

P
panqiangbiao 已提交
1576
close(): void
P
panqiangbiao 已提交
1577 1578 1579

释放 FetchFileResult 实例并使其失效。无法调用其他方法。

P
panqiangbiao 已提交
1580
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1581

P
panqiangbiao 已提交
1582 1583 1584
**示例**

```
P
panqiangbiao 已提交
1585
async function example() {
P
panqiangbiao 已提交
1586 1587 1588 1589
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1590 1591
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1592 1593 1594 1595
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.close();
}
P
panqiangbiao 已提交
1596 1597
```

Z
zengyawen 已提交
1598
### getFirstObject<sup>7+</sup>
P
panqiangbiao 已提交
1599

P
panqiangbiao 已提交
1600
getFirstObject(callback: AsyncCallback&lt;FileAsset&gt;): void
P
panqiangbiao 已提交
1601 1602 1603

获取文件检索结果中的第一个文件资产。此方法使用回调返回FileAsset。

P
panqiangbiao 已提交
1604
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1605

P
panqiangbiao 已提交
1606 1607
**参数**

Z
zengyawen 已提交
1608 1609 1610
| 参数名   | 类型                                          | 必填 | 说明                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------- |
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | 是   | 异步获取结果集中第一个FileAsset完成后的回调 |
P
panqiangbiao 已提交
1611 1612 1613 1614

**示例**

```
P
panqiangbiao 已提交
1615
async function example() {
P
panqiangbiao 已提交
1616 1617 1618 1619
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1620 1621
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.getFirstObject((err, value) => {
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1632 1633
```

Z
zengyawen 已提交
1634
### getFirstObject<sup>7+</sup>
P
panqiangbiao 已提交
1635

P
panqiangbiao 已提交
1636
getFirstObject(): Promise&lt;FileAsset&gt;
P
panqiangbiao 已提交
1637

Z
zengyawen 已提交
1638
获取文件检索结果中的第一个文件资产。此方法使用Promise方式返回FileAsset。
P
panqiangbiao 已提交
1639

P
panqiangbiao 已提交
1640
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1641

P
panqiangbiao 已提交
1642 1643
**返回值**

Z
zengyawen 已提交
1644 1645
| 类型                                    | 说明                       |
| --------------------------------------- | -------------------------- |
Z
zengyawen 已提交
1646
| Promise&lt;[FileAsset](#fileasset7)&gt; | Promise方式返回FileAsset。 |
P
panqiangbiao 已提交
1647 1648 1649 1650

**示例**

```
P
panqiangbiao 已提交
1651
async function example() {
P
panqiangbiao 已提交
1652 1653 1654 1655
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1656 1657
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1658 1659 1660 1661 1662 1663 1664 1665
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.getFirstObject().then(function(fileAsset){
        console.info("getFirstObject successfully:"+ JSON.stringify(fileAsset));
    }).catch(function(err){
        console.info("getFirstObject failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
1666 1667
```

Z
zengyawen 已提交
1668
### getNextObject<sup>7+</sup>
P
panqiangbiao 已提交
1669

P
panqiangbiao 已提交
1670
 getNextObject(callback: AsyncCallback&lt;FileAsset&gt;): void
P
panqiangbiao 已提交
1671 1672 1673

获取文件检索结果中的下一个文件资产。此方法使用callback形式返回结果。

P
panqiangbiao 已提交
1674
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1675

P
panqiangbiao 已提交
1676
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1677

P
panqiangbiao 已提交
1678 1679
**参数**

Z
zengyawen 已提交
1680 1681 1682
| 参数名    | 类型                                          | 必填 | 说明                                      |
| --------- | --------------------------------------------- | ---- | ----------------------------------------- |
| callbacke | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | 是   | 异步返回结果集中下一个FileAsset之后的回调 |
P
panqiangbiao 已提交
1683 1684 1685 1686

**示例**

```
P
panqiangbiao 已提交
1687
async function example() {
P
panqiangbiao 已提交
1688 1689 1690 1691
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1692 1693
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.getNextObject((err, value) => {
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1704 1705
```

Z
zengyawen 已提交
1706
### getNextObject<sup>7+</sup>
P
panqiangbiao 已提交
1707

P
panqiangbiao 已提交
1708
 getNextObject(): Promise&lt;FileAsset&gt;
P
panqiangbiao 已提交
1709 1710 1711

获取文件检索结果中的下一个文件资产。此方法使用promise方式来异步返回FileAsset。

P
panqiangbiao 已提交
1712
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1713

P
panqiangbiao 已提交
1714
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1715

P
panqiangbiao 已提交
1716 1717
**返回值**

Z
zengyawen 已提交
1718 1719 1720
| 类型                                    | 说明              |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | 返回FileAsset对象 |
P
panqiangbiao 已提交
1721 1722 1723 1724

**示例**

```
P
panqiangbiao 已提交
1725
async function example() {
P
panqiangbiao 已提交
1726 1727 1728 1729
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1730 1731
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1732 1733 1734
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    const fetchCount = fetchFileResult.getCount();
P
panqiangbiao 已提交
1735
    console.info('mediaLibraryTest : count:' + fetchCount);
P
panqiangbiao 已提交
1736 1737
    fileAsset = await fetchFileResult.getNextObject();
}
P
panqiangbiao 已提交
1738 1739
```

Z
zengyawen 已提交
1740
### getLastObject<sup>7+</sup>
P
panqiangbiao 已提交
1741

P
panqiangbiao 已提交
1742
getLastObject(callback: AsyncCallback&lt;FileAsset&gt;): void
P
panqiangbiao 已提交
1743 1744 1745

获取文件检索结果中的最后一个文件资产。此方法使用callback回调来返回FileAsset。

P
panqiangbiao 已提交
1746
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1747

P
panqiangbiao 已提交
1748 1749
**参数**

Z
zengyawen 已提交
1750 1751
| 参数名   | 类型                                          | 必填 | 说明                        |
| -------- | --------------------------------------------- | ---- | --------------------------- |
Z
zengyawen 已提交
1752
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | 是   | 异步返回FileAsset之后的回调 |
P
panqiangbiao 已提交
1753 1754 1755 1756

**示例**

```
P
panqiangbiao 已提交
1757
async function example() {
P
panqiangbiao 已提交
1758 1759 1760 1761
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1762 1763
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.getLastObject((err, value) => {
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1774 1775
```

Z
zengyawen 已提交
1776
### getLastObject<sup>7+</sup>
P
panqiangbiao 已提交
1777

P
panqiangbiao 已提交
1778
getLastObject(): Promise&lt;FileAsset&gt;
P
panqiangbiao 已提交
1779 1780 1781

获取文件检索结果中的最后一个文件资产。此方法使用Promise方式来返回FileAsset。

P
panqiangbiao 已提交
1782
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1783

P
panqiangbiao 已提交
1784 1785
**返回值**

Z
zengyawen 已提交
1786 1787 1788
| 类型                                    | 说明              |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | 返回FileAsset对象 |
P
panqiangbiao 已提交
1789 1790 1791 1792

**示例**

```
P
panqiangbiao 已提交
1793
async function example() {
P
panqiangbiao 已提交
1794 1795 1796 1797
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1798 1799
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1800 1801 1802 1803
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    let lastObject = await fetchFileResult.getLastObject();
}
P
panqiangbiao 已提交
1804 1805
```

Z
zengyawen 已提交
1806
### getPositionObject<sup>7+</sup>
P
panqiangbiao 已提交
1807

P
panqiangbiao 已提交
1808
getPositionObject(index: number, callback: AsyncCallback&lt;FileAsset&gt;): void
P
panqiangbiao 已提交
1809 1810 1811

获取文件检索结果中具有指定索引的文件资产。此方法使用回调来返回FileAsset。

P
panqiangbiao 已提交
1812
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1813

P
panqiangbiao 已提交
1814 1815
**参数**

Z
zengyawen 已提交
1816
| 参数名       | 类型                                       | 必填   | 说明                 |
H
HelloCrease 已提交
1817 1818
| -------- | ---------------------------------------- | ---- | ------------------ |
| index    | number                                   | 是    | 要获取的文件的索引,从0开始     |
Z
zengyawen 已提交
1819
| callback | AsyncCallback&lt;[FileAsset](#fileasset7)&gt; | 是    | 异步返回FileAsset之后的回调 |
P
panqiangbiao 已提交
1820 1821 1822 1823

**示例**

```
P
panqiangbiao 已提交
1824
async function example() {
P
panqiangbiao 已提交
1825 1826 1827 1828
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1829 1830
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1831 1832
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
P
panqiangbiao 已提交
1833
    fetchFileResult.getPositionObject(0, (err, value) => {
P
panqiangbiao 已提交
1834 1835 1836 1837 1838 1839 1840
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1841 1842
```

Z
zengyawen 已提交
1843
### getPositionObject<sup>7+</sup>
P
panqiangbiao 已提交
1844

P
panqiangbiao 已提交
1845
getPositionObject(index: number): Promise&lt;FileAsset&gt;
P
panqiangbiao 已提交
1846 1847 1848

获取文件检索结果中具有指定索引的文件资产。此方法使用Promise形式返回文件Asset。

P
panqiangbiao 已提交
1849
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1850

P
panqiangbiao 已提交
1851
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1852

P
panqiangbiao 已提交
1853 1854
**参数**

Z
zengyawen 已提交
1855
| 参数名    | 类型     | 必填   | 说明             |
H
HelloCrease 已提交
1856 1857
| ----- | ------ | ---- | -------------- |
| index | number | 是    | 要获取的文件的索引,从0开始 |
P
panqiangbiao 已提交
1858 1859 1860

**返回值**

Z
zengyawen 已提交
1861 1862 1863
| 类型                                    | 说明              |
| --------------------------------------- | ----------------- |
| Promise&lt;[FileAsset](#fileasset7)&gt; | 返回FileAsset对象 |
P
panqiangbiao 已提交
1864 1865 1866 1867

**示例**

```
P
panqiangbiao 已提交
1868
async function example() {
P
panqiangbiao 已提交
1869 1870 1871 1872
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1873 1874
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1875 1876
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
P
panqiangbiao 已提交
1877
    fetchFileResult.getPositionObject(1, (err, value) => {
P
panqiangbiao 已提交
1878 1879 1880 1881 1882 1883 1884
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1885 1886
```

Z
zengyawen 已提交
1887
### getAllObject<sup>7+</sup>
P
panqiangbiao 已提交
1888

P
panqiangbiao 已提交
1889
getAllObject(callback: AsyncCallback&lt;Array&lt;FileAsset&gt;&gt;): void
P
panqiangbiao 已提交
1890 1891 1892

获取文件检索结果中的所有文件资产。此方法使用Callback回调来返回FileAsset结果集。

P
panqiangbiao 已提交
1893
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
1894

P
panqiangbiao 已提交
1895
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1896

P
panqiangbiao 已提交
1897 1898
**参数**

Z
zengyawen 已提交
1899
| 参数名       | 类型                                       | 必填   | 说明                   |
H
HelloCrease 已提交
1900
| -------- | ---------------------------------------- | ---- | -------------------- |
Z
zengyawen 已提交
1901
| callback | AsyncCallback<Array<[FileAsset](#fileasset7)>> | 是    | 异步返回FileAsset列表之后的回调 |
P
panqiangbiao 已提交
1902 1903 1904 1905

**示例**

```
P
panqiangbiao 已提交
1906
async function example() {
P
panqiangbiao 已提交
1907 1908 1909 1910
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1911 1912
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1913 1914 1915 1916 1917 1918 1919 1920 1921 1922
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    fetchFileResult.getAllObject((err, value) => {
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log(value);
    })
}
P
panqiangbiao 已提交
1923 1924
```

Z
zengyawen 已提交
1925
### getAllObject<sup>7+</sup>
P
panqiangbiao 已提交
1926

P
panqiangbiao 已提交
1927
getAllObject(): Promise&lt;Array&lt;FileAsset&gt;&gt;
P
panqiangbiao 已提交
1928 1929 1930

获取文件检索结果中的所有文件资产。此方法使用Promise来返回FileAsset结果集。

P
panqiangbiao 已提交
1931
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1932

P
panqiangbiao 已提交
1933 1934
**返回值**

Z
zengyawen 已提交
1935 1936 1937
| 类型                                     | 说明                  |
| ---------------------------------------- | --------------------- |
| Promise<Array<[FileAsset](#fileasset7)>> | 返回FileAsset对象列表 |
P
panqiangbiao 已提交
1938 1939 1940 1941

**示例**

```
P
panqiangbiao 已提交
1942
async function example() {
P
panqiangbiao 已提交
1943 1944 1945 1946
    let imageType = mediaLibrary.MediaType.IMAGE;
    let getImageOp = {
      selections: fileKeyObj.MEDIA_TYPE + '= ?',
      selectionArgs: [imageType.toString()],
P
panqiangbiao 已提交
1947 1948
      order: fileKeyObj.DATE_ADDED + " DESC",
      extendArgs: "",
P
panqiangbiao 已提交
1949 1950 1951 1952
    };
    let fetchFileResult = await media.getFileAssets(getImageOp);
    var data = fetchFileResult.getAllObject();
}
P
panqiangbiao 已提交
1953 1954
```

Z
zengyawen 已提交
1955
## Album<sup>7+</sup>
P
panqiangbiao 已提交
1956 1957 1958

实体相册

Z
zengyawen 已提交
1959
### 属性
P
panqiangbiao 已提交
1960

Z
zengyawen 已提交
1961 1962
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

Z
zengyawen 已提交
1963
| 名称           | 类型    | 可读   | 可写   | 说明      |
H
HelloCrease 已提交
1964
| ------------ | ------ | ---- | ---- | ------- |
Z
zengyawen 已提交
1965 1966 1967
| albumId | number | 是    | 否    | 相册编号    |
| albumName | string | 是    | 是    | 相册名称    |
| albumUri<sup>8+</sup> | string | 是    | 否    | 相册Uri   |
H
HelloCrease 已提交
1968
| dateModified | number | 是    | 否    | 修改日期    |
Z
zengyawen 已提交
1969 1970 1971
| count<sup>8+</sup> | number | 是    | 否    | 相册中文件数量 |
| relativePath<sup>8+</sup> | string | 是    | 否    | 相对路径    |
| coverUri<sup>8+</sup> | string | 是    | 否    | 封面文件Uri |
P
panqiangbiao 已提交
1972

P
panqiangbiao 已提交
1973 1974 1975
### commitModify<sup>8+</sup>

commitModify(callback: AsyncCallback&lt;void&gt;): void
P
panqiangbiao 已提交
1976 1977 1978

更新相册属性修改到数据库中。

P
panqiangbiao 已提交
1979
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
1980

P
panqiangbiao 已提交
1981
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
1982

P
panqiangbiao 已提交
1983 1984
**参数**

Z
zengyawen 已提交
1985 1986 1987
| 参数名   | 类型                      | 必填 | 说明       |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback&lt;void&gt; | 是   | 回调返回空 |
P
panqiangbiao 已提交
1988 1989 1990 1991

**示例**

```
P
panqiangbiao 已提交
1992
async function example() {
P
panqiangbiao 已提交
1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
    let AlbumNoArgsfetchOp = {
        selections: '',
        selectionArgs: [],
    };
    const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
    const album = albumList[0];
    album.albumName = 'hello';
    album.commitModify((err) => {
       if (err) {
           console.error('Failed ');
           return;
       }
       console.log('Modify successful.');
    })
}
P
panqiangbiao 已提交
2008 2009
```

P
panqiangbiao 已提交
2010
### commitModify<sup>8+</sup>
P
panqiangbiao 已提交
2011

P
panqiangbiao 已提交
2012
commitModify(): Promise&lt;void&gt;
P
panqiangbiao 已提交
2013 2014 2015

更新相册属性修改到数据库中。

P
panqiangbiao 已提交
2016
**需要权限**:ohos.permission.READ_MEDIA, ohos.permission.WRITE_MEDIA
P
panqiangbiao 已提交
2017

P
panqiangbiao 已提交
2018
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
2019

P
panqiangbiao 已提交
2020 2021
**返回值**

H
HelloCrease 已提交
2022 2023
| 类型                  | 说明           |
| ------------------- | ------------ |
P
panqiangbiao 已提交
2024 2025 2026 2027 2028
| Promise&lt;void&gt; | Promise调用返回空 |

**示例**

```
P
panqiangbiao 已提交
2029
async function example() {
P
panqiangbiao 已提交
2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042
    let AlbumNoArgsfetchOp = {
        selections: '',
        selectionArgs: [],
    };
    const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
    const album = albumList[0];
    album.albumName = 'hello';
    album.commitModify().then(function() {
        console.info("commitModify successfully");
    }).catch(function(err){
        console.info("commitModify failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
2043 2044
```

Z
zengyawen 已提交
2045
### getFileAssets<sup>7+</sup>
P
panqiangbiao 已提交
2046

P
panqiangbiao 已提交
2047
getFileAssets(options: MediaFetchOptions, callback: AsyncCallback&lt;FetchFileResult&gt;): void
P
panqiangbiao 已提交
2048 2049 2050

按照检索条件获取相册中的文件。此方法使用Callback回调来返回文件结果集。

P
panqiangbiao 已提交
2051
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
2052

P
panqiangbiao 已提交
2053
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
2054

P
panqiangbiao 已提交
2055 2056
**参数**

Z
zengyawen 已提交
2057
| 参数名   | 类型                                                | 必填 | 说明                                |
Z
zengyawen 已提交
2058
| -------- | --------------------------------------------------- | ---- | ----------------------------------- |
Z
zengyawen 已提交
2059 2060
| options  | [MediaFetchOptions](#mediafetchoptions7)            | 是   | 媒体检索选项。                      |
| callback | AsyncCallback<[FetchFileResult](#fetchfileresult7)> | 是   | 异步返回FetchFileResult之后的回调。 |
P
panqiangbiao 已提交
2061 2062 2063 2064

**示例**

```
P
panqiangbiao 已提交
2065
async function example() {
P
panqiangbiao 已提交
2066 2067 2068 2069 2070 2071 2072 2073 2074 2075
    let AlbumNoArgsfetchOp = {
        selections: '',
        selectionArgs: [],
    };
    const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
    const album = albumList[0];
    album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack);
    function getFileAssetsCallBack(err, fetchFileResult) {
        // do something
    }
P
panqiangbiao 已提交
2076 2077 2078
}
```

Z
zengyawen 已提交
2079
### getFileAssets<sup>7+</sup>
P
panqiangbiao 已提交
2080

P
panqiangbiao 已提交
2081
 getFileAssets(options?: MediaFetchOptions): Promise&lt;FetchFileResult&gt;
P
panqiangbiao 已提交
2082

Z
zengyawen 已提交
2083
按照检索条件获取相册中的文件。此方法使用异步Promise来返回文件结果集。
P
panqiangbiao 已提交
2084

P
panqiangbiao 已提交
2085
**需要权限**:ohos.permission.READ_MEDIA
P
panqiangbiao 已提交
2086

P
panqiangbiao 已提交
2087
**系统能力**:SystemCapability.Multimedia.MediaLibrary.Core
P
panqiangbiao 已提交
2088 2089 2090

**参数**

Z
zengyawen 已提交
2091
| 参数名  | 类型                                     | 必填 | 说明           |
Z
zengyawen 已提交
2092
| ------- | ---------------------------------------- | ---- | -------------- |
Z
zengyawen 已提交
2093
| options | [MediaFetchOptions](#mediafetchoptions7) | 否   | 媒体检索选项。 |
P
panqiangbiao 已提交
2094 2095 2096

**返回值**

Z
zengyawen 已提交
2097 2098
| 类型                                          | 说明                      |
| --------------------------------------------- | ------------------------- |
Z
zengyawen 已提交
2099
| Promise<[FetchFileResult](#fetchfileresult7)> | 返回FetchFileResult对象。 |
P
panqiangbiao 已提交
2100 2101 2102 2103

**示例**

```
P
panqiangbiao 已提交
2104
async function example() {
P
panqiangbiao 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116
    let AlbumNoArgsfetchOp = {
        selections: '',
        selectionArgs: [],
    };
    const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
    const album = albumList[0];
    album.getFileAssets(fileNoArgsfetchOp).then(function(albumFetchFileResult){
        console.info("getFileAssets successfully:"+ JSON.stringify(albumFetchFileResult));
    }).catch(function(err){
        console.info("getFileAssets failed with error:"+ err);
    });
}
P
panqiangbiao 已提交
2117 2118
```

P
panqiangbiao 已提交
2119
## PeerInfo<sup>8+</sup>
P
panqiangbiao 已提交
2120

P
panqiangbiao 已提交
2121
注册设备的信息。
P
panqiangbiao 已提交
2122

Z
zengyawen 已提交
2123 2124
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

Z
zengyawen 已提交
2125 2126 2127 2128 2129 2130
| 名称       | 类型                       | 可读 | 可写 | 说明             |
| ---------- | -------------------------- | ---- | ---- | ---------------- |
| deviceName | string                     | 是   | 否   | 注册设备的名称   |
| networkId  | string                     | 是   | 否   | 注册设备的网络ID |
| deviceType | [DeviceType](#devicetype8) | 是   | 否   | 设备类型         |
| isOnline   | boolean                    | 是   | 否   | 是否在线         |
P
panqiangbiao 已提交
2131 2132 2133



Z
zengyawen 已提交
2134
## MediaType<sup>8+</sup>
P
panqiangbiao 已提交
2135 2136 2137

枚举,媒体类型。

Z
zengyawen 已提交
2138 2139
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

潘强标 已提交
2140 2141 2142 2143 2144 2145
| 名称  |  说明 |
| ----- |  ---- |
| FILE  |  文件 |
| IMAGE |  图片 |
| VIDEO |  视频 |
| AUDIO |  音频 |
P
panqiangbiao 已提交
2146

Z
zengyawen 已提交
2147
## FileKey<sup>8+</sup>
P
panqiangbiao 已提交
2148 2149 2150

枚举,文件关键信息。

Z
zengyawen 已提交
2151 2152
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

Z
zengyawen 已提交
2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
| 名称          | 默认值              | 说明                                                       |
| ------------- | ------------------- | ---------------------------------------------------------- |
| ID            | file_id             | 文件编号                                                   |
| RELATIVE_PATH | relative_path       | 相对公共目录路径                                           |
| DISPLAY_NAME  | display_name        | 显示名字                                                   |
| PARENT        | parent              | 父目录id                                                   |
| MIME_TYPE     | mime_type           | 文件扩展属性                                               |
| MEDIA_TYPE    | media_type          | 媒体类型                                                   |
| SIZE          | size                | 文件大小(单位:字节)                                     |
| DATE_ADDED    | date_added          | 添加日期(添加文件时间到1970年1月1日的秒数值)             |
| DATE_MODIFIED | date_modified       | 修改日期(修改文件时间到1970年1月1日的秒数值)             |
| DATE_TAKEN    | date_taken          | 拍摄日期(文件拍照时间到1970年1月1日的秒数值)             |
| TITLE         | title               | 文件标题                                                   |
| ARTIST        | artist              | 作者                                                       |
| AUDIOALBUM    | audio_album         | 专辑                                                       |
| DURATION      | duration            | 持续时间(单位:秒)                                       |
| WIDTH         | width               | 图片宽度(单位:像素)                                     |
| HEIGHT        | height              | 图片高度(单位:像素)                                     |
P
panqiangbiao 已提交
2171
| ORIENTATION   | orientation         | 图片显示方向,即顺时针旋转角度,如0,90,180。(单位:度) |
Z
zengyawen 已提交
2172 2173
| ALBUM_ID      | bucket_id           | 文件所归属的相册编号                                       |
| ALBUM_NAME    | bucket_display_name | 文件所归属相册名称                                         |
P
panqiangbiao 已提交
2174

Z
zengyawen 已提交
2175
## DirectoryType<sup>8+</sup>
P
panqiangbiao 已提交
2176 2177 2178

枚举,目录类型。

Z
zengyawen 已提交
2179 2180
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

潘强标 已提交
2181 2182 2183 2184 2185 2186 2187 2188
| 名称          |  说明               |
| ------------- |  ------------------ |
| DIR_CAMERA    |  表示Camera文件路径 |
| DIR_VIDEO     |  表示视频路径       |
| DIR_IMAGE     |  表示图片路径       |
| DIR_AUDIO     |  表示音频路径       |
| DIR_DOCUMENTS |  表示文档路径       |
| DIR_DOWNLOAD  |  表示下载路径       |
P
panqiangbiao 已提交
2189

Z
zengyawen 已提交
2190
## DeviceType<sup>8+</sup>
P
panqiangbiao 已提交
2191 2192 2193

枚举,设备类型。

Z
zengyawen 已提交
2194 2195
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

潘强标 已提交
2196 2197 2198 2199 2200 2201 2202 2203 2204
| 名称         |  说明       |
| ------------ |  ---------- |
| TYPE_UNKNOWN |  未识别设备 |
| TYPE_LAPTOP  |  笔记本电脑 |
| TYPE_PHONE   |  手机       |
| TYPE_TABLET  |  平板电脑   |
| TYPE_WATCH   |  智能手表   |
| TYPE_CAR     |  车载设备   |
| TYPE_TV      |  电视设备   |
P
panqiangbiao 已提交
2205

Z
zengyawen 已提交
2206
## MediaFetchOptions<sup>7+</sup>
P
panqiangbiao 已提交
2207 2208 2209

检索条件。

Z
zengyawen 已提交
2210 2211
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

Z
zengyawen 已提交
2212 2213 2214 2215
| 名称                    | 类型                | 可读 | 可写 | 必填 | 说明                                                         |
| ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ |
| selections              | string              | 是   | 是   | 是   | 检索条件,使用[FileKey](#filekey8)中的枚举值作为检索条件的列名。示例:<br />selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?‘, |
| selectionArgs           | Array&lt;string&gt; | 是   | 是   | 是   | 检索条件的值,对应selections中检索条件列的值。<br />示例:<br />selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
2216
| order                   | string              | 是   | 是   | 否   | 检索结果排序方式,使用[FileKey](#filekey8)中的枚举值作为检索结果排序的列,可以用升序或降序排列。示例:<br />升序排列:order: mediaLibrary.FileKey.DATE_ADDED + " AESC"<br />降序排列:order: mediaLibrary.FileKey.DATE_ADDED + " DESC" |
Z
zengyawen 已提交
2217 2218 2219
| uri<sup>8+</sup>        | string              | 是   | 是   | 否   | 文件URI                                                      |
| networkId<sup>8+</sup>  | string              | 是   | 是   | 否   | 注册设备网络ID                                               |
| extendArgs<sup>8+</sup> | string              | 是   | 是   | 否   | 扩展的检索参数,目前没有扩展检索参数                         |
P
panqiangbiao 已提交
2220

P
panqiangbiao 已提交
2221
## Size<sup>8+</sup>
P
panqiangbiao 已提交
2222 2223 2224

图片尺寸。

H
HelloCrease 已提交
2225 2226 2227 2228
| 名称     | 类型     | 可读   | 可写   | 说明       |
| ------ | ------ | ---- | ---- | -------- |
| width  | number | 是    | 是    | 宽(单位:像素) |
| height | number | 是    | 是    | 高(单位:像素) |
P
panqiangbiao 已提交
2229

Z
update  
zengyawen 已提交
2230
## MediaAssetOption<sup>(deprecated)</sup>
P
panqiangbiao 已提交
2231 2232 2233

媒体资源选项。

Z
update  
zengyawen 已提交
2234
> **说明**: 从API Version 9开始废弃。
P
panqiangbiao 已提交
2235 2236 2237 2238

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core


Z
zengyawen 已提交
2239 2240 2241 2242 2243
| 名称         | 类型   | 必填 | 描述                                                         |
| ------------ | ------ | ---- | ------------------------------------------------------------ |
| src          | string | 是   | 本地文件应用沙箱路径。                                       |
| mimeType     | string | 是   | 媒体MIME(Multipurpose&nbsp;Internet&nbsp;Mail&nbsp;Extensions)类型。<br/>包括:'image/\*'、'video/\*'、'audio/\*'、 'file\*'。 |
| relativePath | string | 否   | 自定义媒体资源保存位置,例:Pictures/ 不填则保存到默认路径。 <br/> image类型默认路径Pictures/ <br/> video类型默认路径Videos/ <br/> audio类型默认路径Audios/ <br/> file类型默认路径Documents/ 。 |
P
panqiangbiao 已提交
2244

Z
update  
zengyawen 已提交
2245
## MediaSelectOption<sup>(deprecated)</sup>
P
panqiangbiao 已提交
2246 2247 2248

媒体资源类型选项。

Z
update  
zengyawen 已提交
2249
> **说明**: 从API Version 9开始废弃。
P
panqiangbiao 已提交
2250 2251 2252

**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core

H
HelloCrease 已提交
2253 2254
| 名称    | 类型     | 必填   | 描述                   |
| ----- | ------ | ---- | -------------------- |
潘强标 已提交
2255 2256
| type  | string | 是    | 媒体类型,包括:image, video, media,当前仅支持media类型 |
| count | number | 是    | 媒体选择,count = 1表示单选,count大于1表示多选。            |