Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
52c5e0c2
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看板
未验证
提交
52c5e0c2
编写于
9月 15, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 15, 2022
浏览文件
操作
浏览文件
下载
差异文件
!9502 Align 3.2-Beta2 to master
Merge pull request !9502 from 胡伟奇/OpenHarmony-3.2-Beta2
上级
c542d5ef
081d6b2f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
365 addition
and
119 deletion
+365
-119
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
+365
-119
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
浏览文件 @
52c5e0c2
...
...
@@ -4,7 +4,7 @@
> 该组件从API Version 6开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
## 导入模块
```
```
js
import
mediaLibrary
from
'
@ohos.multimedia.mediaLibrary
'
;
```
...
...
@@ -32,17 +32,18 @@ getMediaLibrary(context: Context): MediaLibrary
**示例:(从API Version 9开始)**
```
var media = mediaLibrary.getMediaLibrary(this.context);
```
ts
const
context
=
getContext
(
this
);
let
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
```
**示例:(API Version 8)**
```
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
var context = featureAbility.getContext()
var
media = mediaLibrary.getMediaLibrary(context);
let
context
=
featureAbility
.
getContext
();
let
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
```
## mediaLibrary.getMediaLibrary
...
...
@@ -65,7 +66,7 @@ getMediaLibrary(): MediaLibrary
**示例:**
```
js
var
media
=
mediaLibrary
.
getMediaLibrary
();
let
media
=
mediaLibrary
.
getMediaLibrary
();
```
## MediaLibrary
...
...
@@ -90,9 +91,9 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
**示例:**
```
let fileKeyObj = mediaLibrary.FileKey
let imageType = mediaLibrary.MediaType.IMAGE
```
js
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
...
...
@@ -100,13 +101,15 @@ let imagesfetchOp = {
media
.
getFileAssets
(
imagesfetchOp
,
(
error
,
fetchFileResult
)
=>
{
if
(
fetchFileResult
!=
undefined
)
{
console
.
info
(
'
mediaLibraryTest : ASSET_CALLBACK fetchFileResult success
'
);
f
etchFileResult.getAllObject((err, fileAssetList) =>
{
if (fileAssetList != undefined)
{
fileAssetList.forEach(function(getAllObjectInfo)
{
console.info("getAllObjectInfo.displayName :" + getAllObjectInfo.displayName
);
})
;
f
or
(
let
i
=
0
;
i
<
fetchFileResult
.
getCount
();
i
++
)
{
fetchFileResult
.
getNextObject
((
err
,
fileAsset
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed
'
);
return
;
}
});
console
.
log
(
'
fileAsset.displayName
'
+
i
+
'
:
'
+
fileAsset
.
displayName
);
})
}
}
});
```
...
...
@@ -134,9 +137,9 @@ getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>
**示例:**
```
let fileKeyObj = mediaLibrary.FileKey
let imageType = mediaLibrary.MediaType.IMAGE
```
js
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
...
...
@@ -165,7 +168,7 @@ on(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'|
**示例:**
```
```
js
media
.
on
(
'
imageChange
'
,
()
=>
{
// image file had changed, do something
})
...
...
@@ -187,13 +190,13 @@ off(type: 'deviceChange'|'albumChange'|'imageChange'|'audioChange'|'videoChange'
**示例:**
```
```
js
media
.
off
(
'
imageChange
'
,
()
=>
{
// stop listening success
})
```
### createAsset
<sup>8+</sup>
### createAsset<sup>8+</sup>
createAsset(mediaType: MediaType, displayName: string, relativePath: string, callback: AsyncCallback
<
FileAsset
>
): void
...
...
@@ -214,7 +217,7 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string, cal
**示例:**
```
```
js
async
function
example
()
{
// 使用Callback方式创建Image类型文件
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -256,16 +259,106 @@ createAsset(mediaType: MediaType, displayName: string, relativePath: string): Pr
**示例:**
```
js
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
media
.
getPublicDirectory
(
DIR_CAMERA
).
then
(
function
(
dicResult
){
console
.
info
(
"
getPublicDirectory successfully:
"
+
JSON
.
stringify
(
dicResult
));
}).
catch
(
function
(
err
){
console
.
info
(
"
getPublicDirectory failed with error:
"
+
err
);
});
```
### deleteAsset<sup>8+</sup>
deleteAsset(uri: string): Promise
\<
void>
删除媒体文件资源
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | 是 | 需要删除的媒体文件资源的uri |
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise
<
void
>
| Promise回调返回删除的结果。 |
**示例:**
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
};
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
const
fetchFileResult
=
await
media
.
getFileAssets
(
option
);
let
asset
=
await
fetchFileResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
)
return
}
media
.
deleteAsset
(
asset
.
uri
).
then
(()
=>
{
console
.
info
(
"
deleteAsset successfully
"
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
deleteAsset failed with error:
"
+
err
);
});
}
```
### deleteAsset<sup>8+</sup>
deleteAsset(uri: string, callback: AsyncCallback
\<
void>): void
删除媒体文件资源
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA and ohos.permission.WRITE_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------- | ---- | --------------- |
| uri | string | 是 | 需要删除的媒体文件资源的uri。 |
|callback |AsyncCallback
\<
void>| 是 |回调函数,用于获取删除的结果。|
**示例:**
```
js
async
function
example
()
{
// 使用Promise方式创建Image类型文件
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
const
path
=
await
media
.
getPublicDirectory
(
DIR_IMAGE
);
media
.
createAsset
(
mediaType
,
"image01.jpg"
,
path
+
'myPicture/'
)
.
then
(
function
(
asset
)
{
console
.
info
(
"createAsset successfully:"
+
JSON
.
stringify
(
asset
));
})
.
catch
(
function
(
err
){
console
.
info
(
"createAsset failed with error:"
+
err
);
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
};
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
const
fetchFileResult
=
await
media
.
getFileAssets
(
option
);
let
asset
=
await
fetchFileResult
.
getFirstObject
();
if
(
asset
==
undefined
)
{
console
.
error
(
'
asset not exist
'
)
return
}
media
.
deleteAsset
(
asset
.
uri
,
(
err
)
=>
{
if
(
err
!=
undefined
)
{
console
.
info
(
"
deleteAsset successfully
"
);
}
else
{
console
.
info
(
"
deleteAsset failed with error:
"
+
err
);
}
});
}
```
...
...
@@ -287,7 +380,7 @@ getPublicDirectory(type: DirectoryType, callback: AsyncCallback<string>):
**示例:**
```
```
js
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
media
.
getPublicDirectory
(
DIR_CAMERA
,
(
err
,
dicResult
)
=>
{
if
(
dicResult
==
'
Camera/
'
)
{
...
...
@@ -320,7 +413,7 @@ getPublicDirectory(type: DirectoryType): Promise<string>
**示例:**
```
```
js
async
function
example
()
{
let
DIR_CAMERA
=
mediaLibrary
.
DirectoryType
.
DIR_CAMERA
;
const
dicResult
=
await
media
.
getPublicDirectory
(
DIR_CAMERA
);
...
...
@@ -351,7 +444,7 @@ getAlbums(options: MediaFetchOptions, callback: AsyncCallback<Array<Album>
**示例:**
```
```
js
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
selectionArgs
:
[],
...
...
@@ -391,7 +484,7 @@ getAlbums(options: MediaFetchOptions): Promise<Array<Album>>
**示例:**
```
```
js
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
selectionArgs
:
[],
...
...
@@ -420,7 +513,7 @@ release(callback: AsyncCallback<void>): void
**示例:**
```
```
js
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
media
.
release
((
err
)
=>
{
// do something
...
...
@@ -444,7 +537,7 @@ release(): Promise<void>
**示例:**
```
```
js
media
.
release
()
```
...
...
@@ -467,7 +560,7 @@ storeMediaAsset(option: MediaAssetOption, callback: AsyncCallback<string>)
**示例:**
```
```
js
let
option
=
{
src
:
"
/data/storage/el2/base/haps/entry/image.png
"
,
mimeType
:
"
image/*
"
,
...
...
@@ -481,7 +574,7 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option, (err, value) => {
console
.
log
(
"
Media resources stored.
"
);
// Obtain the URI that stores media resources.
});
```
```
### storeMediaAsset<sup>(deprecated)</sup>
...
...
@@ -508,7 +601,7 @@ storeMediaAsset(option: MediaAssetOption): Promise<string>
**示例:**
```
```
js
let
option
=
{
src
:
"
/data/storage/el2/base/haps/entry/image.png
"
,
mimeType
:
"
image/*
"
,
...
...
@@ -520,7 +613,7 @@ mediaLibrary.getMediaLibrary().storeMediaAsset(option).then((value) => {
}).
catch
((
err
)
=>
{
console
.
log
(
"
An error occurred when storing media resources.
"
);
});
```
```
### startImagePreview<sup>(deprecated)</sup>
...
...
@@ -543,7 +636,7 @@ startImagePreview(images: Array<string>, index: number, callback: AsyncCal
**示例:**
```
```
js
let
images
=
[
"
dataability:///media/xxxx/2
"
,
"
dataability:///media/xxxx/3
"
...
...
@@ -562,7 +655,7 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index, (err) => {
}
console
.
log
(
"
Succeeded in previewing the images.
"
);
});
```
```
### startImagePreview<sup>(deprecated)</sup>
...
...
@@ -584,7 +677,7 @@ startImagePreview(images: Array<string>, callback: AsyncCallback<void&g
**示例:**
```
```
js
let
images
=
[
"
dataability:///media/xxxx/2
"
,
"
dataability:///media/xxxx/3
"
...
...
@@ -602,7 +695,7 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, (err) => {
}
console
.
log
(
"
Succeeded in previewing the images.
"
);
});
```
```
### startImagePreview<sup>(deprecated)</sup>
...
...
@@ -630,7 +723,7 @@ startImagePreview(images: Array<string>, index?: number): Promise<void&
**示例:**
```
```
js
let
images
=
[
"
dataability:///media/xxxx/2
"
,
"
dataability:///media/xxxx/3
"
...
...
@@ -647,7 +740,7 @@ mediaLibrary.getMediaLibrary().startImagePreview(images, index).then(() => {
}).
catch
((
err
)
=>
{
console
.
log
(
"
An error occurred when previewing the images.
"
);
});
```
```
### startMediaSelect<sup>(deprecated)</sup>
...
...
@@ -664,12 +757,12 @@ startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| option |
[
MediaSelectOption
](
#mediaselectoption
)
| 是 | 媒体选择选项。 |
| option |
[
MediaSelectOption
](
#mediaselectoption
deprecated
)
| 是 | 媒体选择选项。 |
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 媒体选择回调,返回选择的媒体URI(dataability://)列表。 |
**示例:**
```
```
js
let
option
=
{
type
:
"
media
"
,
count
:
2
...
...
@@ -682,7 +775,7 @@ mediaLibrary.getMediaLibrary().startMediaSelect(option, (err, value) => {
console
.
log
(
"
Media resources selected.
"
);
// Obtain the media selection value.
});
```
```
### startMediaSelect<sup>(deprecated)</sup>
...
...
@@ -699,7 +792,7 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
| 参数名 | 类型 | 必填 | 说明 |
| ------ | --------------------------------------- | ---- | ------- |
| option |
[
MediaSelectOption
](
#mediaselectoption
)
| 是 | 媒体选择选项。 |
| option |
[
MediaSelectOption
](
#mediaselectoption
deprecated
)
| 是 | 媒体选择选项。 |
**返回值:**
...
...
@@ -709,7 +802,7 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
**示例:**
```
```
js
let
option
=
{
type
:
"
media
"
,
count
:
2
...
...
@@ -721,7 +814,155 @@ mediaLibrary.getMediaLibrary().startMediaSelect(option).then((value) => {
console
.
log
(
"
An error occurred when selecting media resources.
"
);
});
```
```
### getActivePeers<sup>8+</sup>
getActivePeers(): Promise
\<
Array
\<
PeerInfo>>;
获取在线对端设备的信息,使用Promise方式返回异步结果
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.DistributedCore
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise
\<
Array
\<
PeerInfo>> | 返回获取的所有在线对端设备的PeerInfo |
**示例:**
```
js
async
function
example
()
{
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
media
.
getActivePeers
().
then
((
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
info
(
'
get distributed info is undefined!
'
)
}
}).
catch
((
err
)
=>
{
console
.
info
(
"
get distributed info failed with error:
"
+
err
);
});
}
```
### getActivePeers<sup>8+</sup>
getActivePeers(callback: AsyncCallback
\<
Array
\<
PeerInfo>>): void;
获取在线对端设备的信息,使用callback方式返回异步结果。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.DistributedCore
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| callback: AsyncCallback
\<
Array
\<
PeerInfo>> | 返回获取的所有在线对端设备的PeerInfo |
**示例:**
```
js
async
function
example
()
{
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
media
.
getActivePeers
((
err
,
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
info
(
'
get distributed fail, message =
'
+
err
)
}
})
}
```
### getAllPeers<sup>8+</sup>
getAllPeers(): Promise
\<
Array
\<
PeerInfo>>;
获取所有对端设备的信息,使用Promise方式返回异步结果
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.DistributedCore
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| Promise
\<
Array
\<
PeerInfo>> | 返回获取的所有对端设备的PeerInfo |
**示例:**
```
js
async
function
example
()
{
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
media
.
getAllPeers
().
then
((
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
info
(
'
get distributed info is undefined!
'
)
}
}).
catch
((
err
)
=>
{
console
.
info
(
"
get distributed info failed with error:
"
+
err
);
});
}
```
### getAllPeers<sup>8+</sup>
getAllPeers(callback: AsyncCallback
\<
Array
\<
PeerInfo>>): void;
获取所有对端设备的信息,使用callback方式返回异步结果。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.READ_MEDIA
**系统能力**
:SystemCapability.Multimedia.MediaLibrary.DistributedCore
**返回值:**
| 类型 | 说明 |
| ------------------- | -------------------- |
| callback: AsyncCallback
\<
Array
\<
PeerInfo>> | 返回获取的所有对端设备的PeerInfo |
**示例:**
```
js
async
function
example
()
{
const
context
=
getContext
(
this
);
var
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
media
.
getAllPeers
((
err
,
devicesInfo
)
=>
{
if
(
devicesInfo
!=
undefined
)
{
for
(
let
i
=
0
;
i
<
devicesInfo
.
length
;
i
++
)
{
console
.
info
(
'
get distributed info
'
+
devicesInfo
[
i
].
deviceName
+
devicesInfo
[
i
].
networkId
);
}
}
else
{
console
.
info
(
'
get distributed fail, message =
'
+
err
)
}
})
}
```
## FileAsset<sup>7+</sup>
...
...
@@ -774,7 +1015,7 @@ isDirectory(callback: AsyncCallback<boolean>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -810,7 +1051,7 @@ isDirectory():Promise<boolean>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -848,7 +1089,7 @@ commitModify(callback: AsyncCallback<void>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -885,7 +1126,7 @@ commitModify(): Promise<void>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -923,7 +1164,7 @@ open(mode: string, callback: AsyncCallback<number>): void
**示例:**
```
```
js
async
function
example
()
{
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
...
...
@@ -965,7 +1206,7 @@ open(mode: string): Promise<number>
**示例:**
```
```
js
async
function
example
()
{
let
mediaType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
DIR_IMAGE
=
mediaLibrary
.
DirectoryType
.
DIR_IMAGE
;
...
...
@@ -1000,7 +1241,7 @@ close(fd: number, callback: AsyncCallback<void>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -1053,7 +1294,7 @@ close(fd: number): Promise<void>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -1101,7 +1342,7 @@ getThumbnail(callback: AsyncCallback<image.PixelMap>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
...
...
@@ -1138,9 +1379,9 @@ getThumbnail(size: Size, callback: AsyncCallback<image.PixelMap>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1181,9 +1422,9 @@ getThumbnail(size?: Size): Promise<image.PixelMap>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1223,9 +1464,9 @@ favorite(isFavorite: boolean, callback: AsyncCallback<void>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1265,9 +1506,9 @@ favorite(isFavorite: boolean): Promise<void>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1303,9 +1544,9 @@ isFavorite(callback: AsyncCallback<boolean>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1343,9 +1584,9 @@ isFavorite():Promise<boolean>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1384,9 +1625,9 @@ trash(isTrash: boolean, callback: AsyncCallback<void>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1429,9 +1670,9 @@ trash(isTrash: boolean): Promise<void>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1467,9 +1708,9 @@ isTrash(callback: AsyncCallback<boolean>): void
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1512,9 +1753,9 @@ isTrash():Promise<boolean>
**示例:**
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1552,9 +1793,9 @@ getCount(): number
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
getFileCountOneOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1583,9 +1824,9 @@ isAfterLast(): boolean
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1621,9 +1862,9 @@ close(): void
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1652,9 +1893,9 @@ getFirstObject(callback: AsyncCallback<FileAsset>): void
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1689,9 +1930,9 @@ getFirstObject(): Promise<FileAsset>
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1724,9 +1965,9 @@ async function example() {
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1761,9 +2002,9 @@ async function example() {
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1794,9 +2035,9 @@ getLastObject(callback: AsyncCallback<FileAsset>): void
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1831,9 +2072,9 @@ getLastObject(): Promise<FileAsset>
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1863,9 +2104,9 @@ getPositionObject(index: number, callback: AsyncCallback<FileAsset>): void
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1906,9 +2147,9 @@ getPositionObject(index: number): Promise<FileAsset>
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1918,9 +2159,9 @@ async function example() {
};
let
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
fetchFileResult
.
getPositionObject
(
1
)
.
then
(
function
(
fileAsset
){
console
.
log
(
'
[Demo]
fileAsset.displayName : '
+
fileAsset
.
displayName
);
console
.
log
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}).
catch
(
function
(
err
)
{
console
.
info
(
"
[Demo]
getFileAssets failed with error:"
+
err
);
console
.
info
(
"
getFileAssets failed with error:
"
+
err
);
});
}
```
...
...
@@ -1941,9 +2182,9 @@ getAllObject(callback: AsyncCallback<Array<FileAsset>>): void
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -1978,9 +2219,9 @@ getAllObject(): Promise<Array<FileAsset>>
**示例**
:
```
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
getImageOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
...
...
@@ -2029,7 +2270,7 @@ commitModify(callback: AsyncCallback<void>): void
**示例**
:
```
```
js
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
...
...
@@ -2066,7 +2307,7 @@ commitModify(): Promise<void>
**示例**
:
```
```
js
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
...
...
@@ -2102,7 +2343,7 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
**示例**
:
```
```
js
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
...
...
@@ -2145,7 +2386,7 @@ async function example() {
**示例**
:
```
```
js
async
function
example
()
{
let
AlbumNoArgsfetchOp
=
{
selections
:
''
,
...
...
@@ -2154,7 +2395,7 @@ async function example() {
let
fileNoArgsfetchOp
=
{
selections
:
''
,
selectionArgs
:
[],
}
}
;
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsfetchOp
);
const
album
=
albumList
[
0
];
album
.
getFileAssets
(
fileNoArgsfetchOp
).
then
(
function
(
albumFetchFileResult
){
...
...
@@ -2168,7 +2409,8 @@ async function example() {
## PeerInfo<sup>8+</sup>
注册设备的信息。
此接口为系统接口。
**系统接口**
:此接口为系统接口。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.DistributedCore
...
...
@@ -2240,7 +2482,8 @@ async function example() {
## DeviceType<sup>8+</sup>
枚举,设备类型。
此接口为系统接口。
**系统接口**
:此接口为系统接口。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.DistributedCore
...
...
@@ -2262,7 +2505,7 @@ async function example() {
| 名称 | 类型 | 可读 | 可写 | 必填 | 说明 |
| ----------------------- | ------------------- | ---- | ---- | ---- | ------------------------------------------------------------ |
| selections | string | 是 | 是 | 是 | 检索条件,使用
[
FileKey
](
#filekey8
)
中的枚举值作为检索条件的列名。示例:
<br
/>
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR
' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?‘
, |
| selections | string | 是 | 是 | 是 | 检索条件,使用
[
FileKey
](
#filekey8
)
中的枚举值作为检索条件的列名。示例:
<br
/>
selections: mediaLibrary.FileKey.MEDIA_TYPE + '= ? OR
' +mediaLibrary.FileKey.MEDIA_TYPE + '= ?'
, |
| selectionArgs | Array
<
string
>
| 是 | 是 | 是 | 检索条件的值,对应selections中检索条件列的值。
<br
/>
示例:
<br
/>
selectionArgs: [mediaLibrary.MediaType.IMAGE.toString(), mediaLibrary.MediaType.VIDEO.toString()], |
| order | string | 是 | 是 | 否 | 检索结果排序方式,使用
[
FileKey
](
#filekey8
)
中的枚举值作为检索结果排序的列,可以用升序或降序排列。示例:
<br
/>
升序排列:order: mediaLibrary.FileKey.DATE_ADDED + " ASC"
<br
/>
降序排列:order: mediaLibrary.FileKey.DATE_ADDED + " DESC" |
| uri
<sup>
8+
</sup>
| string | 是 | 是 | 否 | 文件URI |
...
...
@@ -2272,7 +2515,8 @@ async function example() {
## Size<sup>8+</sup>
图片尺寸。
系统能力: 以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.MediaLibrary.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------ | ------ | ---- | ---- | -------- |
...
...
@@ -2307,3 +2551,5 @@ async function example() {
| type | string | 是 | 媒体类型,包括:image, video, media,当前仅支持media类型 |
| count | number | 是 | 媒体选择,count = 1表示单选,count大于1表示多选。 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录