Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
c667661f
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看板
提交
c667661f
编写于
3月 29, 2022
作者:
Z
zengyawen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete docs
Signed-off-by:
N
zengyawen
<
zengyawen1@huawei.com
>
上级
99bb95bd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
0 addition
and
3600 deletion
+0
-3600
zh-cn/application-dev/media/Readme-CN.md
zh-cn/application-dev/media/Readme-CN.md
+0
-2
zh-cn/application-dev/media/video-recorder.md
zh-cn/application-dev/media/video-recorder.md
+0
-148
zh-cn/application-dev/reference/apis/Readme-CN.md
zh-cn/application-dev/reference/apis/Readme-CN.md
+0
-21
zh-cn/application-dev/reference/apis/js-apis-audio.md
zh-cn/application-dev/reference/apis/js-apis-audio.md
+0
-68
zh-cn/application-dev/reference/apis/js-apis-camera.md
zh-cn/application-dev/reference/apis/js-apis-camera.md
+0
-2611
zh-cn/application-dev/reference/apis/js-apis-image.md
zh-cn/application-dev/reference/apis/js-apis-image.md
+0
-26
zh-cn/application-dev/reference/apis/js-apis-media.md
zh-cn/application-dev/reference/apis/js-apis-media.md
+0
-724
未找到文件。
zh-cn/application-dev/media/Readme-CN.md
浏览文件 @
c667661f
...
@@ -9,7 +9,5 @@
...
@@ -9,7 +9,5 @@
-
视频
-
视频
-
[
视频播放开发指导
](
video-playback.md
)
-
[
视频播放开发指导
](
video-playback.md
)
-
[
视频录制开发指导
](
video-recorder.md
)
-
图片
-
图片
-
[
图片开发指导
](
image.md
)
-
[
图片开发指导
](
image.md
)
zh-cn/application-dev/media/video-recorder.md
已删除
100644 → 0
浏览文件 @
99bb95bd
# 视频录制开发指导
## 场景介绍
视频录制的主要工作是捕获音视频信号,完成音视频编码并保存到文件中,帮助开发者轻松实现音视频录制功能。它允许调用者指定录制的编码格式、封装格式、文件路径等参数。
**图1**
视频录制状态机

**图2**
视频录制零层图

