The full audio playback process includes creating an instance, setting the URI, playing audio, seeking to the playback position, setting the volume, pausing playback, obtaining track information, stopping playback, resetting resources, and releasing resources.
For details about the **src** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
During audio recording, audio signals are captured, encoded, and saved to files. You can specify parameters such as the sampling rate, number of audio channels, encoding format, encapsulation format, and file path for audio recording.
For details about the APIs used for audio recording, see [js-apis-media.md](../reference/apis/js-apis-media.md).
### 全流程场景
### Full-Process Scenario
包含流程:创建实例,设置录制参数,录制音频,暂停录制,恢复录制,停止录制,释放资源等流程。
The full audio recording process includes creating an instance, setting recording parameters, starting, pausing, resuming, and stopping recording, and releasing resources.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
audioRecorder.stop();// The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
audioRecorder.stop();// The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// 6.释放资源
// 6. Release resources.
audioRecorder.release();// audioRecorder资源被销毁
audioRecorder.release();// The AudioRecorder resource is destroyed.
During video recording, audio and video signals are captured, encoded, and saved to files. You can specify parameters such as the encoding format, encapsulation format, and file path for video recording.
For details about the APIs used for video recording, see [js-apis-media.md](../reference/apis/js-apis-media.md).
### 全流程场景
### Full-Process Scenario
包含流程:创建实例,设置录制参数,录制视频,暂停录制,恢复录制,停止录制,释放资源等流程。
The full video recording process includes creating an instance, setting recording parameters, recording video, pausing, resuming, and stopping recording, and releasing resources.
// To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
// Video recording depends on camera-related interfaces. The following operations can be performed only after the video output start interface is invoked.
// 视频录制启动接口
// Start video recording.
awaitvideoRecorder.start().then(()=>{
awaitvideoRecorder.start().then(()=>{
console.info('start success');
console.info('start success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// 调用pause接口时需要暂停camera出流
// Pause video playback before the video output stop interface is invoked.
awaitvideoRecorder.pause().then(()=>{
awaitvideoRecorder.pause().then(()=>{
console.info('pause success');
console.info('pause success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// 调用resume接口时需要恢复camera出流
// Resume video playback after the video output start interface is invoked.
awaitvideoRecorder.resume().then(()=>{
awaitvideoRecorder.resume().then(()=>{
console.info('resume success');
console.info('resume success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// 停止camera出流后,停止视频录制
// Stop video recording after the video output stop interface is invoked.
awaitvideoRecorder.stop().then(()=>{
awaitvideoRecorder.stop().then(()=>{
console.info('stop success');
console.info('stop success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// 重置录制相关配置
// Reset the recording configuration.
awaitvideoRecorder.reset().then(()=>{
awaitvideoRecorder.reset().then(()=>{
console.info('reset success');
console.info('reset success');
},failureCallback).catch(catchCallback);
},failureCallback).catch(catchCallback);
// 释放视频录制相关资源并释放camera对象相关资源
// Release the video recording resources and camera object resources.