Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
6eef87b6
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看板
未验证
提交
6eef87b6
编写于
6月 29, 2022
作者:
O
openharmony_ci
提交者:
Gitee
6月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
!6105 media文档修改
Merge pull request !6105 from zengyawen/OpenHarmony-3.1-Release
上级
44c48f1d
fdb9caa8
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
7 addition
and
704 deletion
+7
-704
zh-cn/application-dev/reference/apis/js-apis-media.md
zh-cn/application-dev/reference/apis/js-apis-media.md
+7
-704
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-media.md
浏览文件 @
6eef87b6
...
@@ -2,8 +2,7 @@
...
@@ -2,8 +2,7 @@
> **说明:**
> **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。
媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。
...
@@ -12,7 +11,6 @@
...
@@ -12,7 +11,6 @@
-
音频播放(
[
AudioPlayer
](
#audioplayer
)
)
-
音频播放(
[
AudioPlayer
](
#audioplayer
)
)
-
视频播放(
[
VideoPlayer
](
#videoplayer8
)
)
-
视频播放(
[
VideoPlayer
](
#videoplayer8
)
)
-
音频录制(
[
AudioRecorder
](
#audiorecorder
)
)
-
音频录制(
[
AudioRecorder
](
#audiorecorder
)
)
-
视频录制(
[
VideoRecorder
](
#videorecorder9
)
)
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。
...
@@ -122,65 +120,6 @@ createAudioRecorder(): AudioRecorder
...
@@ -122,65 +120,6 @@ createAudioRecorder(): AudioRecorder
let
audioRecorder
=
media
.
createAudioRecorder
();
let
audioRecorder
=
media
.
createAudioRecorder
();
```
```
## media.createVideoRecorder<sup>9+</sup>
createVideoRecorder(callback: AsyncCallback
\<
[
VideoRecorder
](
#videorecorder9
)
>): void
异步方式创建视频录制实例。通过注册回调函数获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback
<
[
VideoRecorder
](
#videorecorder9
)
>
| 是 | 异步创建视频录制实例回调方法。 |
**示例:**
```
js
let
videoRecorder
media
.
createVideoRecorder
((
error
,
video
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
videoRecorder
=
video
;
console
.
info
(
'
video createVideoRecorder success
'
);
}
else
{
console
.
info
(
`video createVideoRecorder fail, error:
${
error
.
message
}
`
);
}
});
```
## media.createVideoRecorder<sup>9+</sup>
createVideoRecorder(): Promise
<
[
VideoRecorder
](
#videorecorder9
)
>
异步方式创建视频录制实例。通过Promise获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ----------------------------------- |
| Promise
<
[
VideoRecorder
](
#videorecorder9
)
>
| 异步创建视频录制实例Promise返回值。 |
**示例:**
```
js
let
videoRecorder
media
.
createVideoRecorder
().
then
((
video
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
videoRecorder
=
video
;
console
.
info
(
'
video createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
video createVideoRecorder fail
'
);
}
}).
catch
((
error
)
=>
{
console
.
info
(
`video catchCallback, error:
${
error
.
message
}
`
);
});
```
...
@@ -1527,7 +1466,7 @@ prepare(config: AudioRecorderConfig): void
...
@@ -1527,7 +1466,7 @@ prepare(config: AudioRecorderConfig): void
| 参数名 | 类型 | 必填 | 说明 |
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| config |
[
AudioRecorderConfig
](
#audiorecorderconfig
)
| 是 | 配置录音的相关参数,包括音频输出URI、
[
编码格式
](
#audioencoder
)
、采样率、声道数、
[
输出格式
](
#audiooutputformat
)
等。 |
| config |
[
AudioRecorderConfig
](
#audiorecorderconfig
)
| 是 | 配置录音的相关参数,包括音频输出URI、
编码格式、采样率、声道数、输出格式
等。 |
**示例:**
**示例:**
...
@@ -1745,14 +1684,15 @@ audioRecorder.prepare(); // pre
...
@@ -1745,14 +1684,15 @@ audioRecorder.prepare(); // pre
| 名称 | 参数类型 | 必填 | 说明 |
| 名称 | 参数类型 | 必填 | 说明 |
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| audioEncoder
|
[
AudioEncoder
](
#audioencoder
)
| 否 | 音频编码格式,默认设置为AAC_LC
。 |
| audioEncoder
<sup>
(deprecated)
</sup>
|
[
AudioEncoder
](
#audioencoder
)
| 否 | 音频编码格式,默认设置为AAC_LC。
<br/>
**说明:**
从API Version 8 开始废弃,建议使用audioEncoderMime替代
。 |
| audioEncodeBitRate | number | 否 | 音频编码比特率,默认值为48000。 |
| audioEncodeBitRate | number | 否 | 音频编码比特率,默认值为48000。 |
| audioSampleRate | number | 否 | 音频采集采样率,默认值为48000。 |
| audioSampleRate | number | 否 | 音频采集采样率,默认值为48000。 |
| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。 |
| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。 |
| format
|
[
AudioOutputFormat
](
#audiooutputformat
)
| 否 | 音频输出封装格式,默认设置为MPEG_4
。 |
| format
<sup>
(deprecated)
</sup>
|
[
AudioOutputFormat
](
#audiooutputformat
)
| 否 | 音频输出封装格式,默认设置为MPEG_4。
<br/>
**说明:**
从API Version 8 开始废弃,建议使用fileFormat替代
。 |
| location |
[
Location
](
#location
)
| 否 | 音频采集的地理位置。 |
| location |
[
Location
](
#location
)
| 否 | 音频采集的地理位置。 |
| uri | string | 是 | 音频输出URI:fd://xx
(fd
number)
<br/>