## 开发步骤
详细API含义可参考:
[
js-apis-media.md
](
../reference/apis/js-apis-media.md
)
### 全流程场景
包含流程:创建实例,设置录制参数,录制视频,暂停录制,恢复录制,停止录制,释放资源等流程。
```
js
import
media
from
'
@ohos.multimedia.media
'
import
mediaLibrary
from
'
@ohos.multimedia.mediaLibrary
'
let
testFdNumber
;
// pathName是传入的录制文件名,例如:01.mp4,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp4
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
async
function
getFd
(
pathName
)
{
let
displayName
=
pathName
;
const
mediaTest
=
mediaLibrary
.
getMediaLibrary
();
let
fileKeyObj
=
mediaLibrary
.
FileKey
;
let
mediaType
=
mediaLibrary
.
MediaType
.
VIDEO
;
let
publicPath
=
await
mediaTest
.
getPublicDirectory
(
mediaLibrary
.
DirectoryType
.
DIR_VIDEO
);
let
dataUri
=
await
mediaTest
.
createAsset
(
mediaType
,
displayName
,
publicPath
);
if
(
dataUri
!=
undefined
)
{
let
args
=
dataUri
.
id
.
toString
();
let
fetchOp
=
{
selections
:
fileKeyObj
.
ID
+
"
=?
"
,
selectionArgs
:
[
args
],
}
let
fetchFileResult
=
await
mediaTest
.
getFileAssets
(
fetchOp
);
let
fileAsset
=
await
fetchFileResult
.
getAllObject
();
let
fdNumber
=
await
fileAsset
[
0
].
open
(
'
Rw
'
);
fdNumber
=
"
fd://
"
+
fdNumber
.
toString
();
testFdNumber
=
fdNumber
;
}
}
await
getFd
(
'
01.mp4
'
);
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
:
testFdNumber
,
// testFdNumber由getFd生成
orientationHint
:
0
,
location
:
{
latitude
:
30
,
longitude
:
130
},
}
// 当发生错误上上报的错误回调接口
function
failureCallback
(
error
)
{
console
.
info
(
'
error happened, error name is
'
+
error
.
name
);
console
.
info
(
'
error happened, error code is
'
+
error
.
code
);
console
.
info
(
'
error happened, error message is
'
+
error
.
message
);
}
// 当发生异常时,系统调用的错误回调接口
function
catchCallback
(
error
)
{
console
.
info
(
'
catch error happened, error name is
'
+
error
.
name
);
console
.
info
(
'
catch error happened, error code is
'
+
error
.
code
);
console
.
info
(
'
catch error happened, error message is
'
+
error
.
message
);
}
let
videoRecorder
=
null
;
// videoRecorder空对象在createVideoRecorder成功后赋值
let
surfaceID
=
null
;
// 用于保存getInputSurface返回的surfaceID
// 创建videoRecorder对象
await
media
.
createVideoRecorder
().
then
((
recorder
)
=>
{
console
.
info
(
'
case createVideoRecorder called
'
);
if
(
typeof
(
recorder
)
!=
'
undefined
'
)
{
videoRecorder
=
recorder
;
console
.
info
(
'
createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
createVideoRecorder failed
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
// 获取surfaceID并保存下来传递给camera相关接口
await
videoRecorder
.
getInputSurface
().
then
((
surface
)
=>
{
console
.
info
(
'
getInputSurface success
'
);
surfaceID
=
surface
;
},
failureCallback
).
catch
(
catchCallback
);
// 视频录制依赖相机相关接口,以下需要先调用相机起流接口后才能继续执行
// 视频录制启动接口
await
videoRecorder
.
start
().
then
(()
=>
{
console
.
info
(
'
start success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 调用pause接口时需要暂停camera出流
await
videoRecorder
.
pause
().
then
(()
=>
{
console
.
info
(
'
pause success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 调用resume接口时需要恢复camera出流
await
videoRecorder
.
resume
().
then
(()
=>
{
console
.
info
(
'
resume success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 停止camera出流后,停止视频录制
await
videoRecorder
.
stop
().
then
(()
=>
{
console
.
info
(
'
stop success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 重置录制相关配置
await
videoRecorder
.
reset
().
then
(()
=>
{
console
.
info
(
'
reset success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 释放视频录制相关资源并释放camera对象相关资源
await
videoRecorder
.
release
().
then
(()
=>
{
console
.
info
(
'
release success
'
);
},
failureCallback
).
catch
(
catchCallback
);
// 相关对象置null
videoRecorder
=
null
;
surfaceID
=
null
;
```
zh-cn/application-dev/reference/apis/Readme-CN.md
浏览文件 @
c667661f
...
@@ -45,7 +45,6 @@
...
@@ -45,7 +45,6 @@
-
application/
[
ProcessRunningInfo (ProcessRunningInfo)
](
js-apis-processrunninginfo.md
)
-
application/
[
ProcessRunningInfo (ProcessRunningInfo)
](
js-apis-processrunninginfo.md
)
-
application/
[
ServiceExtensionContext (ServiceExtensionContext)
](
js-apis-service-extension-context.md
)
-
application/
[
ServiceExtensionContext (ServiceExtensionContext)
](
js-apis-service-extension-context.md
)
-
application/
[
shellCmdResult (ShellCmdResult)
](
js-apis-application-shellCmdResult.md
)
-
application/
[
shellCmdResult (ShellCmdResult)
](
js-apis-application-shellCmdResult.md
)
-
公共事件与通知
-
公共事件与通知
-
[
@ohos.commonEvent (公共事件模块)
](
js-apis-commonEvent.md
)
-
[
@ohos.commonEvent (公共事件模块)
](
js-apis-commonEvent.md
)
...
@@ -53,20 +52,17 @@
...
@@ -53,20 +52,17 @@
-
[
@ohos.notification (Notification模块)
](
js-apis-notification.md
)
-
[
@ohos.notification (Notification模块)
](
js-apis-notification.md
)
-
[
@ohos.reminderAgent (后台代理提醒)
](
js-apis-reminderAgent.md
)
-
[
@ohos.reminderAgent (后台代理提醒)
](
js-apis-reminderAgent.md
)
-
application/
[
EventHub (EventHub)
](
js-apis-eventhub.md
)
-
application/
[
EventHub (EventHub)
](
js-apis-eventhub.md
)
-
应用程序包管理
-
应用程序包管理
-
[
@ohos.bundle (Bundle模块)
](
js-apis-Bundle.md
)
-
[
@ohos.bundle (Bundle模块)
](
js-apis-Bundle.md
)
-
[
@ohos.bundleState (设备使用信息统计)
](
js-apis-deviceUsageStatistics.md
)
-
[
@ohos.bundleState (设备使用信息统计)
](
js-apis-deviceUsageStatistics.md
)
-
[
@ohos.zlib (Zip模块)
](
js-apis-zlib.md
)
-
[
@ohos.zlib (Zip模块)
](
js-apis-zlib.md
)
-
UI界面
-
UI界面
-
[
@ohos.animator (动画)
](
js-apis-animator.md
)
-
[
@ohos.animator (动画)
](
js-apis-animator.md
)
-
[
@ohos.mediaquery (媒体查询)
](
js-apis-mediaquery.md
)
-
[
@ohos.mediaquery (媒体查询)
](
js-apis-mediaquery.md
)
-
[
@ohos.prompt (弹窗)
](
js-apis-prompt.md
)
-
[
@ohos.prompt (弹窗)
](
js-apis-prompt.md
)
-
[
@ohos.router (页面路由)
](
js-apis-router.md
)
-
[
@ohos.router (页面路由)
](
js-apis-router.md
)
-
图形图像
-
图形图像
-
[
@ohos.display (屏幕属性)
](
js-apis-display.md
)
-
[
@ohos.display (屏幕属性)
](
js-apis-display.md
)
...
@@ -74,38 +70,31 @@
...
@@ -74,38 +70,31 @@
-
[
@ohos.window (窗口)
](
js-apis-window.md
)
-
[
@ohos.window (窗口)
](
js-apis-window.md
)
-
[
webgl (WebGL)
](
js-apis-webgl.md
)
-
[
webgl (WebGL)
](
js-apis-webgl.md
)
-
[
webgl2 (WebGL2)
](
js-apis-webgl2.md
)
-
[
webgl2 (WebGL2)
](
js-apis-webgl2.md
)
-
媒体
-
媒体
-
[
@ohos.multimedia.audio (音频管理)
](
js-apis-audio.md
)
-
[
@ohos.multimedia.audio (音频管理)
](
js-apis-audio.md
)
-
[
@ohos.multimedia.camera (相机管理)
](
js-apis-camera.md
)
-
[
@ohos.multimedia.image (图片处理)
](
js-apis-image.md
)
-
[
@ohos.multimedia.image (图片处理)
](
js-apis-image.md
)
-
[
@ohos.multimedia.media (媒体服务)
](
js-apis-media.md
)
-
[
@ohos.multimedia.media (媒体服务)
](
js-apis-media.md
)
-
[
@ohos.multimedia.medialibrary (媒体库管理)
](
js-apis-medialibrary.md
)
-
[
@ohos.multimedia.medialibrary (媒体库管理)
](
js-apis-medialibrary.md
)
-
资源管理
-
资源管理
-
[
@ohos.i18n (国际化-I18n)
](
js-apis-i18n.md
)
-
[
@ohos.i18n (国际化-I18n)
](
js-apis-i18n.md
)
-
[
@ohos.intl (国际化-Intl)
](
js-apis-intl.md
)
-
[
@ohos.intl (国际化-Intl)
](
js-apis-intl.md
)
-
[
@ohos.resourceManager (资源管理)
](
js-apis-resource-manager.md
)
-
[
@ohos.resourceManager (资源管理)
](
js-apis-resource-manager.md
)
-
资源调度
-
资源调度
-
[
@ohos.backgroundTaskManager (后台任务管理)
](
js-apis-backgroundTaskManager.md
)
-
[
@ohos.backgroundTaskManager (后台任务管理)
](
js-apis-backgroundTaskManager.md
)
-
[
@ohos.workScheduler (延迟任务调度)
](
js-apis-workScheduler.md
)
-
[
@ohos.workScheduler (延迟任务调度)
](
js-apis-workScheduler.md
)
-
[
@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)
](
js-apis-workScheduler.md
)
-
[
@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)
](
js-apis-workScheduler.md
)
-
定制管理
-
定制管理
-
[
@ohos.configPolicy (配置策略)
](
js-apis-config-policy.md
)
-
[
@ohos.configPolicy (配置策略)
](
js-apis-config-policy.md
)
-
[
@ohos.enterpriseDeviceManager (企业设备管理)
](
js-apis-enterprise-device-manager.md
)
-
[
@ohos.enterpriseDeviceManager (企业设备管理)
](
js-apis-enterprise-device-manager.md
)
-
安全
-
安全
-
[
@ohos.abilityAccessCtrl (访问控制管理)
](
js-apis-abilityAccessCtrl.md
)
-
[
@ohos.abilityAccessCtrl (访问控制管理)
](
js-apis-abilityAccessCtrl.md
)
-
[
@ohos.security.huks (通用密钥库系统)
](
js-apis-huks.md
)
-
[
@ohos.security.huks (通用密钥库系统)
](
js-apis-huks.md
)
-
[
@ohos.userIAM.userAuth (用户认证)
](
js-apis-useriam-userauth.md
)
-
[
@ohos.userIAM.userAuth (用户认证)
](
js-apis-useriam-userauth.md
)
-
[
@system.cipher (加密算法)
](
js-apis-system-cipher.md
)
-
[
@system.cipher (加密算法)
](
js-apis-system-cipher.md
)
-
数据管理
-
数据管理
-
[
@ohos.data.dataAbility (DataAbility谓词)
](
js-apis-data-ability.md
)
-
[
@ohos.data.dataAbility (DataAbility谓词)
](
js-apis-data-ability.md
)
...
@@ -115,7 +104,6 @@
...
@@ -115,7 +104,6 @@
-
[
@ohos.data.rdb (关系型数据库)
](
js-apis-data-rdb.md
)
-
[
@ohos.data.rdb (关系型数据库)
](
js-apis-data-rdb.md
)
-
[
@ohos.settings (设置数据项名称)
](
js-apis-settings.md
)
-
[
@ohos.settings (设置数据项名称)
](
js-apis-settings.md
)
-
data/rdb/
[
resultSet (结果集)
](
js-apis-data-resultset.md
)
-
data/rdb/
[
resultSet (结果集)
](
js-apis-data-resultset.md
)
-
文件管理
-
文件管理
-
[
@ohos.environment (目录环境能力)
](
js-apis-environment.md
)
-
[
@ohos.environment (目录环境能力)
](
js-apis-environment.md
)
...
@@ -124,7 +112,6 @@
...
@@ -124,7 +112,6 @@
-
[
@ohos.statfs (statfs)
](
js-apis-statfs.md
)
-
[
@ohos.statfs (statfs)
](
js-apis-statfs.md
)
-
[
@ohos.storageStatistics (应用空间统计)
](
js-apis-storage-statistics.md
)
-
[
@ohos.storageStatistics (应用空间统计)
](
js-apis-storage-statistics.md
)
-
[
@ohos.volumeManager (卷管理)
](
js-apis-volumemanager.md
)
-
[
@ohos.volumeManager (卷管理)
](
js-apis-volumemanager.md
)
-
电话服务
-
电话服务
-
[
@ohos.contact (联系人)
](
js-apis-contact.md
)
-
[
@ohos.contact (联系人)
](
js-apis-contact.md
)
...
@@ -134,14 +121,12 @@
...
@@ -134,14 +121,12 @@
-
[
@ohos.telephony.sim (SIM卡管理)
](
js-apis-sim.md
)
-
[
@ohos.telephony.sim (SIM卡管理)
](
js-apis-sim.md
)
-
[
@ohos.telephony.sms (短信服务)
](
js-apis-sms.md
)
-
[
@ohos.telephony.sms (短信服务)
](
js-apis-sms.md
)
-
[
@ohos.telephony.data (蜂窝数据)
](
js-apis-telephony-data.md
)
-
[
@ohos.telephony.data (蜂窝数据)
](
js-apis-telephony-data.md
)
-
网络管理
-
网络管理
-
[
@ohos.net.connection (网络连接管理)
](
js-apis-net-connection.md
)
-
[
@ohos.net.connection (网络连接管理)
](
js-apis-net-connection.md
)
-
[
@ohos.net.http (数据请求)
](
js-apis-http.md
)
-
[
@ohos.net.http (数据请求)
](
js-apis-http.md
)
-
[
@ohos.request (上传下载)
](
js-apis-request.md
)
-
[
@ohos.request (上传下载)
](
js-apis-request.md
)
-
[
@ohos.net.socket (Socket连接)
](
js-apis-socket.md
)
-
[
@ohos.net.socket (Socket连接)
](
js-apis-socket.md
)
-
[
@ohos.net.webSocket (WebSocket连接)
](
js-apis-webSocket.md
)
-
[
@ohos.net.webSocket (WebSocket连接)
](
js-apis-webSocket.md
)
-
通信与连接
-
通信与连接
-
[
@ohos.bluetooth (蓝牙)
](
js-apis-bluetooth.md
)
-
[
@ohos.bluetooth (蓝牙)
](
js-apis-bluetooth.md
)
...
@@ -149,7 +134,6 @@
...
@@ -149,7 +134,6 @@
-
[
@ohos.rpc (RPC通信)
](
js-apis-rpc.md
)
-
[
@ohos.rpc (RPC通信)
](
js-apis-rpc.md
)
-
[
@ohos.wifi (WLAN)
](
js-apis-wifi.md
)
-
[
@ohos.wifi (WLAN)
](
js-apis-wifi.md
)
-
[
@ohos.wifiext (WLAN)
](
js-apis-wifiext.md
)
-
[
@ohos.wifiext (WLAN)
](
js-apis-wifiext.md
)
-
系统基础能力
-
系统基础能力
-
[
@ohos.accessibility (辅助功能)
](
js-apis-accessibility.md
)
-
[
@ohos.accessibility (辅助功能)
](
js-apis-accessibility.md
)
...
@@ -167,7 +151,6 @@
...
@@ -167,7 +151,6 @@
-
[
@ohos.systemTime (设置系统时间)
](
js-apis-system-time.md
)
-
[
@ohos.systemTime (设置系统时间)
](
js-apis-system-time.md
)
-
[
@ohos.wallpaper (壁纸)
](
js-apis-wallpaper.md
)
-
[
@ohos.wallpaper (壁纸)
](
js-apis-wallpaper.md
)
-
[
Timer (定时器)
](
js-apis-timer.md
)
-
[
Timer (定时器)
](
js-apis-timer.md
)
-
设备管理
-
设备管理
-
[
@ohos.batteryInfo (电量信息)
](
js-apis-battery-info.md
)
-
[
@ohos.batteryInfo (电量信息)
](
js-apis-battery-info.md
)
...
@@ -187,13 +170,11 @@
...
@@ -187,13 +170,11 @@
-
[
@ohos.update (升级)
](
js-apis-update.md
)
-
[
@ohos.update (升级)
](
js-apis-update.md
)
-
[
@ohos.usb (USB管理)
](
js-apis-usb.md
)
-
[
@ohos.usb (USB管理)
](
js-apis-usb.md
)
-
[
@ohos.vibrator (振动)
](
js-apis-vibrator.md
)
-
[
@ohos.vibrator (振动)
](
js-apis-vibrator.md
)
-
帐号管理
-
帐号管理
-
[
@ohos.account.appAccount (应用帐号管理)
](
js-apis-appAccount.md
)
-
[
@ohos.account.appAccount (应用帐号管理)
](
js-apis-appAccount.md
)
-
[
@ohos.account.distributedAccount (分布式帐号管理)
](
js-apis-distributed-account.md
)
-
[
@ohos.account.distributedAccount (分布式帐号管理)
](
js-apis-distributed-account.md
)
-
[
@ohos.account.osAccount (系统帐号管理)
](
js-apis-osAccount.md
)
-
[
@ohos.account.osAccount (系统帐号管理)
](
js-apis-osAccount.md
)
-
语言基础类库
-
语言基础类库
-
[
@ohos.convertxml (xml转换JavaScript)
](
js-apis-convertxml.md
)
-
[
@ohos.convertxml (xml转换JavaScript)
](
js-apis-convertxml.md
)
...
@@ -217,11 +198,9 @@
...
@@ -217,11 +198,9 @@
-
[
@ohos.util.Vector (线性容器Vector)
](
js-apis-vector.md
)
-
[
@ohos.util.Vector (线性容器Vector)
](
js-apis-vector.md
)
-
[
@ohos.worker (启动一个Worker)
](
js-apis-worker.md
)
-
[
@ohos.worker (启动一个Worker)
](
js-apis-worker.md
)
-
[
@ohos.xml (xml解析与生成)
](
js-apis-xml.md
)
-
[
@ohos.xml (xml解析与生成)
](
js-apis-xml.md
)
-
测试
-
测试
-
[
@ohos.application.testRunner (TestRunner)
](
js-apis-testRunner.md
)
-
[
@ohos.application.testRunner (TestRunner)
](
js-apis-testRunner.md
)
-
[
@ohos.uitest (UiTest)
](
js-apis-uitest.md
)
-
[
@ohos.uitest (UiTest)
](
js-apis-uitest.md
)
-
已停止维护的接口
-
已停止维护的接口
-
[
@ohos.bytrace (性能打点)
](
js-apis-bytrace.md
)
-
[
@ohos.bytrace (性能打点)
](
js-apis-bytrace.md
)
...
...
zh-cn/application-dev/reference/apis/js-apis-audio.md
浏览文件 @
c667661f
...
@@ -435,17 +435,6 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
...
@@ -435,17 +435,6 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
| INTERRUPT_TYPE_BEGIN | 1 | 音频播放中断事件开始。 |
| INTERRUPT_TYPE_BEGIN | 1 | 音频播放中断事件开始。 |
| INTERRUPT_TYPE_END | 2 | 音频播放中断事件结束。 |
| INTERRUPT_TYPE_END | 2 | 音频播放中断事件结束。 |
## InterruptForceType<sup>9+</sup>
枚举,强制打断类型。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
| 名称 | 默认值 | 描述 |
| --------------- | ------ | ------------------------------------ |
| INTERRUPT_FORCE | 0 | 由系统进行操作,强制打断音频播放。 |
| INTERRUPT_SHARE | 1 | 由应用进行操作,可以选择打断或忽略。 |
## InterruptHint
## InterruptHint
枚举,中断提示。
枚举,中断提示。
...
@@ -510,18 +499,6 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
...
@@ -510,18 +499,6 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => {
| streamInfo |
[
AudioStreamInfo
](
#audiostreaminfo8
)
| 是 | 表示音频流信息。 |
| streamInfo |
[
AudioStreamInfo
](
#audiostreaminfo8
)
| 是 | 表示音频流信息。 |
| rendererInfo |
[
AudioRendererInfo
](
#audiorendererinfo8
)
| 是 | 表示渲染器信息。 |
| rendererInfo |
[
AudioRendererInfo
](
#audiorendererinfo8
)
| 是 | 表示渲染器信息。 |
## InterruptEvent<sup>9+</sup>
播放中断时,应用接收的中断事件。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------ | ---- | ------------------------------------ |
| eventType |
[
InterruptType
](
#interrupttype
)
| 是 | 中断事件类型,开始或是结束。 |
| forceType |
[
InterruptForceType
](
#interruptforcetype9
)
| 是 | 操作是由系统执行或是由应用程序执行。 |
| hintType |
[
InterruptHint
](
#interrupthint
)
| 是 | 中断提示。 |
## AudioInterrupt
## AudioInterrupt
音频监听事件传入的参数。
音频监听事件传入的参数。
...
@@ -2498,51 +2475,6 @@ audioRenderer.getRenderRate().then((renderRate) => {
...
@@ -2498,51 +2475,6 @@ audioRenderer.getRenderRate().then((renderRate) => {
});
});
```
```
### on('interrupt')<sup>9+</sup>
on(type: 'interrupt', callback: Callback
\<
InterruptEvent>): void
监听音频中断事件。使用callback获取中断事件。
**系统能力**
: SystemCapability.Multimedia.Audio.Renderer
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 事件回调类型,支持的事件为:'interrupt'(中断事件被触发,音频播放被中断。) |
| callback | Callback
<
[
InterruptEvent
](
#interruptevent9
)
>
| 是 | 被监听的中断事件的回调。 |
**示例:**
```
audioRenderer.on('interrupt', (interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Force paused. Stop writing');
isPlay = false;
break;
case audio.InterruptHint.INTERRUPT_HINT_STOP:
console.log('Force stopped. Stop writing');
isPlay = false;
break;
}
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore');
startRenderer();
break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore');
pauseRenderer();
break;
}
}
});
```
### on('markReach')<sup>8+</sup>
### on('markReach')<sup>8+</sup>
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
on(type: 'markReach', frame: number, callback: (position: number) => {}): void
...
...
zh-cn/application-dev/reference/apis/js-apis-camera.md
已删除
100644 → 0
浏览文件 @
99bb95bd
# 相机管理
> **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
import camera from '@ohos.multimedia.camera';
```
## 权限
ohos.permission.CAMERA
## camera.getCameraManager
getCameraManager(context: Context, callback: AsyncCallback<CameraManager
\>
): void
获取相机管理器实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------------- | ---- | ---------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<
[
CameraManager
](
#cameramanager
)
\>
| 是 | 回调函数,用于获取相机管理器实例。 |
**示例:**
```
camera.getCameraManager(context, (err, cameraManager) => {
if (err) {
console.error('Failed to get the CameraManager instance ${err.message}');
return;
}
console.log('Callback returned with the CameraManager instance');
});
```
## camera.getCameraManager
getCameraManager(context: Context): Promise<CameraManager
\>
获取相机管理器实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | Context | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | ----------------------------------------- |
| Promise<
[
CameraManager
](
#cameramanager
)
\>
| 使用Promise的方式获取一个相机管理器实例。 |
**示例:**
```
camera.getCameraManager(context).then((cameraManger) => {
console.log('Promise returned with the CameraManager instance.');
})
```
## CameraStatus
枚举,相机状态。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ------------------------- | ------ | ------------ |
| CAMERA_STATUS_APPEAR | 0 | 相机存在。 |
| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 |
| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 |
| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 |
## CameraPosition
枚举,相机方向。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| --------------------------- | ------ | ---------------- |
| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 |
| CAMERA_POSITION_BACK | 1 | 后置相机。 |
| CAMERA_POSITION_FRONT | 2 | 前置相机。 |
## CameraType
枚举,相机类型。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ----------------------- | ------ | ---------------- |
| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 |
| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 |
| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 |
| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 |
| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 |
## ConnectionType
枚举,相机连接类型。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ---------------------------- | ------ | ------------- |
| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 |
| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 |
| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 |
## CameraManager
相机管理器类,使用前需要通过getCameraManager获取相机管理实例。
### getCameras
getCameras(callback: AsyncCallback<Array<Camera
\>\>
): void
异步获取设备支持的相机列表,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------------- | ---- | ------------------------------------ |
| callback | AsyncCallback<Array<
[
Camera
](
#camera
)
\>\>
| 是 | 使用callback方式获取支持的相机列表。 |
**示例:**
```
cameraManager.getCameras((err, cameras) => {
if (err) {
console.error('Failed to get the cameras. ${err.message}');
return;
}
console.log('Callback returned with an array of supported cameras: ' + cameras.length);
})
```
### getCameras
getCameras(): Promise<Array<Camera
\>\>
异步获取设备支持的相机列表,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------------------------- | ----------------------------- |
| Promise<Array<
[
Camera
](
#camera
)
\>\>
| 使用promise获取支持相机列表。 |
**示例:**
```
cameraManager.getCameras().then((cameraArray) => {
console.log('Promise returned with an array of supported cameras: ' + cameraArray.length);
})
```
### createCameraInput
createCameraInput(cameraId: string, callback: AsyncCallback<CameraInput
\>
): void
使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| cameraId | string | 是 | 指定相机ID。 |
| callback | AsyncCallback<
[
CameraInput
](
#camerainput
)
\>
| 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraId, (err, cameraInput) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance.');
})
```
### createCameraInput
createCameraInput(cameraId: string): Promise<CameraInput
\>
使用相机ID异步创建CameraInput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 默认值 | 必填 | 说明 |
| -------- | ------ | ---- | ------------ |
| cameraId | string | 是 | 指定相机ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<
[
CameraInput
](
#camerainput
)
\>
| 使用Promise的方式获取CameraInput的实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraId).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback<CameraInput
\>
): void
使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ----------------------------------- |
| position |
[
CameraPosition
](
#cameraposition
)
| 是 | 相机位置。 |
| type |
[
CameraType
](
#cameratype
)
| 是 | 相机类型。 |
| callback | AsyncCallback<
[
CameraInput
](
#camerainput
)
\>
| 是 | 回调函数,用于获取CameraInput实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) => {
if (err) {
console.error('Failed to create the CameraInput instance. ${err.message}');
return;
}
console.log('Callback returned with the CameraInput instance');
})
```
### createCameraInput
createCameraInput(position: CameraPosition, type: CameraType): Promise<CameraInput
\>
使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | ---------- |
| position |
[
CameraPosition
](
#cameraposition
)
| 是 | 相机位置。 |
| type |
[
CameraType
](
#cameratype
)
| 是 | 相机类型。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | ---------------------------------------- |
| Promise<
[
CameraInput
](
#camerainput
)
\>
| 使用Promise的方式获取CameraInput的实例。 |
**示例:**
```
cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) => {
console.log('Promise returned with the CameraInput instance.');
})
```
### on('cameraStatus')
on(type: 'cameraStatus', callback: AsyncCallback<CameraStatusInfo
\>
): void
监听相机的状态变化,通过注册回调函数获取相机的状态变化。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 |
| callback | AsyncCallback<
[
CameraStatusInfo
](
#camerastatusinfo
)
\>
| 是 | 回调函数,用于获取相机状态变化信息。 |
**示例:**
```
cameraManager.on('cameraStatus', (cameraStatusInfo) => {
console.log('camera : ' + cameraStatusInfo.camera.cameraId);
console.log('status: ' + cameraStatusInfo.status);
})
```
## Camera
调用
[
camera.getCameraManager
](
#cameragetcameramanager
)
后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 只读 | 说明 |
| -------------- | --------------------------------- | ---- | -------------- |
| cameraId | string | 是 | 相机ID。 |
| cameraPosition |
[
CameraPosition
](
#cameraposition
)
| 是 | 相机位置。 |
| cameraType |
[
CameraType
](
#cameratype
)
| 是 | 相机类型。 |
| connectionType |
[
ConnectionType
](
#connectiontype
)
| 是 | 相机连接类型。 |
**示例:**
```
async
function
getCameraInfo
()
{
var
cameraManager
=
await
camera
.
getCameraManager
();
var
cameras
=
await
cameraManager
.
getCameras
();
var
cameraObj
=
cameras
[
0
];
var
cameraId
=
cameraObj
.
cameraId
;
var
cameraPosition
=
cameraObj
.
cameraPosition
;
var
cameraType
=
cameraObj
.
cameraType
;
var
cameraId
=
cameraObj
.
connectionType
;
}
```
## CameraStatusInfo
相机管理器回调返回的接口实例,表示相机状态信息。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 说明 |
| ------ | ----------------------------- | ---------- |
| camera |
[
Camera
](
#camera
)
| 相机信息。 |
| status |
[
CameraStatus
](
#camerastatus
)
| 相机状态。 |
## CameraInput
相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。
### getCameraId
getCameraId(callback: AsyncCallback<string
\>\)
: void
异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback<string
\>
| 是 | 回调函数,用于获取相机ID。 |
**示例:**
```
cameraInput.getCameraId((err, cameraId) => {
if (err) {
console.error('Failed to get the camera ID. ${err.message}');
return;
}
console.log('Callback returned with the camera ID: ' + cameraId);
})
```
### getCameraId
getCameraId(): Promise<string
\>
异步获取该CameraInput实例的相机ID,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | ----------------------------- |
| Promise<string
\>
| 使用Promise的方式获取相机ID。 |
**示例:**
```
cameraInput.getCameraId().then((cameraId) => {
console.log('Promise returned with the camera ID:' + cameraId);
})
```
### hasFlash
hasFlash(callback: AsyncCallback<boolean
\>
): void
判断设备是否支持闪光灯,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<boolean
\>
| 是 | 回调函数,返回true表示设备支持闪光灯。 |
**示例:**
```
cameraInput.hasFlash((err, status) => {
if (err) {
console.error('Failed to check whether the device has flash light. ${err.message}');
return;
}
console.log('Callback returned with flash light support status: ' + status);
})
```
### hasFlash
hasFlash(): Promise<boolean
\>
判断设备是否支持闪光灯,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------- |
| Promise<boolean
\>
| 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 |
**示例:**
```
cameraInput.hasFlash().then((status) => {
console.log('Promise returned with the flash light support status:' + status);
})
```
### isFlashModeSupported
isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback<boolean
\>
): void
判断设备是否支持指定闪光灯模式,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------------------------------- |
| flashMode |
[
FlashMode
](
#flashmode
)
| 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<boolean
\>
| 是 | 回调函数,返回true表示支持该闪光灯模式。 |
**示例:**
```
cameraInput.isFlashModeSupported(flashMode, (err, status) => {
if (err) {
console.error('Failed to check whether the flash mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the flash mode support status: ' + status);
})
```
### isFlashModeSupported
isFlashModeSupported(flashMode: FlashMode): Promise<boolean
\>
判断设备是否支持指定闪光灯模式,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode |
[
FlashMode
](
#flashmode
)
| 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean
\>
| 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 |
**示例:**
```
cameraInput.isFlashModeSupported(flashMode).then((status) => {
console.log('Promise returned with flash mode support status.' + status);
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode, callback: AsyncCallback<void
\>
): void
设置闪光灯模式,通过注册回调函数获取结果。
进行设置之前,需要先检查:
1.
设备是否支持闪光灯,可使用方法
[
hasFlash
](
#hasflash
)
。
2.
设备是否支持指定的闪光灯模式,可使用方法
[
isFlashModeSupported
](
#isflashmodesupported
)
。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ------------------------ |
| flashMode |
[
FlashMode
](
#flashmode
)
| 是 | 指定闪光灯模式。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.setFlashMode(flashMode, (err) => {
if (err) {
console.error('Failed to set the flash mode ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFlashMode.');
})
```
### setFlashMode
setFlashMode(flashMode: FlashMode): Promise<void
\>
设置闪光灯模式,通过Promise获取结果。
进行设置之前,需要先检查:
1.
设备是否支持闪光灯,可使用方法
[
hasFlash
](
#hasflash
)
。
2.
设备是否支持指定的闪光灯模式,可使用方法
[
isFlashModeSupported
](
#isflashmodesupported
)
。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------- | ---- | ---------------- |
| flashMode |
[
FlashMode
](
#flashmode
)
| 是 | 指定闪光灯模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setFlashMode(flashMode).then(() => {
console.log('Promise returned with the successful execution of setFlashMode.');
})
```
### getFlashMode
getFlashMode(callback: AsyncCallback<FlashMode
\>
): void
获取当前设备的闪光灯模式,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------------------------------- |
| callback | AsyncCallback<
[
FlashMode
](
#flashmode
)
\>
| 是 | 回调函数,用于获取当前设备的闪光灯模式。 |
**示例:**
```
cameraInput.getFlashMode((err, flashMode) => {
if (err) {
console.error('Failed to get the flash mode ${err.message}');
return;
}
console.log('Callback returned with current flash mode: ' + flashMode);
})
```
### getFlashMode
getFlashMode(): Promise<FlashMode
\>
获取当前设备的闪光灯模式,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------------- |
| Promise<
[
FlashMode
](
#flashmode
)
\>
| 使用Promise的方式获取当前的闪光灯模式。 |
**示例:**
```
cameraInput.getFlashMode().then((flashMode) => {
console.log('Promise returned with current flash mode : ' + flashMode);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback<boolean
\>
): void
判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | -------------------------------------- |
| afMode |
[
FocusMode
](
#focusmode
)
| 是 | 指定的焦距模式。 |
| callback | AsyncCallback<boolean
\>
| 是 | 回调函数,返回true表示支持该焦距模式。 |
**示例:**
```
cameraInput.isFocusModeSupported(afMode, (err, status) => {
if (err) {
console.error('Failed to check whether the focus mode is supported. ${err.message}');
return;
}
console.log('Callback returned with the focus mode support status: ' + status);
})
```
### isFocusModeSupported
isFocusModeSupported(afMode: FocusMode): Promise<boolean
\>
判断设备是否支持指定的焦距模式,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode |
[
FocusMode
](
#focusmode
)
| 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| ----------------- | ----------------------------------------------------------- |
| Promise<boolean
\>
| 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 |
**示例:**
```
cameraInput.isFocusModeSupported(afMode).then((status) => {
console.log('Promise returned with focus mode support status.' + status);
})
```
### setFocusMode
setFocusMode(afMode: FocusMode, callback: AsyncCallback<void
\>
): void
设置焦距模式,通过注册回调函数获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法
[
isFocusModeSupported
](
#isfocusmodesupported
)
。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ------------------------ |
| afMode |
[
FocusMode
](
#focusmode
)
| 是 | 指定的焦距模式。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.setFocusMode(afMode, (err) => {
if (err) {
console.error('Failed to set the focus mode ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setFocusMode.');
})
```
### setFocusMode
setFocusMode(afMode: FocusMode): Promise<void
\>
设置焦距模式,通过Promise获取结果。
进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法
[
isFocusModeSupported
](
#isfocusmodesupported
)
。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------ | ----------------------- | ---- | ---------------- |
| afMode |
[
FocusMode
](
#focusmode
)
| 是 | 指定的焦距模式。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setFocusMode(afMode).then(() => {
console.log('Promise returned with the successful execution of setFocusMode.');
})
```
### getFocusMode
getFocusMode(callback: AsyncCallback<FocusMode
\>
): void
获取当前设备的焦距模式,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback<
[
FocusMode
](
#focusmode
)
\>
| 是 | 回调函数,用于获取当前设备的焦距模式。 |
**示例:**
```
cameraInput.getFocusMode((err, afMode) => {
if (err) {
console.error('Failed to get the focus mode ${err.message}');
return;
}
console.log('Callback returned with current focus mode: ' + afMode);
})
```
### getFocusMode
getFocusMode(): Promise<FocusMode
\>
获取当前设备的焦距模式,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------- | ------------------------------------- |
| Promise<FocusMode
\>
| 使用Promise的方式获取当前的焦距模式。 |
**示例:**
```
cameraInput.getFocusMode().then((afMode) => {
console.log('Promise returned with current focus mode : ' + afMode);
})
```
### getZoomRatioRange
getZoomRatioRange
\(
callback: AsyncCallback<Array<number
\>\>\)
: void
获取可变焦距比范围,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number
\>\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.getZoomRatioRange((err, zoomRatioRange) => {
if (err) {
console.error('Failed to get the zoom ratio range. ${err.message}');
return;
}
console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### getZoomRatioRange
getZoomRatioRange
\(\)
: Promise<Array<number
\>\>
获取可变焦距比范围,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ------------------------ | ------------------------------------------- |
| Promise<Array<number
\>\>
| 使用Promise的方式获取当前的可变焦距比范围。 |
**示例:**
```
cameraInput.getZoomRatioRange().then((zoomRatioRange) => {
console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length);
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number, callback: AsyncCallback<void
\>
): void
设置可变焦距比,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | -------------------- | ---- | ------------------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.setZoomRatio(zoomRatio, (err) => {
if (err) {
console.error('Failed to set the zoom ratio value ${err.message}');
return;
}
console.log('Callback returned with the successful execution of setZoomRatio.');
})
```
### setZoomRatio
setZoomRatio(zoomRatio: number): Promise<void
\>
设置可变焦距比,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ------------ |
| zoomRatio | number | 是 | 可变焦距比。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.setZoomRatio(zoomRatio).then(() => {
console.log('Promise returned with the successful execution of setZoomRatio.');
})
```
### getZoomRatio
getZoomRatio(callback: AsyncCallback<number
\>
): void
获取当前的可变焦距比,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------------ |
| callback | AsyncCallback<number
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.getZoomRatio((err, zoomRatio) => {
if (err) {
console.error('Failed to get the zoom ratio ${err.message}');
return;
}
console.log('Callback returned with current zoom ratio: ' + zoomRatio);
})
```
### getZoomRatio
getZoomRatio(): Promise<number
\>
获取当前的可变焦距比,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| ---------------- | --------------------------- |
| Promise<number
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.getZoomRatio().then((zoomRatio) => {
console.log('Promise returned with current zoom ratio : ' + zoomRatio);
})
```
### release
release
\(
callback: AsyncCallback<void
\>\)
: void
释放相机实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
camera.release((err) => {
if (err) {
console.error('Failed to release the CameraInput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is released successfully.');
});
```
### release
release(): Promise<void
\>
释放相机实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
cameraInput.release().then(() => {
console.log('Promise returned to indicate that the CameraInput instance is released successfully.');
})
```
### on('focusStateChange')
on(type: 'focusStateChange', callback: AsyncCallback<FocusState
\>
): void
监听焦距的状态变化,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- |
| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 |
| callback | AsyncCallback<
[
FocusState
](
#focusstate
)
\>
| 是 | 回调函数,用于获取焦距状态。 |
**示例:**
```
cameraInput.on('focusStateChange', (focusState) => {
console.log('Focus state : ' + focusState);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CameraInputError
\>
): void
监听CameraInput的错误事件,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :---------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即CamerInput错误事件。 |
| callback | ErrorCallback<CameraInputError
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
cameraInput.on('error', (cameraInputError) => {
console.log('Camera input error code: ' + cameraInputError.code);
})
```
## FlashMode
枚举,闪光灯模式。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ---------------------- | ------ | ------------ |
| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 |
| FLASH_MODE_OPEN | 1 | 闪光灯开启。 |
| FLASH_MODE_AUTO | 2 | 自动闪光灯。 |
| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 |
## FocusMode
枚举,焦距模式。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| -------------------------- | ------ | ------------------ |
| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 |
| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 |
| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 |
| FOCUS_MODE_LOCKED | 3 | 定焦模式。 |
## FocusState
枚举,焦距状态。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| --------------------- | ------ | ------------ |
| FOCUS_STATE_SCAN | 0 | 扫描状态。 |
| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 |
| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 |
## camera.createCaptureSession
createCaptureSession
\(
context: Context, callback: AsyncCallback<CaptureSession
\>\)
: void
获取CaptureSession实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | -------------------------------------- |
| context | Context | 是 | 应用上下文。 |
| callback | AsyncCallback<
[
CaptureSession
](
#capturesession
)
\>
| 是 | 回调函数,用于获取CaptureSession实例。 |
**示例:**
```
camera.createCaptureSession((context), (err, captureSession) => {
if (err) {
console.error('Failed to create the CaptureSession instance. ${err.message}');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);
});
```
## camera.createCaptureSession
createCaptureSession(context: Context
\)
: Promise<CaptureSession
\>
;
获取CaptureSession实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------- | ---- | ------------ |
| context | Context | 是 | 应用上下文。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------------- | ----------------------------------------- |
| Promise<
[
CaptureSession
](
#capturesession
)
\>
| 使用Promise的方式获取CaptureSession实例。 |
**示例:**
```
camera.createCaptureSession(context).then((captureSession) => {
console.log('Promise returned with the CaptureSession instance');
})
```
## CaptureSession
拍照会话类。
### beginConfig
beginConfig
\(
callback: AsyncCallback<void
\>\)
: void
开始配置会话,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.beginConfig((err) => {
if (err) {
console.error('Failed to start the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the begin config success.');
});
```
### beginConfig
beginConfig
\(\)
: Promise<void
\>
开始配置会话,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.beginConfig().then(() => {
console.log('Promise returned to indicate the begin config success.');
})
```
### commitConfig
commitConfig
\(
callback: AsyncCallback<void
\>\)
: void
提交会话配置,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.commitConfig((err) => {
if (err) {
console.error('Failed to commit the configuration. ${err.message}');
return;
}
console.log('Callback invoked to indicate the commit config success.');
});
```
### commitConfig
commitConfig
\(\)
: Promise<void
\>
提交会话配置,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.commitConfig().then(() => {
console.log('Promise returned to indicate the commit config success.');
})
```
### addInput
addInput
\(
cameraInput: CameraInput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput |
[
CameraInput
](
#camerainput
)
| 是 | 需要添加的CameraInput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.addInput(cameraInput, (err) => {
if (err) {
console.error('Failed to add the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CameraInput instance is added.');
});
```
### addInput
addInput
\(
cameraInput: CameraInput
\)
: Promise<void
\>
在当前会话中,添加一个CameraInput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput |
[
CameraInput
](
#camerainput
)
| 是 | 需要添加的CameraInput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addInput(cameraInput).then(() => {
console.log('Promise used to indicate that the CameraInput instance is added.');
})
```
### addOutput
addOutput
\(
previewOutput: PreviewOutput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,添加一个PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput |
[
PreviewOutput
](
#previewoutput
)
| 是 | 需要添加的PreviewOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.addOutput(previewOutput, (err) => {
if (err) {
console.error('Failed to add the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is added.');
});
```
### addOutput
addOutput
\(
previewOutput: PreviewOutput
\)
: Promise<void
\>
在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput |
[
PreviewOutput
](
#previewoutput
)
| 是 | 需要添加的PreviewOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(previewOutput).then(() => {
console.log('Promise used to indicate that the PreviewOutput instance is added.');
})
```
### addOutput
addOutput
\(
photoOutput: PhotoOutput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,添加一个PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput |
[
PhotoOutput
](
#photooutput
)
| 是 | 需要添加的PhotoOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.addOutput(photoOutput, (err) => {
if (err) {
console.error('Failed to add the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is added.');
});
```
### addOutput
addOutput
\(
photoOutput: PhotoOutput
\)
: Promise<void
\>
在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput |
[
PhotoOutput
](
#photooutput
)
| 是 | 需要添加的PhotoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise
\<
void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(photoOutput).then(() => {
console.log('Promise used to indicate that the PhotoOutput instance is added.');
})
```
### addOutput
addOutput
\(
videoOutput: VideoOutput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,添加一个VideoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput |
[
VideoOutput
](
#videooutput
)
| 是 | 需要添加的VideoOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.addOutput(videoOutput, (err) => {
if (err) {
console.error('Failed to add the VideoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is added.');
});
```
### addOutput
addOutput
\(
videoOutput: VideoOutput
\)
: Promise<void
\>
在当前会话中,添加一个VideoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput |
[
VideoOutput
](
#videooutput
)
| 是 | 需要添加的VideoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise
\<
void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.addOutput(videoOutput).then(() => {
console.log('Promise used to indicate that the VideoOutput instance is added.');
})
```
### removeInput
removeInput
\(
cameraInput: CameraInput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,移除一个CameraInput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput |
[
CameraInput
](
#camerainput
)
| 是 | 需要移除的CameraInput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.removeInput(cameraInput, (err) => {
if (err) {
console.error('Failed to remove the CameraInput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the cameraInput instance is removed.');
});
```
### removeInput
removeInput
\(
cameraInput: CameraInput
\)
: Promise<void
\>
在当前会话中,移除一个CameraInput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| cameraInput |
[
CameraInput
](
#camerainput
)
| 是 | 需要移除的CameraInput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise
\<
void> | 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeInput(cameraInput).then(() => {
console.log('Promise returned to indicate that the cameraInput instance is removed.');
})
```
### removeOutput
removeOutput
\(
previewOutput: PreviewOutput, callback: AsyncCallback<void
\>\)
: void
在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput |
[
PreviewOutput
](
#previewoutput
)
| 是 | 需要移除的PreviewOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.removeOutput(previewOutput, (err) => {
if (err) {
console.error('Failed to remove the PreviewOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is removed.');
});
```
### removeOutput
removeOutput(previewOutput: PreviewOutput): Promise<void
\>
在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------- | ---- | ----------------------------- |
| previewOutput |
[
PreviewOutput
](
#previewoutput
)
| 是 | 需要移除的PreviewOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(previewOutput).then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is removed.');
})
```
### removeOutput
removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback<void
\>
): void
在当前会话中,移除一个PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput |
[
PhotoOutput
](
#photooutput
)
| 是 | 需要添加的PhotoOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.removeOutput(photoOutput, (err) => {
if (err) {
console.error('Failed to remove the PhotoOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is removed.');
});
```
### removeOutput
removeOutput(photoOutput: PhotoOutput): Promise<void
\>
在当前会话中,移除一个PhotoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| photoOutput |
[
PhotoOutput
](
#photooutput
)
| 是 | 需要添加的PhotoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(photoOutput).then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is removed.');
})
```
### removeOutput
removeOutput(videoOutput: VideoOutput, callback: AsyncCallback<void
\>
): void
在当前会话中,移除一个VideoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput |
[
VideoOutput
](
#videooutput
)
| 是 | 需要添加的VideoOutput实例。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.removeOutput(videoOutput, (err) => {
if (err) {
console.error('Failed to remove the VideoOutput instance. ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is removed.');
});
```
### removeOutput
removeOutput(videoOutput: VideoOutput): Promise<void
\>
在当前会话中,移除一个VideoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ----------- | --------------------------- | ---- | --------------------------- |
| videoOutput |
[
VideoOutput
](
#videooutput
)
| 是 | 需要添加的VideoOutput实例。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.removeOutput(videoOutput).then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is removed.');
})
```
### start
start
\(
callback: AsyncCallback<void
\>\)
: void
启动拍照会话,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.start((err) => {
if (err) {
console.error('Failed to start the session ${err.message}');
return;
}
console.log('Callback invoked to indicate the session start success.');
});
```
### start
start
\(\)
: Promise<void
\>
启动拍照会话,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.start().then(() => {
console.log('Promise returned to indicate the session start success.');
})
```
### stop
stop
\(
callback: AsyncCallback<void
\>\)
: void
停止拍照会话,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.stop((err) => {
if (err) {
console.error('Failed to stop the session ${err.message}');
return;
}
console.log('Callback invoked to indicate the session stop success.');
});
```
### stop
stop(): Promise<void
\>
停止拍照会话,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.stop().then(() => {
console.log('Promise returned to indicate the session stop success.');
})
```
### release
release
\(
callback: AsyncCallback<void
\>\)
: void
释放CaptureSession实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
captureSession.release((err) => {
if (err) {
console.error('Failed to release the CaptureSession instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.');
});
```
### release
release(): Promise<void
\>
释放CaptureSession实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
captureSession.release().then(() => {
console.log('Promise returned to indicate that the CaptureSession instance is released successfully.');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<CaptureSessionError
\>
): void
监听拍照会话的错误事件,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :---------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 |
| callback | ErrorCallback<CaptureSessionError
\>
| 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
captureSession.on('error', (captureSessionError) => {
console.log('Capture session error code: ' + captureSessionError.code);
})
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string, callback: AsyncCallback<PreviewOutput
\>
): void
获取PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ----------------------------------------------- | ---- | ------------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
| callback | AsyncCallback<
[
PreviewOutput
](
#previewoutput
)
\>
| 是 | 回调函数,用于获取PreviewOutput实例。 |
**示例:**
```
camera.createPreviewOutput((surfaceId), (err, previewOutput) => {
if (err) {
console.error('Failed to create the PreviewOutput instance. ${err.message}');
return;
}
console.log('Callback returned with previewOutput instance');
});
```
## camera.createPreviewOutput
createPreviewOutput(surfaceId: string): Promise
\<
PreviewOutput>
获取PreviewOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---------------------------------- |
| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ----------------------------------------- | --------------------------- |
| Promise<
[
PreviewOutput
](
#previewoutput
)
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
camera.createPreviewOutput(surfaceId).then((previewOutput) => {
console.log('Promise returned with the PreviewOutput instance');
})
```
## PreviewOutput
预览输出类。
### release
release(callback: AsyncCallback<void
\>
): void
释放PreviewOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
previewOutput.release((err) => {
if (err) {
console.error('Failed to release the PreviewOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.');
});
```
### release
release(): Promise<void
\>
释放PreviewOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
previewOutput.release().then(() => {
console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void
\>
): void
监听预览帧启动,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
previewOutput.on('frameStart', () => {
console.log('Preview frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void
\>
): void
监听预览帧结束,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
previewOutput.on('frameEnd', () => {
console.log('Preview frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PreviewOutputError
\>
): void
监听预览输出的错误事件,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 |
| callback | ErrorCallback<PreviewOutputError
\>
| 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
previewOutput.on('error', (previewOutputError) => {
console.log('Preview output error code: ' + previewOutputError.code);
})
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string, callback: AsyncCallback<PhotoOutput
\>
): void
获取PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 |
| callback | AsyncCallback<
[
PhotoOutput
](
#photooutput
)
\>
| 是 | 回调函数,用于获取PhotoOutput实例。 |
**示例:**
```
camera.createPhotoOutput((surfaceId), (err, photoOutput) => {
if (err) {
console.error('Failed to create the PhotoOutput instance. ${err.message}');
return;
}
console.log('Callback returned with the PhotoOutput instance.');
});
```
## camera.createPhotoOutput
createPhotoOutput(surfaceId: string): Promise<PhotoOutput
\>
获取PhotoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | -------------------------------------- |
| Promise<
[
PhotoOutput
](
#photooutput
)
\>
| 使用Promise的方式获取PhotoOutput实例。 |
**示例:**
```
camera.createPhotoOutput(surfaceId).then((photoOutput) => {
console.log('Promise returned with PhotoOutput instance');
})
```
## ImageRotation
枚举,图片旋转角度。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| ------------ | ------ | --------------- |
| ROTATION_0 | 0 | 图片旋转0度。 |
| ROTATION_90 | 90 | 图片旋转90度。 |
| ROTATION_180 | 180 | 图片旋转180度。 |
| ROTATION_270 | 270 | 图片旋转270度。 |
## QualityLevel
枚举,图片质量。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 默认值 | 说明 |
| -------------------- | ------ | -------------- |
| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 |
| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 |
| QUALITY_LEVEL_LOW | 2 | 图片质量差。 |
## PhotoCaptureSetting
拍摄照片的设置。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------- |
| quality |
[
QualityLevel
](
#qualitylevel
)
| 否 | 图片质量。 |
| rotation |
[
ImageRotation
](
#imagerotation
)
| 否 | 图片旋转角度。 |
## PhotoOutput
照片输出类。
### capture
capture(callback: AsyncCallback<void
\>
): void
拍照,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
photoOutput.capture((err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting: PhotoCaptureSetting, callback: AsyncCallback<void
\>
): void
根据拍照设置拍照,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------- | ---- | ------------------------ |
| setting |
[
PhotoCaptureSetting
](
#photocapturesetting
)
| 是 | 拍照设置。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
photoOutput.capture(settings, (err) => {
if (err) {
console.error('Failed to capture the photo ${err.message}');
return;
}
console.log('Callback invoked to indicate the photo capture request success.');
});
```
### capture
capture(setting?: PhotoCaptureSetting): Promise<void
\>
根据拍照设置拍照,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------- | ---- | ---------- |
| setting |
[
PhotoCaptureSetting
](
#photocapturesetting
)
| 否 | 拍照设置。 |
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
photoOutput.capture().then(() => {
console.log('Promise returned to indicate that photo capture request success.');
})
```
### release
release(callback: AsyncCallback<void
\>
): void
释放PhotoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
photoOutput.release((err) => {
if (err) {
console.error('Failed to release the PhotoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.');
});
```
### release
release(): Promise<void
\>
释放PhotoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
photoOutput.release().then(() => {
console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.');
})
```
### on('captureStart')
on(type: 'captureStart', callback: AsyncCallback<number
\>
): void
监听拍照启动,通过注册回调函数获取Capture ID。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :--------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 |
| callback | AsyncCallback<number
\>
| 是 | 使用callback的方式获取Capture ID。 |
**示例:**
```
photoOutput.on('captureStart', (captureId) => {
console.log('photo capture stated, captureId : ' + captureId);
})
```
### on('frameShutter')
on(type: 'frameShutter', callback: AsyncCallback<FrameShutterInfo
\>
): void
监听帧刷新,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 |
| callback | AsyncCallback<FrameShutterInfo
\>
| 是 | 回调函数,用于获取相关信息。 |
**示例:**
```
photoOutput.on('frameShutter', (frameShutterInfo) => {
console.log('photo capture end, captureId : ' + frameShutterInfo.captureId);
console.log('Timestamp for frame : ' + frameShutterInfo.timestamp);
})
```
### on('captureEnd')
on(type: 'captureEnd', callback: AsyncCallback<CaptureEndInfo
\>
): void
监听拍照停止,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :----------------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 |
| callback | AsyncCallback<CaptureEndInfo
\>
| 是 | 回调函数,用于获取相关信息。 |
**示例:**
```
photoOutput.on('captureEnd', (captureEndInfo) => {
console.log('photo capture end, captureId : ' + captureEndInfo.captureId);
console.log('frameCount : ' + captureEndInfo.frameCount);
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<PhotoOutputError
\>
): void
监听拍照的错误事件,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------------------- | :--- | :---------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 |
| callback | ErrorCallback<PhotoOutputError
\>
| 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
photoOutput.on('error', (photoOutputError) => {
console.log('Photo output error code: ' + photoOutputError.code);
})
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput
\>
): void
获取VideoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------------------------------------------- | ---- | ----------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
| callback | AsyncCallback<
[
VideoOutput
](
#videooutput
)
\>
| 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:**
```
camera.createVideoOutput((surfaceId), (err, videoOutput) => {
if (err) {
console.error('Failed to create the VideoOutput instance. ${err.message}');
return;
}
console.log('Callback returned with the VideoOutput instance');
});
```
## camera.createVideoOutput
createVideoOutput(surfaceId: string): Promise<VideoOutput
\>
获取VideoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | --------------------------------- |
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
**返回值:**
| 类型 | 说明 |
| ------------------------------------- | -------------------------------------- |
| Promise<
[
VideoOutput
](
#videooutput
)
\>
| 使用Promise的方式获取VideoOutput实例。 |
**示例:**
```
camera.createVideoOutput(surfaceId).then((videoOutput) => {
console.log('Promise returned with the VideoOutput instance');
})
```
## VideoOutput
视频输出类。
### start
start(callback: AsyncCallback<void
\>
): void
开始拍摄视频,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.start((err) => {
if (err) {
console.error('Failed to start the video output ${err.message}');
return;
}
console.log('Callback invoked to indicate the video output start success.');
});
```
### start
start(): Promise<void
\>
开始拍摄视频,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that start method execution success.');
})
```
### stop
stop(callback: AsyncCallback<void
\>
): void
停止拍摄视频,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.stop((err) => {
if (err) {
console.error('Failed to stop the video output ${err.message}');
return;
}
console.log('Callback invoked to indicate the video output stop success.');
});
```
### stop
stop(): Promise<void
\>
停止拍摄视频,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.start().then(() => {
console.log('Promise returned to indicate that stop method execution success.');
})
```
### release
release(callback: AsyncCallback<void
\>
): void
释放VideoOutput实例,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.release((err) => {
if (err) {
console.error('Failed to release the VideoOutput instance ${err.message}');
return;
}
console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.');
});
```
### release
release(): Promise<void
\>
释放VideoOutput实例,通过Promise获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------------- |
| Promise<void
\>
| 使用Promise的方式获取结果。 |
**示例:**
```
videoOutput.release().then(() => {
console.log('Promise returned to indicate that the VideoOutput instance is released successfully.');
})
```
### on('frameStart')
on(type: 'frameStart', callback: AsyncCallback<void
\>
): void
监听视频帧开启,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :----------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.on('frameStart', () => {
console.log('Video frame started');
})
```
### on('frameEnd')
on(type: 'frameEnd', callback: AsyncCallback<void
\>
): void
监听视频帧结束,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :------------------- | :--- | :--------------------------------------------- |
| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 |
| callback | AsyncCallback<void
\>
| 是 | 回调函数,用于获取结果。 |
**示例:**
```
videoOutput.on('frameEnd', () => {
console.log('Video frame ended');
})
```
### on('error')
on(type: 'error', callback: ErrorCallback<VideoOutputError
\>
): void
监听视频输出的错误事件,通过注册回调函数获取结果。
**系统能力:**
SystemCapability.Multimedia.Camera.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| :------- | :-------------------------- | :--- | :-------------------------------------------- |
| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 |
| callback | Callback<VideoOutputError
\>
| 是 | 回调函数,用于获取错误信息。 |
**示例:**
```
videoOutput.on('error', (VideoOutputError) => {
console.log('Video output error code: ' + VideoOutputError.code);
})
```
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-image.md
浏览文件 @
c667661f
...
@@ -990,40 +990,14 @@ release(): Promise\<void>
...
@@ -990,40 +990,14 @@ release(): Promise\<void>
| RGBA_8888 | 3 | 格式为RGBA_8888。 |
| RGBA_8888 | 3 | 格式为RGBA_8888。 |
| RGB_565 | 2 | 格式为RGB_565。 |
| RGB_565 | 2 | 格式为RGB_565。 |
## AlphaType<sup>9+</sup>
枚举,透明度。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 默认值 | 描述 |
| -------- | ------ | ----------------------- |
| UNKNOWN | 0 | 未知透明度。 |
| OPAQUE | 1 | 没有alpha或图片全透明。 |
| PREMUL | 2 | RGB前乘alpha。 |
| UNPREMUL | 3 | RGB不前乘alpha。 |
## ScaleMode<sup>9+</sup>
枚举,缩略值。
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 默认值 | 描述 |
| --------------- | ------ | -------------------------------------------------- |
| CENTER_CROP | 1 | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 |
| FIT_TARGET_SIZE | 2 | 图像适合目标尺寸的效果。 |
## InitializationOptions<sup>8+</sup>
## InitializationOptions<sup>8+</sup>
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Image
**系统能力:**
以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 |
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ---------------------------------- | ---- | ---- | -------------- |
| ----------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType
<sup>
9+
</sup>
|
[
AlphaType
](
#alphatype9
)
| 是 | 是 | 透明度。 |
| editable | boolean | 是 | 是 | 是否可编辑。 |
| editable | boolean | 是 | 是 | 是否可编辑。 |
| pixelFormat |
[
PixelMapFormat
](
#pixelmapformat7
)
| 是 | 是 | 像素格式。 |
| pixelFormat |
[
PixelMapFormat
](
#pixelmapformat7
)
| 是 | 是 | 像素格式。 |
| scaleMode
<sup>
9+
</sup>
|
[
ScaleMode
](
#scalemode9
)
| 是 | 是 | 缩略值。 |
| size |
[
Size
](
#size
)
| 是 | 是 | 创建图片大小。 |
| size |
[
Size
](
#size
)
| 是 | 是 | 创建图片大小。 |
## DecodingOptions<sup>7+</sup>
## DecodingOptions<sup>7+</sup>
...
...
zh-cn/application-dev/reference/apis/js-apis-media.md
浏览文件 @
c667661f
...
@@ -10,7 +10,6 @@
...
@@ -10,7 +10,6 @@
-
音频播放(
[
AudioPlayer
](
#audioplayer
)
)
-
音频播放(
[
AudioPlayer
](
#audioplayer
)
)
-
视频播放(
[
VideoPlayer
](
#videoplayer8
)
)
-
视频播放(
[
VideoPlayer
](
#videoplayer8
)
)
-
音频录制(
[
AudioRecorder
](
#audiorecorder
)
)
-
音频录制(
[
AudioRecorder
](
#audiorecorder
)
)
-
视频录制(
[
VideoRecorder
](
#videorecorder9
)
)
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。
...
@@ -125,73 +124,6 @@ createAudioRecorder(): AudioRecorder
...
@@ -125,73 +124,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
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
)
=>
{
if
(
typeof
(
video
)
!=
'
undefined
'
)
{
videoRecorder
=
video
;
console
.
info
(
'
video createVideoRecorder success
'
);
}
else
{
console
.
info
(
'
video createVideoRecorder fail
'
);
}
},
failureCallback
).
catch
(
catchCallback
);
```
## MediaErrorCode<sup>8+</sup>
## MediaErrorCode<sup>8+</sup>
媒体服务错误类型枚举。
媒体服务错误类型枚举。
...
@@ -1842,662 +1774,6 @@ audioRecorder.prepare(); // pre
...
@@ -1842,662 +1774,6 @@ audioRecorder.prepare(); // pre
| AMR_WB | 4 | 封装为AMR_WB格式。
<br/>
本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| AMR_WB | 4 | 封装为AMR_WB格式。
<br/>
本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。 |
| 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
;
await
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
(()
=>
{
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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
await
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
);
});
```
### 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>
表示容器格式类型的枚举,缩写为CFT。
表示容器格式类型的枚举,缩写为CFT。
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录