Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2bd6e6ce
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2bd6e6ce
编写于
3月 06, 2022
作者:
P
panqiangbiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix code issue
Signed-off-by:
N
panqiangbiao
<
panqiangbiao@huawei.com
>
上级
1f2823b2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
113 addition
and
113 deletion
+113
-113
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
+113
-113
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
浏览文件 @
2bd6e6ce
媒体库管理
==========
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 该组件从API Version 6开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
导入模块
---------
```
import media
l
ibrary from '@ohos.multimedia.medialibrary';
import media
L
ibrary from '@ohos.multimedia.medialibrary';
```
...
...
@@ -19,7 +21,7 @@ function getMediaLibrary(context: Context): MediaLibrary;
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
**参数:**
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | -------------------- |
...
...
@@ -29,19 +31,18 @@ function getMediaLibrary(context: Context): MediaLibrary;
| 类型 | 说明 |
| ------------ | :----- |
|
M
ediaLibrary | 媒体库实例 |
|
m
ediaLibrary | 媒体库实例 |
**示例:**
```
import featureAbility from '@ohos.ability.featureAbility';
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
var context = featureAbility.getContext()
var media
Library
= mediaLibrary.getMediaLibrary(context);
var media = mediaLibrary.getMediaLibrary(context);
```
## media
library.getFileAssets
## media
Library.getFileAssets<sup>8+</sup>
getFileAssets(options: MediaFetchOptions, callback: AsyncCallback
<
FetchFileResult
>
): void;
...
...
@@ -68,9 +69,9 @@ let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
media
l
ibrary.getFileAssets(imagesfetchOp, (error, fetchFileResult) => {
media
L
ibrary.getFileAssets(imagesfetchOp, (error, fetchFileResult) => {
if (fetchFileResult != undefined) {
console.info('
M
ediaLibraryTest : ASSET_CALLBACK fetchFileResult success');
console.info('
m
ediaLibraryTest : ASSET_CALLBACK fetchFileResult success');
fetchFileResult.getAllObject((err, fileAssetList) => {
if (fileAssetList != undefined) {
fileAssetList.forEach(getAllObjectInfo);
...
...
@@ -79,7 +80,7 @@ medialibrary.getFileAssets(imagesfetchOp, (error, fetchFileResult) => {
}
});
```
## media
library.getFileAssets
## media
Library.getFileAssets<sup>8+</sup>
getFileAssets(options: MediaFetchOptions): Promise
<
FetchFileResult
>
;
...
...
@@ -110,14 +111,14 @@ let imagesfetchOp = {
selections: fileKeyObj.MEDIA_TYPE + '= ?',
selectionArgs: [imageType.toString()],
};
media
l
ibrary.getFileAssets(imagesfetchOp).then(function(fetchFileResult){
media
L
ibrary.getFileAssets(imagesfetchOp).then(function(fetchFileResult){
console.info("getFileAssets successfully:"+ JSON.stringify(dir));
}).catch(function(err){
console.info("getFileAssets failed with error:"+ err);
});
```
## media
library.on
## media
Library.on<sup>8+</sup>
on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback: Callback
<
void
>
): void;
...
...
@@ -131,17 +132,17 @@ on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------- | ---- | ------------------- |
| type | type | 是 | 媒体类型
<br/>
'deviceChange':
注册设备变更
<br/>
'albumChange':
相册变更
<br/>
'imageChange':
图片文件变更
<br/>
’audioChange‘:
音频文件变更
<br/>
‘videoChange’:
视频文件变更
<br/>
‘'fileChange':
文件变更
<br/>
‘remoteFileChange’
:
注册设备上文件变更 |
| type | type | 是 | 媒体类型
<br/>
'deviceChange':
注册设备变更
<br/>
'albumChange':
相册变更
<br/>
'imageChange':
图片文件变更
<br/>
'audioChange':
音频文件变更
<br/>
'videoChange':
视频文件变更
<br/>
'fileChange':
文件变更
<br/>
'remoteFileChange'
:
注册设备上文件变更 |
| callback | callback
<
void
>
| 是 | 回调返回空 |
**示例:**
```
media
l
ibrary.on('imageChange', () => {
media
L
ibrary.on('imageChange', () => {
// image file had changed, do something
})
```
## media
library.off
## media
Library.off<sup>8+</sup>
off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|'fileChange'|'remoteFileChange', callback?: Callback
<
void
>
): void;
...
...
@@ -157,24 +158,24 @@ off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------- | ---- | ------------------- |
| type | type | 是 | 媒体类型
<br/>
'deviceChange':
注册设备变更
<br/>
'albumChange':
相册变更
<br/>
'imageChange':
图片文件变更
<br/>
’audioChange‘:
音频文件变更
<br/>
‘videoChange’:
视频文件变更
<br/>
‘'fileChange':
文件变更
<br/>
‘remoteFileChange’
:
注册设备上文件变更 |
| type | type | 是 | 媒体类型
<br/>
'deviceChange':
注册设备变更
<br/>
'albumChange':
相册变更
<br/>
'imageChange':
图片文件变更
<br/>
'audioChange':
音频文件变更
<br/>
'videoChange':
视频文件变更
<br/>
'fileChange':
文件变更
<br/>
'remoteFileChange'
:
注册设备上文件变更 |
| callback | callback
<
void
>
| 否 | 回调返回空 |
**示例:**
```
media
l
ibrary.off('imageChange', () => {
media
L
ibrary.off('imageChange', () => {
// stop listening success
})
```
## media
library.createAsset
## media
Library.createAsset <sup>8+</sup>
createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback
<
FileAsset
>
): void;
创建媒体资源,使用callback方式返回结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -193,7 +194,7 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
// 使用Callback方式创建Image类型文件
let mediaType = mediaLibrary.MediaType.IMAGE;
let path = "Pictures/";
media
library.createAsset(mediaType, “imageCallBack.jpg”
, path, (err, fileAsset) => {
media
Library.createAsset(mediaType, 'imageCallBack.jpg'
, path, (err, fileAsset) => {
if (fileAsset != undefined) {
console.info('createAsset successfully, message = ' + err);
} else {
...
...
@@ -202,13 +203,13 @@ medialibrary.createAsset(mediaType, “imageCallBack.jpg”, path, (err, fileAss
});
```
## media
library.createAsset
## media
Library.createAsset<sup>8+</sup>
createAsset(mediaType: MediaType, displayName: string, relativePath: string): Promise
<
FileAsset
>
;
创建媒体资源,使用Promise方式返回结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -232,14 +233,14 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
// 使用Promise方式创建Image类型文件
let mediaType = mediaLibrary.MediaType.IMAGE;
let path = "Pictures/";
media
l
ibrary.createAsset(mediaType, "image01.jpg", path).then (function (asset) {
media
L
ibrary.createAsset(mediaType, "image01.jpg", path).then (function (asset) {
console.info("createAsset successfully:"+ JSON.stringify(asset));
}).catch(function(err){
console.info("createAsset failed with error:"+ err);
});
```
## media
library.getPublicDirectory
## media
Library.getPublicDirectory<sup>8+</sup>
getPublicDirectory(type: DirectoryType, callback: AsyncCallback
<
string
>
): void;
...
...
@@ -261,16 +262,16 @@ getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>):
```
let DIR_CAMERA = mediaLibrary.DirectoryType.DIR_CAMERA;
media.getPublicDirectory(DIR_CAMERA
,
(err, dicResult) => {
media.getPublicDirectory(DIR_CAMERA
,
(err, dicResult) => {
if (dicResult == 'camera/') {
console.info('
MediaLibraryTest : getPublicDirectory
');
console.info('
mediaLibraryTest : getPublicDirectory passed
');
} else {
console.info('
M
ediaLibraryTest : getPublicDirectory failed');
console.info('
m
ediaLibraryTest : getPublicDirectory failed');
}
});
```
## media
library.getPublicDirectory
## media
Library.getPublicDirectory<sup>8+</sup>
getPublicDirectory(type: DirectoryType): Promise
<
string
>
;
...
...
@@ -306,7 +307,7 @@ async function (done) {
}
```
## media
library.getAlbums
## media
Library.getAlbums<sup>6+</sup>
getAlbums(options: MediaFetchOptions, callback: AsyncCallback
<Array
&
lt
;
Album
&
gt
;
>
): void;
...
...
@@ -330,7 +331,7 @@ let AlbumNoArgsfetchOp = {
selections: '',
selectionArgs: [],
};
media
l
ibrary.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => {
media
L
ibrary.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => {
if (albumList != undefined) {
const album = albumList[0];
console.info('album.albumName = ' + album.albumName);
...
...
@@ -341,7 +342,7 @@ medialibrary.getAlbums(AlbumNoArgsfetchOp, (err, albumList) => {
})
```
## media
library.getAlbums
## media
Library.getAlbums<sup>6+</sup>
getAlbums(options: MediaFetchOptions): Promise
<Array
&
lt
;
Album
&
gt
;
>
;
...
...
@@ -370,18 +371,18 @@ let AlbumNoArgsfetchOp = {
selections: '',
selectionArgs: [],
};
media
l
ibrary.getAlbums(AlbumNoArgsfetchOp).then(function(albumList){
media
L
ibrary.getAlbums(AlbumNoArgsfetchOp).then(function(albumList){
console.info("getAlbums successfully:"+ JSON.stringify(albumList));
}).catch(function(err){
console.info("getAlbums failed with error:"+ err);
});
```
## media
library.release
## media
Library.release<sup>8+</sup>
release(callback: AsyncCallback
<
void
>
): void;
释放
MediaLibrary实例,当用户确认后续不再使用MediaLibrary实例中的方法后调用release方法释放M
ediaLibrary实例。
释放
mediaLibrary实例,当用户确认后续不再使用mediaLibrary实例中的方法后调用release方法释放m
ediaLibrary实例。
**需要权限**
:无
...
...
@@ -396,17 +397,17 @@ release(callback: AsyncCallback<void>): void;
**示例:**
```
var media
Library
= mediaLibrary.getMediaLibrary(context);
media
Library
.release((err, data) => {
var media = mediaLibrary.getMediaLibrary(context);
media.release((err, data) => {
// do something
});
```
## media
library.release
## media
Library.release<sup>8+</sup>
release(): Promise
<
void
>
;
释放
MediaLibrary实例,当用户确认后续不再使用MediaLibrary实例中的方法后调用release方法释放M
ediaLibrary实例。
释放
mediaLibrary实例,当用户确认后续不再使用mediaLibrary实例中的方法后调用release方法释放m
ediaLibrary实例。
**需要权限**
:无
...
...
@@ -421,11 +422,11 @@ release(): Promise<void>;
**示例:**
```
var media
Library
= mediaLibrary.getMediaLibrary(context);
media
Library
.release()
var media = mediaLibrary.getMediaLibrary(context);
media.release()
```
## FileAsset.isDirectory
## FileAsset.isDirectory
<sup>8+</sup>
isDirectory(callback: AsyncCallback
<
boolean
>
): void;
...
...
@@ -460,7 +461,7 @@ async function (done) {
}
```
## FileAsset.isDirectory
## FileAsset.isDirectory
<sup>8+</sup>
isDirectory():Promise
<
boolean
>
;
...
...
@@ -497,13 +498,13 @@ async function (done) {
}
```
## FileAsset.commitModify
## FileAsset.commitModify
<sup>8+</sup>
commitModify(callback: AsyncCallback
<
void
>
): void;
修改文件的元数据,使用callback方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -526,20 +527,20 @@ async function (done) {
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title =
‘
newtitle';
asset.title =
'
newtitle';
asset.commitModify(() => {
console.info('commitModify success');
}
}
);
}
```
## FileAsset.commitModify
## FileAsset.commitModify
<sup>8+</sup>
commitModify(): Promise
<
void
>
;
修改文件的元数据,使用promise方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -562,18 +563,18 @@ async function (done) {
};
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.title =
‘
newtitle';
asset.title =
'
newtitle';
asset.commitModify();
}
```
## FileAsset.open
## FileAsset.open
<sup>8+</sup>
open(mode: string, callback: AsyncCallback
<
number
>
): void;
打开当前文件,使用callback方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA(
‘w’
模式打开)
**需要权限**
:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA(
'w'
模式打开)
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -601,13 +602,13 @@ async function (done) {
}
```
## FileAsset.open
## FileAsset.open
<sup>8+</sup>
open(mode: string): Promise
<
number
>
;
打开当前文件,使用promise方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA(
‘w’
模式打开)
**需要权限**
:ohos.permission.READ_MEDIA('r'模式打开),ohos.permission.WRITE_MEDIA(
'w'
模式打开)
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -640,13 +641,13 @@ async function (done) {
}
```
## FileAsset.close
## FileAsset.close
<sup>8+</sup>
close(fd: number, callback: AsyncCallback
<
void
>
): void;
关闭当前文件,使用callback方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -672,8 +673,8 @@ async function (done) {
const asset = await fetchFileResult.getFirstObject();
asset.close(fd, (closeErr) => {
if (closeErr != undefined) {
console.info('
M
ediaLibraryTest : close : FAIL ' + closeErr.message);
console.info('
M
ediaLibraryTest : ASSET_CALLBACK : FAIL');
console.info('
m
ediaLibraryTest : close : FAIL ' + closeErr.message);
console.info('
m
ediaLibraryTest : ASSET_CALLBACK : FAIL');
} else {
console.info("=======asset.close success====>");
}
...
...
@@ -681,13 +682,13 @@ async function (done) {
}
```
## FileAsset.close
## FileAsset.close
<sup>8+</sup>
close(fd: number): Promise
<
void
>
;
关闭当前文件,使用promise方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -718,8 +719,8 @@ async function (done) {
const asset = await fetchFileResult.getFirstObject();
asset.close(fd).then((closeErr) => {
if (closeErr != undefined) {
console.info('
M
ediaLibraryTest : close : FAIL ' + closeErr.message);
console.info('
M
ediaLibraryTest : ASSET_CALLBACK : FAIL');
console.info('
m
ediaLibraryTest : close : FAIL ' + closeErr.message);
console.info('
m
ediaLibraryTest : ASSET_CALLBACK : FAIL');
} else {
console.info("=======asset.close success====>");
...
...
@@ -728,7 +729,7 @@ async function (done) {
}
```
## FileAsset.getThumbnail
## FileAsset.getThumbnail
<sup>8+</sup>
getThumbnail(callback: AsyncCallback
<
image.PixelMap
>
): void;
...
...
@@ -758,12 +759,12 @@ async function (done) {
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail((err, pixelmap) => {
console.info('
M
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
console.info('
m
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
});
}
```
## FileAsset.getThumbnail
## FileAsset.getThumbnail
<sup>8+</sup>
getThumbnail(size: Size, callback: AsyncCallback
<
image.PixelMap
>
): void;
...
...
@@ -794,12 +795,12 @@ async function (done) {
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size, (err, pixelmap) => {
console.info('
M
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
console.info('
m
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
});
}
```
## FileAsset.getThumbnail
## FileAsset.getThumbnail
<sup>8+</sup>
getThumbnail(size?: Size): Promise
<
image.PixelMap
>
;
...
...
@@ -835,18 +836,18 @@ async function (done) {
const fetchFileResult = await media.getFileAssets(getImageOp);
const asset = await fetchFileResult.getFirstObject();
asset.getThumbnail(size, (err, pixelmap) => {
console.info('
M
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
console.info('
m
ediaLibraryTest : getThumbnail Successfull '+ pixelmap);
});
}
```
## FileAsset.favorite
## FileAsset.favorite
<sup>8+</sup>
favorite(isFavorite: boolean, callback: AsyncCallback
<
void
>
): void;
将文件设置为收藏文件,使用callback方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -876,13 +877,13 @@ async function (done) {
}
```
## FileAsset.favorite
## FileAsset.favorite
<sup>8+</sup>
favorite(isFavorite: boolean): Promise
<
void
>
;
将文件设置为收藏文件,使用promise方式返回异步结果。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -919,7 +920,7 @@ async function (done) {
}
```
## FileAsset.isFavorite
## FileAsset.isFavorite
<sup>8+</sup>
isFavorite(callback: AsyncCallback
<
boolean
>
): void;
...
...
@@ -958,7 +959,7 @@ async function (done) {
}
```
## FileAsset.isFavorite
## FileAsset.isFavorite
<sup>8+</sup>
isFavorite():Promise
<
boolean
>
;
...
...
@@ -995,7 +996,7 @@ async function (done) {
}
```
## FileAsset.trash
## FileAsset.trash
<sup>8+</sup>
trash(isTrash: boolean, callback: AsyncCallback
<
void
&g;
): void;
...
...
@@ -1003,7 +1004,7 @@ trash(isTrash: boolean, callback: AsyncCallback<void&g;): void;
放入垃圾文件夹的文件不会被真正删除,可以通过isTrash = false参数恢复成正常文件。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -1029,12 +1030,12 @@ async function (done) {
const asset = await fetchFileResult.getFirstObject();
asset.trash(true, trashCallBack);
function trashCallBack(err, trash) {
console.info('
M
ediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash');
console.info('
m
ediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK trash');
}
}
```
## FileAsset.trash
## FileAsset.trash
<sup>8+</sup>
trash(isTrash: boolean,): Promise
<
void
>
;
...
...
@@ -1042,7 +1043,7 @@ trash(isTrash: boolean,): Promise<void>;
放入垃圾文件夹的文件不会被真正删除,可以通过isTrash = false参数恢复成正常文件。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -1079,7 +1080,7 @@ async function (done) {
}
```
## FileAsset.isTrash
## FileAsset.isTrash
<sup>8+</sup>
isTrash(callback: AsyncCallback
<
boolean
>
): void;
...
...
@@ -1111,19 +1112,19 @@ async function (done) {
asset.isTrash(isTrashCallBack);
function isTrashCallBack(err, isTrash) {
if (isTrash == true) {
console.info('
M
ediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isTrash = ' + isTrash);
console.info('
m
ediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isTrash = ' + isTrash);
asset.trash(true, trashCallBack);
} else {
console.info('
M
ediaLibraryTest : ASSET_CALLBACK isTrash Unsuccessfull = ' + err);
console.info('
M
ediaLibraryTest : ASSET_CALLBACK isTrash : FAIL');
console.info('
m
ediaLibraryTest : ASSET_CALLBACK isTrash Unsuccessfull = ' + err);
console.info('
m
ediaLibraryTest : ASSET_CALLBACK isTrash : FAIL');
}
}
}
```
## FileAsset.isTrash
## FileAsset.isTrash
<sup>8+</sup>
isTrash():Promise
<
boolean
>
;
...
...
@@ -1164,7 +1165,7 @@ async function (done) {
文件检索结果集。
## FetchFileResult.getCount
## FetchFileResult.getCount
<sup>8+</sup>
getCount(): number;
...
...
@@ -1195,7 +1196,7 @@ async function (done) {
}
```
## FetchFileResult.isAfterLast
## FetchFileResult.isAfterLast
<sup>8+</sup>
isAfterLast(): boolean;
...
...
@@ -1224,15 +1225,15 @@ async function (done) {
};
let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount();
console.info('
M
ediaLibraryTest : count:' + fetchCount);
console.info('
m
ediaLibraryTest : count:' + fetchCount);
let fileAsset = await fetchFileResult.getFirstObject();
for (var i = 1; i < fetchCount; i++) {
fileAsset = await fetchFileResult.getNextObject();
if(i == fetchCount - 1) {
console.info('
M
ediaLibraryTest : isLast');
console.info('
m
ediaLibraryTest : isLast');
var result = fetchFileResult.isAfterLast();
console.info('
M
ediaLibraryTest : isAfterLast:' + result);
console.info('
M
ediaLibraryTest : isAfterLast end');
console.info('
m
ediaLibraryTest : isAfterLast:' + result);
console.info('
m
ediaLibraryTest : isAfterLast end');
fetchFileResult.close();
}
...
...
@@ -1240,7 +1241,7 @@ async function (done) {
}
```
## FetchFileResult.close
## FetchFileResult.close
<sup>8+</sup>
close(): void;
...
...
@@ -1266,7 +1267,7 @@ async function (done) {
}
```
## FetchFileResult.getFirstObject
## FetchFileResult.getFirstObject
<sup>8+</sup>
getFirstObject(callback: AsyncCallback
<
FileAsset
>
): void;
...
...
@@ -1304,7 +1305,7 @@ async function (done) {
}
```
## FetchFileResult.getFirstObject
## FetchFileResult.getFirstObject
<sup>8+</sup>
getFirstObject(): Promise
<
FileAsset
>
;
...
...
@@ -1341,7 +1342,7 @@ async function (done) {
}
```
## FetchFileResult.getNextObject
## FetchFileResult.getNextObject
<sup>8+</sup>
getNextObject(callback: AsyncCallback
<
FileAsset
>
): void;
...
...
@@ -1379,7 +1380,7 @@ async function (done) {
}
```
## FetchFileResult.getNextObject
## FetchFileResult.getNextObject
<sup>8+</sup>
getNextObject(): Promise
<
FileAsset
>
;
...
...
@@ -1408,12 +1409,12 @@ async function (done) {
};
let fetchFileResult = await media.getFileAssets(getImageOp);
const fetchCount = fetchFileResult.getCount();
console.info('
M
ediaLibraryTest : count:' + fetchCount);
console.info('
m
ediaLibraryTest : count:' + fetchCount);
fileAsset = await fetchFileResult.getNextObject();
}
```
## FetchFileResult.getLastObject
## FetchFileResult.getLastObject
<sup>8+</sup>
getLastObject(callback: AsyncCallback
<
FileAsset
>
): void;
...
...
@@ -1451,7 +1452,7 @@ async function (done) {
}
```
## FetchFileResult.getLastObject
## FetchFileResult.getLastObject
<sup>8+</sup>
getLastObject(): Promise
<
FileAsset
>
;
...
...
@@ -1483,7 +1484,7 @@ async function (done) {
}
```
## FetchFileResult.getPositionObject
## FetchFileResult.getPositionObject
<sup>8+</sup>
getPositionObject(index: number, callback: AsyncCallback
<
FileAsset
>
): void;
...
...
@@ -1512,7 +1513,7 @@ async function (done) {
extendArgs: "LIMIT 0,10",
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(
1,
(err, value) => {
fetchFileResult.getPositionObject(
0,
(err, value) => {
if (err) {
console.error('Failed ');
return;
...
...
@@ -1522,7 +1523,7 @@ async function (done) {
}
```
## FetchFileResult.getPositionObject
## FetchFileResult.getPositionObject
<sup>8+</sup>
getPositionObject(index: number): Promise
<
FileAsset
>
;
...
...
@@ -1556,7 +1557,7 @@ async function (done) {
extendArgs: "LIMIT 0,10",
};
let fetchFileResult = await media.getFileAssets(getImageOp);
fetchFileResult.getPositionObject(1
,
(err, value) => {
fetchFileResult.getPositionObject(1
,
(err, value) => {
if (err) {
console.error('Failed ');
return;
...
...
@@ -1566,7 +1567,7 @@ async function (done) {
}
```
## FetchFileResult.getAllObject
## FetchFileResult.getAllObject
<sup>8+</sup>
getAllObject(callback: AsyncCallback
<
Array
<
FileAsset
>>
): void;
...
...
@@ -1604,7 +1605,7 @@ async function (done) {
}
```
## FetchFileResult.getAllObject
## FetchFileResult.getAllObject
<sup>8+</sup>
getAllObject(): Promise
<
Array
<
FileAsset
>>
;
...
...
@@ -1636,13 +1637,13 @@ async function (done) {
}
```
## Album.commitModify
## Album.commitModify
<sup>8+</sup>
commitModify(callback: AsyncCallback
<
void
>
): void;
更新相册属性修改到数据库中。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -1673,13 +1674,13 @@ async function (done) {
}
```
## Album.commitModify
## Album.commitModify
<sup>8+</sup>
commitModify(): Promise
<
void
>
;
更新相册属性修改到数据库中。
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**需要权限**
:ohos.permission.READ_MEDIA
,
ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
...
...
@@ -1708,7 +1709,7 @@ async function (done) {
}
```
## Album.getFileAssets
## Album.getFileAssets
<sup>8+</sup>
getFileAssets(options: MediaFetchOptions, callback: AsyncCallback
<
FetchFileResult
>
): void;
...
...
@@ -1736,14 +1737,13 @@ async function (done) {
const albumList = await media.getAlbums(AlbumNoArgsfetchOp);
const album = albumList[0];
album.getFileAssets(fileNoArgsfetchOp, getFileAssetsCallBack);
})
function getFileAssetsCallBack(err, fetchFileResult) {
// do something
}
}
```
## Album.getFileAssets
## Album.getFileAssets
<sup>8+</sup>
getFileAssets(options?: MediaFetchOptions): Promise
<
FetchFileResult
>
;
...
...
@@ -1783,7 +1783,7 @@ async function (done) {
}
```
## PeerInfo
## PeerInfo
<sup>8+</sup>
注册设备信息。
...
...
@@ -1908,7 +1908,7 @@ DeviceType
| TYPE_CAR | 5 | 车载设备 |
| TYPE_TV | 6 | 电视设备 |
## MediaFetchOptions
## MediaFetchOptions
<sup>8+</sup>
检索条件。
...
...
@@ -1921,7 +1921,7 @@ DeviceType
| networkId | string | 是 | 是 | 否 |注册设备网络ID |
| extendArgs | string | 是 | 是 | 否 |扩展的检索参数 |
## Size
## Size
<sup>8+</sup>
图片尺寸。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录