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

!23018 鸿蒙指南文档ArkTS规范整改

Merge pull request !23018 from shuboxu/monthly_20230815
......@@ -20,11 +20,11 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
import media from '@ohos.multimedia.media';
let avRecorder = undefined;
media.createAVRecorder().then((recorder) => {
let avRecorder: media.AVRecorder;
media.createAVRecorder().then((recorder: media.AVRecorder) => {
avRecorder = recorder;
}, (err) => {
console.error(`Invoke createAVRecorder failed, code is ${err.code}, message is ${err.message}`);
}, (error: Error) => {
console.error(`createAVRecorder failed`);
})
```
......@@ -37,13 +37,13 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
// Callback function for state changes.
avRecorder.on('stateChange', (state, reason) => {
avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.log(`current state is ${state}`);
// You can add the action to be performed after the state is switched.
})
// Callback function for errors.
avRecorder.on('error', (err) => {
avRecorder.on('error', (err: BusinessError) => {
console.error(`avRecorder failed, code is ${err.code}, message is ${err.message}`);
})
```
......@@ -62,21 +62,21 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
let avProfile = {
let avProfile: media.AVRecorderProfile = {
audioBitrate: 100000, // Audio bit rate.
audioChannels: 2, // Number of audio channels.
audioCodec: media.CodecMimeType.AUDIO_AAC, // Audio encoding format. Currently, only AAC is supported.
audioSampleRate: 48000, // Audio sampling rate.
fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // Encapsulation format. Currently, only M4A is supported.
}
let avConfig = {
let avConfig: media.AVRecorderConfig = {
audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, // Audio input source. In this example, the microphone is used.
profile: avProfile,
url: 'fd://35', // Obtain the file descriptor of the created audio file by referring to the sample code in Application File Access and Management.
}
avRecorder.prepare(avConfig).then(() => {
console.log('Invoke prepare succeeded.');
}, (err) => {
}, (err: BusinessError) => {
console.error(`Invoke prepare failed, code is ${err.code}, message is ${err.message}`);
})
```
......@@ -100,17 +100,17 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
import media from '@ohos.multimedia.media';
import { BusinessError } from '@ohos.base';
export class AudioRecorderDemo {
private avRecorder;
private avProfile = {
private avRecorder: media.AVRecorder;
private avProfile: media.AVRecorderProfile = {
audioBitrate: 100000, // Audio bit rate.
audioChannels: 2, // Number of audio channels.
audioCodec: media.CodecMimeType.AUDIO_AAC, // Audio encoding format. Currently, only AAC is supported.
audioSampleRate: 48000, // Audio sampling rate.
fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // Encapsulation format. Currently, only M4A is supported.
};
private avConfig = {
private avConfig: media.AVRecorderConfig = {
audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, // Audio input source. In this example, the microphone is used.
profile: this.avProfile,
url: 'fd://35', // Create, read, and write a file by referring to the sample code in Application File Access and Management.
......@@ -119,11 +119,11 @@ export class AudioRecorderDemo {
// Set AVRecorder callback functions.
setAudioRecorderCallback() {
// Callback function for state changes.
this.avRecorder.on('stateChange', (state, reason) => {
this.avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.log(`AudioRecorder current state is ${state}`);
})
// Callback function for errors.
this.avRecorder.on('error', (err) => {
this.avRecorder.on('error', (err: BusinessError) => {
console.error(`AudioRecorder failed, code is ${err.code}, message is ${err.message}`);
})
}
......
......@@ -24,10 +24,10 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
import media from '@ohos.multimedia.media'
let avRecorder
media.createAVRecorder().then((recorder) => {
let avRecorder: media.AVRecorder;
media.createAVRecorder().then((recorder: media.AVRecorder) => {
avRecorder = recorder
}, (error) => {
}, (error: Error) => {
console.error('createAVRecorder failed')
})
```
......@@ -40,11 +40,11 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
```ts
// Callback function for state changes.
avRecorder.on('stateChange', (state, reason) => {
avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.info('current state is: ' + state);
})
// Callback function for errors.
avRecorder.on('error', (err) => {
avRecorder.on('error', (err: BusinessError) => {
console.error('error happened, error message is ' + err);
})
```
......@@ -62,7 +62,7 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
> - The recording output URL (URL in **avConfig** in the sample code) must be in the format of fd://xx (where xx indicates a file descriptor). You must call [ohos.file.fs](../reference/apis/js-apis-file-fs.md) to implement access to the application file. For details, see [Application File Access and Management](../file-management/app-file-access.md).
```ts
let avProfile = {
let avProfile: media.AVRecorderProfile = {
fileFormat: media.ContainerFormatType.CFT_MPEG_4, // Video file encapsulation format. Only MP4 is supported.
videoBitrate: 200000, // Video bit rate.
videoCodec: media.CodecMimeType.VIDEO_AVC, // Video file encoding format. Both MPEG-4 and AVC are supported.
......@@ -70,15 +70,15 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
videoFrameHeight: 480, // Video frame height.
videoFrameRate: 30 // Video frame rate.
}
let avConfig = {
let avConfig: media.AVRecorderConfig = {
videoSourceType: media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // Video source type. YUV and ES are supported.
profile : this.avProfile,
profile : avProfile,
url: 'fd://35', // Create, read, and write a file by referring to the sample code in Application File Access and Management.
rotation: 0, // Video rotation angle. The default value is 0, indicating that the video is not rotated. The value can be 0, 90, 180, or 270.
}
avRecorder.prepare(avConfig).then(() => {
console.info('avRecorder prepare success')
}, (error) => {
}, (error: Error) => {
console.error('avRecorder prepare failed')
})
```
......@@ -90,9 +90,9 @@ Read [AVRecorder](../reference/apis/js-apis-media.md#avrecorder9) for the API re
The video data collection module obtains the surface based on the surface ID and transmits video data to the AVRecorder through the surface. Then the AVRecorder processes the video data.
```ts
avRecorder.getInputSurface().then((surfaceId) => {
avRecorder.getInputSurface().then((surfaceId: string) => {
console.info('avRecorder getInputSurface success')
}, (error) => {
}, (error: Error) => {
console.error('avRecorder getInputSurface failed')
})
```
......@@ -123,19 +123,20 @@ Refer to the sample code below to complete the process of starting, pausing, res
```ts
import media from '@ohos.multimedia.media'
import { BusinessError } from '@ohos.base';
const TAG = 'VideoRecorderDemo:'
export class VideoRecorderDemo {
private avRecorder;
private videoOutSurfaceId;
private avProfile = {
private avRecorder: media.AVRecorder;
private videoOutSurfaceId: string;
private avProfile: media.AVRecorderProfile = {
fileFormat: media.ContainerFormatType.CFT_MPEG_4, // Video file encapsulation format. Only MP4 is supported.
videoBitrate : 100000, // Video bit rate.
videoBitrate: 100000, // Video bit rate.
videoCodec: media.CodecMimeType.VIDEO_AVC, // Video file encoding format. Both MPEG-4 and AVC are supported.
videoFrameWidth: 640, // Video frame width.
videoFrameHeight: 480, // Video frame height.
videoFrameRate: 30 // Video frame rate.
}
private avConfig = {
private avConfig: media.AVRecorderConfig = {
videoSourceType: media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // Video source type. YUV and ES are supported.
profile : this.avProfile,
url: 'fd://35', // Create, read, and write a file by referring to the sample code in Application File Access and Management.
......@@ -145,11 +146,11 @@ export class VideoRecorderDemo {
// Set AVRecorder callback functions.
setAvRecorderCallback() {
// Callback function for state changes.
this.avRecorder.on('stateChange', (state, reason) => {
this.avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.info(TAG + 'current state is: ' + state);
})
// Callback function for errors.
this.avRecorder.on('error', (err) => {
this.avRecorder.on('error', (err: BusinessError) => {
console.error(TAG + 'error ocConstantSourceNode, error message is ' + err);
})
}
......@@ -188,7 +189,7 @@ export class VideoRecorderDemo {
// 5. Start the camera stream output.
await this.startCameraOutput();
// 6. Start recording.
await this.videoRecorder.start();
await this.avRecorder.start();
}
// Process of pausing recording.
......
......@@ -20,11 +20,11 @@
```ts
import media from '@ohos.multimedia.media';
let avRecorder = undefined;
media.createAVRecorder().then((recorder) => {
let avRecorder: media.AVRecorder;
media.createAVRecorder().then((recorder: media.AVRecorder) => {
avRecorder = recorder;
}, (err) => {
console.error(`Invoke createAVRecorder failed, code is ${err.code}, message is ${err.message}`);
}, (error: Error) => {
console.error(`createAVRecorder failed`);
})
```
......@@ -37,13 +37,13 @@
```ts
// 状态上报回调函数
avRecorder.on('stateChange', (state, reason) => {
avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.log(`current state is ${state}`);
// 用户可以在此补充状态发生切换后想要进行的动作
})
// 错误上报回调函数
avRecorder.on('error', (err) => {
avRecorder.on('error', (err: BusinessError) => {
console.error(`avRecorder failed, code is ${err.code}, message is ${err.message}`);
})
```
......@@ -61,21 +61,21 @@
```ts
let avProfile = {
let avProfile: media.AVRecorderProfile = {
audioBitrate: 100000, // 音频比特率
audioChannels: 2, // 音频声道数
audioCodec: media.CodecMimeType.AUDIO_AAC, // 音频编码格式,当前只支持aac
audioSampleRate: 48000, // 音频采样率
fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // 封装格式,当前只支持m4a
}
let avConfig = {
let avConfig: media.AVRecorderConfig = {
audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, // 音频输入源,这里设置为麦克风
profile: avProfile,
url: 'fd://35', // 参考应用文件访问与管理中的开发示例获取创建的音频文件fd填入此处
}
avRecorder.prepare(avConfig).then(() => {
console.log('Invoke prepare succeeded.');
}, (err) => {
}, (err: BusinessError) => {
console.error(`Invoke prepare failed, code is ${err.code}, message is ${err.message}`);
})
```
......@@ -99,17 +99,18 @@
```ts
import media from '@ohos.multimedia.media';
import { BusinessError } from '@ohos.base';
export class AudioRecorderDemo {
private avRecorder;
private avProfile = {
private avRecorder: media.AVRecorder;
private avProfile: media.AVRecorderProfile = {
audioBitrate: 100000, // 音频比特率
audioChannels: 2, // 音频声道数
audioCodec: media.CodecMimeType.AUDIO_AAC, // 音频编码格式,当前只支持aac
audioSampleRate: 48000, // 音频采样率
fileFormat: media.ContainerFormatType.CFT_MPEG_4A, // 封装格式,当前只支持m4a
};
private avConfig = {
private avConfig: media.AVRecorderConfig = {
audioSourceType: media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, // 音频输入源,这里设置为麦克风
profile: this.avProfile,
url: 'fd://35', // 参考应用文件访问与管理开发示例新建并读写一个文件
......@@ -118,11 +119,11 @@ export class AudioRecorderDemo {
// 注册audioRecorder回调函数
setAudioRecorderCallback() {
// 状态机变化回调函数
this.avRecorder.on('stateChange', (state, reason) => {
this.avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.log(`AudioRecorder current state is ${state}`);
})
// 错误上报回调函数
this.avRecorder.on('error', (err) => {
this.avRecorder.on('error', (err: BusinessError) => {
console.error(`AudioRecorder failed, code is ${err.code}, message is ${err.message}`);
})
}
......
......@@ -24,10 +24,10 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
```ts
import media from '@ohos.multimedia.media'
let avRecorder
media.createAVRecorder().then((recorder) => {
let avRecorder: media.AVRecorder;
media.createAVRecorder().then((recorder: media.AVRecorder) => {
avRecorder = recorder
}, (error) => {
}, (error: Error) => {
console.error('createAVRecorder failed')
})
```
......@@ -40,11 +40,11 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
```ts
// 状态上报回调函数
avRecorder.on('stateChange', (state, reason) => {
avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.info('current state is: ' + state);
})
// 错误上报回调函数
avRecorder.on('error', (err) => {
avRecorder.on('error', (err: BusinessError) => {
console.error('error happened, error message is ' + err);
})
```
......@@ -62,7 +62,7 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
> - 录制输出的url地址(即示例里avConfig中的url),形式为fd://xx (fd number)。需要调用基础文件操作接口([ohos.file.fs](../reference/apis/js-apis-file-fs.md))实现应用文件访问能力,获取方式参考[应用文件访问与管理](../file-management/app-file-access.md)。
```ts
let avProfile = {
let avProfile: media.AVRecorderProfile = {
fileFormat : media.ContainerFormatType.CFT_MPEG_4, // 视频文件封装格式,只支持MP4
videoBitrate : 200000, // 视频比特率
videoCodec : media.CodecMimeType.VIDEO_AVC, // 视频文件编码格式,支持mpeg4和avc两种格式
......@@ -70,15 +70,15 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
videoFrameHeight : 480, // 视频分辨率的高
videoFrameRate : 30 // 视频帧率
}
let avConfig = {
let avConfig: media.AVRecorderConfig = {
videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // 视频源类型,支持YUV和ES两种格式
profile : this.avProfile,
profile : avProfile,
url : 'fd://35', // 参考应用文件访问与管理开发示例新建并读写一个文件
rotation : 0, // 视频旋转角度,默认为0不旋转,支持的值为0、90、180、270
}
avRecorder.prepare(avConfig).then(() => {
console.info('avRecorder prepare success')
}, (error) => {
}, (error: Error) => {
console.error('avRecorder prepare failed')
})
```
......@@ -89,9 +89,9 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
输入源模块通过SurfaceID可以获取到Surface,通过Surface可以将视频数据流传递给AVRecorder,由AVRecorder再进行视频数据的处理。
```ts
avRecorder.getInputSurface().then((surfaceId) => {
avRecorder.getInputSurface().then((surfaceId: string) => {
console.info('avRecorder getInputSurface success')
}, (error) => {
}, (error: Error) => {
console.error('avRecorder getInputSurface failed')
})
```
......@@ -118,11 +118,12 @@ AVRecorder详细的API说明请参考[AVRecorder API参考](../reference/apis/js
```ts
import media from '@ohos.multimedia.media'
import { BusinessError } from '@ohos.base';
const TAG = 'VideoRecorderDemo:'
export class VideoRecorderDemo {
private avRecorder;
private videoOutSurfaceId;
private avProfile = {
private avRecorder: media.AVRecorder;
private videoOutSurfaceId: string;
private avProfile: media.AVRecorderProfile = {
fileFormat : media.ContainerFormatType.CFT_MPEG_4, // 视频文件封装格式,只支持MP4
videoBitrate : 100000, // 视频比特率
videoCodec : media.CodecMimeType.VIDEO_AVC, // 视频文件编码格式,支持mpeg4和avc两种格式
......@@ -130,7 +131,7 @@ export class VideoRecorderDemo {
videoFrameHeight : 480, // 视频分辨率的高
videoFrameRate : 30 // 视频帧率
}
private avConfig = {
private avConfig: media.AVRecorderConfig = {
videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, // 视频源类型,支持YUV和ES两种格式
profile : this.avProfile,
url : 'fd://35', // 参考应用文件访问与管理开发示例新建并读写一个文件
......@@ -140,11 +141,11 @@ export class VideoRecorderDemo {
// 注册avRecorder回调函数
setAvRecorderCallback() {
// 状态机变化回调函数
this.avRecorder.on('stateChange', (state, reason) => {
this.avRecorder.on('stateChange', (state: media.AVRecorderState, reason: media.StateChangeReason) => {
console.info(TAG + 'current state is: ' + state);
})
// 错误上报回调函数
this.avRecorder.on('error', (err) => {
this.avRecorder.on('error', (err: BusinessError) => {
console.error(TAG + 'error ocConstantSourceNode, error message is ' + err);
})
}
......@@ -183,7 +184,7 @@ export class VideoRecorderDemo {
// 5.启动相机出流
await this.startCameraOutput();
// 6. 启动录制
await this.videoRecorder.start();
await this.avRecorder.start();
}
// 暂停录制对应的流程
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册