<br/>
文件需要由调用者创建,并赋予适当的权限。 |
| uri | string | 是 | 音频输出URI:fd://xx
(fd
number)
<br/>

<br/>
文件需要由调用者创建,并赋予适当的权限。 |
| audioEncoderMime |
[
CodecMimeType
](
#codecmimetype8
)
| 否 | 音频编码格式。 |
| audioEncoderMime
<sup>
8+
</sup>
|
[
CodecMimeType
](
#codecmimetype8
)
| 否 | 音频编码格式。 |
| fileFormat
<sup>
8+
</sup>
|
[
ContainerFormatType
](
#containerformattype8
)
| 否 | 音频编码格式。 |
## AudioEncoder<sup>(deprecated)</sup>
## AudioEncoder<sup>(deprecated)</sup>
...
@@ -1790,643 +1730,6 @@ audioRecorder.prepare(); // pre
...
@@ -1790,643 +1730,6 @@ audioRecorder.prepare(); // pre
| AMR_WB | 4 | 封装为AMR_WB格式。
<br/>
仅做接口定义,暂不支持使用。 |
| AMR_WB | 4 | 封装为AMR_WB格式。
<br/>
仅做接口定义,暂不支持使用。 |
| AAC_ADTS | 6 | 封装为ADTS(Audio
Data
Transport
Stream)格式,是AAC音频的传输流格式。 |
| AAC_ADTS | 6 | 封装为ADTS(Audio
Data
Transport
Stream)格式,是AAC音频的传输流格式。 |
## VideoRecorder<sup>9+</sup>
视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过
[
createVideoRecorder()
](
#mediacreatevideorecorder9
)
构建一个
[
VideoRecorder
](
#videorecorder9
)
实例。
视频录制demo可参考:
[
视频录制开发指导
](
../../media/video-recorder.md
)
### 属性
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------------ | -------------------------------------- | ---- | ---- | ---------------- |
| state
<sup>
8+
</sup>
|
[
VideoRecordState
](
#videorecordstate9
)
| 是 | 否 | 视频录制的状态。 |
### prepare<sup>9+</sup><a name=videorecorder_prepare1></a>
prepare(config: VideoRecorderConfig, callback: AsyncCallback
\<
void>): void;
异步方式进行视频录制的参数设置。通过注册回调函数获取返回值。
**需要权限:**
ohos.permission.MICROPHONE
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------- | ---- | ----------------------------------- |
| config |
[
VideoRecorderConfig
](
#videorecorderconfig9
)
| 是 | 配置视频录制的相关参数。 |
| callback | AsyncCallback
\<
void> | 是 | 异步视频录制prepare方法的回调方法。 |
**示例:**
```
js
let
videoProfile
=
{
audioBitrate
:
48000
,
audioChannels
:
2
,
audioCodec
:
'
audio/mp4a-latm
'
,
audioSampleRate
:
48000
,
fileFormat
:
'
mp4
'
,
videoBitrate
:
48000
,
videoCodec
:
'
video/mp4v-es
'
,
videoFrameWidth
:
640
,
videoFrameHeight
:
480
,
videoFrameRate
:
30
}
let
videoConfig
=
{
audioSourceType
:
1
,
videoSourceType
:
0
,
profile
:
videoProfile
,
url
:
'
fd://xx
'
,
// 文件需先由调用者创建,并给予适当的权限
orientationHint
:
0
,
location
:
{
latitude
:
30
,
longitude
:
130
},
}
// asyncallback
let
videoRecorder
=
null
;
let
events
=
require
(
'
events
'
);
let
eventEmitter
=
new
events
.
EventEmitter
();
eventEmitter
.
on
(
'
prepare
'
,
()
=>
{
videoRecorder
.
prepare
(
videoConfig
,
(
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
prepare success
'
);
}
else
{
console
.
info
(
'
prepare failed and error is
'
+
err
.
message
);
}
});
});
media
.
createVideoRecorder
((
err
,
recorder
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
&&
typeof
(
recorder
)
!=
'
undefined
'
)
{
videoRecorder
=
recorder
;
console
.
info
(
'
createVideoRecorder success
'
);
eventEmitter
.
emit
(
'
prepare
'
);
// prepare事件触发
}
else
{
console
.
info
(
'
createVideoRecorder failed and error is
'
+
err
.
message
);
}
});
```
### prepare<sup>9+</sup><a name=videorecorder_prepare2></a>
prepare(config: VideoRecorderConfig): Promise
\<
void>;
异步方式进行视频录制的参数设置。通过Promise获取返回值。
**需要权限:**
ohos.permission.MICROPHONE,ohos.permission.CAMERA
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | -------------------------------------------- | ---- | ------------------------ |
| config |
[
VideoRecorderConfig
](
#videorecorderconfig9
)
| 是 | 配置视频录制的相关参数。 |
**返回值:**
| 类型 | 说明 |
| -------------- | ---------------------------------------- |
| Promise
\<
void> | 异步视频录制prepare方法的Promise返回值。 |
**示例:**
```
js
let
videoProfile
=
{
audioBitrate
:
48000
,
audioChannels
:
2
,
audioCodec
:
'
audio/mp4a-latm
'
,
audioSampleRate
:
48000
,
fileFormat
:
'
mp4
'
,
videoBitrate
:
48000
,
videoCodec
:
'
video/mp4v-es
'
,
videoFrameWidth
:
640
,
videoFrameHeight
:
480
,
videoFrameRate
:
30
}
let
videoConfig
=
{
audioSourceType
:
1
,
videoSourceType
:
0
,
profile
:
videoProfile
,
url
:
'
fd://xx
'
,
// 文件需先由调用者创建,并给予适当的权限
orientationHint
:
0
,
location
:
{
latitude
:
30
,
longitude
:
130
},
}
// promise
let
videoRecorder
=
null
;
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
if
(
typeof
(
recorder
)
!=
'
undefined
'
)
{
videoRecorder
=
recorder
;
console
.
info
(
'
createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
createVideoRecorder failed
'
);
}
}).
catch
((
err
)
=>
{
console
.
info
(
'
catch err error message is
'
+
err
.
message
);
});
videoRecorder
.
prepare
(
videoConfig
).
then
(()
=>
{
console
.
info
(
'
prepare success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
prepare failed and catch error is
'
+
err
.
message
);
});
```
### getInputSurface<sup>9+</sup>
getInputSurface(callback: AsyncCallback
\<
string>): void;
异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。
只能在
[
prepare()
](
#videorecorder_prepare1
)
接口调用后调用。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | --------------------------- |
| callback | AsyncCallback
\<
string> | 是 | 异步获得surface的回调方法。 |
**示例:**
```
js
// asyncallback
let
surfaceID
=
null
;
// 传递给外界的surfaceID
videoRecorder
.
getInputSurface
((
err
,
surfaceId
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
getInputSurface success
'
);
surfaceID
=
surfaceId
;
}
else
{
console
.
info
(
'
getInputSurface failed and error is
'
+
err
.
message
);
}
});
```
### getInputSurface<sup>9+</sup>
getInputSurface(): Promise
\<
string>;
异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。
只能在
[
prepare()
](
#videorecorder_prepare1
)
接口调用后调用。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------------------- |
| Promise
\<
string> | 异步获得surface的Promise返回值。 |
**示例:**
```
js
// promise
let
surfaceID
=
null
;
// 传递给外界的surfaceID
videoRecorder
.
getInputSurface
().
then
((
surfaceId
)
=>
{
console
.
info
(
'
getInputSurface success
'
);
surfaceID
=
surfaceId
;
}).
catch
((
err
)
=>
{
console
.
info
(
'
getInputSurface failed and catch error is
'
+
err
.
message
);
});
```
### start<sup>9+</sup><a name=videorecorder_start1></a>
start(callback: AsyncCallback
\<
void>): void;
异步方式开始视频录制。通过注册回调函数获取返回值。
在
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
后调用,需要依赖数据源先给surface传递数据。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步开始视频录制的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
start
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
start videorecorder success
'
);
}
else
{
console
.
info
(
'
start videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### start<sup>9+</sup><a name=videorecorder_start2></a>
start(): Promise
\<
void>;
异步方式开始视频录制。通过Promise获取返回值。
在
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
后调用,需要依赖数据源先给surface传递数据。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
void> | 异步开始视频录制方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
start
().
then
(()
=>
{
console
.
info
(
'
start videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
start videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### pause<sup>9+</sup><a name=videorecorder_pause1></a>
pause(callback: AsyncCallback
\<
void>): void;
异步方式暂停视频录制。通过注册回调函数获取返回值。
在
[
start()
](
#videorecorder_start1
)
后调用。可以通过调用
[
resume()
](
#videorecorder_resume1
)
接口来恢复录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步暂停视频录制的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
pause
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
pause videorecorder success
'
);
}
else
{
console
.
info
(
'
pause videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### pause<sup>9+</sup><a name=videorecorder_pause2></a>
pause(): Promise
\<
void>;
异步方式暂停视频录制。通过Promise获取返回值。
在
[
start()
](
#videorecorder_start1
)
后调用。可以通过调用
[
resume()
](
#videorecorder_resume1
)
接口来恢复录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
void> | 异步暂停视频录制方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
pause videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### resume<sup>9+</sup><a name=videorecorder_resume1></a>
resume(callback: AsyncCallback
\<
void>): void;
异步方式恢复视频录制。通过注册回调函数获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步恢复视频录制的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
resume
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
resume videorecorder success
'
);
}
else
{
console
.
info
(
'
resume videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### resume<sup>9+</sup><a name=videorecorder_resume2></a>
resume(): Promise
\<
void>;
异步方式恢复视频录制。通过Promise获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
void> | 异步恢复视频录制方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
resume
().
then
(()
=>
{
console
.
info
(
'
resume videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
resume videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### stop<sup>9+</sup><a name=videorecorder_stop1></a>
stop(callback: AsyncCallback
\<
void>): void;
异步方式停止视频录制。通过注册回调函数获取返回值。
需要重新调用
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
接口才能重新录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步停止视频录制的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
stop
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
stop videorecorder success
'
);
}
else
{
console
.
info
(
'
stop videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### stop<sup>9+</sup><a name=videorecorder_stop2></a>
stop(): Promise
\<
void>;
异步方式停止视频录制。通过Promise获取返回值。
需要重新调用
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
接口才能重新录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
void> | 异步停止视频录制方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
stop videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### release<sup>9+</sup><a name=videorecorder_release1></a>
release(callback: AsyncCallback
\<
void>): void;
异步方式释放视频录制资源。通过注册回调函数获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步释放视频录制资源的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
release
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
release videorecorder success
'
);
}
else
{
console
.
info
(
'
release videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### release<sup>9+</sup><a name=videorecorder_release2></a>
release(): Promise
\<
void>;
异步方式释放视频录制资源。通过Promise获取返回值。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ----------------------------------------- |
| Promise
\<
void> | 异步释放视频录制资源方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
release
().
then
(()
=>
{
console
.
info
(
'
release videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
release videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### reset<sup>9+</sup><a name=videorecorder_reset1></a>
reset(callback: AsyncCallback
\<
void>): void;
异步方式重置视频录制。通过注册回调函数获取返回值。
需要重新调用
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
接口才能重新录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 异步重置视频录制的回调方法。 |
**示例:**
```
js
// asyncallback
videoRecorder
.
reset
((
err
)
=>
{
if
(
typeof
(
err
)
==
'
undefined
'
)
{
console
.
info
(
'
reset videorecorder success
'
);
}
else
{
console
.
info
(
'
reset videorecorder failed and error is
'
+
err
.
message
);
}
});
```
### reset<sup>9+</sup><a name=videorecorder_reset2></a>
reset(): Promise
\<
void>;
异步方式重置视频录制。通过Promise获取返回值。
需要重新调用
[
prepare()
](
#videorecorder_prepare1
)
和
[
getInputSurface()
](
#getinputsurface8
)
接口才能重新录制。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------------------------- |
| Promise
\<
void> | 异步重置视频录制方法的Promise返回值。 |
**示例:**
```
js
// promise
videoRecorder
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset videorecorder success
'
);
}).
catch
((
err
)
=>
{
console
.
info
(
'
reset videorecorder failed and catch error is
'
+
err
.
message
);
});
```
### on('error')<sup>9+</sup>
on(type: 'error', callback: ErrorCallback): void
开始订阅视频录制错误事件。
**系统能力:**
SystemCapability.Multimedia.Media.VideoRecorder
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 录制错误事件回调类型'error'。
<br/>
-
'error':视频录制过程中发生错误,触发该事件。 |
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 |
**示例:**
```
js
videoRecorder
.
on
(
'
error
'
,
(
error
)
=>
{
// 设置'error'事件回调
console
.
info
(
`audio error called, errName is
${
error
.
name
}
`
);
// 打印错误类型名称
console
.
info
(
`audio error called, errCode is
${
error
.
code
}
`
);
// 打印错误码
console
.
info
(
`audio error called, errMessage is
${
error
.
message
}
`
);
// 打印错误类型详细描述
});
// 当获取videoRecordState接口出错时通过此订阅事件上报
```
## VideoRecordState<sup>9+</sup>
视频录制的状态机。可通过state属性获取当前状态。
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 类型 | 描述 |
| -------- | ------ | ---------------------- |
| idle | string | 视频录制空闲。 |
| prepared | string | 视频录制参数设置完成。 |
| playing | string | 视频正在录制。 |
| paused | string | 视频暂停录制。 |
| stopped | string | 视频录制停止。 |
| error | string | 错误状态。 |
## VideoRecorderConfig<sup>9+</sup>
表示视频录制的参数设置。
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 参数类型 | 必填 | 说明 |
| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ |
| audioSourceType |
[
AudioSourceType
](
#audiosourcetype9
)
| 是 | 视频录制的音频源类型。 |
| videoSourceType |
[
VideoSourceType
](
#videosourcetype9
)
| 是 | 视频录制的视频源类型。 |
| profile |
[
VideoRecorderProfile
](
#videorecorderprofile9
)
| 是 | 视频录制的profile。 |
| rotation | number | 否 | 录制视频的旋转角度。 |
| location |
[
Location
](
#location
)
| 否 | 录制视频的地理位置。 |
| url | string | 是 | 视频输出URL:fd://xx
(fd
number)
<br/>

<br/>
文件需要由调用者创建,并赋予适当的权限。 |
## AudioSourceType<sup>9+</sup>
表示视频录制中音频源类型的枚举。
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 值 | 说明 |
| ------------------------- | ---- | ---------------------- |
| AUDIO_SOURCE_TYPE_DEFAULT | 0 | 默认的音频输入源类型。 |
| AUDIO_SOURCE_TYPE_MIC | 1 | 表示MIC的音频输入源。 |
## VideoSourceType<sup>9+</sup>
表示视频录制中视频源类型的枚举。
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 值 | 说明 |
| ----------------------------- | ---- | ------------------------------- |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | 输入surface中携带的是raw data。 |
| VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | 输入surface中携带的是ES data。 |
## VideoRecorderProfile<sup>9+</sup>
视频录制的配置文件。
**系统能力:**
以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。
| 名称 | 参数类型 | 必填 | 说明 |
| ---------------- | -------------------------------------------- | ---- | ---------------- |
| audioBitrate | number | 是 | 音频编码比特率。 |
| audioChannels | number | 是 | 音频采集声道数。 |
| audioCodec |
[
CodecMimeType
](
#codecmimetype8
)
| 是 | 音频编码格式。 |
| audioSampleRate | number | 是 | 音频采样率。 |
| fileFormat |
[
ContainerFormatType
](
#containerformattype8
)
| 是 | 文件的容器格式。 |
| videoBitrate | number | 是 | 视频编码比特率。 |
| videoCodec |
[
CodecMimeType
](
#codecmimetype8
)
| 是 | 视频编码格式。 |
| videoFrameWidth | number | 是 | 录制视频帧的宽。 |
| videoFrameHeight | number | 是 | 录制视频帧的高。 |
| videoFrameRate | number | 是 | 录制视频帧率。 |
## ContainerFormatType<sup>8+</sup>
## ContainerFormatType<sup>8+</sup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录