Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
ed1330c7
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看板
未验证
提交
ed1330c7
编写于
9月 05, 2022
作者:
Z
zengyawen
提交者:
Gitee
9月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
适配dts
Signed-off-by:
N
zengyawen
<
zengyawen1@huawei.com
>
上级
957ee78f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
243 addition
and
242 deletion
+243
-242
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
+243
-242
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
浏览文件 @
ed1330c7
...
...
@@ -265,6 +265,101 @@ media.getPublicDirectory(DIR_CAMERA).then(function(dicResult){
});
```
### 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
()
{
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
);
}
});
}
```
### getPublicDirectory<sup>8+</sup>
getPublicDirectory(type: DirectoryType, callback: AsyncCallback
<
string
>
): void
...
...
@@ -659,7 +754,7 @@ startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------- | ---- | ------------------------------------ |
| option |
[
MediaSelectOption
](
#mediaselectoption
)
| 是 | 媒体选择选项。 |
| option |
[
MediaSelectOption
](
#mediaselectoption
deprecated
)
| 是 | 媒体选择选项。 |
| callback | AsyncCallback
<
Array
<
string
>>
| 是 | 媒体选择回调,返回选择的媒体URI(dataability://)列表。 |
**示例:**
...
...
@@ -694,7 +789,7 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
| 参数名 | 类型 | 必填 | 说明 |
| ------ | --------------------------------------- | ---- | ------- |
| option |
[
MediaSelectOption
](
#mediaselectoption
)
| 是 | 媒体选择选项。 |
| option |
[
MediaSelectOption
](
#mediaselectoption
deprecated
)
| 是 | 媒体选择选项。 |
**返回值:**
...
...
@@ -716,6 +811,152 @@ 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>
...
...
@@ -1527,246 +1768,6 @@ async function example() {
}
```
### 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
()
{
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
);
}
});
}
```
### 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(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(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
)
}
})
}
```
## FetchFileResult<sup>7+</sup>
文件检索结果集。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录