提交 705c65d9 编写于 作者: W wusongqing

updated docs

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 d2a1c33f
# 音频播放开发指导 # Audio Playback Development
## 场景介绍 ## When to Use
音频播放的主要工作是将音频数据转码为可听见的音频模拟信号并通过输出设备进行播放,同时对播放任务进行管理。 You can use audio playback APIs to convert audio data into audible analog signals, play the signals using output devices, and manage playback tasks.
**图1** 音频播放状态机 **Figure 1** Playback status
![zh-ch_image_audio_state_machine](figures/zh-ch_image_audio_state_machine.png) ![en-us_image_audio_state_machine](figures/en-us_image_audio_state_machine.png)
**图2** 音频播放零层图 **Figure 2** Layer 0 diagram of audio playback
![zh-ch_image_audio_player](figures/zh-ch_image_audio_player.png) ![en-us_image_audio_player](figures/en-us_image_audio_player.png)
## 开发步骤 ## How to Develop
详细API含义可参考:[js-apis-media.md](../reference/apis/js-apis-media.md) For details about the APIs used for audio playback, see [js-apis-media.md](../reference/apis/js-apis-media.md).
### 全流程场景 ### Full-Process Scenario
包含流程:创建实例,设置uri,播放音频,跳转播放位置,设置音量,暂停播放,获取轨道信息,停止播放,重置,释放资源等流程。 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.
AudioPlayer支持的src媒体源输入类型可参考:[src属性说明](../reference/apis/js-apis-media.md#audioplayer_属性) For details about the **src** media source input types supported by **AudioPlayer**, see the [src attribute](../reference/apis/js-apis-media.md#audioplayer_attributes).
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success'); console.info('audio set source success');
//播放界面可切换至已准备好,可点击播放按钮进行播放状态 // The playback page is ready. You can click the Play button to start the playback.
}); });
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success'); console.info('audio play success');
//将播放按钮切换至可暂停状态 // The Play button is changed to the pausable state.
}); });
audioPlayer.on('pause', () => { //设置'pause'事件回调 audioPlayer.on('pause', () => { // Set the 'pause' event callback.
console.info('audio pause success'); console.info('audio pause success');
//将播放按钮切换至可播放状态 // The Play button is changed to the playable state.
}); });
audioPlayer.on('stop', () => { //设置'stop'事件回调 audioPlayer.on('stop', () => { // Set the 'stop' event callback.
console.info('audio stop success'); console.info('audio stop success');
//播放停止,播放进度条归零,播放按钮切换至可播放状态 // The playback stops, the playback progress bar returns to 0, and the Play button is changed to the playable state.
}); });
audioPlayer.on('reset', () => { //设置'reset'事件回调 audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.info('audio reset success'); console.info('audio reset success');
//需重新设置src属性后,可继续播放其他音频 // You can reconfigure the src attribute to play another audio file.
}); });
audioPlayer.on('timeUpdate', (seekDoneTime) => {//设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime) => {// Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == 'undefined') { if (typeof(seekDoneTime) == 'undefined') {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
} }
console.info('audio seek success, and seek time is ' + seekDoneTime); console.info('audio seek success, and seek time is ' + seekDoneTime);
//播放进度条更新到seek对应的位置 // The playback progress bar is updated to the seek position.
}); });
audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback.
console.info('audio volumeChange success'); console.info('audio volumeChange success');
//更新音量显示 // Display the updated volume.
}); });
audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
}); });
audioPlayer.on('error', (error) => { //设置'error'事件回调 audioPlayer.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`); console.info(`audio error called, errMessage is ${error.message}`);
...@@ -79,10 +79,10 @@ function printfDescription(obj) { ...@@ -79,10 +79,10 @@ function printfDescription(obj) {
} }
} }
//1、创建实例 // 1. Create an audioPlayer instance.
let audioPlayer = media.createAudioPlayer(); let audioPlayer = media.createAudioPlayer();
SetCallBack(audioPlayer); //设置事件回调 SetCallBack(audioPlayer); // Set the event callbacks.
//2、用户选择音频,设置uri // 2. Set the URI of the audio file.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -94,17 +94,17 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -94,17 +94,17 @@ await fileIO.open(path).then(fdNumber) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
//3、播放音频 // 3. Play the audio.
audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调 audioPlayer.play(); // The play() method can be invoked only after the 'dataLoad' event callback is complete. The 'play' event callback is triggered.
//4、跳转播放位置 // 4. Seek to the playback position.
audioPlayer.seek(30000); //触发'timeUpdate'事件回调,seek到30000ms处播放 audioPlayer.seek(30000); // Trigger the 'timeUpdate' event callback, and seek to 30000 ms for playback.
//5、设置音量 // 5. Set the volume.
audioPlayer.setVolume(0.5); //触发'volumeChange'事件回调 audioPlayer.setVolume(0.5); // Trigger the 'volumeChange' event callback.
//6、暂停播放 // 6. Pause the playback.
audioPlayer.pause(); //触发'pause'事件回调,暂停播放 audioPlayer.pause(); // Trigger the 'pause' event callback and pause the playback.
//7、获取轨道信息 // 7. Obtain the track information.
audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获取音频轨道信息 audioPlayer.getTrackDescription((error, arrlist) => { // Obtain the audio track information in callback mode.
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
for (let i = 0; i < arrlist.length; i++) { for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]); printfDescription(arrlist[i]);
...@@ -113,39 +113,39 @@ audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获 ...@@ -113,39 +113,39 @@ audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获
console.log(`audio getTrackDescription fail, error:${error.message}`); console.log(`audio getTrackDescription fail, error:${error.message}`);
} }
}); });
//8、停止播放 // 8. Stop playback.
audioPlayer.stop(); //触发'stop'事件回调 audioPlayer.stop(); // Trigger the 'stop' event callback.
//9、重置播放资源 // 9. Reset the playback resources.
audioPlayer.reset(); //触发'reset'事件回调后,重新设置src属性,可完成切歌 audioPlayer.reset(); // Trigger the 'reset' event callback, and reconfigure the src attribute to switch to the next song.
//10、释放资源 // 10. Release the resource.
audioPlayer.release(); //audioPlayer资源被销毁 audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
``` ```
### 正常播放场景 ### Normal Playback Scenario
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success'); console.info('audio set source success');
audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 audioPlayer.play(); // Call the play() method to start the playback and trigger the 'play' event callback.
}); });
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success'); console.info('audio play success');
}); });
audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.release(); //audioPlayer资源被销毁 audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
} }
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
SetCallBack(audioPlayer); //设置事件回调 SetCallBack(audioPlayer); // Set the event callbacks.
/* 用户选择视频设置fd(本地播放) */ /* Set the FD (local playback) of the audio file selected by the user. */
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -157,33 +157,33 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -157,33 +157,33 @@ await fileIO.open(path).then(fdNumber) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
``` ```
### 切歌场景 ### Switching to the Next Song
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success'); console.info('audio set source success');
audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 audioPlayer.play(); // Call the play() method to start the playback and trigger the 'play' event callback.
}); });
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success'); console.info('audio play success');
}); });
audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.release(); //audioPlayer资源被销毁 audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
} }
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
SetCallBack(audioPlayer); //设置事件回调 SetCallBack(audioPlayer); // Set the event callbacks.
/* 用户选择视频设置fd(本地播放) */ /* Set the FD (local playback) of the audio file selected by the user. */
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -195,11 +195,11 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -195,11 +195,11 @@ await fileIO.open(path).then(fdNumber) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
/* 播放一段时间后,下发切歌指令 */ /* Send the instruction to switch to the next song after a period of time. */
audioPlayer.reset(); audioPlayer.reset();
/* 用户选择视频设置fd(本地播放) */ /* Set the FD (local playback) of the audio file selected by the user. */
let fdNextPath = 'fd://' let fdNextPath = 'fd://'
let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(nextPath).then(fdNumber) => { await fileIO.open(nextPath).then(fdNumber) => {
...@@ -213,31 +213,31 @@ await fileIO.open(nextPath).then(fdNumber) => { ...@@ -213,31 +213,31 @@ await fileIO.open(nextPath).then(fdNumber) => {
audioPlayer.src = fdNextPath; audioPlayer.src = fdNextPath;
``` ```
### 单曲循环场景 ### Looping a Song
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
function SetCallBack(audioPlayer) { function SetCallBack(audioPlayer) {
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success'); console.info('audio set source success');
audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 audioPlayer.play(); // Call the play() method to start the playback and trigger the 'play' event callback.
}); });
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success'); console.info('audio play success');
}); });
audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 audioPlayer.on('finish', () => { // Set the 'finish' event callback, which is triggered when the playback is complete.
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.release(); //audioPlayer资源被销毁 audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
} }
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
SetCallBack(audioPlayer); //设置事件回调 SetCallBack(audioPlayer); // Set the event callbacks.
/* 用户选择视频设置fd(本地播放) */ /* Set the FD (local playback) of the audio file selected by the user. */
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -249,6 +249,6 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -249,6 +249,6 @@ await fileIO.open(path).then(fdNumber) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
audioPlayer.loop = true; //设置循环播放属性 audioPlayer.loop = true; // Set the loop playback attribute.
``` ```
\ No newline at end of file
# 音频录制开发指导 # Audio Recording Development
## 场景介绍 ## When to Use
音频录制的主要工作是捕获音频信号,完成音频编码并保存到文件中,帮助开发者轻松实现音频录制功能。它允许调用者指定音频录制的采样率、声道数、编码格式、封装格式、文件路径等参数。 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.
**图1** 音频录制状态机 **Figure 1** Audio recording state transition
![zh-ch_image_audio_recorder_state_machine](figures/zh-ch_image_audio_recorder_state_machine.png) ![en-us_image_audio_recorder_state_machine](figures/en-us_image_audio_recorder_state_machine.png)
**图2** 音频录制零层图 **Figure 2** Layer 0 diagram of audio recording
![zh-ch_image_audio_recorder_zero](figures/zh-ch_image_audio_recorder_zero.png) ![en-us_image_audio_recorder_zero](figures/en-us_image_audio_recorder_zero.png)
## 开发步骤 ## How to Develop
详细API含义可参考:[js-apis-media.md](../reference/apis/js-apis-media.md) 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.
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary' import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber; let testFdNumber;
function SetCallBack(audioRecorder) { function SetCallBack(audioRecorder) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
console.log('prepare success'); console.log('prepare success');
// 录制界面可切换至已准备好,可点击录制按钮进行录制 // The recording page is ready. You can click the Record button to start recording.
}); });
audioRecorder.on('start', () => { // 设置'start'事件回调 audioRecorder.on('start', () => { // Set the 'start' event callback.
console.log('audio recorder start success'); console.log('audio recorder start success');
// 将录制按钮切换至可暂停状态 // The Record button is changed to the pausable state.
}); });
audioRecorder.on('pause', () => { // 设置'pause'事件回调 audioRecorder.on('pause', () => { // Set the 'pause' event callback.
console.log('audio recorder pause success'); console.log('audio recorder pause success');
// 将录制按钮切换至可录制状态 // The Record button is changed to the recordable state.
}); });
audioRecorder.on('resume', () => { // 设置'resume'事件回调 audioRecorder.on('resume', () => { // Set the 'resume' event callback.
console.log('audio recorder resume success'); console.log('audio recorder resume success');
// 将录制按钮切换至可暂停状态 // The Record button is changed to the pausable state.
}); });
audioRecorder.on('stop', () => { // 设置'stop'事件回调 audioRecorder.on('stop', () => { // Set the 'stop' event callback.
console.log('audio recorder stop success'); console.log('audio recorder stop success');
}); });
audioRecorder.on('release', () => { // 设置'release'事件回调 audioRecorder.on('release', () => { // Set the 'release' event callback.
console.log('audio recorder release success'); console.log('audio recorder release success');
}); });
audioRecorder.on('reset', () => { // 设置'reset'事件回调 audioRecorder.on('reset', () => { // Set the 'reset' event callback.
console.log('audio recorder reset success'); console.log('audio recorder reset success');
// 需要重新设置录制参数才能再次录制 // You need to reset the recording parameters for another recording.
}); });
audioRecorder.on('error', (error) => { // 设置'error'事件回调 audioRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`); console.info(`audio error called, errMessage is ${error.message}`);
}); });
} }
// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3 // pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA // To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
async function getFd(pathName) { async function getFd(pathName) {
let displayName = pathName; let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary(); const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO; let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) { if (dataUri != undefined) {
let args = dataUri.id.toString(); let args = dataUri.id.toString();
let fetchOp = { let fetchOp = {
selections : fileKeyObj.ID + "=?", selections : fileKeyObj.ID + "=?",
selectionArgs : [args], selectionArgs : [args],
} }
let fetchFileResult = await mediaTest.getFileAssets(fetchOp); let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject(); let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw'); let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString(); fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber; testFdNumber = fdNumber;
} }
} }
await getFd('01.mp3'); await getFd('01.mp3');
// 1.创建实例 // 1. Create an AudioRecorder instance.
let audioRecorder = media.createAudioRecorder(); let audioRecorder = media.createAudioRecorder();
// 2.设置回调 // 2. Set the callbacks.
SetCallBack(audioRecorder); SetCallBack(audioRecorder);
// 3.设置录制参数 // 3. Set the recording parameters.
let audioRecorderConfig = { let audioRecorderConfig = {
audioEncoder : media.AudioEncoder.AAC_LC , audioEncoder : media.AudioEncoder.AAC_LC ,
audioEncodeBitRate : 22050, audioEncodeBitRate : 22050,
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS, format : media.AudioOutputFormat.AAC_ADTS,
uri : testFdNumber, // testFdNumber由getFd生成 uri : testFdNumber, // testFdNumber is generated by getFd.
location : { latitude : 30, longitude : 130}, location : { latitude : 30, longitude : 130},
} }
audioRecorder.prepare(audioRecorderConfig); audioRecorder.prepare(audioRecorderConfig);
// 4.开始录制 // 4. Start recording.
audioRecorder.start(); // 需等待'prepare'事件回调完成后,才可调用start进行录制,触发'start'事件回调 audioRecorder.start(); // The start method can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
// 5.暂停录制 // 5. Pause recording.
audioRecorder.pause(); // 需等待'start'事件回调完成后,才可调用pause进行暂停,触发'pause'事件回调 audioRecorder.pause(); // The pause method can be called to trigger the 'pause' event callback only after the 'start' event callback is complete.
// 6.恢复录制 // 6. Resume recording.
audioRecorder.resume(); // 需等待'pause'事件回调完成后,才可调用resume进行录制,触发'resume'事件回调 audioRecorder.resume(); // The resume method can be called to trigger the 'resume' event callback only after the 'pause' event callback is complete.
// 7.停止录制 // 7. Stop recording.
audioRecorder.stop(); // 需等待'start'或'resume'事件回调完成后,才可调用stop进行暂停,触发'stop'事件回调 audioRecorder.stop(); // The stop method can be called to trigger the 'stop' event callback only after the 'start' or 'resume' event callback is complete.
// 8.重置录制 // 8. Reset recording.
audioRecorder.reset(); // 触发'reset'事件回调后,重新进行prepare,才可重新录制 audioRecorder.reset(); // The prepare method can be called for another recording only after the 'reset' event callback is complete.
// 9.释放资源 // 9. Release resources.
audioRecorder.release(); // audioRecorder资源被销毁 audioRecorder.release(); // The AudioRecorder resource is destroyed.
audioRecorder = undefined; audioRecorder = undefined;
``` ```
### 正常录制场景 ### Normal Recording Scenario
与全流程场景不同,不包括暂停录制,恢复录制的过程。 Unlike the full-process scenario, the normal recording scenario does not include the process of pausing and resuming recording.
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary' import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber; let testFdNumber;
function SetCallBack(audioPlayer) { function SetCallBack(audioPlayer) {
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
console.log('prepare success'); console.log('prepare success');
// 录制界面可切换至已准备好,可点击录制按钮进行录制 // The recording page is ready. You can click the Record button to start recording.
}); });
audioRecorder.on('start', () => { // 设置'start'事件回调 audioRecorder.on('start', () => { // Set the 'start' event callback.
console.log('audio recorder start success'); console.log('audio recorder start success');
// 将录制按钮切换至可暂停状态 // The Record button is changed to the pausable state.
}); });
audioRecorder.on('stop', () => { // 设置'stop'事件回调 audioRecorder.on('stop', () => { // Set the 'stop' event callback.
console.log('audio recorder stop success'); console.log('audio recorder stop success');
}); });
audioRecorder.on('release', () => { // 设置'release'事件回调 audioRecorder.on('release', () => { // Set the 'release' event callback.
console.log('audio recorder release success'); console.log('audio recorder release success');
}); });
} }
// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3 // pathName indicates the passed recording file name, for example, 01.mp3. The generated file address is /storage/media/100/local/files/Movies/01.mp3.
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA // To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
async function getFd(pathName) { async function getFd(pathName) {
let displayName = pathName; let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary(); const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO; let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) { if (dataUri != undefined) {
let args = dataUri.id.toString(); let args = dataUri.id.toString();
let fetchOp = { let fetchOp = {
selections : fileKeyObj.ID + "=?", selections : fileKeyObj.ID + "=?",
selectionArgs : [args], selectionArgs : [args],
} }
let fetchFileResult = await mediaTest.getFileAssets(fetchOp); let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject(); let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw'); let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString(); fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber; testFdNumber = fdNumber;
} }
} }
await getFd('01.mp3'); await getFd('01.mp3');
// 1.创建实例 // 1. Create an AudioRecorder instance.
let audioRecorder = media.createAudioRecorder(); let audioRecorder = media.createAudioRecorder();
// 2.设置回调 // 2. Set the callbacks.
SetCallBack(audioRecorder); SetCallBack(audioRecorder);
// 3.设置录制参数 // 3. Set the recording parameters.
let audioRecorderConfig = { let audioRecorderConfig = {
audioEncoder : media.AudioEncoder.AAC_LC , audioEncoder : media.AudioEncoder.AAC_LC ,
audioEncodeBitRate : 22050, audioEncodeBitRate : 22050,
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS, format : media.AudioOutputFormat.AAC_ADTS,
uri : testFdNumber, // testFdNumber由getFd生成 uri : testFdNumber, // testFdNumber is generated by getFd.
location : { latitude : 30, longitude : 130}, location : { latitude : 30, longitude : 130},
} }
audioRecorder.prepare(audioRecorderConfig) audioRecorder.prepare(audioRecorderConfig)
// 4.开始录制 // 4. Start recording.
audioRecorder.start(); // 需等待'prepare'事件回调完成后,才可调用start进行录制,触发'start'事件回调 audioRecorder.start(); // The start method can be called to trigger the 'start' event callback only after the 'prepare' event callback is complete.
// 5.停止录制 // 5. Stop recording.
audioRecorder.stop(); // 需等待'start'或'resume'事件回调完成后,才可调用stop进行暂停,触发'stop'事件回调 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.
audioRecorder = undefined; audioRecorder = undefined;
``` ```
# 视频播放开发指导 # Video Playback Development
## 场景介绍 ## When to Use
视频播放的主要工作是将视频数据转码并输出到设备进行播放,同时管理播放任务。本文将对视频播放全流程、视频切换、视频循环播放等场景开发进行介绍说明。 You can use video playback APIs to convert video data into visible signals, play the signals using output devices, and manage playback tasks. This document describes the following video playback development scenarios: full-process, normal playback, video switching, and loop playback.
**图1** 视频播放状态机 **Figure 1** Video playback state transition
![zh-ch_image_video_state_machine](figures/zh-ch_image_video_state_machine.png) ![en-us_image_video_state_machine](figures/en-us_image_video_state_machine.png)
**图2** 视频播放零层图 **Figure 2** Layer 0 diagram of video playback
![zh-ch_image_video_player](figures/zh-ch_image_video_player.png) ![en-us_image_video_player](figures/en-us_image_video_player.png)
*注意:视频播放需要显示、音频、编解码等硬件能力。 Note: Video playback requires hardware capabilities such as display, audio, and codec.
1. 三方应用从Xcomponent组件获取surfaceID。 1. A third-party application obtains a surface ID from the Xcomponent.
2. 三方应用把surfaceID传递给VideoPlayer JS。 2. The third-party application transfers the surface ID to the VideoPlayer JS.
3. 媒体服务把帧数据flush给surface buffer。 3. The media service flushes the frame data to the surface buffer.
## 开发步骤 ## How to Develop
详细API含义可参考:[js-apis-media.md](../reference/apis/js-apis-media.md) For details about the APIs used for video playback, see [js-apis-media.md](../reference/apis/js-apis-media.md).
### 全流程场景 ### Full-Process Scenario
包含流程:创建实例,设置url,设置SurfaceId,准备播放视频,播放视频,暂停播放,获取轨道信息,跳转播放位置,设置音量,设置倍速,结束播放,重置,释放资源等流程。 The full video playback process includes creating an instance, setting the URL, setting the surface ID, preparing for video playback, playing video, pausing playback, obtaining track information, seeking to a playback position, setting the volume, setting the playback speed, stopping playback, resetting the playback configuration, and releasing resources.
VideoPlayer支持的url媒体源输入类型可参考:[url属性说明](../reference/apis/js-apis-media.md#videoplayer_属性) For details about the **url** media source input types supported by **VideoPlayer**, see the [url attribute](../reference/apis/js-apis-media.md#videoplayer_attributes).
Xcomponent创建方法可参考:[Xcomponent创建方法](#Xcomponent创建方法) For details about how to create an Xcomponent, see [Xcomponent Creation](#Xcomponent).
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method.
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 // The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
} }
// 函数调用发生错误时用于上报错误信息 // Report an error in the case of a function invocation failure.
function failureCallback(error) { function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// 当函数调用发生异常时用于上报错误信息 // Report an error in the case of a function invocation exception.
function catchCallback(error) { function catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); 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 Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// 用于打印视频轨道信息 // Used to print the video track information.
function printfDescription(obj) { function printfDescription(obj) {
for (let item in obj) { for (let item in obj) {
let property = obj[item]; let property = obj[item];
...@@ -68,7 +68,7 @@ function printfDescription(obj) { ...@@ -68,7 +68,7 @@ function printfDescription(obj) {
} }
} }
// 调用createVideoPlayer接口返回videoPlayer实例对象 // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => { await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') { if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
...@@ -78,7 +78,7 @@ await media.createVideoPlayer().then((video) => { ...@@ -78,7 +78,7 @@ await media.createVideoPlayer().then((video) => {
} }
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -92,27 +92,27 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -92,27 +92,27 @@ await fileIO.open(path).then(fdNumber) => {
videoPlayer.url = fdPath; videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面 // Set the surface ID to display the video image.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用prepare完成播放前准备工作 // Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => { await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用play接口正式开始播放 // Call the play interface to start playback.
await videoPlayer.play().then(() => { await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 暂停播放 // Pause playback.
await videoPlayer.pause().then(() => { await videoPlayer.pause().then(() => {
console.info('pause success'); console.info('pause success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 通过promise回调方式获取视频轨道信息 // Use a promise to obtain the video track information.
let arrayDescription; let arrayDescription;
await videoPlayer.getTrackDescription().then((arrlist) => { await videoPlayer.getTrackDescription().then((arrlist) => {
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
...@@ -126,74 +126,74 @@ for (let i = 0; i < arrayDescription.length; i++) { ...@@ -126,74 +126,74 @@ for (let i = 0; i < arrayDescription.length; i++) {
printfDescription(arrayDescription[i]); printfDescription(arrayDescription[i]);
} }
// 跳转播放时间到50s位置,具体入参意义请参考接口文档 // Seek to the 50s position. For details about the input parameters, see the interface document.
let seekTime = 50000; let seekTime = 50000;
await videoPlayer.seek(seekTime, media.SeekMode._NEXT_SYNC).then((seekDoneTime) => { await videoPlayer.seek(seekTime, media.SeekMode._NEXT_SYNC).then((seekDoneTime) => {
console.info('seek success'); console.info('seek success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 音量设置接口,具体入参意义请参考接口文档 // Set the volume. For details about the input parameters, see the interface document.
let volume = 0.5; let volume = 0.5;
await videoPlayer.setVolume(volume).then(() => { await videoPlayer.setVolume(volume).then(() => {
console.info('setVolume success'); console.info('setVolume success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 倍速设置接口,具体入参意义请参考接口文档 // Set the playback speed. For details about the input parameters, see the interface document.
let speed = media.PlaybackRateMode.SPEED_FORWARD_2_00_X; let speed = media.PlaybackRateMode.SPEED_FORWARD_2_00_X;
await videoPlayer.setSpeed(speed).then(() => { await videoPlayer.setSpeed(speed).then(() => {
console.info('setSpeed success'); console.info('setSpeed success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 结束播放 // Stop playback.
await videoPlayer.stop().then(() => { await videoPlayer.stop().then(() => {
console.info('stop success'); console.info('stop success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 重置播放配置 // Reset the playback configuration.
await videoPlayer.reset().then(() => { await videoPlayer.reset().then(() => {
console.info('reset success'); console.info('reset success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 释放播放资源 // Release playback resources.
await videoPlayer.release().then(() => { await videoPlayer.release().then(() => {
console.info('release success'); console.info('release success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 相关对象置undefined // Set the related instances to undefined.
videoPlayer = undefined; videoPlayer = undefined;
surfaceID = undefined; surfaceID = undefined;
``` ```
### 正常播放场景 ### Normal Playback Scenario
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method.
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 // The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
} }
// 函数调用发生错误时用于上报错误信息 // Report an error in the case of a function invocation failure.
function failureCallback(error) { function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// 当函数调用发生异常时用于上报错误信息 // Report an error in the case of a function invocation exception.
function catchCallback(error) { function catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); 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 Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// 设置'playbackCompleted'事件回调,播放完成触发 // Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
function SetCallBack(videoPlayer) { function SetCallBack(videoPlayer) {
videoPlayer.on('playbackCompleted', () => { videoPlayer.on('playbackCompleted', () => {
console.info('video play finish'); console.info('video play finish');
...@@ -207,7 +207,7 @@ function SetCallBack(videoPlayer) { ...@@ -207,7 +207,7 @@ function SetCallBack(videoPlayer) {
}); });
} }
// 调用createVideoPlayer接口返回videoPlayer实例对象 // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => { await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') { if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
...@@ -217,10 +217,10 @@ await media.createVideoPlayer().then((video) => { ...@@ -217,10 +217,10 @@ await media.createVideoPlayer().then((video) => {
} }
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 设置事件回调 // Set the event callbacks.
SetCallBack(videoPlayer); SetCallBack(videoPlayer);
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -234,52 +234,52 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -234,52 +234,52 @@ await fileIO.open(path).then(fdNumber) => {
videoPlayer.url = fdPath; videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面 // Set the surface ID to display the video image.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用prepare完成播放前准备工作 // Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => { await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用play接口正式开始播放 // Call the play interface to start playback.
await videoPlayer.play().then(() => { await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
``` ```
### 切视频场景 ### Switching to the Next Video Clip
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method.
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 // The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
} }
// 函数调用发生错误时用于上报错误信息 // Report an error in the case of a function invocation failure.
function failureCallback(error) { function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// 当函数调用发生异常时用于上报错误信息 // Report an error in the case of a function invocation exception.
function catchCallback(error) { function catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); 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 Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// 设置'playbackCompleted'事件回调,播放完成触发 // Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
function SetCallBack(videoPlayer) { function SetCallBack(videoPlayer) {
videoPlayer.on('playbackCompleted', () => { videoPlayer.on('playbackCompleted', () => {
console.info('video play finish'); console.info('video play finish');
...@@ -293,7 +293,7 @@ function SetCallBack(videoPlayer) { ...@@ -293,7 +293,7 @@ function SetCallBack(videoPlayer) {
}); });
} }
// 调用createVideoPlayer接口返回videoPlayer实例对象 // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => { await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') { if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
...@@ -303,10 +303,10 @@ await media.createVideoPlayer().then((video) => { ...@@ -303,10 +303,10 @@ await media.createVideoPlayer().then((video) => {
} }
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 设置事件回调 // Set the event callbacks.
SetCallBack(videoPlayer); SetCallBack(videoPlayer);
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -320,28 +320,28 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -320,28 +320,28 @@ await fileIO.open(path).then(fdNumber) => {
videoPlayer.url = fdPath; videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面 // Set the surface ID to display the video image.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用prepare完成播放前准备工作 // Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => { await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用play接口正式开始播放 // Call the play interface to start playback.
await videoPlayer.play().then(() => { await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 播放一段时间后,下发切视频指令 // Send the instruction to switch to the next video clip after a period of time.
// 重置播放配置 // Reset the playback configuration.
await videoPlayer.reset().then(() => { await videoPlayer.reset().then(() => {
console.info('reset success'); console.info('reset success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdNextPath = 'fd://' let fdNextPath = 'fd://'
let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4'; let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4';
await fileIO.open(nextPath).then(fdNumber) => { await fileIO.open(nextPath).then(fdNumber) => {
...@@ -355,52 +355,52 @@ await fileIO.open(nextPath).then(fdNumber) => { ...@@ -355,52 +355,52 @@ await fileIO.open(nextPath).then(fdNumber) => {
videoPlayer.url = fdNextPath; videoPlayer.url = fdNextPath;
// 设置surfaceID用于显示视频画面 // Set the surface ID to display the video image.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用prepare完成播放前准备工作 // Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => { await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用play接口正式开始播放 // Call the play interface to start playback.
await videoPlayer.play().then(() => { await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
``` ```
### 单个视频循环场景 ### Looping a Video Clip
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import fileIO from '@ohos.fileio' import fileIO from '@ohos.fileio'
let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 let videoPlayer = undefined; // Used to store instances created by calling the createVideoPlayer method.
let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID let surfaceID = undefined; // Used to save the surface ID returned by the Xcomponent interface.
// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 // The LoadXcomponent() method is used to obtain the surface ID and save it to the **surfaceID** variable. This method is automatically called when the Xcomponent is loaded.
LoadXcomponent() { LoadXcomponent() {
surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); surfaceID = this.$element('Xcomponent').getXComponentSurfaceId();
console.info('LoadXcomponent surfaceID is' + surfaceID); console.info('LoadXcomponent surfaceID is' + surfaceID);
} }
// 函数调用发生错误时用于上报错误信息 // Report an error in the case of a function invocation failure.
function failureCallback(error) { function failureCallback(error) {
console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Name is ${error.name}`);
console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Code is ${error.code}`);
console.info(`error happened,error Message is ${error.message}`); console.info(`error happened,error Message is ${error.message}`);
} }
// 当函数调用发生异常时用于上报错误信息 // Report an error in the case of a function invocation exception.
function catchCallback(error) { function catchCallback(error) {
console.info(`catch error happened,error Name is ${error.name}`); 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 Code is ${error.code}`);
console.info(`catch error happened,error Message is ${error.message}`); console.info(`catch error happened,error Message is ${error.message}`);
} }
// 设置'playbackCompleted'事件回调,播放完成触发 // Set the 'playbackCompleted' event callback, which is triggered when the playback is complete.
function SetCallBack(videoPlayer) { function SetCallBack(videoPlayer) {
videoPlayer.on('playbackCompleted', () => { videoPlayer.on('playbackCompleted', () => {
console.info('video play finish'); console.info('video play finish');
...@@ -414,7 +414,7 @@ function SetCallBack(videoPlayer) { ...@@ -414,7 +414,7 @@ function SetCallBack(videoPlayer) {
}); });
} }
// 调用createVideoPlayer接口返回videoPlayer实例对象 // Call createVideoPlayer to create a VideoPlayer instance.
await media.createVideoPlayer().then((video) => { await media.createVideoPlayer().then((video) => {
if (typeof (video) != 'undefined') { if (typeof (video) != 'undefined') {
console.info('createVideoPlayer success!'); console.info('createVideoPlayer success!');
...@@ -424,10 +424,10 @@ await media.createVideoPlayer().then((video) => { ...@@ -424,10 +424,10 @@ await media.createVideoPlayer().then((video) => {
} }
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 设置事件回调 // Set the event callbacks.
SetCallBack(videoPlayer); SetCallBack(videoPlayer);
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -441,35 +441,33 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -441,35 +441,33 @@ await fileIO.open(path).then(fdNumber) => {
videoPlayer.url = fdPath; videoPlayer.url = fdPath;
// 设置surfaceID用于显示视频画面 // Set the surface ID to display the video image.
await videoPlayer.setDisplaySurface(surfaceID).then(() => { await videoPlayer.setDisplaySurface(surfaceID).then(() => {
console.info('setDisplaySurface success'); console.info('setDisplaySurface success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 调用prepare完成播放前准备工作 // Call the prepare interface to prepare for playback.
await videoPlayer.prepare().then(() => { await videoPlayer.prepare().then(() => {
console.info('prepare success'); console.info('prepare success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 设置循环播放属性 // Set the loop playback attribute.
videoPlayer.loop = true; videoPlayer.loop = true;
// 调用play接口正式开始播放 // Call the play interface to start playback.
await videoPlayer.play().then(() => { await videoPlayer.play().then(() => {
console.info('play success'); console.info('play success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
``` ```
### Xcomponent创建方法 ### Xcomponent Creation
播放视频中获取surfaceID依赖了Xcomponent,需要创建一个和xxx.js同名的xxx.hml文件,xxx.hml里面需要添加如下代码:
```js ```js
The Xcomponent is used to obtain the surface ID during video playback. You need to create an xxx.hml file and add the following code to the xxx.hml file, where xxx is the same as that in the xxx.js file:
<xcomponent id = 'Xcomponent' <xcomponent id = 'Xcomponent'
if = "{{isFlush}}" // 刷新surfaceID,isFlush赋值false再赋值true为一次刷新,会主动再次加载LoadXcomponet获取新的surfaceID if = "{{isFlush}}" // Refresh the surface ID. To enable automatic loading of the Xcomponent and obtain the new surface ID, assign **false** to **isFlush** and then assign **true** to **isFlush**.
type = 'surface' type = 'surface'
onload = 'LoadXcomponet' // 默认加载接口 onload = 'LoadXcomponent' // Default interface for loading the Xcomponent.
style = "wodth:720px;height:480px;border-color:red;border-width:5px;"> // 设置窗口宽高等属性 style = "width:720px;height:480px;border-color:red;border-width:5px;"> // Set the window width, height, and other attributes.
</xcomponent> </xcomponent>
``` ```
# 视频录制开发指导 # Video Recording Development
## 场景介绍 ## When to Use
视频录制的主要工作是捕获音视频信号,完成音视频编码并保存到文件中,帮助开发者轻松实现音视频录制功能。它允许调用者指定录制的编码格式、封装格式、文件路径等参数。 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.
**图1** 视频录制状态机 **Figure 1** Video recording state transition
![zh-ch_image_video_recorder_state_machine](figures/zh-ch_image_video_recorder_state_machine.png) ![en-us_image_video_recorder_state_machine](figures/en-us_image_video_recorder_state_machine.png)
**图2** 视频录制零层图 **Figure 2** Layer 0 diagram of video recording
![zh-ch_image_video_recorder_zero](figures/zh-ch_image_video_recorder_zero.png) ![en-us_image_video_recorder_zero](figures/en-us_image_video_recorder_zero.png)
## 开发步骤 ## How to Develop
详细API含义可参考:[js-apis-media.md](../reference/apis/js-apis-media.md) 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.
```js ```js
import media from '@ohos.multimedia.media' import media from '@ohos.multimedia.media'
import mediaLibrary from '@ohos.multimedia.mediaLibrary' import mediaLibrary from '@ohos.multimedia.mediaLibrary'
let testFdNumber; let testFdNumber;
// pathName是传入的录制文件名,例如:01.mp4,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp4 // pathName indicates the passed recording file name, for example, 01.mp4. The generated file address is /storage/media/100/local/files/Movies/01.mp4.
// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA // To use the media library, declare the following permissions: ohos.permission.MEDIA_LOCATION, ohos.permission.WRITE_MEDIA, and ohos.permission.READ_MEDIA.
async function getFd(pathName) { async function getFd(pathName) {
let displayName = pathName; let displayName = pathName;
const mediaTest = mediaLibrary.getMediaLibrary(); const mediaTest = mediaLibrary.getMediaLibrary();
let fileKeyObj = mediaLibrary.FileKey; let fileKeyObj = mediaLibrary.FileKey;
let mediaType = mediaLibrary.MediaType.VIDEO; let mediaType = mediaLibrary.MediaType.VIDEO;
let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO);
let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath);
if (dataUri != undefined) { if (dataUri != undefined) {
let args = dataUri.id.toString(); let args = dataUri.id.toString();
let fetchOp = { let fetchOp = {
selections : fileKeyObj.ID + "=?", selections : fileKeyObj.ID + "=?",
selectionArgs : [args], selectionArgs : [args],
} }
let fetchFileResult = await mediaTest.getFileAssets(fetchOp); let fetchFileResult = await mediaTest.getFileAssets(fetchOp);
let fileAsset = await fetchFileResult.getAllObject(); let fileAsset = await fetchFileResult.getAllObject();
let fdNumber = await fileAsset[0].open('Rw'); let fdNumber = await fileAsset[0].open('Rw');
fdNumber = "fd://" + fdNumber.toString(); fdNumber = "fd://" + fdNumber.toString();
testFdNumber = fdNumber; testFdNumber = fdNumber;
} }
} }
await getFd('01.mp4'); await getFd('01.mp4');
let videoProfile = { let videoProfile = {
audioBitrate : 48000, audioBitrate : 48000,
audioChannels : 2, audioChannels : 2,
audioCodec : 'audio/mp4a-latm', audioCodec : 'audio/mp4a-latm',
audioSampleRate : 48000, audioSampleRate : 48000,
fileFormat : 'mp4', fileFormat : 'mp4',
videoBitrate : 48000, videoBitrate : 48000,
videoCodec : 'video/mp4v-es', videoCodec : 'video/mp4v-es',
videoFrameWidth : 640, videoFrameWidth : 640,
videoFrameHeight : 480, videoFrameHeight : 480,
videoFrameRate : 30 videoFrameRate : 30
} }
let videoConfig = { let videoConfig = {
audioSourceType : 1, audioSourceType : 1,
videoSourceType : 0, videoSourceType : 0,
profile : videoProfile, profile : videoProfile,
url : testFdNumber, // testFdNumber由getFd生成 url: testFdNumber, // testFdNumber is generated by getFd.
orientationHint : 0, orientationHint : 0,
location : { latitude : 30, longitude : 130 }, location : { latitude : 30, longitude : 130 },
} }
// 当发生错误上上报的错误回调接口 // Error callback triggered in the case of an error
function failureCallback(error) { function failureCallback(error) {
console.info('error happened, error name is ' + error.name); console.info('error happened, error name is ' + error.name);
console.info('error happened, error code is ' + error.code); console.info('error happened, error code is ' + error.code);
console.info('error happened, error message is ' + error.message); console.info('error happened, error message is ' + error.message);
} }
// 当发生异常时,系统调用的错误回调接口 // Error callback triggered in the case of an exception
function catchCallback(error) { function catchCallback(error) {
console.info('catch error happened, error name is ' + error.name); 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 code is ' + error.code);
console.info('catch error happened, error message is ' + error.message); console.info('catch error happened, error message is ' + error.message);
} }
let videoRecorder = null; // videoRecorder空对象在createVideoRecorder成功后赋值 let videoRecorder = null; // videoRecorder is an empty object and assigned with a value after createVideoRecorder is successfully called.
let surfaceID = null; // 用于保存getInputSurface返回的surfaceID let surfaceID = null; // Used to save the surface ID returned by getInputSurface.
// 创建videoRecorder对象 // Create a VideoRecorder object.
await media.createVideoRecorder().then((recorder) => { await media.createVideoRecorder().then((recorder) => {
console.info('case createVideoRecorder called'); console.info('case createVideoRecorder called');
if (typeof (recorder) != 'undefined') { if (typeof (recorder) != 'undefined') {
videoRecorder = recorder; videoRecorder = recorder;
console.info('createVideoRecorder success'); console.info('createVideoRecorder success');
} else { } else {
console.info('createVideoRecorder failed'); console.info('createVideoRecorder failed');
} }
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 获取surfaceID并保存下来传递给camera相关接口 // Obtain the surface ID, save it, and pass it to camera-related interfaces.
await videoRecorder.getInputSurface().then((surface) => { await videoRecorder.getInputSurface().then((surface) => {
console.info('getInputSurface success'); console.info('getInputSurface success');
surfaceID = surface; surfaceID = surface;
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 视频录制依赖相机相关接口,以下需要先调用相机起流接口后才能继续执行 // 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.
await videoRecorder.start().then(() => { await videoRecorder.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.
await videoRecorder.pause().then(() => { await videoRecorder.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.
await videoRecorder.resume().then(() => { await videoRecorder.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.
await videoRecorder.stop().then(() => { await videoRecorder.stop().then(() => {
console.info('stop success'); console.info('stop success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 重置录制相关配置 // Reset the recording configuration.
await videoRecorder.reset().then(() => { await videoRecorder.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.
await videoRecorder.release().then(() => { await videoRecorder.release().then(() => {
console.info('release success'); console.info('release success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
// 相关对象置null // Set the related object to null.
videoRecorder = null; videoRecorder = null;
surfaceID = null; surfaceID = null;
``` ```
# 媒体服务 # Media
> **说明:** > **NOTE**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。 The multimedia subsystem provides a set of simple and easy-to-use APIs for you to access the system and use media resources.
媒体子系统包含了音视频相关媒体业务,提供以下常用功能: This subsystem offers various media services covering audio and video, which provide the following capabilities:
- 音频播放([AudioPlayer](#audioplayer) - Audio playback ([AudioPlayer](#audioplayer))
- 视频播放([VideoPlayer](#videoplayer8) - Video playback ([VideoPlayer](#videoplayer8))
- 音频录制([AudioRecorder](#audiorecorder) - Audio recording ([AudioRecorder](#audiorecorder))
- 视频录制([VideoRecorder](#VideoRecorder<sup>8+</sup>)) - Video recording ([VideoRecorder](#VideoRecorder<sup>8+</sup>))
后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。 The following capabilities will be provided in later versions: data source audio/video playback, audio/video encoding and decoding, container encapsulation and decapsulation, and media capability query.
## 导入模块 ## Modules to Import
```js ```js
import media from '@ohos.multimedia.media'; import media from '@ohos.multimedia.media';
...@@ -24,17 +24,17 @@ import media from '@ohos.multimedia.media'; ...@@ -24,17 +24,17 @@ import media from '@ohos.multimedia.media';
createAudioPlayer(): [AudioPlayer](#audioplayer) createAudioPlayer(): [AudioPlayer](#audioplayer)
同步方式创建音频播放实例。 Creates an **AudioPlayer** instance in synchronous mode.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| --------------------------- | ------------------------------------------------------------ | | --------------------------- | ------------------------------------------------------------ |
| [AudioPlayer](#audioplayer) | 返回AudioPlayer类实例,失败时返回null。可用于音频播放、暂停、停止等操作。 | | [AudioPlayer](#audioplayer) | Returns the **AudioPlayer** instance if the operation is successful; returns **null** otherwise. After the instance is created, you can start, pause, or stop audio playback.|
**示例:** **Example**
```js ```js
let audioPlayer = media.createAudioPlayer(); let audioPlayer = media.createAudioPlayer();
...@@ -44,17 +44,17 @@ let audioPlayer = media.createAudioPlayer(); ...@@ -44,17 +44,17 @@ let audioPlayer = media.createAudioPlayer();
createVideoPlayer(callback: AsyncCallback\<[VideoPlayer](#videoplayer8)>): void createVideoPlayer(callback: AsyncCallback\<[VideoPlayer](#videoplayer8)>): void
异步方式创建视频播放实例,通过注册回调函数获取返回值。 Creates a **VideoPlayer** instance in asynchronous mode. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ------------------------------ | | -------- | ------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[VideoPlayer](#videoplayer8)> | 是 | 异步创建视频播放实例回调方法。 | | callback | AsyncCallback<[VideoPlayer](#videoplayer8)> | Yes | Callback used to return the **VideoPlayer** instance created.|
**示例:** **Example**
```js ```js
let videoPlayer let videoPlayer
...@@ -73,17 +73,17 @@ media.createVideoPlayer((error, video) => { ...@@ -73,17 +73,17 @@ media.createVideoPlayer((error, video) => {
createVideoPlayer: Promise<[VideoPlayer](#videoplayer8)> createVideoPlayer: Promise<[VideoPlayer](#videoplayer8)>
异步方式创建视频播放实例,通过Promise获取返回值。 Creates a **VideoPlayer** instance in asynchronous mode. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ------------------------------------- | ----------------------------------- | | ------------------------------------- | ----------------------------------- |
| Promise<[VideoPlayer](#videoplayer8)> | 异步创建视频播放实例Promise返回值。 | | Promise<[VideoPlayer](#videoplayer8)> | Promise used to return the **VideoPlayer** instance created.|
**示例:** **Example**
```js ```js
let videoPlayer let videoPlayer
...@@ -109,17 +109,17 @@ await media.createVideoPlayer.then((video) => { ...@@ -109,17 +109,17 @@ await media.createVideoPlayer.then((video) => {
createAudioRecorder(): AudioRecorder createAudioRecorder(): AudioRecorder
创建音频录制的实例来控制音频的录制。 Creates an **AudioRecorder** instance to control audio recording.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ------------------------------- | ----------------------------------------- | | ------------------------------- | ----------------------------------------- |
| [AudioRecorder](#audiorecorder) | 返回AudioRecorder类实例,失败时返回null。 | | [AudioRecorder](#audiorecorder) | Returns the **AudioRecorder** instance if the operation is successful; returns **null** otherwise.|
**示例:** **Example**
```js ```js
let audiorecorder = media.createAudioRecorder(); let audiorecorder = media.createAudioRecorder();
...@@ -129,17 +129,17 @@ let audiorecorder = media.createAudioRecorder(); ...@@ -129,17 +129,17 @@ let audiorecorder = media.createAudioRecorder();
createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder8)>): void createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder8)>): void
异步方式创建视频录制实例。通过注册回调函数获取返回值。 Creates a **VideoRecorder** instance in asynchronous mode. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------- | ---- | ------------------------------ | | -------- | ----------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[VideoRecorder](#videorecorder8)> | 是 | 异步创建视频录制实例回调方法。 | | callback | AsyncCallback<[VideoRecorder](#videorecorder8)> | Yes | Callback used to return the **VideoRecorder** instance created.|
**示例:** **Example**
```js ```js
let videoRecorder let videoRecorder
...@@ -158,17 +158,17 @@ media.createVideoRecorder((error, video) => { ...@@ -158,17 +158,17 @@ media.createVideoRecorder((error, video) => {
createVideoRecorder: Promise<[VideoRecorder](#videorecorder8)> createVideoRecorder: Promise<[VideoRecorder](#videorecorder8)>
异步方式创建视频录制实例。通过Promise获取返回值。 Creates a **VideoRecorder** instance in asynchronous mode. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ----------------------------------------- | ----------------------------------- | | ----------------------------------------- | ----------------------------------- |
| Promise<[VideoRecorder](#videorecorder8)> | 异步创建视频录制实例Promise返回值。 | | Promise<[VideoRecorder](#videorecorder8)> | Promise used to return the **VideoRecorder** instance created.|
**示例:** **Example**
```js ```js
let videoRecorder let videoRecorder
...@@ -194,97 +194,97 @@ await media.createVideoRecorder.then((video) => { ...@@ -194,97 +194,97 @@ await media.createVideoRecorder.then((video) => {
## MediaErrorCode<sup>8+</sup> ## MediaErrorCode<sup>8+</sup>
媒体服务错误类型枚举。 Enumerates the media error codes.
| 名称 | 值 | 说明 | | Name | Value | Description |
| -------------------------- | ---- | ------------------------------------------------------------ | | -------------------------- | ---- | ------------------------------------------------------------ |
| MSERR_OK | 0 | 表示操作成功。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_OK | 0 | The operation is successful.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_NO_MEMORY | 1 | 表示申请内存失败,系统可能无可用内存。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_NO_MEMORY | 1 | Failed to allocate memory. The system may have no available memory.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_OPERATION_NOT_PERMIT | 2 | 表示无权限执行此操作。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_OPERATION_NOT_PERMIT | 2 | No permission to perform this operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_INVALID_VAL | 3 | 表示传入入参无效。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_INVALID_VAL | 3 | Invalid input parameter.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_IO | 4 | 表示发生IO错误。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_IO | 4 | An I/O error occurs.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_TIMEOUT | 5 | 表示操作超时。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_TIMEOUT | 5 | The operation times out.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_UNKNOWN | 6 | 表示未知错误。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_UNKNOWN | 6 | An unknown error occurs.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_SERVICE_DIED | 7 | 表示服务端失效。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_SERVICE_DIED | 7 | Invalid server.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_INVALID_STATE | 8 | 表示在当前状态下,不允许执行此操作。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_INVALID_STATE | 8 | The operation is not allowed in the current state.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MSERR_UNSUPPORTED | 9 | 表示在当前版本下,不支持此操作。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MSERR_UNSUPPORTED | 9 | The operation is not supported in the current version.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## MediaType<sup>8+</sup> ## MediaType<sup>8+</sup>
媒体类型枚举。 Enumerates the media types.
| 名称 | 值 | 说明 | | Name | Value | Description |
| -------------- | ---- | ------------------------------------------------------------ | | -------------- | ---- | ------------------------------------------------------------ |
| MEDIA_TYPE_AUD | 0 | 表示音频。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MEDIA_TYPE_AUD | 0 | Media.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MEDIA_TYPE_VID | 1 | 表示视频。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MEDIA_TYPE_VID | 1 | Video.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## CodecMimeType<sup>8+</sup> ## CodecMimeType<sup>8+</sup>
Codec MIME类型枚举。 Enumerates the codec MIME types.
| 名称 | 值 | 说明 | | Name | Value | Description |
| ------------ | ----------------- | ------------------------------------------------------------ | | ------------ | ----------------- | ------------------------------------------------------------ |
| VIDEO_MPEG4 | ”video/mp4v-es“ | 表示视频/mpeg4类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | VIDEO_MPEG4 | "video/mp4v-es" | Video in MPEG-4 format.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| AUDIO_AAC | "audio/mp4a-latm" | 表示音频/mp4a-latm类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | AUDIO_AAC | "audio/mp4a-latm" | Audio in MP4A-LATM format.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| AUDIO_VORBIS | "audio/vorbis" | 表示音频/vorbis类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | AUDIO_VORBIS | "audio/vorbis" | Audio in Vorbis format.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| AUDIO_FLAC | "audio/flac" | 表示音频/flac类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | AUDIO_FLAC | "audio/flac" | Audio in FLAC format.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## MediaDescriptionKey<sup>8+</sup> ## MediaDescriptionKey<sup>8+</sup>
媒体信息描述枚举。 Enumerates the media description keys.
| 名称 | 值 | 说明 | | Name | Value | Description |
| ------------------------ | --------------- | ------------------------------------------------------------ | | ------------------------ | --------------- | ------------------------------------------------------------ |
| MD_KEY_TRACK_INDEX | "track_index" | 表示轨道序号,其对应键值类型为number。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_TRACK_INDEX | "track_index" | Track index, which is a number.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_TRACK_TYPE | "track_type" | 表示轨道类型,其对应键值类型为number,参考[MediaType](#mediatype8)<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_TRACK_TYPE | "track_type" | Track type, which is a number. For details, see [MediaType](#mediatype8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_CODEC_MIME | "codec_mime" | 表示codec_mime类型,其对应键值类型为string。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_CODEC_MIME | "codec_mime" | Codec MIME type, which is a string.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_DURATION | "duration" | 表示媒体时长,其对应键值类型为number,单位为ms。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_DURATION | "duration" | Media duration, which is a number, in units of ms.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_BITRATE | "bitrate" | 表示比特率,其对应键值类型为number,单位为bps。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_BITRATE | "bitrate" | Bit rate, which is a number, in units of bit/s.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_WIDTH | "width" | 表示视频宽度,其对应键值类型为number,单位为像素。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_WIDTH | "width" | Video width, which is a number, in units of pixel.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_HEIGHT | "height" | 表示视频高度,其对应键值类型为number,单位为像素。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_HEIGHT | "height" | Video height, which is a number, in units of pixel.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_FRAME_RATE | "frame_rate" | 表示视频帧率,其对应键值类型为number,单位为100fps。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_FRAME_RATE | "frame_rate" | Video frame rate, which is a number, in units of 100 fps.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | 表示声道数,其对应键值类型为number。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_AUD_CHANNEL_COUNT | "channel_count" | Number of audio channels, which is a number.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| MD_KEY_AUD_SAMPLE_RATE | "sample_rate" | 表示采样率,其对应键值类型为number,单位为HZ。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | MD_KEY_AUD_SAMPLE_RATE | "sample_rate" | Sampling rate, which is a number, in units of Hz.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## BufferingInfoType<sup>8+</sup> ## BufferingInfoType<sup>8+</sup>
缓存事件类型枚举。 Enumerates the buffering event types.
| 名称 | 值 | 说明 | | Name | Value | Description |
| ----------------- | ---- | ------------------------------------------------------------ | | ----------------- | ---- | ------------------------------------------------------------ |
| BUFFERING_START | 1 | 表示开始缓存。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | BUFFERING_START | 1 | Buffering starts.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| BUFFERING_END | 2 | 表示结束缓存。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | BUFFERING_END | 2 | Buffering ends.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| BUFFERING_PERCENT | 3 | 表示缓存百分比。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | BUFFERING_PERCENT | 3 | Buffering progress, in percent.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| CACHED_DURATION | 4 | 表示缓存时长,单位为毫秒。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | CACHED_DURATION | 4 | Cache duration, in milliseconds.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## AudioPlayer ## AudioPlayer
音频播放管理类,用于管理和播放音频媒体。在调用AudioPlayer的方法前,需要先通过[createAudioPlayer()](#mediacreateaudioplayer)构建一个[AudioPlayer](#audioplayer)实例。 Provides methods to manage and play audio. Before calling a method of **AudioPlayer**, you must use [createAudioPlayer()](#mediacreateaudioplayer) to create an **AudioPlayer** instance.
音频播放demo可参考:[音频播放开发指导](../../media/audio-playback.md) For details about the audio playback demo, see [Audio Playback Development](../../media/audio-playback.md).
### 属性<a name=audioplayer_属性></a> ### Attributes<a name=audioplayer_attributes></a>
| 名称 | 类型 | 可读 | 可写 | 说明 | | Name | Type | Readable| Writable| Description |
| ----------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ | | ----------- | ------------------------- | ---- | ---- | ------------------------------------------------------------ |
| src | string | 是 | 是 | 音频媒体URI,支持当前主流的音频格式(mp4、aac、mp3、ogg)。<br>**支持路径示例**<br>1、fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>2、http网络播放路径:开发中<br>3、hls网络播放路径:开发中<br>**注意事项**<br>使用媒体素材需要获取读权限,否则无法正常播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | src | string | Yes | Yes | Audio media URI. The mainstream audio formats (MP4, AAC, MP3, and OGG) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xxx<br>![en-us_image_0000001164217678](figures/en-us_image_url.png)<br>2. HTTP network playback path (under development)<br>3. HLS network playback path (under development)<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| loop | boolean | 是 | 是 | 音频循环播放属性,设置为'true'表示循环播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| currentTime | number | 是 | 否 | 音频的当前播放位置。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | currentTime | number | Yes | No | Current audio playback position.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| duration | number | 是 | 否 | 音频时长。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | duration | number | Yes | No | Audio duration.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| state | [AudioState](#audiostate) | 是 | 否 | 音频播放的状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | state | [AudioState](#audiostate) | Yes | No | Audio playback state.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
### play<a name=audioplayer_play></a> ### play<a name=audioplayer_play></a>
play(): void play(): void
开始播放音频资源,需在[dataLoad](#on('play' | 'pause' | 'stop' | 'reset' | 'dataload' | 'finish' | 'volumechange'))事件成功触发后,才能调用play方法。 Starts to play audio resources. This method can be called only after the [dataLoad](#on('play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange')) event is triggered.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**示例:** **Example**
```js ```js
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.log('audio play success'); console.log('audio play success');
}); });
audioPlayer.play(); audioPlayer.play();
...@@ -294,14 +294,14 @@ audioPlayer.play(); ...@@ -294,14 +294,14 @@ audioPlayer.play();
pause(): void pause(): void
暂停播放音频资源。 Pauses audio playback.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**示例:** **Example**
```js ```js
audioPlayer.on('pause', () => { //设置'pause'事件回调 audioPlayer.on('pause', () => { // Set the 'pause' event callback.
console.log('audio pause success'); console.log('audio pause success');
}); });
audioPlayer.pause(); audioPlayer.pause();
...@@ -311,14 +311,14 @@ audioPlayer.pause(); ...@@ -311,14 +311,14 @@ audioPlayer.pause();
stop(): void stop(): void
停止播放音频资源。 Stops audio playback.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**示例:** **Example**
```js ```js
audioPlayer.on('stop', () => { //设置'stop'事件回调 audioPlayer.on('stop', () => { // Set the 'stop' event callback.
console.log('audio stop success'); console.log('audio stop success');
}); });
audioPlayer.stop(); audioPlayer.stop();
...@@ -328,14 +328,14 @@ audioPlayer.stop(); ...@@ -328,14 +328,14 @@ audioPlayer.stop();
reset(): void reset(): void
切换播放音频资源。 Switches the audio resource to be played.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**示例:** **Example**
```js ```js
audioPlayer.on('reset', () => { //设置'reset'事件回调 audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.log('audio reset success'); console.log('audio reset success');
}); });
audioPlayer.reset(); audioPlayer.reset();
...@@ -345,61 +345,61 @@ audioPlayer.reset(); ...@@ -345,61 +345,61 @@ audioPlayer.reset();
seek(timeMs: number): void seek(timeMs: number): void
跳转到指定播放位置。 Seeks to the specified playback position.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------ | | ------ | ------ | ---- | ------------------------------ |
| timeMs | number | 是 | 指定的跳转时间节点,单位毫秒。 | | timeMs | number | Yes | Position to seek to, in milliseconds.|
**示例:** **Example**
```js ```js
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof (seekDoneTime) == 'undefined') { if (typeof (seekDoneTime) == 'undefined') {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
} }
console.log('audio seek success. seekDoneTime: ' + seekDoneTime); console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
}); });
audioPlayer.seek(30000); //seek到30000ms的位置 audioPlayer.seek(30000); // Seek to 30000 ms.
``` ```
### setVolume<a name=audioplayer_setvolume></a> ### setVolume<a name=audioplayer_setvolume></a>
setVolume(vol: number): void setVolume(vol: number): void
设置音量。 Sets the volume.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| vol | number | 是 | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 | | vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|
**示例:** **Example**
```js ```js
audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback.
console.log('audio volumeChange success'); console.log('audio volumeChange success');
}); });
audioPlayer.setVolume(1); //设置音量到100% audioPlayer.setVolume(1); // Set the volume to 100%.
``` ```
### release<a name=audioplayer_release></a> ### release<a name=audioplayer_release></a>
release(): void release(): void
释放音频资源。 Releases the audio playback resource.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**示例:** **Example**
```js ```js
audioPlayer.release(); audioPlayer.release();
...@@ -410,17 +410,17 @@ audioPlayer = undefined; ...@@ -410,17 +410,17 @@ audioPlayer = undefined;
getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8)>>): void getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8)>>): void
通过回调方式获取音频轨道信息。 Obtains the audio track information. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | -------------------------- | | -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | 是 | 获取音频轨道信息回调方法。 | | callback | AsyncCallback<Array<[MediaDescription](#mediadescription8)>> | Yes | Callback used to return the audio track information obtained.|
**示例:** **Example**
```js ```js
function printfDescription(obj) { function printfDescription(obj) {
...@@ -446,17 +446,17 @@ audioPlayer.getTrackDescription((error, arrlist) => { ...@@ -446,17 +446,17 @@ audioPlayer.getTrackDescription((error, arrlist) => {
getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8)>> getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8)>>
通过Promise方式获取音频轨道信息。 Obtains the audio track information. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ------------------------------------------------------ | ------------------------------- | | ------------------------------------------------------ | ------------------------------- |
| Promise<Array<[MediaDescription](#mediadescription8)>> | 获取音频轨道信息Promise返回值。 | | Promise<Array<[MediaDescription](#mediadescription8)>> | Promise used to return the audio track information obtained.|
**示例:** **Example**
```js ```js
function printfDescription(obj) { function printfDescription(obj) {
...@@ -489,18 +489,18 @@ for (let i = 0; i < arrayDescription.length; i++) { ...@@ -489,18 +489,18 @@ for (let i = 0; i < arrayDescription.length; i++) {
on(type: 'bufferingUpdate', callback: (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void): void on(type: 'bufferingUpdate', callback: (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void): void
开始订阅音频缓存更新事件。 Subscribes to the audio buffering update event.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type | string | 是 | 音频缓存事件回调类型,支持的事件:'bufferingUpdate'。 | | type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| callback | (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void | 是 | 音频缓存事件回调方法。<br>[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 | | callback | (infoType: [BufferingInfoType](#bufferinginfotype8), value: number) => void | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
**示例:** **Example**
```js ```js
audioPlayer.on('bufferingUpdate', (infoType, value) => { audioPlayer.on('bufferingUpdate', (infoType, value) => {
...@@ -513,61 +513,61 @@ audioPlayer.on('bufferingUpdate', (infoType, value) => { ...@@ -513,61 +513,61 @@ audioPlayer.on('bufferingUpdate', (infoType, value) => {
on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void on(type: 'play' | 'pause' | 'stop' | 'reset' | 'dataLoad' | 'finish' | 'volumeChange', callback: () => void): void
开始订阅音频播放事件。 Subscribes to the audio playback events.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ---------- | ---- | ------------------------------------------------------------ | | -------- | ---------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 播放事件回调类型,支持的事件包括:'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'。<br>- 'play':完成[play()](#play)调用,音频开始播放,触发该事件。<br>- 'pause':完成[pause()](#pause)调用,音频暂停播放,触发该事件。<br>- 'stop':完成[stop()](#stop)调用,音频停止播放,触发该事件。<br>- 'reset':完成[reset()](#reset7)调用,播放器重置,触发该事件。<br>- 'dataLoad':完成音频数据加载后触发该事件,即src属性设置完成后触发该事件。<br>- 'finish':完成音频播放后触发该事件。<br>- 'volumeChange':完成[setVolume()](#setvolume)调用,播放音量改变后触发该事件。 | | type | string | Yes | Type of the event to subscribe to. The following events are supported: 'play' \| 'pause' \| 'stop' \| 'reset' \| 'dataLoad' \| 'finish' \| 'volumeChange'<br>- The 'play' event is triggered when the [play()](#play) method is called and audio playback starts.<br>- The 'pause' event is triggered when the [pause()](#pause) method is called and audio playback is paused.<br>- The 'stop' event is triggered when the [stop()](#stop) method is called and audio playback stops.<br>- The 'reset' event is triggered when the [reset()](#reset7) method is called and audio playback is reset.<br>- The 'dataLoad' event is triggered when the audio data is loaded, that is, when the **src** attribute is configured.<br>- The 'finish' event is triggered when the audio playback is finished.<br>- The 'volumeChange' event is triggered when the [setVolume()](#setvolume) method is called and the playback volume is changed.|
| callback | () => void | 是 | 播放事件回调方法。 | | callback | () => void | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 let audioPlayer = media.createAudioPlayer(); // Create an AudioPlayer instance.
audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 audioPlayer.on('dataLoad', () => { // Set the 'dataLoad' event callback, which is triggered when the src attribute is set successfully.
console.info('audio set source success'); console.info('audio set source success');
audioPlayer.play(); //开始播放,并触发'play'事件回调 audioPlayer.play(); // Start the playback and trigger the 'play' event callback.
}); });
audioPlayer.on('play', () => { //设置'play'事件回调 audioPlayer.on('play', () => { // Set the 'play' event callback.
console.info('audio play success'); console.info('audio play success');
audioPlayer.seek(30000); //调用seek方法,并触发'timeUpdate'事件回调 audioPlayer.seek(30000); // Call the seek() method and trigger the 'timeUpdate' event callback.
}); });
audioPlayer.on('pause', () => { //设置'pause'事件回调 audioPlayer.on('pause', () => { // Set the 'pause' event callback.
console.info('audio pause success'); console.info('audio pause success');
audioPlayer.stop(); //停止播放,并触发'stop'事件回调 audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback.
}); });
audioPlayer.on('reset', () => { //设置'reset'事件回调 audioPlayer.on('reset', () => { // Set the 'reset' event callback.
console.info('audio reset success'); console.info('audio reset success');
audioPlayer.release(); //释放播放实例资源 audioPlayer.release(); // Release the AudioPlayer instance.
audioPlayer = undefined; audioPlayer = undefined;
}); });
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof(seekDoneTime) == "undefined") { if (typeof(seekDoneTime) == "undefined") {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
} }
console.info('audio seek success, and seek time is ' + seekDoneTime); console.info('audio seek success, and seek time is ' + seekDoneTime);
audioPlayer.setVolume(0.5); //设置音量为50%,并触发'volumeChange'事件回调 audioPlayer.setVolume(0.5); // Set the volume to 50% and trigger the 'volumeChange' event callback.
}); });
audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 audioPlayer.on('volumeChange', () => { // Set the 'volumeChange' event callback.
console.info('audio volumeChange success'); console.info('audio volumeChange success');
audioPlayer.pause(); //暂停播放,并触发'pause'事件回调 audioPlayer.pause(); // Pause the playback and trigger the 'pause' event callback.
}); });
audioPlayer.on('finish', () => { //设置'finish'事件回调 audioPlayer.on('finish', () => { // Set the 'finish' event callback.
console.info('audio play finish'); console.info('audio play finish');
audioPlayer.stop(); //停止播放,并触发'stop'事件回调 audioPlayer.stop(); // Stop the playback and trigger the 'stop' event callback.
}); });
audioPlayer.on('error', (error) => { //设置'error'事件回调 audioPlayer.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`); console.info(`audio error called, errMessage is ${error.message}`);
}); });
// 用户选择视频设置fd(本地播放) // Set the FD (local playback) of the video file selected by the user.
let fdPath = 'fd://' let fdPath = 'fd://'
let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3';
await fileIO.open(path).then(fdNumber) => { await fileIO.open(path).then(fdNumber) => {
...@@ -578,109 +578,109 @@ await fileIO.open(path).then(fdNumber) => { ...@@ -578,109 +578,109 @@ await fileIO.open(path).then(fdNumber) => {
}),catch((err) => { }),catch((err) => {
console.info('open fd failed err is' + err); console.info('open fd failed err is' + err);
}); });
audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 audioPlayer.src = fdPath; // Set the src attribute and trigger the 'dataLoad' event callback.
``` ```
### on('timeUpdate') ### on('timeUpdate')
on(type: 'timeUpdate', callback: Callback\<number>): void on(type: 'timeUpdate', callback: Callback\<number>): void
开始订阅音频播放[seek()](#seek)时间更新事件。 Subscribes to the 'timeUpdate' event.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ----------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 播放事件回调类型,支持的事件包括:'timeUpdate'。<br>- 'timeUpdate':[seek()](#seek)调用完成,触发该事件。 | | type | string | Yes | Type of the event to subscribe to, which is 'timeUpdate' in this method.<br>The 'timeUpdate' event is triggered when the [seek()](#seek) method is called.|
| callback | Callback\<number> | 是 | 播放事件回调方法。回调方法入参为成功seek的时间。 | | callback | Callback\<number> | Yes | Callback invoked when the event is triggered. The input parameter of the callback is the time when the seek operation is successful. |
**示例:** **Example**
```js ```js
audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 audioPlayer.on('timeUpdate', (seekDoneTime) => { // Set the 'timeUpdate' event callback.
if (typeof (seekDoneTime) == 'undefined') { if (typeof (seekDoneTime) == 'undefined') {
console.info('audio seek fail'); console.info('audio seek fail');
return; return;
} }
console.log('audio seek success. seekDoneTime: ' + seekDoneTime); console.log('audio seek success. seekDoneTime: ' + seekDoneTime);
}); });
audioPlayer.seek(30000); //seek到30000ms的位置 audioPlayer.seek(30000); // Seek to 30000 ms.
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
开始订阅音频播放错误事件。 Subscribes to the audio playback error event.
**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ | | -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':音频播放中发生错误,触发该事件。 | | type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during audio playback.|
| callback | ErrorCallback | 是 | 播放错误事件回调方法。 | | callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
audioPlayer.on('error', (error) => { //设置'error'事件回调 audioPlayer.on('error', (error) => { // Set the error event callback.
console.info(`audio error called, errName is ${error.name}`); //打印错误类型名称 console.info(`audio error called, errName is ${error.name}`); // Print the error name.
console.info(`audio error called, errCode is ${error.code}`); //打印错误码 console.info(`audio error called, errCode is ${error.code}`); // Print the error code.
console.info(`audio error called, errMessage is ${error.message}`);//打印错误类型详细描述 console.info(`audio error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
}); });
audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件 audioPlayer.setVolume(3); // Set volume to an invalid value to trigger the 'error' event.
``` ```
## AudioState ## AudioState
音频播放的状态机。可通过state属性获取当前状态。 Enumerates the audio playback states. You can obtain the state through the **state** attribute.
| 名称 | 类型 | 描述 | | Name | Type | Description |
| ------------------ | ------ | ------------------------------------------------------------ | | ------------------ | ------ | ------------------------------------------------------------ |
| idle | string | 音频播放空闲。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | idle | string | The audio player is idle.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| playing | string | 音频正在播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | playing | string | Audio playback is in progress.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| paused | string | 音频暂停播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | paused | string | Audio playback is paused.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| stopped | string | 音频播放停止。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | stopped | string | Audio playback is stopped.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
| error<sup>8+</sup> | string | 错误状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioPlayer | | error<sup>8+</sup> | string | Audio playback is in the error state.<br>**System capability**: SystemCapability.Multimedia.Media.AudioPlayer|
## VideoPlayer<sup>8+</sup> ## VideoPlayer<sup>8+</sup>
视频播放管理类,用于管理和播放视频媒体。在调用VideoPlayer的方法前,需要先通过[createVideoPlayer()](#media.createvideoplayer8)构建一个[VideoPlayer](#videoplayer8)实例。 Provides methods to manage and play video. Before calling a method of the **VideoPlayer** class, you must call [createVideoPlayer()](#media.createvideoplayer8) to create a [VideoPlayer](#videoplayer8) instance.
视频播放demo可参考:[视频播放开发指导](../../media/video-playback.md) For details about the video playback demo, see [Video Playback Development](../../media/video-playback.md).
### 属性<a name=videoplayer_属性></a> ### Attributes<a name=videoplayer_attributes></a>
| 名称 | 类型 | 可读 | 可写 | 说明 | | Name | Type | Readable| Writable| Description |
| ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| url<sup>8+</sup> | string | 是 | 是 | 视频媒体URL,支持当前主流的视频格式(mp4、mpeg-ts、webm、mkv)。<br>**支持路径示例**<br>1. fd类型播放:fd://xxx<br>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png)<br>**注意事项**<br>使用媒体素材需要获取读权限,否则无法正常播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD playback: fd://xxx<br>![en-us_image_0000001164217678](figures/en-us_image_url.png)<br>**Note**:<br>To use media materials, you must declare the read permission. Otherwise, the media materials cannot be played properly.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| loop<sup>8+</sup> | boolean | 是 | 是 | 视频循环播放属性,设置为'true'表示循环播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | loop<sup>8+</sup> | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| currentTime<sup>8+</sup> | number | 是 | 否 | 视频的当前播放位置。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | currentTime<sup>8+</sup> | number | Yes | No | Current video playback position.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| duration<sup>8+</sup> | number | 是 | 否 | 视频时长,返回-1表示直播模式。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | duration<sup>8+</sup> | number | Yes | No | Video duration. The value **-1** indicates the live streaming mode.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| state<sup>8+</sup> | [VideoPlayState](#videoplaystate8) | 是 | 否 | 视频播放的状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | state<sup>8+</sup> | [VideoPlayState](#videoplaystate8) | Yes | No | Video playback state.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| width<sup>8+</sup> | number | 是 | 否 | 视频宽。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | width<sup>8+</sup> | number | Yes | No | Video width.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| height<sup>8+</sup> | number | 是 | 否 | 视频高。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | height<sup>8+</sup> | number | Yes | No | Video height.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
### setDisplaySurface<sup>8+</sup> ### setDisplaySurface<sup>8+</sup>
setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
通过回调方式设置SurfaceId。 Sets **SurfaceId**. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| --------- | -------- | ---- | ------------------------- | | --------- | -------- | ---- | ------------------------- |
| surfaceId | string | 是 | SurfaceId | | surfaceId | string | Yes | Surface ID to set. |
| callback | function | 是 | 设置SurfaceId的回调方法。 | | callback | function | Yes | Callback used to set **SurfaceId**.|
**示例:** **Example**
```js ```js
videoPlayer.setDisplaySurface(surfaceId, (err) => { videoPlayer.setDisplaySurface(surfaceId, (err) => {
...@@ -696,23 +696,23 @@ videoPlayer.setDisplaySurface(surfaceId, (err) => { ...@@ -696,23 +696,23 @@ videoPlayer.setDisplaySurface(surfaceId, (err) => {
setDisplaySurface(surfaceId: string): Promise\<void> setDisplaySurface(surfaceId: string): Promise\<void>
通过Promise方式设置SurfaceId。 Sets **SurfaceId**. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| --------- | ------ | ---- | --------- | | --------- | ------ | ---- | --------- |
| surfaceId | string | 是 | SurfaceId | | surfaceId | string | Yes | Surface ID to set.|
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ------------- | ------------------------------ | | ------------- | ------------------------------ |
| Promise<void> | 设置SurfaceId的Promise返回值。 | | Promise<void> | Promise used to set **SurfaceId**.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -730,17 +730,17 @@ await videoPlayer.setDisplaySurface(surfaceId).then(() => { ...@@ -730,17 +730,17 @@ await videoPlayer.setDisplaySurface(surfaceId).then(() => {
prepare(callback: AsyncCallback\<void>): void prepare(callback: AsyncCallback\<void>): void
通过回调方式准备播放视频。 Prepares for video playback. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 准备播放视频的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.prepare((err) => { videoPlayer.prepare((err) => {
...@@ -756,17 +756,17 @@ videoPlayer.prepare((err) => { ...@@ -756,17 +756,17 @@ videoPlayer.prepare((err) => {
prepare(): Promise\<void> prepare(): Promise\<void>
通过Promise方式准备播放视频。 Prepares for video playback. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 准备播放视频的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -784,17 +784,17 @@ await videoPlayer.prepare().then(() => { ...@@ -784,17 +784,17 @@ await videoPlayer.prepare().then(() => {
play(callback: AsyncCallback\<void>): void; play(callback: AsyncCallback\<void>): void;
通过回调方式开始播放视频。 Starts to play video resources. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 开始播放视频的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.play((err) => { videoPlayer.play((err) => {
...@@ -810,17 +810,17 @@ videoPlayer.play((err) => { ...@@ -810,17 +810,17 @@ videoPlayer.play((err) => {
play(): Promise\<void>; play(): Promise\<void>;
通过Promise方式开始播放视频。 Starts to play video resources. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 开始播放视频的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -838,17 +838,17 @@ await videoPlayer.play().then(() => { ...@@ -838,17 +838,17 @@ await videoPlayer.play().then(() => {
pause(callback: AsyncCallback\<void>): void pause(callback: AsyncCallback\<void>): void
通过回调方式暂停播放视频。 Pauses video playback. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 暂停播放视频的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.pause((err) => { videoPlayer.pause((err) => {
...@@ -864,17 +864,17 @@ videoPlayer.pause((err) => { ...@@ -864,17 +864,17 @@ videoPlayer.pause((err) => {
pause(): Promise\<void> pause(): Promise\<void>
通过Promise方式暂停播放视频。 Pauses video playback. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 暂停播放视频的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -892,17 +892,17 @@ await videoPlayer.pause().then(() => { ...@@ -892,17 +892,17 @@ await videoPlayer.pause().then(() => {
stop(callback: AsyncCallback\<void>): void stop(callback: AsyncCallback\<void>): void
通过回调方式停止播放视频。 Stops video playback. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 停止播放视频的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.stop((err) => { videoPlayer.stop((err) => {
...@@ -918,17 +918,17 @@ videoPlayer.stop((err) => { ...@@ -918,17 +918,17 @@ videoPlayer.stop((err) => {
stop(): Promise\<void> stop(): Promise\<void>
通过Promise方式停止播放视频。 Stops video playback. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 停止播放视频的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -946,17 +946,17 @@ await videoPlayer.stop().then(() => { ...@@ -946,17 +946,17 @@ await videoPlayer.stop().then(() => {
reset(callback: AsyncCallback\<void>): void reset(callback: AsyncCallback\<void>): void
通过回调方式切换播放视频。 Switches the video resource to be played. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 切换播放视频的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.reset((err) => { videoPlayer.reset((err) => {
...@@ -972,17 +972,17 @@ videoPlayer.reset((err) => { ...@@ -972,17 +972,17 @@ videoPlayer.reset((err) => {
reset(): Promise\<void> reset(): Promise\<void>
通过Promise方式切换播放视频。 Switches the video resource to be played. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 切换播放视频的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -1000,18 +1000,18 @@ await videoPlayer.reset().then(() => { ...@@ -1000,18 +1000,18 @@ await videoPlayer.reset().then(() => {
seek(timeMs: number, callback: AsyncCallback\<number>): void seek(timeMs: number, callback: AsyncCallback\<number>): void
通过回调方式跳转到指定播放位置,默认跳转到指定时间点的下一个关键帧。 Seeks to the specified playback position. The next key frame at the specified position is played. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------ | | -------- | -------- | ---- | ------------------------------ |
| timeMs | number | 是 | 指定的跳转时间节点,单位毫秒。 | | timeMs | number | Yes | Position to seek to, in milliseconds.|
| callback | function | 是 | 跳转到指定播放位置的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.seek((seekTime, err) => { videoPlayer.seek((seekTime, err) => {
...@@ -1027,19 +1027,19 @@ videoPlayer.seek((seekTime, err) => { ...@@ -1027,19 +1027,19 @@ videoPlayer.seek((seekTime, err) => {
seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\<number>): void
通过回调方式跳转到指定播放位置。 Seeks to the specified playback position. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | ---- | ---------------------------------------- |
| timeMs | number | 是 | 指定的跳转时间节点,单位毫秒。 | | timeMs | number | Yes | Position to seek to, in milliseconds. |
| mode | SeekMode | 是 | 跳转模式,具体见[SeekMode](#seekmode8)| | mode | SeekMode | Yes | Seek mode. For details, see [SeekMode](#seekmode8).|
| callback | function | 是 | 跳转到指定播放位置的回调方法。 | | callback | function | Yes | Callback used to return the result. |
**示例:** **Example**
```js ```js
videoPlayer.seek((seekTime, seekMode, err) => { videoPlayer.seek((seekTime, seekMode, err) => {
...@@ -1055,24 +1055,24 @@ videoPlayer.seek((seekTime, seekMode, err) => { ...@@ -1055,24 +1055,24 @@ videoPlayer.seek((seekTime, seekMode, err) => {
seek(timeMs: number, mode?:SeekMode): Promise\<number> seek(timeMs: number, mode?:SeekMode): Promise\<number>
通过Promise方式跳转到指定播放位置,如果没有设置mode则跳转到指定时间点的下一个关键帧。 Seeks to the specified playback position. If **mode** is not specified, the next key frame at the specified position is played. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | -------- | ---- | -------------------------------------- | | ------ | -------- | ---- | -------------------------------------- |
| timeMs | number | 是 | 指定的跳转时间节点,单位毫秒。 | | timeMs | number | Yes | Position to seek to, in milliseconds. |
| mode | SeekMode | 否 | 跳转模式,具体见[SeekMode](#seekmode8) | | mode | SeekMode | No | Seek mode. For details, see [SeekMode](#seekmode8).|
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------------- | | -------------- | ----------------------------------- |
| Promise\<void> | 跳转到指定播放位置的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -1081,7 +1081,7 @@ function failureCallback(error) { ...@@ -1081,7 +1081,7 @@ function failureCallback(error) {
function catchCallback(error) { function catchCallback(error) {
console.info(`video catchCallback, error:${error.message}`); console.info(`video catchCallback, error:${error.message}`);
} }
await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点 await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime indicates the position after the seek operation is complete.
console.info('seek success'); console.info('seek success');
}, failureCallback).catch(catchCallback); }, failureCallback).catch(catchCallback);
...@@ -1094,18 +1094,18 @@ await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { ...@@ -1094,18 +1094,18 @@ await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => {
setVolume(vol: number, callback: AsyncCallback\<void>): void setVolume(vol: number, callback: AsyncCallback\<void>): void
通过回调方式设置音量。 Sets the volume. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| vol | number | 是 | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 | | vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|
| callback | function | 是 | 设置音量的回调方法。 | | callback | function | Yes | Callback used to return the result. |
**示例:** **Example**
```js ```js
videoPlayer.setVolume((vol, err) => { videoPlayer.setVolume((vol, err) => {
...@@ -1121,23 +1121,23 @@ videoPlayer.setVolume((vol, err) => { ...@@ -1121,23 +1121,23 @@ videoPlayer.setVolume((vol, err) => {
setVolume(vol: number): Promise\<void> setVolume(vol: number): Promise\<void>
通过Promise方式设置音量。 Sets the volume. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ | | ------ | ------ | ---- | ------------------------------------------------------------ |
| vol | number | 是 | 指定的相对音量大小,取值范围为[0.00-1.00],1表示最大音量,即100%。 | | vol | number | Yes | Relative volume. The value ranges from 0.00 to 1.00. The value **1** indicates the maximum volume (100%).|
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------- | | -------------- | ------------------------- |
| Promise\<void> | 设置音量的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -1155,17 +1155,17 @@ await videoPlayer.setVolume(vol).then() => { ...@@ -1155,17 +1155,17 @@ await videoPlayer.setVolume(vol).then() => {
release(callback: AsyncCallback\<void>): void release(callback: AsyncCallback\<void>): void
通过回调方式释放视频资源。 Releases the video playback resource. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------ | | -------- | -------- | ---- | ------------------------ |
| callback | function | 是 | 释放视频资源的回调方法。 | | callback | function | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
videoPlayer.release((err) => { videoPlayer.release((err) => {
...@@ -1181,17 +1181,17 @@ videoPlayer.release((err) => { ...@@ -1181,17 +1181,17 @@ videoPlayer.release((err) => {
release(): Promise\<void> release(): Promise\<void>
通过Promise方式释放视频资源。 Releases the video playback resource. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------- | | -------------- | ----------------------------- |
| Promise\<void> | 释放视频资源的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -1209,17 +1209,17 @@ await videoPlayer.release().then() => { ...@@ -1209,17 +1209,17 @@ await videoPlayer.release().then() => {
getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8>>)>>): void getTrackDescription(callback: AsyncCallback<Array<[MediaDescription](#mediadescription8>>)>>): void
通过回调方式获取视频轨道信息。 Obtains the video track information. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | -------------------------- | | -------- | -------- | ---- | -------------------------- |
| callback | function | 是 | 获取视频轨道信息回调方法。 | | callback | function | Yes | Callback used to return the video track information obtained.|
**示例:** **Example**
```js ```js
function printfDescription(obj) { function printfDescription(obj) {
...@@ -1245,17 +1245,17 @@ videoPlayer.getTrackDescription((error, arrlist) => { ...@@ -1245,17 +1245,17 @@ videoPlayer.getTrackDescription((error, arrlist) => {
getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8>>)>> getTrackDescription(): Promise<Array<[MediaDescription](#mediadescription8>>)>>
通过Promise方式获取视频轨道信息。 Obtains the video track information. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------------------------------------------------- | ------------------------------- | | -------------------------------------------------------- | ------------------------------- |
| Promise<Array<[MediaDescription](#mediadescription8>>)>> | 获取视频轨道信息Promise返回值。 | | Promise<Array<[MediaDescription](#mediadescription8>>)>> | Promise used to return the video track information obtained.|
**示例:** **Example**
```js ```js
function printfDescription(obj) { function printfDescription(obj) {
...@@ -1289,18 +1289,18 @@ for (let i = 0; i < arrayDescription.length; i++) { ...@@ -1289,18 +1289,18 @@ for (let i = 0; i < arrayDescription.length; i++) {
setSpeed(speed:number, callback: AsyncCallback\<number>): void setSpeed(speed:number, callback: AsyncCallback\<number>): void
通过回调方式设置播放速度。 Sets the video playback speed. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ---------------------------------------------------------- | | -------- | -------- | ---- | ---------------------------------------------------------- |
| speed | number | 是 | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)| | speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
| callback | function | 是 | 设置播放速度的回调方法。 | | callback | function | Yes | Callback used to return the result. |
**示例:** **Example**
```js ```js
videoPlayer.setSpeed((speed:number, err) => { videoPlayer.setSpeed((speed:number, err) => {
...@@ -1316,17 +1316,17 @@ videoPlayer.setSpeed((speed:number, err) => { ...@@ -1316,17 +1316,17 @@ videoPlayer.setSpeed((speed:number, err) => {
setSpeed(speed:number): Promise\<number> setSpeed(speed:number): Promise\<number>
通过Promise方式设置播放速度。 Sets the video playback speed. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ---------------------------------------------------------- | | ------ | ------ | ---- | ---------------------------------------------------------- |
| speed | number | 是 | 指定播放视频速度,具体见[PlaybackSpeed](#playbackspeed8)| | speed | number | Yes | Video playback speed. For details, see [PlaybackSpeed](#playbackspeed8).|
**示例:** **Example**
```js ```js
function failureCallback(error) { function failureCallback(error) {
...@@ -1344,18 +1344,18 @@ await videoPlayer.setSpeed(speed).then() => { ...@@ -1344,18 +1344,18 @@ await videoPlayer.setSpeed(speed).then() => {
on(type: 'playbackCompleted', callback: Callback\<void>): void on(type: 'playbackCompleted', callback: Callback\<void>): void
开始监听视频播放完成事件。 Subscribes to the video playback completion event.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ----------------------------------------------------------- | | -------- | -------- | ---- | ----------------------------------------------------------- |
| type | string | 是 | 视频播放完成事件回调类型,支持的事件:'playbackCompleted'。 | | type | string | Yes | Type of the event to subscribe to, which is 'playbackCompleted' in this example.|
| callback | function | 是 | 视频播放完成事件回调方法。 | | callback | function | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
videoPlayer.on('playbackCompleted', () => { videoPlayer.on('playbackCompleted', () => {
...@@ -1367,18 +1367,18 @@ videoPlayer.on('playbackCompleted', () => { ...@@ -1367,18 +1367,18 @@ videoPlayer.on('playbackCompleted', () => {
on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: number) => void): void
开始监听视频缓存更新事件。 Subscribes to the video buffering update event.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 视频缓存事件回调类型,支持的事件:'bufferingUpdate'。 | | type | string | Yes | Type of the event to subscribe to, which is 'bufferingUpdate' in this example. |
| callback | function | 是 | 视频缓存事件回调方法。<br>[BufferingInfoType](#bufferinginfotype8)为BUFFERING_PERCENT或CACHED_DURATION时,value值有效,否则固定为0。 | | callback | function | Yes | Callback invoked when the event is triggered.<br>When [BufferingInfoType](#bufferinginfotype8) is set to **BUFFERING_PERCENT** or **CACHED_DURATION**, **value** is valid. Otherwise, **value** is fixed at **0**.|
**示例:** **Example**
```js ```js
videoPlayer.on('bufferingUpdate', (infoType, value) => { videoPlayer.on('bufferingUpdate', (infoType, value) => {
...@@ -1391,18 +1391,18 @@ videoPlayer.on('bufferingUpdate', (infoType, value) => { ...@@ -1391,18 +1391,18 @@ videoPlayer.on('bufferingUpdate', (infoType, value) => {
on(type: 'startRenderFrame', callback: Callback\<void>): void on(type: 'startRenderFrame', callback: Callback\<void>): void
开始监听视频播放首帧送显上报事件。 Subscribes to the frame rendering start event.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 视频播放首帧送显上报事件回调类型,支持的事件:'startRenderFrame'。 | | type | string | Yes | Type of the event to subscribe to, which is 'startRenderFrame' in this example.|
| callback | function | 是 | 视频播放首帧送显上报事件回调方法。 | | callback | function | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
videoPlayer.on('startRenderFrame', () => { videoPlayer.on('startRenderFrame', () => {
...@@ -1414,18 +1414,18 @@ videoPlayer.on('startRenderFrame', () => { ...@@ -1414,18 +1414,18 @@ videoPlayer.on('startRenderFrame', () => {
on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): void
开始监听视频播放宽高变化事件。 Subscribes to the video width and height change event.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 视频播放宽高变化事件回调类型,支持的事件:'videoSizeChanged'。 | | type | string | Yes | Type of the event to subscribe to, which is 'videoSizeChanged' in this example.|
| callback | function | 是 | 视频播放宽高变化事件回调方法,width表示宽,height表示高。 | | callback | function | Yes | Callback invoked when the event is triggered. **width** indicates the video width, and **height** indicates the video height. |
**示例:** **Example**
```js ```js
videoPlayer.on('videoSizeChanged', (width, height) => { videoPlayer.on('videoSizeChanged', (width, height) => {
...@@ -1438,74 +1438,74 @@ videoPlayer.on('videoSizeChanged', (width, height) => { ...@@ -1438,74 +1438,74 @@ videoPlayer.on('videoSizeChanged', (width, height) => {
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
开始监听视频播放错误事件。 Subscribes to the video playback error event.
**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer **System capability**: SystemCapability.Multimedia.Media.VideoPlayer
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 播放错误事件回调类型,支持的事件包括:'error'。<br>- 'error':视频播放中发生错误,触发该事件。 | | type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during video playback.|
| callback | function | 是 | 播放错误事件回调方法。 | | callback | function | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
videoPlayer.on('error', (error) => { // 设置'error'事件回调 videoPlayer.on('error', (error) => { // Set the 'error' event callback.
console.info(`video error called, errName is ${error.name}`); // 打印错误类型名称 console.info(`video error called, errName is ${error.name}`); // Print the error name.
console.info(`video error called, errCode is ${error.code}`); // 打印错误码 console.info(`video error called, errCode is ${error.code}`); // Print the error code.
console.info(`video error called, errMessage is ${error.message}`);// 打印错误类型详细描述 console.info(`video error called, errMessage is ${error.message}`);// Print the detailed description of the error type.
}); });
videoPlayer.setVolume(3); //设置volume为无效值,触发'error'事件 videoPlayer.setVolume(3); // Set volume to an invalid value to trigger the 'error' event.
``` ```
## VideoPlayState<sup>8+</sup> ## VideoPlayState<sup>8+</sup>
视频播放的状态机,可通过state属性获取当前状态。 Enumerates the video playback states. You can obtain the state through the **state** attribute.
| 名称 | 类型 | 描述 | | Name | Type | Description |
| -------- | ------ | ------------------------------------------------------------ | | -------- | ------ | ------------------------------------------------------------ |
| idle | string | 视频播放空闲。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | idle | string | The video player is idle.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| prepared | string | 视频播放准备。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | prepared | string | Video playback is being prepared.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| playing | string | 视频正在播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | playing | string | Video playback is in progress.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| paused | string | 视频暂停播放。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | paused | string | Video playback is paused.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| stopped | string | 视频播放停止。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | stopped | string | Video playback is stopped.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| error | string | 错误状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | error | string | Video playback is in the error state.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
## SeekMode<sup>8+</sup> ## SeekMode<sup>8+</sup>
视频播放的Seek模式枚举,可通过seek方法作为参数传递下去。 Enumerates the video playback seek modes, which can be passed in the **seek** method.
| 名称 | 值 | 描述 | | Name | Value | Description |
| -------------- | ---- | ------------------------------------------------------------ | | -------------- | ---- | ------------------------------------------------------------ |
| SEEK_NEXT_SYNC | 0 | 表示跳转到指定时间点的下一个关键帧,建议向后快进的时候用这个枚举值。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | SEEK_NEXT_SYNC | 0 | Seeks to the next key frame at the specified position. You are advised to use this value for the rewind operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| SEEK_PREV_SYNC | 1 | 表示跳转到指定时间点的上一个关键帧,建议向前快进的时候用这个枚举值。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | SEEK_PREV_SYNC | 1 | Seeks to the previous key frame at the specified position. You are advised to use this value for the fast-forward operation.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## PlaybackSpeed<sup>8+</sup> ## PlaybackSpeed<sup>8+</sup>
视频播放的倍速枚举,可通过setSpeed方法作为参数传递下去。 Enumerates the video playback speeds, which can be passed in the **setSpeed** method.
| 名称 | 值 | 描述 | | Name | Value | Description |
| -------------------- | ---- | ------------------------------------------------------------ | | -------------------- | ---- | ------------------------------------------------------------ |
| SPEED_FORWARD_0_75_X | 0 | 表示视频播放正常播速的0.75倍。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | SPEED_FORWARD_0_75_X | 0 | Plays the video at 0.75 times the normal speed.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| SPEED_FORWARD_1_00_X | 1 | 表示视频播放正常播速。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | SPEED_FORWARD_1_00_X | 1 | Plays the video at the normal speed.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| SPEED_FORWARD_1_25_X | 2 | 表示视频播放正常播速的1.25倍。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | SPEED_FORWARD_1_25_X | 2 | Plays the video at 1.25 times the normal speed.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| SPEED_FORWARD_1_75_X | 3 | 表示视频播放正常播速的1.75倍。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | SPEED_FORWARD_1_75_X | 3 | Plays the video at 1.75 times the normal speed.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
| SPEED_FORWARD_2_00_X | 4 | 表示视频播放正常播速的2.00倍。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoPlayer | | SPEED_FORWARD_2_00_X | 4 | Plays the video at 2.00 times the normal speed.<br>**System capability**: SystemCapability.Multimedia.Media.VideoPlayer|
## MediaDescription<sup>8+</sup> ## MediaDescription<sup>8+</sup>
### [key : string] : any ### [key : string] : any
通过key-value方式获取媒体信息。 Defines media information in key-value mode.
| 名称 | 类型 | 说明 | | Name | Type | Description |
| ----- | ------ | ------------------------------------------------------------ | | ----- | ------ | ------------------------------------------------------------ |
| key | string | 通过key值获取对应的value。key值具体可见[MediaDescriptionKey](#mediadescriptionkey8)<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | key | string | Key of the media information. For details about the keys, see [MediaDescriptionKey](#mediadescriptionkey8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| value | any | 对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey](#mediadescriptionkey8)的描述信息。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | value | any | Value of the key. For details about the values, see [MediaDescriptionKey](#mediadescriptionkey8).<br>**System capability**: SystemCapability.Multimedia.Media.Core|
**示例:** **Example**
```js ```js
function printfItemDescription(obj, key) { function printfItemDescription(obj, key) {
...@@ -1517,7 +1517,7 @@ function printfItemDescription(obj, key) { ...@@ -1517,7 +1517,7 @@ function printfItemDescription(obj, key) {
audioPlayer.getTrackDescription((error, arrlist) => { audioPlayer.getTrackDescription((error, arrlist) => {
if (typeof (arrlist) != 'undefined') { if (typeof (arrlist) != 'undefined') {
for (let i = 0; i < arrlist.length; i++) { for (let i = 0; i < arrlist.length; i++) {
printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值 printfItemDescription(arrlist[i], MD_KEY_TRACK_TYPE); // Print the MD_KEY_TRACK_TYPE value of each track.
} }
} else { } else {
console.log(`audio getTrackDescription fail, error:${error.message}`); console.log(`audio getTrackDescription fail, error:${error.message}`);
...@@ -1527,27 +1527,27 @@ audioPlayer.getTrackDescription((error, arrlist) => { ...@@ -1527,27 +1527,27 @@ audioPlayer.getTrackDescription((error, arrlist) => {
## AudioRecorder ## AudioRecorder
音频录制管理类,用于录制音频媒体。在调用AudioRecorder的方法前,需要先通过[createAudioRecorder()](#media.createaudiorecorder) 构建一个[AudioRecorder](#audiorecorder)实例。 Implements audio recording. Before calling a method of the **AudioRecorder** class, you must call [createAudioRecorder()](#media.createaudiorecorder) to create an [AudioRecorder](#audiorecorder) instance.
音频录制demo可参考:[音频录制开发指导](../../media/audio-recorder.md) For details about the audio recording demo, see [Audio Recording Development](../../media/audio-recorder.md).
### prepare<a name=audiorecorder_prepare></a> ### prepare<a name=audiorecorder_prepare></a>
prepare(config: AudioRecorderConfig): void prepare(config: AudioRecorderConfig): void
录音准备。 Prepares for recording.
**需要权限:** ohos.permission.MICROPHONE **Required permissions:** ohos.permission.MICROPHONE
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ | | ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| config | [AudioRecorderConfig](#audiorecorderconfig) | 是 | 配置录音的相关参数,包括音频输出URI、[编码格式](#audioencoder)、采样率、声道数、[输出格式](#audiooutputformat)等。 | | config | [AudioRecorderConfig](#audiorecorderconfig) | Yes | Audio recording parameters, including the audio output URI, [encoding format](#audioencoder), sampling rate, number of audio channels, and [output format](#audiooutputformat).|
**示例:** **Example**
```js ```js
let audioRecorderConfig = { let audioRecorderConfig = {
...@@ -1556,10 +1556,10 @@ let audioRecorderConfig = { ...@@ -1556,10 +1556,10 @@ let audioRecorderConfig = {
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS, format : media.AudioOutputFormat.AAC_ADTS,
uri : 'fd://1', // 文件需先由调用者创建,并给予适当的权限 uri : 'fd://1', // The file must be created by the caller and granted with proper permissions.
location : { latitude : 30, longitude : 130}, location : { latitude : 30, longitude : 130},
} }
audioRecorder.on('prepare', () => { //设置'prepare'事件回调 audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
console.log('prepare success'); console.log('prepare success');
}); });
audioRecorder.prepare(audioRecorderConfig); audioRecorder.prepare(audioRecorderConfig);
...@@ -1570,14 +1570,14 @@ audioRecorder.prepare(audioRecorderConfig); ...@@ -1570,14 +1570,14 @@ audioRecorder.prepare(audioRecorderConfig);
start(): void start(): void
开始录制,需在[prepare](#audiorecorder_on)事件成功触发后,才能调用start方法。 Starts audio recording. This method can be called only after the [prepare](#audiorecorder_on) event is triggered.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('start', () => { //设置'start'事件回调 audioRecorder.on('start', () => { // Set the 'start' event callback.
console.log('audio recorder start success'); console.log('audio recorder start success');
}); });
audioRecorder.start(); audioRecorder.start();
...@@ -1587,14 +1587,14 @@ audioRecorder.start(); ...@@ -1587,14 +1587,14 @@ audioRecorder.start();
pause():void pause():void
暂停录制,需要在[start](#audiorecorder_on)事件成功触发后,才能调用pause方法。 Pauses audio recording. This method can be called only after the [start](#audiorecorder_on) event is triggered.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('pause', () => { //设置'pause'事件回调 audioRecorder.on('pause', () => { // Set the 'pause' event callback.
console.log('audio recorder pause success'); console.log('audio recorder pause success');
}); });
audioRecorder.pause(); audioRecorder.pause();
...@@ -1604,14 +1604,14 @@ audioRecorder.pause(); ...@@ -1604,14 +1604,14 @@ audioRecorder.pause();
resume():void resume():void
暂停录制,需要在[pause](#audiorecorder_on)事件成功触发后,才能调用resume方法。 Resumes audio recording. This method can be called only after the [pause](#audiorecorder_on) event is triggered.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('resume', () => { //设置'resume'事件回调 audioRecorder.on('resume', () => { // Set the 'resume' event callback.
console.log('audio recorder resume success'); console.log('audio recorder resume success');
}); });
audioRecorder.resume(); audioRecorder.resume();
...@@ -1621,14 +1621,14 @@ audioRecorder.resume(); ...@@ -1621,14 +1621,14 @@ audioRecorder.resume();
stop(): void stop(): void
停止录音。 Stops audio recording.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('stop', () => { //设置'stop'事件回调 audioRecorder.on('stop', () => { // Set the 'stop' event callback.
console.log('audio recorder stop success'); console.log('audio recorder stop success');
}); });
audioRecorder.stop(); audioRecorder.stop();
...@@ -1638,14 +1638,14 @@ audioRecorder.stop(); ...@@ -1638,14 +1638,14 @@ audioRecorder.stop();
release(): void release(): void
释放录音资源。 Releases the audio recording resource.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('release', () => { //设置'release'事件回调 audioRecorder.on('release', () => { // Set the 'release' event callback.
console.log('audio recorder release success'); console.log('audio recorder release success');
}); });
audioRecorder.release(); audioRecorder.release();
...@@ -1656,16 +1656,16 @@ audioRecorder = undefined; ...@@ -1656,16 +1656,16 @@ audioRecorder = undefined;
reset(): void reset(): void
重置录音。 Resets audio recording.
进行重置录音之前,需要先调用[stop()](#audiorecorder_stop)停止录音。重置录音之后,需要调用[prepare()](#audiorecorder_prepare)设置录音参数项,才能再次进行录音。 Before resetting audio recording, you must call [stop()](#audiorecorder_stop) to stop recording. After audio recording is reset, you must call [prepare()](#audiorecorder_prepare) to set the recording parameters for another recording.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**示例:** **Example**
```js ```js
audioRecorder.on('reset', () => { //设置'reset'事件回调 audioRecorder.on('reset', () => { // Set the 'reset' event callback.
console.log('audio recorder reset success'); console.log('audio recorder reset success');
}); });
audioRecorder.reset(); audioRecorder.reset();
...@@ -1675,156 +1675,156 @@ audioRecorder.reset(); ...@@ -1675,156 +1675,156 @@ audioRecorder.reset();
on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset', callback: () => void): void
开始订阅音频录制事件。 Subscribes to the audio recording events.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------- | ---- | ------------------------------------------------------------ | | -------- | -------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 录制事件回调类型,支持的事件包括:'prepare'&nbsp;\|&nbsp;'start'&nbsp;\| 'pause' \| ’resume‘ \|&nbsp;'stop'&nbsp;\|&nbsp;'release'&nbsp;\|&nbsp;'reset'。<br/>-&nbsp;'prepare'&nbsp;:完成[prepare](#audiorecorder_prepare)调用,音频录制参数设置完成,触发该事件。<br/>-&nbsp;'start'&nbsp;:完成[start](#audiorecorder_start)调用,音频录制开始,触发该事件。<br/>-&nbsp;'pause': 完成[pause](#audiorecorder_pause)调用,音频暂停录制,触发该事件。<br/>-&nbsp;'resume': 完成[resume](#audiorecorder_resume)调用,音频恢复录制,触发该事件。<br/>-&nbsp;'stop'&nbsp;:完成[stop](#audiorecorder_stop)调用,音频停止录制,触发该事件。<br/>-&nbsp;'release'&nbsp;:完成[release](#audiorecorder_release)调用,音频释放录制资源,触发该事件。<br/>-&nbsp;'reset':完成[reset](#audiorecorder_reset)调用,音频重置为初始状态,触发该事件。 | | type | string | Yes | Type of the event to subscribe to. The following events are supported: 'prepare'\|'start'\| 'pause' \| 'resume' \|'stop'\|'release'\|'reset'<br>- The 'prepare' event is triggered when the [prepare](#audiorecorder_prepare) method is called and the audio recording parameters are set.<br>- The 'start' event is triggered when the [start](#audiorecorder_start) method is called and audio recording starts.<br>- The 'pause' event is triggered when the [pause](#audiorecorder_pause) method is called and audio recording is paused.<br>- The 'resume' event is triggered when the [resume](#audiorecorder_resume) method is called and audio recording is resumed.<br>- The 'stop' event is triggered when the [stop](#audiorecorder_stop) method is called and audio recording stops.<br>- The 'release' event is triggered when the [release](#audiorecorder_release) method is called and the recording resource is released.<br>- The 'reset' event is triggered when the [reset](#audiorecorder_reset) method is called and audio recording is reset.|
| callback | ()=>void | 是 | 录制事件回调方法。 | | callback | ()=>void | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
let audiorecorder = media.createAudioRecorder(); // 创建一个音频录制实例 let audiorecorder = media.createAudioRecorder(); // Create an AudioRecorder instance.
let audioRecorderConfig = { let audioRecorderConfig = {
audioEncoder : media.AudioEncoder.AAC_LC, , audioEncoder : media.AudioEncoder.AAC_LC, ,
audioEncodeBitRate : 22050, audioEncodeBitRate : 22050,
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
format : media.AudioOutputFormat.AAC_ADTS, format : media.AudioOutputFormat.AAC_ADTS,
uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 uri : 'fd://xx', // The file must be created by the caller and granted with proper permissions.
location : { latitude : 30, longitude : 130}, location : { latitude : 30, longitude : 130},
} }
audioRecorder.on('error', (error) => { // 设置'error'事件回调 audioRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errName is ${error.name}`);
console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errCode is ${error.code}`);
console.info(`audio error called, errMessage is ${error.message}`); console.info(`audio error called, errMessage is ${error.message}`);
}); });
audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 audioRecorder.on('prepare', () => { // Set the 'prepare' event callback.
console.log('prepare success'); console.log('prepare success');
audioRecorder.start(); // 开始录制,并触发'start'事件回调 audioRecorder.start(); // Start recording and trigger the 'start' event callback.
}); });
audioRecorder.on('start', () => { // 设置'start'事件回调 audioRecorder.on('start', () => { // Set the 'start' event callback.
console.log('audio recorder start success'); console.log('audio recorder start success');
}); });
audioRecorder.on('pause', () => { // 设置'pause'事件回调 audioRecorder.on('pause', () => { // Set the 'pause' event callback.
console.log('audio recorder pause success'); console.log('audio recorder pause success');
}); });
audioRecorder.on('resume', () => { // 设置'resume'事件回调 audioRecorder.on('resume', () => { // Set the 'resume' event callback.
console.log('audio recorder resume success'); console.log('audio recorder resume success');
}); });
audioRecorder.on('stop', () => { // 设置'stop'事件回调 audioRecorder.on('stop', () => { // Set the 'stop' event callback.
console.log('audio recorder stop success'); console.log('audio recorder stop success');
}); });
audioRecorder.on('release', () => { // 设置'release'事件回调 audioRecorder.on('release', () => { // Set the 'release' event callback.
console.log('audio recorder release success'); console.log('audio recorder release success');
}); });
audioRecorder.on('reset', () => { // 设置'reset'事件回调 audioRecorder.on('reset', () => { // Set the 'reset' event callback.
console.log('audio recorder reset success'); console.log('audio recorder reset success');
}); });
audioRecorder.prepare(audioRecorderConfig) // 设置录制参数 ,并触发'prepare'事件回调 audioRecorder.prepare(audioRecorderConfig) // Set recording parameters and trigger the 'prepare' event callback.
``` ```
### on('error') ### on('error')
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
开始订阅音频录制错误事件。 Subscribes to the audio recording error event.
**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder **System capability**: SystemCapability.Multimedia.Media.AudioRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ | | -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':音频录制过程中发生错误,触发该事件。 | | type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during audio recording.|
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 | | callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
audioRecorder.on('error', (error) => { // 设置'error'事件回调 audioRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); // 打印错误类型名称 console.info(`audio error called, errName is ${error.name}`); // Print the error name.
console.info(`audio error called, errCode is ${error.code}`); // 打印错误码 console.info(`audio error called, errCode is ${error.code}`); // Print the error code.
console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述 console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type.
}); });
audioRecorder.prepare(); // prepare不设置参数,触发'error'事件 audioRecorder.prepare(); // Do no set any parameter in prepare and trigger the 'error' event callback.
``` ```
## AudioRecorderConfig ## AudioRecorderConfig
表示音频的录音配置。 Describes audio recording configurations.
| 名称 | 参数类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | --------------------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| audioEncoder | [AudioEncoder](#audioencoder) | 否 | 音频编码格式,默认设置为AAC_LC。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | audioEncoder | [AudioEncoder](#audioencoder) | No | Audio encoding format. The default value is **AAC_LC**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| audioEncodeBitRate | number | 否 | 音频编码比特率,默认值为48000。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | audioEncodeBitRate | number | No | Audio encoding bit rate. The default value is **48000**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| audioSampleRate | number | 否 | 音频采集采样率,默认值为48000。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | audioSampleRate | number | No | Audio sampling rate. The default value is **48000**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| numberOfChannels | number | 否 | 音频采集声道数,默认值为2。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | numberOfChannels | number | No | Number of audio channels. The default value is **2**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| format | [AudioOutputFormat](#audiooutputformat) | 否 | 音量输出封装格式,默认设置为MPEG_4。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | format | [AudioOutputFormat](#audiooutputformat) | No | Audio output format. The default value is **MPEG_4**.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| location<sup>8+</sup> | [Location](#location8) | 否 | 音频采集的地理位置。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | location<sup>8+</sup> | [Location](#location8) | No | Geographical location of the recorded audio.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| uri | string | 是 | 视频输出URI:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | uri | string | Yes | Audio output URI. Supported: fd://xx&nbsp;(fd&nbsp;number)<br>![en-us_image_0000001164217678](figures/en-us_image_url.png) <br>The file must be created by the caller and granted with proper permissions.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
## AudioEncoder ## AudioEncoder
表示音频编码格式的枚举。 Enumerates the audio encoding formats.
| 名称 | 默认值 | 说明 | | Name | Default Value| Description |
| ------- | ------ | ------------------------------------------------------------ | | ------- | ------ | ------------------------------------------------------------ |
| DEFAULT | 0 | Default audio encoding format is AMR_NB。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | DEFAULT | 0 | Default audio encoding format, which is Adaptive Multi Rate-Narrow Band Speech Codec (AMR-NB).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_NB | 1 | AMR-NB(Adaptive Multi Rate-Narrow Band Speech Codec) 编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AMR_NB | 1 | AMR-NB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_WB | 2 | AMR-WB(Adaptive Multi Rate-Wide Band Speech Codec) 编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AMR_WB | 2 | Adaptive Multi Rate-Wide Band Speech Codec (AMR-WB).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AAC_LC | 3 | AAC-LC(Advanced&nbsp;Audio&nbsp;Coding&nbsp;Low&nbsp;Complexity)编码格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AAC_LC | 3 | Advanced Audio Coding Low Complexity (AAC-LC).<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| HE_AAC | 4 | HE_AAC(High-Efficiency Advanced&nbsp;Audio&nbsp;Coding)编码格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | HE_AAC | 4 | High-Efficiency Advanced&nbsp;Audio&nbsp;Coding (HE_AAC).<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
## AudioOutputFormat ## AudioOutputFormat
表示音频封装格式的枚举。 Enumerates the audio output formats.
| 名称 | 默认值 | 说明 | | Name | Default Value| Description |
| -------- | ------ | ------------------------------------------------------------ | | -------- | ------ | ------------------------------------------------------------ |
| DEFAULT | 0 | 默认封装格式为MPEG-4。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | DEFAULT | 0 | Default encapsulation format, which is MPEG-4.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| MPEG_4 | 2 | 封装为MPEG-4格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | MPEG_4 | 2 | MPEG-4.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_NB | 3 | 封装为AMR_NB格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AMR_NB | 3 | AMR_NB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AMR_WB | 4 | 封装为AMR_WB格式。<br/>本接口在OpenHarmony 3.1 Release版本仅为接口定义,暂不支持使用。接口将在OpenHarmony 3.1 MR版本中提供使用支持。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AMR_WB | 4 | AMR_WB.<br>This API is merely defined in OpenHarmony 3.1 Release and cannot be used currently. It can be used in OpenHarmony 3.1 MR.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
| AAC_ADTS | 6 | 封装为ADTS(Audio&nbsp;Data&nbsp;Transport&nbsp;Stream)格式,是AAC音频的传输流格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.AudioRecorder | | AAC_ADTS | 6 | Audio Data Transport Stream (ADTS), which is a transport stream format of AAC-based audio.<br>**System capability**: SystemCapability.Multimedia.Media.AudioRecorder|
## VideoRecorder<sup>8+</sup> ## VideoRecorder<sup>8+</sup>
视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorder()](#media.createvideorecorder8)构建一个[VideoRecorder](#videorecorder8)实例。 Implements video recording. Before calling a method of the **VideoRecorder** class, you must call [createVideoRecorder()](#media.createvideorecorder8) to create a [VideoRecorder](#videorecorder8) instance.
视频录制demo可参考:[视频录制开发指导](../../media/video-recorder.md) For details about the video recording demo, see [Video Recording Development](../../media/video-recorder.md).
### 属性 ### Attributes
| 名称 | 类型 | 可读 | 可写 | 说明 | | Name | Type | Readable| Writable| Description |
| ------------------ | ------------------------------------- | ---- | ---- | ---------------- | | ------------------ | ------------------------------------- | ---- | ---- | ---------------- |
| state<sup>8+</sup> | [VideoRecordState](#videorecordstate) | 是 | 否 | 视频录制的状态。 | | state<sup>8+</sup> | [VideoRecordState](#videorecordstate) | Yes | No | Video recording state.|
### prepare<sup>8+</sup><a name=videorecorder_prepare1></a> ### prepare<sup>8+</sup><a name=videorecorder_prepare1></a>
prepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void; prepare(config: VideoRecorderConfig, callback: AsyncCallback\<void>): void;
异步方式进行视频录制的参数设置。通过注册回调函数获取返回值。 Sets video recording parameters in asynchronous mode. This API uses a callback to return the result.
**需要权限:** ohos.permission.MICROPHONE ohos.permission.CAMERA **Required permissions:** ohos.permission.MICROPHONE ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------- | ---- | ----------------------------------- | | -------- | ------------------------------------------- | ---- | ----------------------------------- |
| config | [VideoRecorderConfig](#videorecorderconfig) | 是 | 配置视频录制的相关参数。 | | config | [VideoRecorderConfig](#videorecorderconfig) | Yes | Video recording parameters to set. |
| callback | AsyncCallback\<void> | 是 | 异步视频录制prepare方法的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
let videoProfile = { let videoProfile = {
...@@ -1844,7 +1844,7 @@ let videoConfig = { ...@@ -1844,7 +1844,7 @@ let videoConfig = {
audioSourceType : 1, audioSourceType : 1,
videoSourceType : 0, videoSourceType : 0,
profile : videoProfile, profile : videoProfile,
url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 url : 'fd://xx', // The file must be created by the caller and granted with proper permissions.
orientationHint : 0, orientationHint : 0,
location : { latitude : 30, longitude : 130 }, location : { latitude : 30, longitude : 130 },
} }
...@@ -1868,7 +1868,7 @@ media.createVideoRecorder((err, recorder) => { ...@@ -1868,7 +1868,7 @@ media.createVideoRecorder((err, recorder) => {
if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') { if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') {
videoRecorder = recorder; videoRecorder = recorder;
console.info('createVideoRecorder success'); console.info('createVideoRecorder success');
eventEmitter.emit('prepare'); // prepare事件触发 eventEmitter.emit('prepare'); // Trigger the 'prepare' event.
} else { } else {
console.info('createVideoRecorder failed and error is ' + err.message); console.info('createVideoRecorder failed and error is ' + err.message);
} }
...@@ -1879,25 +1879,25 @@ media.createVideoRecorder((err, recorder) => { ...@@ -1879,25 +1879,25 @@ media.createVideoRecorder((err, recorder) => {
prepare(config: VideoRecorderConfig): Promise\<void>; prepare(config: VideoRecorderConfig): Promise\<void>;
异步方式进行视频录制的参数设置。通过Promise获取返回值。 Sets video recording parameters in asynchronous mode. This API uses a promise to return the result.
**需要权限:** ohos.permission.MICROPHONE ohos.permission.CAMERA **Required permissions:** ohos.permission.MICROPHONE ohos.permission.CAMERA
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name| Type | Mandatory| Description |
| ------ | ------------------------------------------- | ---- | ------------------------ | | ------ | ------------------------------------------- | ---- | ------------------------ |
| config | [VideoRecorderConfig](#videorecorderconfig) | 是 | 配置视频录制的相关参数。 | | config | [VideoRecorderConfig](#videorecorderconfig) | Yes | Video recording parameters to set.|
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ---------------------------------------- | | -------------- | ---------------------------------------- |
| Promise\<void> | 异步视频录制prepare方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
let videoProfile = { let videoProfile = {
...@@ -1917,7 +1917,7 @@ let videoConfig = { ...@@ -1917,7 +1917,7 @@ let videoConfig = {
audioSourceType : 1, audioSourceType : 1,
videoSourceType : 0, videoSourceType : 0,
profile : videoProfile, profile : videoProfile,
url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 url : 'fd://xx', // The file must be created by the caller and granted with proper permissions.
orientationHint : 0, orientationHint : 0,
location : { latitude : 30, longitude : 130 }, location : { latitude : 30, longitude : 130 },
} }
...@@ -1950,25 +1950,25 @@ await videoRecorder.prepare(videoConfig).then(() => { ...@@ -1950,25 +1950,25 @@ await videoRecorder.prepare(videoConfig).then(() => {
getInputSurface(callback: AsyncCallback\<string>): void; getInputSurface(callback: AsyncCallback\<string>): void;
异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。 Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。 Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.
只能在[prepare()](#videorecorder_prepare1)接口调用后调用。 This method can be called only after [prepare()](#videorecorder_prepare1) is called.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | --------------------------- | | -------- | ---------------------- | ---- | --------------------------- |
| callback | AsyncCallback\<string> | 是 | 异步获得surface的回调方法。 | | callback | AsyncCallback\<string> | Yes | Callback used to obtain the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
let surfaceID = null; // 传递给外界的surfaceID let surfaceID = null; // Surface ID passed to the external system.
videoRecorder.getInputSurface((err, surfaceId) => { videoRecorder.getInputSurface((err, surfaceId) => {
if (typeof (err) == 'undefined') { if (typeof (err) == 'undefined') {
console.info('getInputSurface success'); console.info('getInputSurface success');
...@@ -1983,25 +1983,25 @@ videoRecorder.getInputSurface((err, surfaceId) => { ...@@ -1983,25 +1983,25 @@ videoRecorder.getInputSurface((err, surfaceId) => {
getInputSurface(): Promise\<string>; getInputSurface(): Promise\<string>;
异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。 Obtains the surface required for recording in asynchronous mode. This surface is provided for the caller. The caller obtains the **surfaceBuffer** from this surface and fills in the corresponding data.
应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。 Note that the video data must carry the timestamp (in ns) and buffer size, and the start time of the timestamp is based on the system startup time.
只能在[prepare()](#videorecorder_prepare1)接口调用后调用。 This method can be called only after [prepare()](#videorecorder_prepare1) is called.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| ---------------- | -------------------------------- | | ---------------- | -------------------------------- |
| Promise\<string> | 异步获得surface的Promise返回值。 | | Promise\<string> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
let surfaceID = null; // 传递给外界的surfaceID let surfaceID = null; // Surface ID passed to the external system.
await videoRecorder.getInputSurface().then((surfaceId) => { await videoRecorder.getInputSurface().then((surfaceId) => {
console.info('getInputSurface success'); console.info('getInputSurface success');
surfaceID = surfaceId; surfaceID = surfaceId;
...@@ -2016,19 +2016,19 @@ await videoRecorder.getInputSurface().then((surfaceId) => { ...@@ -2016,19 +2016,19 @@ await videoRecorder.getInputSurface().then((surfaceId) => {
start(callback: AsyncCallback\<void>): void; start(callback: AsyncCallback\<void>): void;
异步方式开始视频录制。通过注册回调函数获取返回值。 Starts video recording in asynchronous mode. This API uses a callback to return the result.
[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。 This method can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- | | -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步开始视频录制的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2045,19 +2045,19 @@ videoRecorder.start((err) => { ...@@ -2045,19 +2045,19 @@ videoRecorder.start((err) => {
start(): Promise\<void>; start(): Promise\<void>;
异步方式开始视频录制。通过Promise获取返回值。 Starts video recording in asynchronous mode. This API uses a promise to return the result.
[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。 This method can be called only after [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) are called, because the data source must pass data to the surface first.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------------------- | | -------------- | ------------------------------------- |
| Promise\<void> | 异步开始视频录制方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2074,19 +2074,19 @@ await videoRecorder.start().then(() => { ...@@ -2074,19 +2074,19 @@ await videoRecorder.start().then(() => {
pause(callback: AsyncCallback\<void>): void; pause(callback: AsyncCallback\<void>): void;
异步方式暂停视频录制。通过注册回调函数获取返回值。 Pauses video recording in asynchronous mode. This API uses a callback to return the result.
[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。 This method can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- | | -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步暂停视频录制的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2103,19 +2103,19 @@ videoRecorder.pause((err) => { ...@@ -2103,19 +2103,19 @@ videoRecorder.pause((err) => {
pause(): Promise\<void>; pause(): Promise\<void>;
异步方式暂停视频录制。通过Promise获取返回值。 Pauses video recording in asynchronous mode. This API uses a promise to return the result.
[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。 This method can be called only after [start()](#videorecorder_start1) is called. You can resume recording by calling [resume()](#videorecorder_resume1).
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------------------- | | -------------- | ------------------------------------- |
| Promise\<void> | 异步暂停视频录制方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2132,17 +2132,17 @@ await videoRecorder.pause().then(() => { ...@@ -2132,17 +2132,17 @@ await videoRecorder.pause().then(() => {
resume(callback: AsyncCallback\<void>): void; resume(callback: AsyncCallback\<void>): void;
异步方式恢复视频录制。通过注册回调函数获取返回值。 Resumes video recording in asynchronous mode. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- | | -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步恢复视频录制的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2159,17 +2159,17 @@ videoRecorder.resume((err) => { ...@@ -2159,17 +2159,17 @@ videoRecorder.resume((err) => {
resume(): Promise\<void>; resume(): Promise\<void>;
异步方式恢复视频录制。通过Promise获取返回值。 Resumes video recording in asynchronous mode. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------------------- | | -------------- | ------------------------------------- |
| Promise\<void> | 异步恢复视频录制方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2186,19 +2186,19 @@ await videoRecorder.resume().then(() => { ...@@ -2186,19 +2186,19 @@ await videoRecorder.resume().then(() => {
stop(callback: AsyncCallback\<void>): void; stop(callback: AsyncCallback\<void>): void;
异步方式停止视频录制。通过注册回调函数获取返回值。 Stops video recording in asynchronous mode. This API uses a callback to return the result.
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。 To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- | | -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步停止视频录制的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2215,19 +2215,19 @@ videoRecorder.stop((err) => { ...@@ -2215,19 +2215,19 @@ videoRecorder.stop((err) => {
stop(): Promise\<void>; stop(): Promise\<void>;
异步方式停止视频录制。通过Promise获取返回值。 Stops video recording in asynchronous mode. This API uses a promise to return the result.
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。 To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------------------- | | -------------- | ------------------------------------- |
| Promise\<void> | 异步停止视频录制方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2244,17 +2244,17 @@ await videoRecorder.stop().then(() => { ...@@ -2244,17 +2244,17 @@ await videoRecorder.stop().then(() => {
release(callback: AsyncCallback\<void>): void; release(callback: AsyncCallback\<void>): void;
异步方式释放视频录制资源。通过注册回调函数获取返回值。 Releases the video recording resource in asynchronous mode. This API uses a callback to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | -------------------------------- | | -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步释放视频录制资源的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2271,17 +2271,17 @@ videoRecorder.release((err) => { ...@@ -2271,17 +2271,17 @@ videoRecorder.release((err) => {
release(): Promise\<void>; release(): Promise\<void>;
异步方式释放视频录制资源。通过Promise获取返回值。 Releases the video recording resource in asynchronous mode. This API uses a promise to return the result.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ----------------------------------------- | | -------------- | ----------------------------------------- |
| Promise\<void> | 异步释放视频录制资源方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2298,19 +2298,19 @@ await videoRecorder.release().then(() => { ...@@ -2298,19 +2298,19 @@ await videoRecorder.release().then(() => {
reset(callback: AsyncCallback\<void>): void; reset(callback: AsyncCallback\<void>): void;
异步方式重置视频录制。通过注册回调函数获取返回值。 Resets video recording in asynchronous mode. This API uses a callback to return the result.
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。 To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | -------------------- | ---- | ---------------------------- | | -------- | -------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | 是 | 异步重置视频录制的回调方法。 | | callback | AsyncCallback\<void> | Yes | Callback used to return the result.|
**示例:** **Example**
```js ```js
// asyncallback // asyncallback
...@@ -2327,19 +2327,19 @@ videoRecorder.reset((err) => { ...@@ -2327,19 +2327,19 @@ videoRecorder.reset((err) => {
reset(): Promise\<void>; reset(): Promise\<void>;
异步方式重置视频录制。通过Promise获取返回值。 Resets video recording in asynchronous mode. This API uses a promise to return the result.
需要重新调用[prepare()](#videorecorder_prepare1)[getInputSurface()](#getinputsurface8)接口才能重新录制。 To start another recording, you must call [prepare()](#videorecorder_prepare1) and [getInputSurface()](#getinputsurface8) again.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**返回值:** **Return value**
| 类型 | 说明 | | Type | Description |
| -------------- | ------------------------------------- | | -------------- | ------------------------------------- |
| Promise\<void> | 异步重置视频录制方法的Promise返回值。 | | Promise\<void> | Promise used to return the result.|
**示例:** **Example**
```js ```js
// promise // promise
...@@ -2356,101 +2356,101 @@ await videoRecorder.reset().then(() => { ...@@ -2356,101 +2356,101 @@ await videoRecorder.reset().then(() => {
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
开始订阅视频录制错误事件。 Subscribes to the video recording error event.
**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder **System capability**: SystemCapability.Multimedia.Media.VideoRecorder
**参数:** **Parameters**
| 参数名 | 类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| -------- | ------------- | ---- | ------------------------------------------------------------ | | -------- | ------------- | ---- | ------------------------------------------------------------ |
| type | string | 是 | 录制错误事件回调类型'error'。<br/>-&nbsp;'error':音频录制过程中发生错误,触发该事件。 | | type | string | Yes | Type of the event to subscribe to, which is 'error' in this method.<br>The 'error' event is triggered when an error occurs during video recording.|
| callback | ErrorCallback | 是 | 录制错误事件回调方法。 | | callback | ErrorCallback | Yes | Callback invoked when the event is triggered. |
**示例:** **Example**
```js ```js
videoRecorder.on('error', (error) => { // 设置'error'事件回调 videoRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, errName is ${error.name}`); // 打印错误类型名称 console.info(`audio error called, errName is ${error.name}`); // Print the error name.
console.info(`audio error called, errCode is ${error.code}`); // 打印错误码 console.info(`audio error called, errCode is ${error.code}`); // Print the error code.
console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述 console.info(`audio error called, errMessage is ${error.message}`); // Print the detailed description of the error type.
}); });
// 当获取videoRecordState接口出错时通过此订阅事件上报 // This event is reported when an error occurs during the retrieval of videoRecordState.
``` ```
## VideoRecordState<sup>8+</sup> ## VideoRecordState<sup>8+</sup>
视频录制的状态机。可通过state属性获取当前状态。 Enumerates the video recording states. You can obtain the state through the **state** attribute.
| 名称 | 类型 | 描述 | | Name | Type | Description |
| -------- | ------ | ------------------------------------------------------------ | | -------- | ------ | ------------------------------------------------------------ |
| idle | string | 视频录制空闲。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | idle | string | The video recorder is idle.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| prepared | string | 视频录制参数设置完成。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | prepared | string | The video recording parameters are set.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| playing | string | 视频正在录制。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | playing | string | Video recording is in progress.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| paused | string | 视频暂停录制。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | paused | string | Video recording is paused.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| stopped | string | 视频录制停止。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | stopped | string | Video recording is stopped.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| error | string | 错误状态。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | error | string | Video recording is in the error state.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
## VideoRecorderConfig<sup>8+</sup> ## VideoRecorderConfig<sup>8+</sup>
表示视频录制的参数设置。 Describes the video recording parameters.
| 名称 | 参数类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| --------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ | | --------------- | ---------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| audioSourceType | [AudioSourceType](#audiosourcetype<sup>8+</sup>) | 是 | 视频录制的音频源类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | audioSourceType | [AudioSourceType](#audiosourcetype<sup>8+</sup>) | Yes | Type of the audio source for video recording.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| videoSourceType | [VideoSourceType](#videosourcetype<sup>8+</sup>) | 是 | 视频录制的视频源类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | videoSourceType | [VideoSourceType](#videosourcetype<sup>8+</sup>) | Yes | Type of the video source for video recording.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| profile | [VideoRecorderProfile](#videorecorderprofile<sup>8+</sup>) | 是 | 视频录制的profile。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | profile | [VideoRecorderProfile](#videorecorderprofile<sup>8+</sup>) | Yes | Video recording profile.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| orientationHint | number | 否 | 录制视频的旋转角度。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | orientationHint | number | No | Rotation angle of the recorded video.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| location | [Location](#location8) | 否 | 录制视频的地理位置。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | location | [Location](#location8) | No | Geographical location of the recorded video.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| url | string | 是 | 视频输出URL:fd://xx&nbsp;(fd&nbsp;number)<br/>![zh-cn_image_0000001164217678](figures/zh-cn_image_url.png) <br/>文件需要由调用者创建,并赋予适当的权限。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | url | string | Yes | Video output URL. Supported: fd://xx&nbsp;(fd&nbsp;number)<br>![en-us_image_0000001164217678](figures/en-us_image_url.png) <br>The file must be created by the caller and granted with proper permissions.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
## AudioSourceType<sup>8+</sup> ## AudioSourceType<sup>8+</sup>
表示视频录制中音频源类型的枚举。 Enumerates the audio source types for video recording.
| 名称 | 值 | 说明 | | Name | Value | Description |
| ------------------------- | ---- | ------------------------------------------------------------ | | ------------------------- | ---- | ------------------------------------------------------------ |
| AUDIO_SOURCE_TYPE_DEFAULT | 0 | 默认的音频输入源类型。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | AUDIO_SOURCE_TYPE_DEFAULT | 0 | Default audio input source.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| AUDIO_SOURCE_TYPE_MIC | 1 | 表示MIC的音频输入源。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | AUDIO_SOURCE_TYPE_MIC | 1 | Mic audio input source.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
## VideoSourceType<sup>8+</sup> ## VideoSourceType<sup>8+</sup>
表示视频录制中视频源类型的枚举。 Enumerates the video source types for video recording.
| 名称 | 值 | 说明 | | Name | Value | Description |
| ----------------------------- | ---- | ------------------------------------------------------------ | | ----------------------------- | ---- | ------------------------------------------------------------ |
| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | 输入surface中携带的是raw data。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | The input surface carries raw data.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | 输入surface中携带的是ES data。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | The input surface carries ES data.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
## VideoRecorderProfile<sup>8+</sup> ## VideoRecorderProfile<sup>8+</sup>
视频录制的配置文件。 Describes the video recording profile.
| 名称 | 参数类型 | 必填 | 说明 | | Name | Type | Mandatory| Description |
| ---------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | | ---------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| audioBitrate | number | 是 | 音频编码比特率。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | audioBitrate | number | Yes | Audio encoding bit rate.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| audioChannels | number | 是 | 音频采集声道数。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | audioChannels | number | Yes | Number of audio channels.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| audioCodec | [CodecMimeType](#CodecMimeType8) | 是 | 音频编码格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | audioCodec | [CodecMimeType](#CodecMimeType8) | Yes | Audio encoding format.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| audioSampleRate | number | 是 | 音频采样率。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | audioSampleRate | number | Yes | Audio sampling rate.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| fileFormat | [ContainerFormatType](#containerformattype8) | 是 | 文件的容器格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | fileFormat | [ContainerFormatType](#containerformattype8) | Yes | Container format of a file.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| videoCodec | [CodecMimeType](#CodecMimeType8) | 是 | 视频编码格式。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | videoCodec | [CodecMimeType](#CodecMimeType8) | Yes | Video encoding format.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| videoFrameWidth | number | 是 | 录制视频帧的宽。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | videoFrameWidth | number | Yes | Width of the recorded video frame.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
| videoFrameHeight | number | 是 | 录制视频帧的高。<br/>**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder | | videoFrameHeight | number | Yes | Height of the recorded video frame.<br>**System capability**: SystemCapability.Multimedia.Media.VideoRecorder|
## ContainerFormatType<sup>8+</sup> ## ContainerFormatType<sup>8+</sup>
表示容器格式类型的枚举,缩写为CFT。 Enumerates the container format types (CFTs).
| 名称 | 值 | 说明 | | Name | Value | Description |
| ----------- | ----- | ------------------------------------------------------------ | | ----------- | ----- | ------------------------------------------------------------ |
| CFT_MPEG_4 | "mp4" | 视频的容器格式,MP4。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | CFT_MPEG_4 | "mp4" | Video container format MP4.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| CFT_MPEG_4A | "m4a" | 音频的容器格式,M4A。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | CFT_MPEG_4A | "m4a" | Audio container format M4A.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
## Location<sup>8+</sup> ## Location<sup>8+</sup>
视频录制的地理位置。 Describes the geographical location of the recorded video.
| 名称 | 参数类型 | 必填 | 说明 | | Name | Type| Mandatory| Description |
| --------- | -------- | ---- | ------------------------------------------------------------ | | --------- | -------- | ---- | ------------------------------------------------------------ |
| latitude | number | 是 | 地理位置的纬度。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | latitude | number | Yes | Latitude of the geographical location.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
| longitude | number | 是 | 地理位置的经度。<br/>**系统能力:** SystemCapability.Multimedia.Media.Core | | longitude | number | Yes | Longitude of the geographical location.<br>**System capability**: SystemCapability.Multimedia.Media.Core|
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册