未验证 提交 4a2a7b98 编写于 作者: O openharmony_ci 提交者: Gitee

!3614 目录+断链修改

Merge pull request !3614 from LiAn/OpenHarmony-3.1-Release
......@@ -11,7 +11,7 @@ You can create a button by invoking either of the following APIs:
- Button(options?: {type?: ButtonType, stateEffect?: boolean})
This API creates a button that contains child components. In the syntax, **type** indicates the button type, and **stateEffect** indicates whether to enable the click effect for the button.
```
Button({ type: ButtonType.Normal, stateEffect: true }) {
Row() {
......@@ -26,7 +26,7 @@ You can create a button by invoking either of the following APIs:
- Button(label?: string, options?: { type?: ButtonType, stateEffect?: boolean })
This API creates a button that does not contain any child components. In the syntax, **label** indicates whether the created button contains child components.
```
Button('Ok', { type: ButtonType.Normal, stateEffect: true })
.borderRadius(8)
......@@ -42,7 +42,7 @@ You can create a button by invoking either of the following APIs:
Use the **type** parameter to set the button type to **Capsule**, **Circle**, or **Normal**.
- Capsule button (default type)
```
Button('Disable', { type: ButtonType.Capsule, stateEffect: false })
.backgroundColor(0x317aff)
......@@ -52,7 +52,7 @@ Use the **type** parameter to set the button type to **Capsule**, **Circle**, or
![en-us_image_0000001215645452](figures/en-us_image_0000001215645452.png)
- Circle button
```
Button('Circle', { type: ButtonType.Circle, stateEffect: false })
.backgroundColor(0x317aff)
......@@ -68,18 +68,18 @@ Use the **type** parameter to set the button type to **Capsule**, **Circle**, or
- Set the border radius:
In general cases, you can use universal attributes to define the button styles. For example, you can use the **borderRadius** attribute to set the border radius.
```
Button('circle border', { type: ButtonType.Normal })
.borderRadius(20)
```
![zh-cn_image_0000001190463780](figures/zh-cn_image_0000001190463780.png)
![en-us_image_0000001215645452](figures/en-us_image_0000001215645452.png)
- Setting Text Styles
Add a font style for text displayed on the button.
```
Button('font style', { type: ButtonType.Normal })
.fontSize(20)
......@@ -87,12 +87,12 @@ Use the **type** parameter to set the button type to **Capsule**, **Circle**, or
.fontWeight(800)
```
![zh-cn_image_0000001189744672](figures/zh-cn_image_0000001189744672.png)
![en-us_image_0000001215965420](figures/en-us_image_0000001215965420.png)
- Set the background color:
You can do so by adding the **backgroundColor** attribute.
```
Button('background color').backgroundColor(0xF55A42)
```
......@@ -102,7 +102,7 @@ Use the **type** parameter to set the button type to **Capsule**, **Circle**, or
- Assign a function to the button:
In this example, we are creating a button with the delete function.
```
Button({ type: ButtonType.Circle, stateEffect: true }) {
Image($r('app.media.ic_public_delete_filled')).width(30).height(30)
......@@ -133,7 +133,7 @@ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
```
import router from '@ohos.router'
@Entry
@Component
struct ButtonCase1 {
......@@ -144,13 +144,13 @@ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
router.push({ url: 'xxx' })
})
}
ListItem() {
Button("Second").onClick(() => {
router.push({ url: 'yyy' })
})
}
ListItem() {
Button("Third").onClick(() => {
router.push({ url: 'zzz' })
......@@ -170,7 +170,7 @@ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
- Using the Button for Submitting Forms
On the user login/registration page, you can use a button to submit a login or registration request.
```
@Entry
@Component
......@@ -184,5 +184,5 @@ Button('Ok', { type: ButtonType.Normal, stateEffect: true })
}
}
```
![en-us_image_0000001190466492](figures/en-us_image_0000001190466492.png)
......@@ -45,9 +45,9 @@ screen and (device-type: tv) or (resolution < 2) // This is a multi-condition
### media-type
| Type| Description|
| -------- | -------- |
| screen | Media query based on screen-related parameters.|
| Type | Description |
| ------ | ---------------------------------------- |
| screen | Media query based on screen-related parameters. |
### Media Logic Operation (and|not|only)
......@@ -56,48 +56,48 @@ You can use logical operators (**and**, **or**, **not**, and **only**) to compos
**Table 1** Media logical operators
| Type| Description|
| -------- | -------- |
| and | The **and** operator is used to combine multiple media features into one media query, in a logical AND operation. The query is valid only when all media features are true. It can also combine media types and media functions.<br>For example, **screen&nbsp;and&nbsp;(device-type:&nbsp;wearable)&nbsp;and&nbsp;(max-height:&nbsp;600)&nbsp;** indicates that the query is valid when the device type is wearable and the maximum height of the application is 600 pixel units.|
| not | The **not** operator is used to perform a logical negation for a media query. **true** is returned if the query condition is not met. Otherwise, **false** is returned. In a media query list, logical negation is performed only for the media query using the **not** operator.<br>For example, **not&nbsp;screen&nbsp;and&nbsp;(min-height:&nbsp;50)&nbsp;and&nbsp;(max-height:&nbsp;600)&nbsp;** indicates that the query is valid when the height of the application is less than 50 pixel units or greater than 600 pixel units.<br>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**NOTE**<br>>&nbsp;When the **not** operator is used, the media type must be specified.|
| only | The **only** operator applies the selected style only when the entire expression is matched. It can be used to prevent ambiguity on browsers of earlier versions. The statements that contain both media types and media features produce ambiguity when they are received by some browsers of earlier versions. For example:<br>screen&nbsp;and&nbsp;(min-height:&nbsp;50)<br>The browsers of earlier versions would mislead this sentence into screen, causing the fact that the specified style is applied when only the media type is matched. In this case, the **only** operator can be used to avoid this problem.<br>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**NOTE**<br>>&nbsp;When the **only** operator is used, the media type must be specified.|
| ,(comma) | The **or** operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true. The effect of a comma operator is equivalent to that of the **or** operator.<br>For example, **screen&nbsp;and&nbsp;(min-height:&nbsp;1000),&nbsp;&nbsp;(round-screen: true)&nbsp;** indicates that the query is valid when the minimum height of the application is 1000 pixel units or the device screen is round.|
| or | The **or** operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true.<br>For example, **screen&nbsp;and&nbsp;(max-height:&nbsp;1000)&nbsp;or&nbsp;&nbsp;(round-screen: true)** indicates that the query is valid when the maximum height of the application is 1000 pixel units or the device screen is round.|
| Type | Description |
| -------- | ---------------------------------------- |
| and | The **and** operator is used to combine multiple media features into one media query, in a logical AND operation. The query is valid only when all media features are true. It can also combine media types and media functions.<br>For example, **screen&nbsp;and&nbsp;(device-type:&nbsp;wearable)&nbsp;and&nbsp;(max-height:&nbsp;600)&nbsp;** indicates that the query is valid when the device type is wearable and the maximum height of the application is 600 pixel units. |
| not | The **not** operator is used to perform a logical negation for a media query. **true** is returned if the query condition is not met. Otherwise, **false** is returned. In a media query list, logical negation is performed only for the media query using the **not** operator.<br>For example, **not&nbsp;screen&nbsp;and&nbsp;(min-height:&nbsp;50)&nbsp;and&nbsp;(max-height:&nbsp;600)&nbsp;** indicates that the query is valid when the height of the application is less than 50 pixel units or greater than 600 pixel units.<br>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**NOTE**<br>>&nbsp;When the **not** operator is used, the media type must be specified. |
| only | The **only** operator applies the selected style only when the entire expression is matched. It can be used to prevent ambiguity on browsers of earlier versions. The statements that contain both media types and media features produce ambiguity when they are received by some browsers of earlier versions. For example:<br>screen&nbsp;and&nbsp;(min-height:&nbsp;50)<br>The browsers of earlier versions would mislead this sentence into screen, causing the fact that the specified style is applied when only the media type is matched. In this case, the **only** operator can be used to avoid this problem.<br>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**NOTE**<br>>&nbsp;When the **only** operator is used, the media type must be specified. |
| ,(comma) | The **or** operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true. The effect of a comma operator is equivalent to that of the **or** operator.<br>For example, **screen&nbsp;and&nbsp;(min-height:&nbsp;1000),&nbsp;&nbsp;(round-screen: true)&nbsp;** indicates that the query is valid when the minimum height of the application is 1000 pixel units or the device screen is round. |
| or | The **or** operator is used to combine multiple media features into one media query, in a logical OR operation. The query is valid if a media feature is true.<br>For example, **screen&nbsp;and&nbsp;(max-height:&nbsp;1000)&nbsp;or&nbsp;&nbsp;(round-screen: true)** indicates that the query is valid when the maximum height of the application is 1000 pixel units or the device screen is round. |
At MediaQuery Level 4, range query is imported so that you can use the operators including &lt;=, &gt;=, &lt;, and &gt; besides the **max-** and **min-** operators.
**Table 2** Logical operators for range query
| Type| Description|
| -------- | -------- |
| &lt;= | Less than or equal to, for example, **screen&nbsp;and&nbsp;(50&nbsp;&lt;=&nbsp;height)**.|
| &gt;= | Greater than or equal to, for example, **screen&nbsp;and&nbsp;(600&nbsp;&gt;=&nbsp;height)**.|
| &lt; | Less than, for example, **screen&nbsp;and&nbsp;(50&nbsp;&lt;&nbsp;height)**.|
| &gt; | Greater than, for example, **screen&nbsp;and&nbsp;(600&nbsp;&gt;&nbsp;height)**.|
| Type | Description |
| ----- | ---------------------------------------- |
| &lt;= | Less than or equal to, for example, **screen&nbsp;and&nbsp;(50&nbsp;&lt;=&nbsp;height)**. |
| &gt;= | Greater than or equal to, for example, **screen&nbsp;and&nbsp;(600&nbsp;&gt;=&nbsp;height)**. |
| &lt; | Less than, for example, **screen&nbsp;and&nbsp;(50&nbsp;&lt;&nbsp;height)**. |
| &gt; | Greater than, for example, **screen&nbsp;and&nbsp;(600&nbsp;&gt;&nbsp;height)**. |
### media-feature
| Type| Description|
| -------- | -------- |
| height | Height of the display area on the application page.|
| min-height | Minimum height of the display area on the application page.|
| max-height | Maximum height of the display area on the application page.|
| width | Width of the display area on the app page.|
| min-width | Minimum width of the display area on the application page.|
| max-width | Maximum width of the display area on the application page.|
| resolution | Resolution of the device. The unit can be dpi, dppx, or dpcm.<br>-&nbsp;**dpi** indicates the number of physical pixels per inch. 1 dpi ≈ 0.39 dpcm.<br>-&nbsp;**dpcm** indicates the number of physical pixels per centimeter. 1 dpcm&nbsp;&nbsp;2.54 dpi.<br>-&nbsp;**dppx** indicates the number of physical pixels in each pixel. (This unit is calculated based on this formula: 96 px = 1 inch, which is different from the calculation method of the px unit on the page.) 1 dppx&nbsp;=&nbsp;96 dpi.|
| min-resolution | Minimum device resolution.|
| max-resolution | Maximum device resolution.|
| orientation | Screen orientation.<br>Options are as follows:<br>-&nbsp;orientation:&nbsp;portrait<br>-&nbsp;orientation:&nbsp;landscape|
| device-height | Height of the device.|
| min-device-height | Minimum height of the device.|
| max-device-height | Maximum height of the device.|
| device-width | Width of the device.|
| min-device-width | Minimum width of the device.|
| max-device-width | Maximum width of the device.|
| round-screen | Screen type. The value **true** means that the screen is round, and **false** means the opposite.|
| dark-mode | Whether the device is in dark mode. The value **true** means that the device is in dark mode, and **false** means the opposite.|
| Type | Description |
| ----------------- | ---------------------------------------- |
| height | Height of the display area on the application page. |
| min-height | Minimum height of the display area on the application page. |
| max-height | Maximum height of the display area on the application page. |
| width | Width of the display area on the app page. |
| min-width | Minimum width of the display area on the application page. |
| max-width | Maximum width of the display area on the application page. |
| resolution | Resolution of the device. The unit can be dpi, dppx, or dpcm.<br>-&nbsp;**dpi** indicates the number of physical pixels per inch. 1 dpi ≈ 0.39 dpcm.<br>-&nbsp;**dpcm** indicates the number of physical pixels per centimeter. 1 dpcm&nbsp;&nbsp;2.54 dpi.<br>-&nbsp;**dppx** indicates the number of physical pixels in each pixel. (This unit is calculated based on this formula: 96 px = 1 inch, which is different from the calculation method of the px unit on the page.) 1 dppx&nbsp;=&nbsp;96 dpi. |
| min-resolution | Minimum device resolution. |
| max-resolution | Maximum device resolution. |
| orientation | Screen orientation.<br>Options are as follows:<br>-&nbsp;orientation:&nbsp;portrait<br>-&nbsp;orientation:&nbsp;landscape |
| device-height | Height of the device. |
| min-device-height | Minimum height of the device. |
| max-device-height | Maximum height of the device. |
| device-width | Width of the device. |
| min-device-width | Minimum width of the device. |
| max-device-width | Maximum width of the device. |
| round-screen | Screen type. The value **true** means that the screen is round, and **false** means the opposite. |
| dark-mode | Whether the device is in dark mode. The value **true** means that the device is in dark mode, and **false** means the opposite. |
## Example Scenario
......@@ -139,7 +139,7 @@ Use media queries to apply different content and styles to the page text when th
}
```
When the device is in landscape orientation, the text content is displayed in landscape mode in the color of #FFD700.<br/>
![zh-cn_image_0000001262954829](figures/zh-cn_image_0000001262954829.png)
![en-us_image_0000001262954829](figures/en-us_image_0000001262954829.png)
When the device is not in landscape orientation, the text content is displayed in portrait mode in the color of #DB7093.<br/>
![en-us_image_0000001263074739](figures/en-us_image_0000001263074739.png)
......@@ -159,13 +159,13 @@
- [自定义组件生命周期回调函数](ui/ts-custom-component-lifecycle-callbacks.md)
- [组件创建和重新初始化示例](ui/ts-component-creation-re-initialization.md)
- [语法糖](ui/ts-syntactic-sugar.md)
- 常见组件开发指导
- [Button开发指导](ui/ui-ts-basic-components-button.md)
- [Web开发指导](ui/ui-ts-components-web.md)
- 常见布局开发指导
- [弹性布局](ui/ui-ts-layout-flex.md)
- [栅格布局](ui/ui-ts-layout-grid-container.md)
- [媒体查询](ui/ui-ts-layout-mediaquery.md)
- 常见组件开发指导
- [Button开发指导](ui/ui-ts-basic-components-button.md)
- [Web开发指导](ui/ui-ts-components-web.md)
- 常见布局开发指导
- [弹性布局](ui/ui-ts-layout-flex.md)
- [栅格布局](ui/ui-ts-layout-grid-container.md)
- [媒体查询](ui/ui-ts-layout-mediaquery.md)
- 体验声明式UI
- [创建声明式UI工程](ui/ui-ts-creating-project.md)
- [初识Component](ui/ui-ts-components.md)
......@@ -198,6 +198,7 @@
- [音频采集开发指导](media/audio-capturer.md)
- 视频
- [视频播放开发指导](media/video-playback.md)
- [视频录制开发指导](media/video-recorder.md)
- 图片
- [图片开发指导](media/image.md)
- 安全
......
......@@ -9,5 +9,7 @@
- 视频
- [视频播放开发指导](video-playback.md)
- [视频录制开发指导](video-recorder.md)
- 图片
- [图片开发指导](image.md)
# 视频录制开发指导
## 场景介绍
视频录制的主要工作是捕获音视频信号,完成音视频编码并保存到文件中,帮助开发者轻松实现音视频录制功能。它允许调用者指定录制的编码格式、封装格式、文件路径等参数。
**图1** 视频录制状态机
![zh-ch_image_video_recorder_state_machine](figures/zh-ch_image_video_recorder_state_machine.png)
**图2** 视频录制零层图
![zh-ch_image_video_recorder_zero](figures/zh-ch_image_video_recorder_zero.png)
## 开发步骤
详细API含义可参考:[媒体服务API文档VideoRecorder](../reference/apis/js-apis-media.md)
### 全流程场景
包含流程:创建实例,设置录制参数,录制视频,暂停录制,恢复录制,停止录制,释放资源等流程。
```js
import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
export class VideoRecorderDemo {
private testFdNumber; // 用于保存fd地址
// pathName是传入的录制文件名,例如:01.mp4,生成后的文件地址:/storage/media/100/local/files/Video/01.mp4
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA
async 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');
this.testFdNumber = "fd://" + fdNumber.toString();
}
}
// 当发生错误上上报的错误回调接口
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);
}
// 当发生异常时,系统调用的错误回调接口
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);
}
async videoRecorderDemo() {
let videoRecorder = null; // videoRecorder空对象在createVideoRecorder成功后赋值
let surfaceID = null; // 用于保存getInputSurface返回的surfaceID
// 获取需要录制的视频的fd地址
await this.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 : this.testFdNumber, // testFdNumber由getFd生成
orientationHint : 0,
location : { latitude : 30, longitude : 130 },
}
// 创建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');
}
}, this.failureCallback).catch(this.catchCallback);
// 调用prepare完成视频录制前的准备工作
await videoRecorder.prepare(videoConfig).then(() => {
console.info('prepare success');
}, this.failureCallback).catch(this.catchCallback);
// 获取surfaceID并保存下来传递给camera相关接口
await videoRecorder.getInputSurface().then((surface) => {
console.info('getInputSurface success');
surfaceID = surface;
}, this.failureCallback).catch(this.catchCallback);
// 视频录制依赖相机相关接口,以下需要先调用相机起流接口后才能继续执行,具体的相机接口调用请参考sample用例
// 视频录制启动接口
await videoRecorder.start().then(() => {
console.info('start success');
}, this.failureCallback).catch(this.catchCallback);
// 调用pause接口时需要暂停camera出流
await videoRecorder.pause().then(() => {
console.info('pause success');
}, this.failureCallback).catch(this.catchCallback);
// 调用resume接口时需要恢复camera出流
await videoRecorder.resume().then(() => {
console.info('resume success');
}, this.failureCallback).catch(this.catchCallback);
// 停止camera出流后,停止视频录制
await videoRecorder.stop().then(() => {
console.info('stop success');
}, this.failureCallback).catch(this.catchCallback);
// 重置录制相关配置
await videoRecorder.reset().then(() => {
console.info('reset success');
}, this.failureCallback).catch(this.catchCallback);
// 释放视频录制相关资源并释放camera对象相关资源
await videoRecorder.release().then(() => {
console.info('release success');
}, this.failureCallback).catch(this.catchCallback);
// 相关对象置null
videoRecorder = undefined;
surfaceID = undefined;
}
}
```
......@@ -14,15 +14,22 @@
- [SysCap说明](quick-start/syscap.md)
- 开发
- Ability开发
- [FA模型综述](ability/fa-brief.md)
- [PageAbility开发指导](ability/fa-pageability.md)
- [ServiceAbility开发指导](ability/fa-serviceability.md)
- [DataAbility开发指导](ability/fa-dataability.md)
- [FA卡片开发指导](ability/fa-formability.md)
- [Ability框架概述](ability/ability-brief.md)
- FA模型
- [FA模型综述](ability/fa-brief.md)
- [PageAbility开发指导](ability/fa-pageability.md)
- [ServiceAbility开发指导](ability/fa-serviceability.md)
- [DataAbility开发指导](ability/fa-dataability.md)
- [FormAbility开发指导](ability/fa-formability.md)
- Stage模型
- [Stage模型综述](ability/stage-brief.md)
- [Ability开发指导](ability/stage-ability.md)
- [ServiceExtensionAbility开发指导](ability/stage-serviceextension.md)
- [FormExtensionAbility开发指导](ability/stage-formextension.md)
- [应用迁移开发指导](ability/stage-ability-continuation.md)
- 其他
- [WantAgent使用指导](ability/wantagent.md)
- [Ability助手使用指导](ability/ability-assistant-guidelines.md)
- [测试框架使用指导](ability-delegator.md)
- UI开发
- [方舟开发框架(ArkUI)概述](ui/arkui-overview.md)
- 基于JS扩展的类Web开发范式
......@@ -152,13 +159,13 @@
- [自定义组件生命周期回调函数](ui/ts-custom-component-lifecycle-callbacks.md)
- [组件创建和重新初始化示例](ui/ts-component-creation-re-initialization.md)
- [语法糖](ui/ts-syntactic-sugar.md)
- 常见组件开发指导
- [Button开发指导](ui/ui-ts-basic-components-button.md)
- [Web开发指导](ui/ui-ts-components-web.md)
- 常见布局开发指导
- [弹性布局](ui/ui-ts-layout-flex.md)
- [栅格布局](ui/ui-ts-layout-grid-container.md)
- [媒体查询](ui/ui-ts-layout-mediaquery.md)
- 常见组件开发指导
- [Button开发指导](ui/ui-ts-basic-components-button.md)
- [Web开发指导](ui/ui-ts-components-web.md)
- 常见布局开发指导
- [弹性布局](ui/ui-ts-layout-flex.md)
- [栅格布局](ui/ui-ts-layout-grid-container.md)
- [媒体查询](ui/ui-ts-layout-mediaquery.md)
- 体验声明式UI
- [创建声明式UI工程](ui/ui-ts-creating-project.md)
- [初识Component](ui/ui-ts-components.md)
......@@ -191,6 +198,7 @@
- [音频采集开发指导](media/audio-capturer.md)
- 视频
- [视频播放开发指导](media/video-playback.md)
- [视频录制开发指导](media/video-recorder.md)
- 图片
- [图片开发指导](media/image.md)
- 安全
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册