Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c7c61728
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看板
未验证
提交
c7c61728
编写于
9月 16, 2022
作者:
O
openharmony_ci
提交者:
Gitee
9月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
!9588 Align master to 3.2-Beta3
Merge pull request !9588 from 胡伟奇/cherry-pick-1663321400
上级
b90f6bba
498caa4d
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
53 deletion
+61
-53
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
+61
-53
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md
浏览文件 @
c7c61728
...
...
@@ -42,7 +42,7 @@ let media = mediaLibrary.getMediaLibrary(context);
```
js
import
featureAbility
from
'
@ohos.ability.featureAbility
'
;
let
context
=
featureAbility
.
getContext
()
let
context
=
featureAbility
.
getContext
()
;
let
media
=
mediaLibrary
.
getMediaLibrary
(
context
);
```
## mediaLibrary.getMediaLibrary
...
...
@@ -92,8 +92,8 @@ getFileAssets(options: MediaFetchOptions, callback: AsyncCallback<FetchFileRe
**示例:**
```
js
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
...
...
@@ -101,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
);
})
}
}
});
```
...
...
@@ -136,8 +138,8 @@ getFileAssets(options: MediaFetchOptions): Promise<FetchFileResult>
**示例:**
```
js
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
...
...
@@ -293,8 +295,8 @@ deleteAsset(uri: string): Promise\<void>
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
...
...
@@ -337,8 +339,8 @@ deleteAsset(uri: string, callback: AsyncCallback\<void>): void
```
js
async
function
example
()
{
let
fileKeyObj
=
mediaLibrary
.
FileKey
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
fileType
=
mediaLibrary
.
MediaType
.
FILE
;
let
option
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
fileType
.
toString
()],
...
...
@@ -761,11 +763,13 @@ startMediaSelect(option: MediaSelectOption, callback: AsyncCallback<Array<
**示例:**
```
js
let
option
=
{
type
:
"
media
"
,
count
:
2
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
};
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
option
,
(
err
,
value
)
=>
{
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
imagesfetchOp
,
(
err
,
value
)
=>
{
if
(
err
)
{
console
.
log
(
"
An error occurred when selecting media resources.
"
);
return
;
...
...
@@ -801,11 +805,13 @@ startMediaSelect(option: MediaSelectOption): Promise<Array<string>>
**示例:**
```
js
let
option
=
{
type
:
"
media
"
,
count
:
2
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
imageType
=
mediaLibrary
.
MediaType
.
IMAGE
;
let
imagesfetchOp
=
{
selections
:
fileKeyObj
.
MEDIA_TYPE
+
'
= ?
'
,
selectionArgs
:
[
imageType
.
toString
()],
};
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
option
).
then
((
value
)
=>
{
mediaLibrary
.
getMediaLibrary
().
startMediaSelect
(
imagesfetchOp
).
then
((
value
)
=>
{
console
.
log
(
"
Media resources selected.
"
);
// Obtain the media selection value.
}).
catch
((
err
)
=>
{
...
...
@@ -1255,7 +1261,7 @@ async function example() {
console
.
info
(
'
File fd!
'
+
fd
);
asset
.
close
(
fd
,
(
closeErr
)
=>
{
if
(
closeErr
!=
undefined
)
{
console
.
info
(
'
mediaLibraryTest : close : FAIL
'
+
closeErr
.
message
);
console
.
info
(
'
mediaLibraryTest : close : FAIL
'
+
closeErr
);
console
.
info
(
'
mediaLibraryTest : ASSET_CALLBACK : FAIL
'
);
}
else
{
console
.
info
(
"
=======asset.close success====>
"
);
...
...
@@ -1308,7 +1314,7 @@ async function example() {
console
.
info
(
'
File fd!
'
+
fd
);
asset
.
close
(
fd
).
then
((
closeErr
)
=>
{
if
(
closeErr
!=
undefined
)
{
console
.
info
(
'
mediaLibraryTest : close : FAIL
'
+
closeErr
.
message
);
console
.
info
(
'
mediaLibraryTest : close : FAIL
'
+
closeErr
);
console
.
info
(
'
mediaLibraryTest : ASSET_CALLBACK : FAIL
'
);
}
else
{
...
...
@@ -1379,7 +1385,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1422,7 +1428,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1464,7 +1470,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1506,7 +1512,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1544,7 +1550,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1584,7 +1590,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1625,7 +1631,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1670,7 +1676,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1708,7 +1714,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1722,7 +1728,7 @@ async function example() {
function
isTrashCallBack
(
err
,
isTrash
)
{
if
(
isTrash
==
true
)
{
console
.
info
(
'
mediaLibraryTest : ASSET_CALLBACK ASSET_CALLBACK isTrash =
'
+
isTrash
);
asset
.
trash
(
true
,
is
t
rashCallBack
);
asset
.
trash
(
true
,
is
T
rashCallBack
);
}
else
{
console
.
info
(
'
mediaLibraryTest : ASSET_CALLBACK isTrash Unsuccessfull =
'
+
err
);
...
...
@@ -1753,7 +1759,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1793,7 +1799,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1824,7 +1830,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1862,7 +1868,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1893,7 +1899,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1930,7 +1936,7 @@ 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
+
'
= ?
'
,
...
...
@@ -1965,7 +1971,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2002,7 +2008,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2035,7 +2041,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2072,7 +2078,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2104,7 +2110,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2147,7 +2153,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2182,7 +2188,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2192,11 +2198,13 @@ async function example() {
};
let
fetchFileResult
=
await
media
.
getFileAssets
(
getImageOp
);
fetchFileResult
.
getAllObject
((
err
,
fileAsset
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
Failed
'
);
return
;
}
console
.
log
(
'
fileAsset.displayName :
'
+
fileAsset
.
displayName
);
}
for
(
let
i
=
0
;
i
<
fetchFileResult
.
getCount
();
i
++
)
{
console
.
log
(
'
fileAsset.displayName :
'
+
fileAsset
[
i
].
displayName
);
}
})
}
```
...
...
@@ -2219,7 +2227,7 @@ 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
+
'
= ?
'
,
...
...
@@ -2393,7 +2401,7 @@ async function example() {
let
fileNoArgsfetchOp
=
{
selections
:
''
,
selectionArgs
:
[],
}
}
;
const
albumList
=
await
media
.
getAlbums
(
AlbumNoArgsfetchOp
);
const
album
=
albumList
[
0
];
album
.
getFileAssets
(
fileNoArgsfetchOp
).
then
(
function
(
albumFetchFileResult
){
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录