Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
290da771
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看板
提交
290da771
编写于
4月 16, 2022
作者:
W
wusongqing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
updated docs
Signed-off-by:
N
wusongqing
<
wusongqing@huawei.com
>
上级
1797374e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
146 deletion
+73
-146
en/application-dev/reference/apis/js-apis-media.md
en/application-dev/reference/apis/js-apis-media.md
+73
-146
未找到文件。
en/application-dev/reference/apis/js-apis-media.md
浏览文件 @
290da771
...
...
@@ -88,21 +88,16 @@ Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise
```
js
let
videoPlayer
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
media
.
createVideoPlayer
.
then
((
video
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
media
.
createVideoPlayer
().
then
((
video
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
videoPlayer
=
video
;
console
.
info
(
'
video createVideoPlayer success
'
);
}
else
{
console
.
info
(
'
video createVideoPlayer fail
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
## media.createAudioRecorder
...
...
@@ -173,21 +168,16 @@ Creates a **VideoRecorder** instance in asynchronous mode. This API uses a promi
```
js
let
videoRecorder
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
media
.
createVideoRecorder
.
then
((
video
)
=>
{
media
.
createVideoRecorder
().
then
((
video
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
videoRecorder
=
video
;
console
.
info
(
'
video createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
video createVideoRecorder fail
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
...
...
@@ -482,20 +472,17 @@ function printfDescription(obj) {
console
.
info
(
'
audio value is
'
+
property
);
}
}
function
failureCallback
(
error
)
{
console
.
info
(
`audio failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`audio catchCallback, error:
${
error
.
message
}
`
);
}
a
wait
audioPlayer
.
getTrackDescription
.
then
((
arrlist
)
=>
{
a
udioPlayer
.
getTrackDescription
()
.
then
((
arrlist
)
=>
{
if
(
typeof
(
arrlist
)
!=
'
undefined
'
)
{
arrayDescription
=
arrlist
;
}
else
{
console
.
log
(
'
audio getTrackDescription fail
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`audio catchCallback, error:
${
error
.
message
}
`
);
});
for
(
let
i
=
0
;
i
<
arrayDescription
.
length
;
i
++
)
{
printfDescription
(
arrayDescription
[
i
]);
}
...
...
@@ -586,12 +573,12 @@ audioPlayer.on('error', (error) => { // Set the 'error' event callback
// Set the FD (local playback) of the video file selected by the user.
let
fdPath
=
'
fd://
'
let
path
=
'
data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3
'
;
await
fileIO
.
open
(
path
).
then
(
fdNumber
)
=>
{
fileIO
.
open
(
path
).
then
(
fdNumber
)
=>
{
fdPath
=
fdPath
+
''
+
fdNumber
;
console
.
info
(
'
open fd sucess fd is
'
+
fdPath
);
},
(
err
)
=>
{
console
.
info
(
'
open fd failed err is
'
+
err
);
})
,
catch
((
err
)
=>
{
})
.
catch
((
err
)
=>
{
console
.
info
(
'
open fd failed err is
'
+
err
);
});
audioPlayer
.
src
=
fdPath
;
// Set the src attribute and trigger the 'dataLoad' event callback.
...
...
@@ -735,15 +722,11 @@ Sets **SurfaceId**. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
setDisplaySurface
(
surfaceId
).
then
(()
=>
{
videoPlayer
.
setDisplaySurface
(
surfaceId
).
then
(()
=>
{
console
.
info
(
'
setDisplaySurface success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### prepare<sup>8+</sup>
...
...
@@ -789,15 +772,11 @@ Prepares for video playback. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
prepare
().
then
(()
=>
{
videoPlayer
.
prepare
().
then
(()
=>
{
console
.
info
(
'
prepare success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### play<sup>8+</sup>
...
...
@@ -843,15 +822,11 @@ Starts to play video resources. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
play
().
then
(()
=>
{
videoPlayer
.
play
().
then
(()
=>
{
console
.
info
(
'
play success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### pause<sup>8+</sup>
...
...
@@ -897,15 +872,11 @@ Pauses video playback. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
pause
().
then
(()
=>
{
videoPlayer
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### stop<sup>8+</sup>
...
...
@@ -951,15 +922,11 @@ Stops video playback. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
stop
().
then
(()
=>
{
videoPlayer
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### reset<sup>8+</sup>
...
...
@@ -1005,15 +972,11 @@ Switches the video resource to be played. This API uses a promise to return the
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
reset
().
then
(()
=>
{
videoPlayer
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### seek<sup>8+</sup>
...
...
@@ -1095,19 +1058,17 @@ Seeks to the specified playback position. If **mode** is not specified, the next
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
seek
(
seekTime
).
then
((
seekDoneTime
)
=>
{
// seekDoneTime indicates the position after the seek operation is complete.
videoPlayer
.
seek
(
seekTime
).
then
((
seekDoneTime
)
=>
{
// seekDoneTime indicates the position after the seek operation is complete.
console
.
info
(
'
seek success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
await
videoPlayer
.
seek
(
seekTime
,
seekMode
).
then
((
seekDoneTime
)
=>
{
videoPlayer
.
seek
(
seekTime
,
seekMode
).
then
((
seekDoneTime
)
=>
{
console
.
info
(
'
seek success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### setVolume<sup>8+</sup>
...
...
@@ -1160,15 +1121,11 @@ Sets the volume. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
setVolume
(
vol
).
then
()
=>
{
videoPlayer
.
setVolume
(
vol
).
then
()
=>
{
console
.
info
(
'
setVolume success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### release<sup>8+</sup>
...
...
@@ -1214,15 +1171,11 @@ Releases the video playback resource. This API uses a promise to return the resu
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
release
().
then
()
=>
{
videoPlayer
.
release
().
then
()
=>
{
console
.
info
(
'
release success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### getTrackDescription<sup>8+</sup>
...
...
@@ -1285,21 +1238,17 @@ function printfDescription(obj) {
console
.
info
(
'
video value is
'
+
property
);
}
}
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
let
arrayDescription
;
await
videoPlayer
.
getTrackDescription
().
then
((
arrlist
)
=>
{
videoPlayer
.
getTrackDescription
().
then
((
arrlist
)
=>
{
if
(
typeof
(
arrlist
)
!=
'
undefined
'
)
{
arrayDescription
=
arrlist
;
}
else
{
console
.
log
(
'
video getTrackDescription fail
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
for
(
let
i
=
0
;
i
<
arrayDescription
.
length
;
i
++
)
{
printfDescription
(
arrayDescription
[
i
]);
}
...
...
@@ -1355,15 +1304,11 @@ Sets the video playback speed. This API uses a promise to return the result.
**Example**
```
js
function
failureCallback
(
error
)
{
console
.
info
(
`video failureCallback, error:
${
error
.
message
}
`
);
}
function
catchCallback
(
error
)
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
}
await
videoPlayer
.
setSpeed
(
speed
).
then
()
=>
{
videoPlayer
.
setSpeed
(
speed
).
then
()
=>
{
console
.
info
(
'
setSpeed success
'
);
},
failureCallback
).
catch
(
catchCallback
);
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
### on('playbackCompleted')<sup>8+</sup>
...
...
@@ -1973,23 +1918,19 @@ let videoConfig = {
// promise
let
videoRecorder
=
null
;
await
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
if
(
typeof
(
recorder
)
!=
'
undefined
'
)
{
videoRecorder
=
recorder
;
console
.
info
(
'
createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
createVideoRecorder failed
'
);
}
},
(
err
)
=>
{
console
.
info
(
'
error hanppend message is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
catch err error message is
'
+
err
.
message
);
});
await
videoRecorder
.
prepare
(
videoConfig
).
then
(()
=>
{
videoRecorder
.
prepare
(
videoConfig
).
then
(()
=>
{
console
.
info
(
'
prepare success
'
);
},
(
err
)
=>
{
console
.
info
(
'
prepare failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
prepare failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2051,11 +1992,9 @@ This API can be called only after [prepare()](#videorecorder_prepare1) is called
```
js
// promise
let
surfaceID
=
null
;
// Surface ID passed to the external system.
await
videoRecorder
.
getInputSurface
().
then
((
surfaceId
)
=>
{
videoRecorder
.
getInputSurface
().
then
((
surfaceId
)
=>
{
console
.
info
(
'
getInputSurface success
'
);
surfaceID
=
surfaceId
;
},
(
err
)
=>
{
console
.
info
(
'
getInputSurface failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
getInputSurface failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2110,10 +2049,8 @@ This API can be called only after [prepare()](#videorecorder_prepare1) and [getI
```
js
// promise
await
videoRecorder
.
start
().
then
(()
=>
{
videoRecorder
.
start
().
then
(()
=>
{
console
.
info
(
'
start videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
start videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
start videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2168,10 +2105,8 @@ This API can be called only after [start()](#videorecorder_start1) is called. Yo
```
js
// promise
await
videoRecorder
.
pause
().
then
(()
=>
{
videoRecorder
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
pause videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
pause videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2222,10 +2157,8 @@ Resumes video recording in asynchronous mode. This API uses a promise to return
```
js
// promise
await
videoRecorder
.
resume
().
then
(()
=>
{
videoRecorder
.
resume
().
then
(()
=>
{
console
.
info
(
'
resume videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
resume videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
resume videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2280,10 +2213,8 @@ To start another recording, you must call [prepare()](#videorecorder_prepare1) a
```
js
// promise
await
videoRecorder
.
stop
().
then
(()
=>
{
videoRecorder
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
stop videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
stop videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2334,10 +2265,8 @@ Releases the video recording resource in asynchronous mode. This API uses a prom
```
js
// promise
await
videoRecorder
.
release
().
then
(()
=>
{
videoRecorder
.
release
().
then
(()
=>
{
console
.
info
(
'
release videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
release videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
release videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
@@ -2392,10 +2321,8 @@ To start another recording, you must call [prepare()](#videorecorder_prepare1) a
```
js
// promise
await
videoRecorder
.
reset
().
then
(()
=>
{
videoRecorder
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset videorecorder success
'
);
},
(
err
)
=>
{
console
.
info
(
'
reset videorecorder failed and error is
'
+
err
.
message
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
reset videorecorder failed and catch error is
'
+
err
.
message
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录