Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
648c6a4c
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
“f209585766c8d5d80b6a59401eebd722c97c01c2”上不存在“NO56/csdn/items.py”
未验证
提交
648c6a4c
编写于
9月 05, 2023
作者:
O
openharmony_ci
提交者:
Gitee
9月 05, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23788 ArkTs 媒体库适配整改
Merge pull request !23788 from 胡伟奇/ArkTs_update
上级
c9a9b67f
5b6bf995
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
202 addition
and
159 deletion
+202
-159
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
+202
-159
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
浏览文件 @
648c6a4c
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
## 导入模块
## 导入模块
```
j
s
```
t
s
import
mediaLibrary
from
'
@ohos.multimedia.mediaLibrary
'
;
import
mediaLibrary
from
'
@ohos.multimedia.mediaLibrary
'
;
```
```
...
@@ -37,21 +37,12 @@ getMediaLibrary(context: Context): MediaLibrary
...
@@ -37,21 +37,12 @@ getMediaLibrary(context: Context): MediaLibrary
| ----------------------------- | :---- |
| ----------------------------- | :---- |
|
[
MediaLibrary
](
#medialibrary
)
| 媒体库实例。 |
|
[
MediaLibrary
](
#medialibrary
)
| 媒体库实例。 |
**示例:
(从API version 9开始)
**
**示例:**
```
ts
```
ts
// 获取mediaLibrary实例,后续用到此实例均采用此处获取的实例。
// 获取mediaLibrary实例,后续用到此实例均采用此处获取的实例。
const
context
=
getContext
(
this
);
const
context
=
getContext
(
this
);
let
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
let
media
:
mediaLibrary
.
MediaLibrary
=
mediaLibrary
.
getMediaLibrary
(
context
);
```
**示例:(API version 8)**
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
();
let
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
```
```
## mediaLibrary.getMediaLibrary
## mediaLibrary.getMediaLibrary
...
@@ -76,8 +67,8 @@ getMediaLibrary(): MediaLibrary
...
@@ -76,8 +67,8 @@ getMediaLibrary(): MediaLibrary
**示例:**
**示例:**
```
j
s
```
t
s
let
media
=
mediaLibrary
.
getMediaLibrary
();
let
media
:
mediaLibrary
.
MediaLibrary
=
mediaLibrary
.
getMediaLibrary
();
```
```
## MediaLibrary
## MediaLibrary
...
@@ -106,12 +97,12 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
...
@@ -106,12 +97,12 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
// 创建文件获取选项,此处参数为获取image类型的文件资源。
// 创建文件获取选项,此处参数为获取image类型的文件资源。
let
imagesFetchOp
=
{
let
imagesFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
};
};
...
@@ -184,12 +175,14 @@ getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>
...
@@ -184,12 +175,14 @@ getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
// 创建文件获取选项,此处参数为获取image类型的文件资源。
// 创建文件获取选项,此处参数为获取image类型的文件资源。
let
imagesFetchOp
=
{
let
imagesFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
};
};
...
@@ -218,11 +211,11 @@ async function example() {
...
@@ -218,11 +211,11 @@ async function example() {
}
}
// 释放FetchFileResult实例并使其失效。无法调用其他方法。
// 释放FetchFileResult实例并使其失效。无法调用其他方法。
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
// 调用getFirstObject接口失败。
// 调用getFirstObject接口失败。
console
.
error
(
'
get first object failed with error:
'
+
error
);
console
.
error
(
'
get first object failed with error:
'
+
error
);
});
});
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
// 调用getFileAssets接口失败。
// 调用getFileAssets接口失败。
console
.
error
(
'
get file assets failed with error:
'
+
error
);
console
.
error
(
'
get file assets failed with error:
'
+
error
);
});
});
...
@@ -250,7 +243,7 @@ on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'
...
@@ -250,7 +243,7 @@ on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'
**示例:**
**示例:**
```
j
s
```
t
s
media
.
on
(
'
imageChange
'
,
()
=>
{
media
.
on
(
'
imageChange
'
,
()
=>
{
// image file had changed, do something.
// image file had changed, do something.
});
});
...
@@ -277,7 +270,7 @@ off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange
...
@@ -277,7 +270,7 @@ off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange
**示例:**
**示例:**
```
j
s
```
t
s
media
.
off
(
'
imageChange
'
,
()
=>
{
media
.
off
(
'
imageChange
'
,
()
=>
{
// stop listening successfully.
// stop listening successfully.
});
});
...
@@ -309,7 +302,7 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
...
@@ -309,7 +302,7 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
// 使用Callback方式创建Image类型文件。
// 使用Callback方式创建Image类型文件。
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
@@ -356,7 +349,9 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
...
@@ -356,7 +349,9 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
// 使用Promise方式创建Image类型文件。
// 使用Promise方式创建Image类型文件。
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
@@ -364,7 +359,7 @@ async function example() {
...
@@ -364,7 +359,7 @@ async function example() {
const
path
=
await
media
.
getPublicDirectory
(
DIR_IMAGE
);
const
path
=
await
media
.
getPublicDirectory
(
DIR_IMAGE
);
media
.
createAsset
(
mediaType
,
'
imagePromise.jpg
'
,
path
+
'
myPicture/
'
).
then
((
fileAsset
)
=>
{
media
.
createAsset
(
mediaType
,
'
imagePromise.jpg
'
,
path
+
'
myPicture/
'
).
then
((
fileAsset
)
=>
{
console
.
info
(
'
createAsset successfully, message =
'
+
JSON
.
stringify
(
fileAsset
));
console
.
info
(
'
createAsset successfully, message =
'
+
JSON
.
stringify
(
fileAsset
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
createAsset failed with error:
'
+
error
);
console
.
error
(
'
createAsset failed with error:
'
+
error
);
});
});
}
}
...
@@ -402,11 +397,13 @@ deleteAsset(uri: string): Promise\<void>
...
@@ -402,11 +397,13 @@ deleteAsset(uri: string): Promise\<void>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
let
option
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
selectionArgs
:
[
fileType
.
toString
()],
};
};
...
@@ -418,7 +415,7 @@ async function example() {
...
@@ -418,7 +415,7 @@ async function example() {
}
}
media
.
deleteAsset
(
asset
.
uri
).
then
(()
=>
{
media
.
deleteAsset
(
asset
.
uri
).
then
(()
=>
{
console
.
info
(
'
deleteAsset successfully
'
);
console
.
info
(
'
deleteAsset successfully
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
deleteAsset failed with error:
'
+
error
);
console
.
error
(
'
deleteAsset failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -452,11 +449,11 @@ deleteAsset(uri: string, callback: AsyncCallback\<void>): void
...
@@ -452,11 +449,11 @@ deleteAsset(uri: string, callback: AsyncCallback\<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
let
option
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
selectionArgs
:
[
fileType
.
toString
()],
};
};
...
@@ -498,7 +495,7 @@ getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>):
...
@@ -498,7 +495,7 @@ getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>):
**示例:**
**示例:**
```
j
s
```
t
s
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
media
.
getPublicDirectory
(
DIR_CAMERA
,
(
error
,
dicResult
)
=>
{
media
.
getPublicDirectory
(
DIR_CAMERA
,
(
error
,
dicResult
)
=>
{
if
(
dicResult
==
'
Camera/
'
)
{
if
(
dicResult
==
'
Camera/
'
)
{
...
@@ -535,7 +532,9 @@ getPublicDirectory(type: DirectoryType): Promise<string>
...
@@ -535,7 +532,9 @@ getPublicDirectory(type: DirectoryType): Promise<string>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
media
.
getPublicDirectory
(
DIR_CAMERA
).
then
((
dicResult
)
=>
{
media
.
getPublicDirectory
(
DIR_CAMERA
).
then
((
dicResult
)
=>
{
...
@@ -544,7 +543,7 @@ async function example() {
...
@@ -544,7 +543,7 @@ async function example() {
}
else
{
}
else
{
console
.
error
(
'
getPublicDirectory DIR_CAMERA failed
'
);
console
.
error
(
'
getPublicDirectory DIR_CAMERA failed
'
);
}
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getPublicDirectory failed with error:
'
+
error
);
console
.
error
(
'
getPublicDirectory failed with error:
'
+
error
);
});
});
}
}
...
@@ -574,13 +573,13 @@ getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album&
...
@@ -574,13 +573,13 @@ getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album&
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
Camera
'
],
selectionArgs
:
[
'
Camera
'
],
};
};
media
.
getAlbums
(
AlbumNoArgsf
etchOp
,
(
error
,
albumList
)
=>
{
media
.
getAlbums
(
albumF
etchOp
,
(
error
,
albumList
)
=>
{
if
(
albumList
!=
undefined
)
{
if
(
albumList
!=
undefined
)
{
console
.
info
(
'
getAlbums successfully:
'
+
JSON
.
stringify
(
albumList
));
console
.
info
(
'
getAlbums successfully:
'
+
JSON
.
stringify
(
albumList
));
}
else
{
}
else
{
...
@@ -619,15 +618,17 @@ getAlbums(options: MediaFetchOptions): Promise<Array<Album>>
...
@@ -619,15 +618,17 @@ getAlbums(options: MediaFetchOptions): Promise<Array<Album>>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
Camera
'
],
selectionArgs
:
[
'
Camera
'
],
};
};
media
.
getAlbums
(
AlbumNoArgsf
etchOp
).
then
((
albumList
)
=>
{
media
.
getAlbums
(
albumF
etchOp
).
then
((
albumList
)
=>
{
console
.
info
(
'
getAlbums successfully:
'
+
JSON
.
stringify
(
albumList
));
console
.
info
(
'
getAlbums successfully:
'
+
JSON
.
stringify
(
albumList
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getAlbums failed with error:
'
+
error
);
console
.
error
(
'
getAlbums failed with error:
'
+
error
);
});
});
}
}
...
@@ -654,7 +655,7 @@ release(callback: AsyncCallback<void>): void
...
@@ -654,7 +655,7 @@ release(callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
media
.
release
(()
=>
{
media
.
release
(()
=>
{
// do something.
// do something.
});
});
...
@@ -681,7 +682,7 @@ release(): Promise<void>
...
@@ -681,7 +682,7 @@ release(): Promise<void>
**示例:**
**示例:**
```
j
s
```
t
s
media
.
release
();
media
.
release
();
```
```
...
@@ -707,8 +708,8 @@ storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>)
...
@@ -707,8 +708,8 @@ storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>)
**示例:**
**示例:**
```
j
s
```
t
s
let
option
=
{
let
option
:
mediaLibrary
.
MediaAssetOption
=
{
src
:
'
/data/storage/el2/base/haps/entry/image.png
'
,
src
:
'
/data/storage/el2/base/haps/entry/image.png
'
,
mimeType
:
'
image/*
'
,
mimeType
:
'
image/*
'
,
relativePath
:
'
Pictures/
'
relativePath
:
'
Pictures/
'
...
@@ -750,8 +751,10 @@ storeMediaAsset(option: MediaAssetOption): Promise<string>
...
@@ -750,8 +751,10 @@ storeMediaAsset(option: MediaAssetOption): Promise<string>
**示例:**
**示例:**
```
js
```
ts
let
option
=
{
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
option
:
mediaLibrary
.
MediaAssetOption
=
{
src
:
'
/data/storage/el2/base/haps/entry/image.png
'
,
src
:
'
/data/storage/el2/base/haps/entry/image.png
'
,
mimeType
:
'
image/*
'
,
mimeType
:
'
image/*
'
,
relativePath
:
'
Pictures/
'
relativePath
:
'
Pictures/
'
...
@@ -759,7 +762,7 @@ let option = {
...
@@ -759,7 +762,7 @@ let option = {
mediaLibrary
.
getMediaLibrary
().
storeMediaAsset
(
option
).
then
((
value
)
=>
{
mediaLibrary
.
getMediaLibrary
().
storeMediaAsset
(
option
).
then
((
value
)
=>
{
console
.
info
(
'
Media resources stored.
'
);
console
.
info
(
'
Media resources stored.
'
);
// Obtain the URI that stores media resources.
// Obtain the URI that stores media resources.
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
storeMediaAsset failed with error:
'
+
error
);
console
.
error
(
'
storeMediaAsset failed with error:
'
+
error
);
});
});
```
```
...
@@ -787,7 +790,7 @@ startImagePreview(images: Array<string>, index: number, callback: AsyncCal
...
@@ -787,7 +790,7 @@ startImagePreview(images: Array<string>, index: number, callback: AsyncCal
**示例:**
**示例:**
```
j
s
```
t
s
let
images
=
[
let
images
=
[
'
file://media/xxxx/2
'
,
'
file://media/xxxx/2
'
,
'
file://media/xxxx/3
'
'
file://media/xxxx/3
'
...
@@ -830,7 +833,7 @@ startImagePreview(images: Array<string>, callback: AsyncCallback<void&g
...
@@ -830,7 +833,7 @@ startImagePreview(images: Array<string>, callback: AsyncCallback<void&g
**示例:**
**示例:**
```
j
s
```
t
s
let
images
=
[
let
images
=
[
'
file://media/xxxx/2
'
,
'
file://media/xxxx/2
'
,
'
file://media/xxxx/3
'
'
file://media/xxxx/3
'
...
@@ -878,7 +881,9 @@ startImagePreview(images: Array<string>, index?: number): Promise<void&
...
@@ -878,7 +881,9 @@ startImagePreview(images: Array<string>, index?: number): Promise<void&
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
images
=
[
let
images
=
[
'
file://media/xxxx/2
'
,
'
file://media/xxxx/2
'
,
'
file://media/xxxx/3
'
'
file://media/xxxx/3
'
...
@@ -892,7 +897,7 @@ let images = [
...
@@ -892,7 +897,7 @@ let images = [
let
index
=
1
;
let
index
=
1
;
mediaLibrary
.
getMediaLibrary
().
startImagePreview
(
images
,
index
).
then
(()
=>
{
mediaLibrary
.
getMediaLibrary
().
startImagePreview
(
images
,
index
).
then
(()
=>
{
console
.
info
(
'
Succeeded in previewing the images.
'
);
console
.
info
(
'
Succeeded in previewing the images.
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
startImagePreview failed with error:
'
+
error
);
console
.
error
(
'
startImagePreview failed with error:
'
+
error
);
});
});
```
```
...
@@ -919,7 +924,7 @@ startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<
...
@@ -919,7 +924,7 @@ startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<
**示例:**
**示例:**
```
j
s
```
t
s
let
option
:
mediaLibrary
.
MediaSelectOption
=
{
let
option
:
mediaLibrary
.
MediaSelectOption
=
{
type
:
'
media
'
,
type
:
'
media
'
,
count
:
2
count
:
2
...
@@ -961,7 +966,9 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
...
@@ -961,7 +966,9 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
option
:
mediaLibrary
.
MediaSelectOption
=
{
let
option
:
mediaLibrary
.
MediaSelectOption
=
{
type
:
'
media
'
,
type
:
'
media
'
,
count
:
2
count
:
2
...
@@ -969,7 +976,7 @@ let option : mediaLibrary.MediaSelectOption = {
...
@@ -969,7 +976,7 @@ let option : mediaLibrary.MediaSelectOption = {
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
option
).
then
((
value
)
=>
{
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
option
).
then
((
value
)
=>
{
console
.
info
(
'
Media resources selected.
'
);
console
.
info
(
'
Media resources selected.
'
);
// Obtain the media selection value.
// Obtain the media selection value.
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
startMediaSelect failed with error:
'
+
error
);
console
.
error
(
'
startMediaSelect failed with error:
'
+
error
);
});
});
```
```
...
@@ -998,7 +1005,9 @@ getActivePeers(): Promise\<Array\<PeerInfo>>;
...
@@ -998,7 +1005,9 @@ getActivePeers(): Promise\<Array\<PeerInfo>>;
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
media
.
getActivePeers
().
then
((
devicesInfo
)
=>
{
media
.
getActivePeers
().
then
((
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
if
(
devicesInfo
!=
undefined
)
{
...
@@ -1006,7 +1015,7 @@ async function example() {
...
@@ -1006,7 +1015,7 @@ async function example() {
}
else
{
}
else
{
console
.
info
(
'
get distributed info is undefined!
'
);
console
.
info
(
'
get distributed info is undefined!
'
);
}
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
get distributed info failed with error:
'
+
error
);
console
.
error
(
'
get distributed info failed with error:
'
+
error
);
});
});
}
}
...
@@ -1036,7 +1045,7 @@ getActivePeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;
...
@@ -1036,7 +1045,7 @@ getActivePeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
media
.
getActivePeers
((
error
,
devicesInfo
)
=>
{
media
.
getActivePeers
((
error
,
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
if
(
devicesInfo
!=
undefined
)
{
...
@@ -1072,7 +1081,9 @@ getAllPeers(): Promise\<Array\<PeerInfo>>;
...
@@ -1072,7 +1081,9 @@ getAllPeers(): Promise\<Array\<PeerInfo>>;
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
media
.
getAllPeers
().
then
((
devicesInfo
)
=>
{
media
.
getAllPeers
().
then
((
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
if
(
devicesInfo
!=
undefined
)
{
...
@@ -1080,7 +1091,7 @@ async function example() {
...
@@ -1080,7 +1091,7 @@ async function example() {
}
else
{
}
else
{
console
.
info
(
'
get distributed info is undefined!
'
);
console
.
info
(
'
get distributed info is undefined!
'
);
}
}
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
get distributed info failed with error:
'
+
error
);
console
.
error
(
'
get distributed info failed with error:
'
+
error
);
});
});
}
}
...
@@ -1110,7 +1121,7 @@ getAllPeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;
...
@@ -1110,7 +1121,7 @@ getAllPeers(callback: AsyncCallback\<Array\<PeerInfo>>): void;
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
media
.
getAllPeers
((
error
,
devicesInfo
)
=>
{
media
.
getAllPeers
((
error
,
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
if
(
devicesInfo
!=
undefined
)
{
...
@@ -1182,11 +1193,11 @@ isDirectory(callback: AsyncCallback<boolean>): void
...
@@ -1182,11 +1193,11 @@ isDirectory(callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1226,11 +1237,13 @@ isDirectory():Promise<boolean>
...
@@ -1226,11 +1237,13 @@ isDirectory():Promise<boolean>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1239,7 +1252,7 @@ async function example() {
...
@@ -1239,7 +1252,7 @@ async function example() {
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
isDirectory
().
then
((
isDirectory
)
=>
{
asset
.
isDirectory
().
then
((
isDirectory
)
=>
{
console
.
info
(
'
isDirectory result:
'
+
isDirectory
);
console
.
info
(
'
isDirectory result:
'
+
isDirectory
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
isDirectory failed with error:
'
+
error
);
console
.
error
(
'
isDirectory failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1269,11 +1282,11 @@ commitModify(callback: AsyncCallback<void>): void
...
@@ -1269,11 +1282,11 @@ commitModify(callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1311,11 +1324,11 @@ commitModify(): Promise<void>
...
@@ -1311,11 +1324,11 @@ commitModify(): Promise<void>
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1353,7 +1366,7 @@ open(mode: string, callback: AsyncCallback<number>): void
...
@@ -1353,7 +1366,7 @@ open(mode: string, callback: AsyncCallback<number>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
...
@@ -1399,7 +1412,9 @@ open(mode: string): Promise<number>
...
@@ -1399,7 +1412,9 @@ open(mode: string): Promise<number>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
...
@@ -1407,7 +1422,7 @@ async function example() {
...
@@ -1407,7 +1422,7 @@ async function example() {
const
asset
=
await
media
.
createAsset
(
mediaType
,
'
image00003.jpg
'
,
path
);
const
asset
=
await
media
.
createAsset
(
mediaType
,
'
image00003.jpg
'
,
path
);
asset
.
open
(
'
rw
'
).
then
((
fd
)
=>
{
asset
.
open
(
'
rw
'
).
then
((
fd
)
=>
{
console
.
info
(
'
File open fd:
'
+
fd
);
console
.
info
(
'
File open fd:
'
+
fd
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
File open failed with error:
'
+
error
);
console
.
error
(
'
File open failed with error:
'
+
error
);
});
});
}
}
...
@@ -1436,11 +1451,13 @@ close(fd: number, callback: AsyncCallback<void>): void
...
@@ -1436,11 +1451,13 @@ close(fd: number, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1456,7 +1473,7 @@ async function example() {
...
@@ -1456,7 +1473,7 @@ async function example() {
console
.
info
(
'
asset.close successfully
'
);
console
.
info
(
'
asset.close successfully
'
);
}
}
});
});
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
File open failed with error:
'
+
error
);
console
.
error
(
'
File open failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1491,11 +1508,13 @@ close(fd: number): Promise<void>
...
@@ -1491,11 +1508,13 @@ close(fd: number): Promise<void>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1509,7 +1528,7 @@ async function example() {
...
@@ -1509,7 +1528,7 @@ async function example() {
}).
catch
((
closeErr
)
=>
{
}).
catch
((
closeErr
)
=>
{
console
.
error
(
'
asset.close fail, closeErr:
'
+
closeErr
);
console
.
error
(
'
asset.close fail, closeErr:
'
+
closeErr
);
});
});
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
open File failed with error:
'
+
error
);
console
.
error
(
'
open File failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1538,11 +1557,11 @@ getThumbnail(callback: AsyncCallback<image.PixelMap>): void
...
@@ -1538,11 +1557,11 @@ getThumbnail(callback: AsyncCallback<image.PixelMap>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1583,16 +1602,16 @@ getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void
...
@@ -1583,16 +1602,16 @@ getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
};
};
let
size
=
{
width
:
720
,
height
:
720
};
let
size
:
mediaLibrary
.
Size
=
{
width
:
720
,
height
:
720
};
const
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
const
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
getThumbnail
(
size
,
(
error
,
pixelmap
)
=>
{
asset
.
getThumbnail
(
size
,
(
error
,
pixelmap
)
=>
{
...
@@ -1634,21 +1653,23 @@ getThumbnail(size?: Size): Promise<image.PixelMap>
...
@@ -1634,21 +1653,23 @@ getThumbnail(size?: Size): Promise<image.PixelMap>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
};
};
let
size
=
{
width
:
720
,
height
:
720
};
let
size
:
mediaLibrary
.
Size
=
{
width
:
720
,
height
:
720
};
const
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
const
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
getThumbnail
(
size
).
then
((
pixelmap
)
=>
{
asset
.
getThumbnail
(
size
).
then
((
pixelmap
)
=>
{
console
.
info
(
'
mediaLibrary getThumbnail Successful, pixelmap
'
+
JSON
.
stringify
(
pixelmap
));
console
.
info
(
'
mediaLibrary getThumbnail Successful, pixelmap
'
+
JSON
.
stringify
(
pixelmap
));
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
mediaLibrary getThumbnail failed with error:
'
+
error
);
console
.
error
(
'
mediaLibrary getThumbnail failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1678,11 +1699,11 @@ favorite(isFavorite: boolean, callback: AsyncCallback<void>): void
...
@@ -1678,11 +1699,11 @@ favorite(isFavorite: boolean, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1728,11 +1749,13 @@ favorite(isFavorite: boolean): Promise<void>
...
@@ -1728,11 +1749,13 @@ favorite(isFavorite: boolean): Promise<void>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1741,7 +1764,7 @@ async function example() {
...
@@ -1741,7 +1764,7 @@ async function example() {
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
favorite
(
true
).
then
(()
=>
{
asset
.
favorite
(
true
).
then
(()
=>
{
console
.
info
(
'
mediaLibrary favorite Successful
'
);
console
.
info
(
'
mediaLibrary favorite Successful
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
mediaLibrary favorite failed with error:
'
+
error
);
console
.
error
(
'
mediaLibrary favorite failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1770,11 +1793,11 @@ isFavorite(callback: AsyncCallback<boolean>): void
...
@@ -1770,11 +1793,11 @@ isFavorite(callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1814,11 +1837,13 @@ isFavorite():Promise<boolean>
...
@@ -1814,11 +1837,13 @@ isFavorite():Promise<boolean>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1827,7 +1852,7 @@ async function example() {
...
@@ -1827,7 +1852,7 @@ async function example() {
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
isFavorite
().
then
((
isFavorite
)
=>
{
asset
.
isFavorite
().
then
((
isFavorite
)
=>
{
console
.
info
(
'
mediaLibrary isFavorite Successful, isFavorite result:
'
+
isFavorite
);
console
.
info
(
'
mediaLibrary isFavorite Successful, isFavorite result:
'
+
isFavorite
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
mediaLibrary favoriisFavoritete failed with error:
'
+
error
);
console
.
error
(
'
mediaLibrary favoriisFavoritete failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1859,11 +1884,11 @@ trash(isTrash: boolean, callback: AsyncCallback<void>): void
...
@@ -1859,11 +1884,11 @@ trash(isTrash: boolean, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1911,11 +1936,13 @@ trash(isTrash: boolean): Promise<void>
...
@@ -1911,11 +1936,13 @@ trash(isTrash: boolean): Promise<void>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1924,7 +1951,7 @@ async function example() {
...
@@ -1924,7 +1951,7 @@ async function example() {
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
trash
(
true
).
then
(()
=>
{
asset
.
trash
(
true
).
then
(()
=>
{
console
.
info
(
'
trash successfully
'
);
console
.
info
(
'
trash successfully
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
trash failed with error:
'
+
error
);
console
.
error
(
'
trash failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -1953,11 +1980,11 @@ isTrash(callback: AsyncCallback<boolean>): void
...
@@ -1953,11 +1980,11 @@ isTrash(callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -1997,11 +2024,13 @@ isTrash():Promise<boolean>
...
@@ -1997,11 +2024,13 @@ isTrash():Promise<boolean>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2010,7 +2039,7 @@ async function example() {
...
@@ -2010,7 +2039,7 @@ async function example() {
const
asset
=
await
fetchFileResult
.
getFirstObject
();
const
asset
=
await
fetchFileResult
.
getFirstObject
();
asset
.
isTrash
().
then
((
isTrash
)
=>
{
asset
.
isTrash
().
then
((
isTrash
)
=>
{
console
.
info
(
'
isTrash result:
'
+
isTrash
);
console
.
info
(
'
isTrash result:
'
+
isTrash
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
isTrash failed with error:
'
+
error
);
console
.
error
(
'
isTrash failed with error:
'
+
error
);
});
});
fetchFileResult
.
close
();
fetchFileResult
.
close
();
...
@@ -2045,11 +2074,11 @@ getCount(): number
...
@@ -2045,11 +2074,11 @@ getCount(): number
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
getFileCountOneOp
=
{
let
getFileCountOneOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
selectionArgs
:
[
fileType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2081,11 +2110,11 @@ isAfterLast(): boolean
...
@@ -2081,11 +2110,11 @@ isAfterLast(): boolean
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2094,10 +2123,10 @@ async function example() {
...
@@ -2094,10 +2123,10 @@ async function example() {
const
fetchCount
=
fetchFileResult
.
getCount
();
const
fetchCount
=
fetchFileResult
.
getCount
();
console
.
info
(
'
mediaLibrary fetchFileResult.getCount, count:
'
+
fetchCount
);
console
.
info
(
'
mediaLibrary fetchFileResult.getCount, count:
'
+
fetchCount
);
let
fileAsset
=
await
fetchFileResult
.
getFirstObject
();
let
fileAsset
=
await
fetchFileResult
.
getFirstObject
();
for
(
var
i
=
1
;
i
<
fetchCount
;
i
++
)
{
for
(
let
i
=
1
;
i
<
fetchCount
;
i
++
)
{
fileAsset
=
await
fetchFileResult
.
getNextObject
();
fileAsset
=
await
fetchFileResult
.
getNextObject
();
if
(
i
==
fetchCount
-
1
)
{
if
(
i
==
fetchCount
-
1
)
{
var
result
=
fetchFileResult
.
isAfterLast
();
let
result
=
fetchFileResult
.
isAfterLast
();
console
.
info
(
'
mediaLibrary fileAsset isAfterLast result:
'
+
result
);
console
.
info
(
'
mediaLibrary fileAsset isAfterLast result:
'
+
result
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}
}
...
@@ -2119,11 +2148,11 @@ close(): void
...
@@ -2119,11 +2148,11 @@ close(): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2153,11 +2182,11 @@ getFirstObject(callback: AsyncCallback<FileAsset>): void
...
@@ -2153,11 +2182,11 @@ getFirstObject(callback: AsyncCallback<FileAsset>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2194,11 +2223,13 @@ getFirstObject(): Promise<FileAsset>
...
@@ -2194,11 +2223,13 @@ getFirstObject(): Promise<FileAsset>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2207,7 +2238,7 @@ async function example() {
...
@@ -2207,7 +2238,7 @@ async function example() {
fetchFileResult
.
getFirstObject
().
then
((
fileAsset
)
=>
{
fetchFileResult
.
getFirstObject
().
then
((
fileAsset
)
=>
{
console
.
info
(
'
getFirstObject successfully, displayName:
'
+
fileAsset
.
displayName
);
console
.
info
(
'
getFirstObject successfully, displayName:
'
+
fileAsset
.
displayName
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getFirstObject failed with error:
'
+
error
);
console
.
error
(
'
getFirstObject failed with error:
'
+
error
);
});
});
}
}
...
@@ -2234,11 +2265,11 @@ getNextObject(callback: AsyncCallback<FileAsset>): void
...
@@ -2234,11 +2265,11 @@ getNextObject(callback: AsyncCallback<FileAsset>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2281,11 +2312,13 @@ getNextObject(): Promise<FileAsset>
...
@@ -2281,11 +2312,13 @@ getNextObject(): Promise<FileAsset>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2297,7 +2330,7 @@ async function example() {
...
@@ -2297,7 +2330,7 @@ async function example() {
fetchFileResult
.
getNextObject
().
then
((
fileAsset
)
=>
{
fetchFileResult
.
getNextObject
().
then
((
fileAsset
)
=>
{
console
.
info
(
'
fetchFileResult getNextObject successfully, displayName:
'
+
fileAsset
.
displayName
);
console
.
info
(
'
fetchFileResult getNextObject successfully, displayName:
'
+
fileAsset
.
displayName
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
fetchFileResult getNextObject failed with error:
'
+
error
);
console
.
error
(
'
fetchFileResult getNextObject failed with error:
'
+
error
);
})
})
}
}
...
@@ -2324,11 +2357,11 @@ getLastObject(callback: AsyncCallback<FileAsset>): void
...
@@ -2324,11 +2357,11 @@ getLastObject(callback: AsyncCallback<FileAsset>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2365,11 +2398,13 @@ getLastObject(): Promise<FileAsset>
...
@@ -2365,11 +2398,13 @@ getLastObject(): Promise<FileAsset>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2378,7 +2413,7 @@ async function example() {
...
@@ -2378,7 +2413,7 @@ async function example() {
fetchFileResult
.
getLastObject
().
then
((
fileAsset
)
=>
{
fetchFileResult
.
getLastObject
().
then
((
fileAsset
)
=>
{
console
.
info
(
'
getLastObject successfully, displayName:
'
+
fileAsset
.
displayName
);
console
.
info
(
'
getLastObject successfully, displayName:
'
+
fileAsset
.
displayName
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getLastObject failed with error:
'
+
error
);
console
.
error
(
'
getLastObject failed with error:
'
+
error
);
});
});
}
}
...
@@ -2405,11 +2440,11 @@ getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void
...
@@ -2405,11 +2440,11 @@ getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2452,11 +2487,13 @@ getPositionObject(index: number): Promise<FileAsset>
...
@@ -2452,11 +2487,13 @@ getPositionObject(index: number): Promise<FileAsset>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2465,7 +2502,7 @@ async function example() {
...
@@ -2465,7 +2502,7 @@ async function example() {
fetchFileResult
.
getPositionObject
(
0
).
then
((
fileAsset
)
=>
{
fetchFileResult
.
getPositionObject
(
0
).
then
((
fileAsset
)
=>
{
console
.
info
(
'
getPositionObject successfully, displayName:
'
+
fileAsset
.
displayName
);
console
.
info
(
'
getPositionObject successfully, displayName:
'
+
fileAsset
.
displayName
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getPositionObject failed with error:
'
+
error
);
console
.
error
(
'
getPositionObject failed with error:
'
+
error
);
});
});
}
}
...
@@ -2491,11 +2528,11 @@ getAllObject(callback: AsyncCallback<Array<FileAsset>>): void
...
@@ -2491,11 +2528,11 @@ getAllObject(callback: AsyncCallback<Array<FileAsset>>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2534,11 +2571,13 @@ getAllObject(): Promise<Array<FileAsset>>
...
@@ -2534,11 +2571,13 @@ getAllObject(): Promise<Array<FileAsset>>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
let
getImageOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
selectionArgs
:
[
imageType
.
toString
()],
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
order
:
fileKeyObj
.
DATE_ADDED
+
'
DESC
'
,
...
@@ -2549,7 +2588,7 @@ async function example() {
...
@@ -2549,7 +2588,7 @@ async function example() {
console
.
info
(
'
getAllObject fileAssetList
'
+
i
+
'
displayName:
'
+
fileAssetList
[
i
].
displayName
);
console
.
info
(
'
getAllObject fileAssetList
'
+
i
+
'
displayName:
'
+
fileAssetList
[
i
].
displayName
);
}
}
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
getAllObject failed with error:
'
+
error
);
console
.
error
(
'
getAllObject failed with error:
'
+
error
);
});
});
}
}
...
@@ -2599,14 +2638,14 @@ commitModify(callback: AsyncCallback<void>): void
...
@@ -2599,14 +2638,14 @@ commitModify(callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
],
selectionArgs
:
[
'
新建相册1
'
],
};
};
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsf
etchOp
);
const
albumList
=
await
media
.
getAlbums
(
albumF
etchOp
);
const
album
=
albumList
[
0
];
const
album
=
albumList
[
0
];
album
.
albumName
=
'
hello
'
;
album
.
albumName
=
'
hello
'
;
album
.
commitModify
((
error
)
=>
{
album
.
commitModify
((
error
)
=>
{
...
@@ -2641,19 +2680,21 @@ commitModify(): Promise<void>
...
@@ -2641,19 +2680,21 @@ commitModify(): Promise<void>
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
],
selectionArgs
:
[
'
新建相册1
'
],
};
};
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsf
etchOp
);
const
albumList
=
await
media
.
getAlbums
(
albumF
etchOp
);
const
album
=
albumList
[
0
];
const
album
=
albumList
[
0
];
album
.
albumName
=
'
hello
'
;
album
.
albumName
=
'
hello
'
;
album
.
commitModify
().
then
(()
=>
{
album
.
commitModify
().
then
(()
=>
{
console
.
info
(
'
commitModify successfully
'
);
console
.
info
(
'
commitModify successfully
'
);
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
commitModify failed with error:
'
+
error
);
console
.
error
(
'
commitModify failed with error:
'
+
error
);
});
});
}
}
...
@@ -2681,15 +2722,15 @@ getFileAssets(callback: AsyncCallback<FetchFileResult>): void
...
@@ -2681,15 +2722,15 @@ getFileAssets(callback: AsyncCallback<FetchFileResult>): void
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
],
selectionArgs
:
[
'
新建相册1
'
],
};
};
// 获取符合检索要求的相册,返回相册列表。
// 获取符合检索要求的相册,返回相册列表。
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsf
etchOp
);
const
albumList
=
await
media
.
getAlbums
(
albumF
etchOp
);
const
album
=
albumList
[
0
];
const
album
=
albumList
[
0
];
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
album
.
getFileAssets
((
error
,
fetchFileResult
)
=>
{
album
.
getFileAssets
((
error
,
fetchFileResult
)
=>
{
...
@@ -2727,19 +2768,19 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
...
@@ -2727,19 +2768,19 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
**示例:**
**示例:**
```
j
s
```
t
s
async
function
example
()
{
async
function
example
()
{
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
],
selectionArgs
:
[
'
新建相册1
'
],
};
};
let
fileNoArgsfetchOp
=
{
let
fileNoArgsfetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
''
,
selections
:
''
,
selectionArgs
:
[],
selectionArgs
:
[],
};
};
// 获取符合检索要求的相册,返回相册列表。
// 获取符合检索要求的相册,返回相册列表。
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsf
etchOp
);
const
albumList
=
await
media
.
getAlbums
(
albumF
etchOp
);
const
album
=
albumList
[
0
];
const
album
=
albumList
[
0
];
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
album
.
getFileAssets
(
fileNoArgsfetchOp
,
(
error
,
fetchFileResult
)
=>
{
album
.
getFileAssets
(
fileNoArgsfetchOp
,
(
error
,
fetchFileResult
)
=>
{
...
@@ -2782,26 +2823,28 @@ async function example() {
...
@@ -2782,26 +2823,28 @@ async function example() {
**示例:**
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
async
function
example
()
{
async
function
example
()
{
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
// 获取相册需要先预置相册和资源,示例代码为预置的新建相册1。
let
AlbumNoArgsfetchOp
=
{
let
albumFetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selections
:
mediaLibrary
.
FileKey
.
ALBUM_NAME
+
'
= ?
'
,
selectionArgs
:
[
'
新建相册1
'
],
selectionArgs
:
[
'
新建相册1
'
],
};
};
let
fileNoArgsfetchOp
=
{
let
fileNoArgsfetchOp
:
mediaLibrary
.
MediaFetchOptions
=
{
selections
:
''
,
selections
:
''
,
selectionArgs
:
[],
selectionArgs
:
[],
};
};
// 获取符合检索要求的相册,返回相册列表。
// 获取符合检索要求的相册,返回相册列表。
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsf
etchOp
);
const
albumList
=
await
media
.
getAlbums
(
albumF
etchOp
);
const
album
=
albumList
[
0
];
const
album
=
albumList
[
0
];
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
// 取到相册列表中的一个相册,获取此相册中所有符合媒体检索选项的媒体资源。
album
.
getFileAssets
(
fileNoArgsfetchOp
).
then
((
fetchFileResult
)
=>
{
album
.
getFileAssets
(
fileNoArgsfetchOp
).
then
((
fetchFileResult
)
=>
{
let
count
=
fetchFileResult
.
getCount
();
let
count
=
fetchFileResult
.
getCount
();
console
.
info
(
'
album getFileAssets successfully, count:
'
+
count
);
console
.
info
(
'
album getFileAssets successfully, count:
'
+
count
);
fetchFileResult
.
close
();
fetchFileResult
.
close
();
}).
catch
((
error
)
=>
{
}).
catch
((
error
:
BusinessError
)
=>
{
console
.
error
(
'
album getFileAssets failed with error:
'
+
error
);
console
.
error
(
'
album getFileAssets failed with error:
'
+
error
);
});
});
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录