diff --git a/zh-cn/application-dev/media/audio-playback.md b/zh-cn/application-dev/media/audio-playback.md index bab96ad467fba7c32fdbff769f636ee9fe926872..0bb72e8f6dade18281ab4d1a400efa728eafd2d2 100644 --- a/zh-cn/application-dev/media/audio-playback.md +++ b/zh-cn/application-dev/media/audio-playback.md @@ -28,26 +28,37 @@ AudioPlayer支持的src媒体源输入类型可参考:[src属性说明](../ref import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' -function SetCallBack(audioPlayer) { +//打印码流轨道信息 +function printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } +} + +//设置播放器回调函数 +function setCallBack(audioPlayer) { audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 console.info('audio set source success'); - //播放界面可切换至已准备好,可点击播放按钮进行播放状态 + audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调 }); audioPlayer.on('play', () => { //设置'play'事件回调 console.info('audio play success'); - //将播放按钮切换至可暂停状态 + audioPlayer.pause(); //触发'pause'事件回调,暂停播放 }); audioPlayer.on('pause', () => { //设置'pause'事件回调 console.info('audio pause success'); - //将播放按钮切换至可播放状态 + audioPlayer.seek(5000); //触发'timeUpdate'事件回调,seek到5000ms处播放 }); audioPlayer.on('stop', () => { //设置'stop'事件回调 console.info('audio stop success'); - //播放停止,播放进度条归零,播放按钮切换至可播放状态 + audioPlayer.reset(); //触发'reset'事件回调后,重新设置src属性,可完成切歌 }); audioPlayer.on('reset', () => { //设置'reset'事件回调 console.info('audio reset success'); - //需重新设置src属性后,可继续播放其他音频 + audioPlayer.release(); //audioPlayer资源被销毁 + audioPlayer = undefined; }); audioPlayer.on('timeUpdate', (seekDoneTime) => {//设置'timeUpdate'事件回调 if (typeof(seekDoneTime) == 'undefined') { @@ -55,71 +66,49 @@ function SetCallBack(audioPlayer) { return; } console.info('audio seek success, and seek time is ' + seekDoneTime); - //播放进度条更新到seek对应的位置 + audioPlayer.setVolume(0.5); //触发'volumeChange'事件回调 }); audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 console.info('audio volumeChange success'); - //更新音量显示 + audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获取音频轨道信息 + if (typeof (arrlist) != 'undefined') { + for (let i = 0; i < arrlist.length; i++) { + printfDescription(arrlist[i]); + } + } else { + console.log(`audio getTrackDescription fail, error:${error.message}`); + } + audioPlayer.stop(); //触发'stop'事件回调,停止播放 + }); }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 + audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 console.info('audio play finish'); }); - audioPlayer.on('error', (error) => { //设置'error'事件回调 + audioPlayer.on('error', (error) => { //设置'error'事件回调 console.info(`audio error called, errName is ${error.name}`); console.info(`audio error called, errCode is ${error.code}`); console.info(`audio error called, errMessage is ${error.message}`); }); } -function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } +async function audioPlayerDemo() { + // 1. 创建实例 + let audioPlayer = media.createAudioPlayer(); + setCallBack(audioPlayer); //设置事件回调 + //2. 用户选择音频,设置uri + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); + }); + audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 } - -//1. 创建实例 -let audioPlayer = media.createAudioPlayer(); -SetCallBack(audioPlayer); //设置事件回调 -//2. 用户选择音频,设置uri -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 -//3. 播放音频 -audioPlayer.play(); //需等待'dataLoad'事件回调完成后,才可调用play进行播放,触发'play'事件回调 -//4. 跳转播放位置 -audioPlayer.seek(30000); //触发'timeUpdate'事件回调,seek到30000ms处播放 -//5. 设置音量 -audioPlayer.setVolume(0.5); //触发'volumeChange'事件回调 -//6. 暂停播放 -audioPlayer.pause(); //触发'pause'事件回调,暂停播放 -//7. 获取轨道信息 -audioPlayer.getTrackDescription((error, arrlist) => { //通过回调方式获取音频轨道信息 - if (typeof (arrlist) != 'undefined') { - for (let i = 0; i < arrlist.length; i++) { - printfDescription(arrlist[i]); - } - } else { - console.log(`audio getTrackDescription fail, error:${error.message}`); - } -}); -//8. 停止播放 -audioPlayer.stop(); //触发'stop'事件回调 -//9. 重置播放资源 -audioPlayer.reset(); //触发'reset'事件回调后,重新设置src属性,可完成切歌 -//10. 释放资源 -audioPlayer.release(); //audioPlayer资源被销毁 -audioPlayer = undefined; ``` ### 正常播放场景 @@ -127,37 +116,40 @@ audioPlayer = undefined; ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -function SetCallBack(audioPlayer) { +export class AudioDemo { + // 设置播放器回调函数 + setCallBack(audioPlayer) { audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 + console.info('audio set source success'); + audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 }); audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); + console.info('audio play success'); }); audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; + console.info('audio play finish'); + audioPlayer.release(); //audioPlayer资源被销毁 + audioPlayer = undefined; }); + } + + async audioPlayerDemo() { + let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 + this.setCallBack(audioPlayer); //设置事件回调 + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); + }); + audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 + } } - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 -/* 用户选择音频设置fd(本地播放) */ -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 ``` ### 切歌场景 @@ -165,52 +157,62 @@ audioPlayer.src = fdPath; //设置src属性,并触 ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -function SetCallBack(audioPlayer) { +export class AudioDemo { +// 设置播放器回调函数 + private isNextMusic = false; + setCallBack(audioPlayer) { audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 + console.info('audio set source success'); + audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 }); audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); + console.info('audio play success'); + audioPlayer.reset(); //调用reset方法,触发'reset'事件回调 }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); + audioPlayer.on('reset', () => { //设置'reset'事件回调 + console.info('audio play success'); + if (!this.isNextMusic) { //当isNextMusic 为false时,实现切歌功能 + this.nextMusic(audioPlayer); //实现切歌功能 + } else { audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; + audioPlayer = undefined; + } + }); + } + + async nextMusic(audioPlayer) { + this.isNextMusic = true; + let nextFdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\02.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let nextpath = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/02.mp3'; + await fileIO.open(nextpath).then((fdNumber) => { + nextFdPath = nextFdPath + '' + fdNumber; + console.info('open fd sucess fd is' + nextFdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); }); + audioPlayer.src = nextFdPath; //设置src属性,并重新触发触发'dataLoad'事件回调 + } + + async audioPlayerDemo() { + let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 + this.setCallBack(audioPlayer); //设置事件回调 + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); + }); + audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 + } } - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 -/* 用户选择音频设置fd(本地播放) */ -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 -/* 播放一段时间后,下发切歌指令 */ -audioPlayer.reset(); - -/* 用户选择音频设置fd(本地播放) */ -let fdNextPath = 'fd://' -let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(nextPath).then(fdNumber) => { - fdNextPath = fdNextPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdNextPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); -audioPlayer.src = fdNextPath; ``` ### 单曲循环场景 @@ -218,39 +220,36 @@ audioPlayer.src = fdNextPath; ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -function SetCallBack(audioPlayer) { +export class AudioDemo { + // 设置播放器回调函数 + setCallBack(audioPlayer) { audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 + console.info('audio set source success'); + audioPlayer.loop = true; //设置循环播放属性 + audioPlayer.play(); //调用play方法开始播放,触发'play'事件回调 }); - audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); + audioPlayer.on('play', () => { //设置'play'事件回调,开始循环播放 + console.info('audio play success'); }); - audioPlayer.on('finish', () => { //设置'finish'事件回调,播放完成触发 - console.info('audio play finish'); - audioPlayer.release(); //audioPlayer资源被销毁 - audioPlayer = undefined; + } + + async audioPlayerDemo() { + let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 + this.setCallBack(audioPlayer); //设置事件回调 + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\01.mp3 /data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.audio.audioplayer/ohos.acts.multimedia.audio.audioplayer/assets/entry/resources/rawfile/01.mp3'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); }); + audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 + } } - -let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 -SetCallBack(audioPlayer); //设置事件回调 - -/* 用户选择音频设置fd(本地播放) */ -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 -audioPlayer.loop = true; //设置循环播放属性 ``` ## 相关实例 @@ -258,7 +257,6 @@ audioPlayer.loop = true; //设置循环播放属性 针对音频播放开发,有以下相关实例可供参考: - [`JsDistributedMusicPlayer`:分布式音乐播放(JS)(API7)](https://gitee.com/openharmony/app_samples/tree/master/ability/JsDistributedMusicPlayer) - - [`JsAudioPlayer`:音频播放和管理(JS)(API7)](https://gitee.com/openharmony/app_samples/tree/master/media/JsAudioPlayer) - +- [`eTsAudioPlayer`: 音频播放器(eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets) - [音频播放器](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) \ No newline at end of file diff --git a/zh-cn/application-dev/media/audio-recorder.md b/zh-cn/application-dev/media/audio-recorder.md index 0b2708b5d963ccafeb6f9ae221ee980ea7f9c24e..6ce349669def897a154a0b582662d066f543608e 100644 --- a/zh-cn/application-dev/media/audio-recorder.md +++ b/zh-cn/application-dev/media/audio-recorder.md @@ -25,46 +25,49 @@ ```js import media from '@ohos.multimedia.media' import mediaLibrary from '@ohos.multimedia.mediaLibrary' - -let testFdNumber; - -function SetCallBack(audioRecorder) { - audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 - console.log('prepare success'); - // 录制界面可切换至已准备好,可点击录制按钮进行录制 +export class AudioRecorderDemo { + private testFdNumber; // 用于保存fd地址 + + // 设置音频录制相关回调函数 + setCallBack(audioRecorder) { + audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 + console.log('prepare success'); + audioRecorder.start(); // 调用start方法开始录制,并触发start回调 }); - audioRecorder.on('start', () => { // 设置'start'事件回调 - console.log('audio recorder start success'); - // 将录制按钮切换至可暂停状态 + audioRecorder.on('start', () => { // 设置'start'事件回调 + console.log('audio recorder start success'); + audioRecorder.pause(); // 调用pause方法暂停录制,并触发pause回调 }); - audioRecorder.on('pause', () => { // 设置'pause'事件回调 - console.log('audio recorder pause success'); - // 将录制按钮切换至可录制状态 + audioRecorder.on('pause', () => { // 设置'pause'事件回调 + console.log('audio recorder pause success'); + audioRecorder.resume(); // 调用resume方法恢复录制,并触发resume回调 }); - audioRecorder.on('resume', () => { // 设置'resume'事件回调 - console.log('audio recorder resume success'); - // 将录制按钮切换至可暂停状态 + audioRecorder.on('resume', () => { // 设置'resume'事件回调 + console.log('audio recorder resume success'); + audioRecorder.stop(); // 调用stop方法停止录制,并触发stop回调 }); - audioRecorder.on('stop', () => { // 设置'stop'事件回调 - console.log('audio recorder stop success'); + audioRecorder.on('stop', () => { // 设置'stop'事件回调 + console.log('audio recorder stop success'); + audioRecorder.reset(); // 调用reset方法重置录制,并触发reset回调 }); - audioRecorder.on('release', () => { // 设置'release'事件回调 - console.log('audio recorder release success'); + audioRecorder.on('reset', () => { // 设置'reset'事件回调 + console.log('audio recorder reset success'); + audioRecorder.release(); // 调用release方法,释放资源,并触发release回调 }); - audioRecorder.on('reset', () => { // 设置'reset'事件回调 - console.log('audio recorder reset success'); - // 需要重新设置录制参数才能再次录制 + audioRecorder.on('release', () => { // 设置'release'事件回调 + console.log('audio recorder release success'); + audioRecorder = undefined; }); - audioRecorder.on('error', (error) => { // 设置'error'事件回调 - console.info(`audio error called, errName is ${error.name}`); - console.info(`audio error called, errCode is ${error.code}`); - console.info(`audio error called, errMessage is ${error.message}`); + audioRecorder.on('error', (error) => { // 设置'error'事件回调 + console.info(`audio error called, errName is ${error.name}`); + console.info(`audio error called, errCode is ${error.code}`); + console.info(`audio error called, errMessage is ${error.message}`); }); -} + } -// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3 -// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA -async function getFd(pathName) { + // pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Video/01.mp3 + // 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA + async getFd(pathName) { let displayName = pathName; const mediaTest = mediaLibrary.getMediaLibrary(); let fileKeyObj = mediaLibrary.FileKey; @@ -72,49 +75,37 @@ async function getFd(pathName) { let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchFileResult = await mediaTest.getFileAssets(fetchOp); - let fileAsset = await fetchFileResult.getAllObject(); - let fdNumber = await fileAsset[0].open('Rw'); - fdNumber = "fd://" + fdNumber.toString(); - testFdNumber = fdNumber; + let args = dataUri.id.toString(); + let fetchOp = { + selections : fileKeyObj.ID + "=?", + selectionArgs : [args], + } + let fetchFileResult = await mediaTest.getFileAssets(fetchOp); + let fileAsset = await fetchFileResult.getAllObject(); + let fdNumber = await fileAsset[0].open('Rw'); + this.testFdNumber = "fd://" + fdNumber.toString(); + } + } + + async audioRecorderDemo() { + // 1.创建实例 + let audioRecorder = media.createAudioRecorder(); + // 2.设置回调 + this.setCallBack(audioRecorder); + await this.getFd('01.mp3'); // 调用getFd方法获取需要录制文件的fd地址 + // 3.设置录制参数 + let audioRecorderConfig = { + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + uri : this.testFdNumber, // testFdNumber由getFd生成 + location : { latitude : 30, longitude : 130}, + audioEncoderMime : media.CodecMimeType.AUDIO_AAC, + fileFormat : media.ContainerFormatType.CFT_MPEG_4A, } + audioRecorder.prepare(audioRecorderConfig); // 调用prepare方法,触发prepare回调函数 + } } - -await getFd('01.mp3'); - -// 1.创建实例 -let audioRecorder = media.createAudioRecorder(); -// 2.设置回调 -SetCallBack(audioRecorder); -// 3.设置录制参数 -let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC , - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : testFdNumber, // testFdNumber由getFd生成 - location : { latitude : 30, longitude : 130}, -} -audioRecorder.prepare(audioRecorderConfig); -// 4.开始录制 -audioRecorder.start(); // 需等待'prepare'事件回调完成后,才可调用start进行录制,触发'start'事件回调 -// 5.暂停录制 -audioRecorder.pause(); // 需等待'start'事件回调完成后,才可调用pause进行暂停,触发'pause'事件回调 -// 6.恢复录制 -audioRecorder.resume(); // 需等待'pause'事件回调完成后,才可调用resume进行录制,触发'resume'事件回调 -// 7.停止录制 -audioRecorder.stop(); // 需等待'start'或'resume'事件回调完成后,才可调用stop进行暂停,触发'stop'事件回调 -// 8.重置录制 -audioRecorder.reset(); // 触发'reset'事件回调后,重新进行prepare,才可重新录制 -// 9.释放资源 -audioRecorder.release(); // audioRecorder资源被销毁 -audioRecorder = undefined; ``` ### 正常录制场景 @@ -124,29 +115,37 @@ audioRecorder = undefined; ```js import media from '@ohos.multimedia.media' import mediaLibrary from '@ohos.multimedia.mediaLibrary' - -let testFdNumber; - -function SetCallBack(audioRecorder) { - audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 - console.log('prepare success'); - // 录制界面可切换至已准备好,可点击录制按钮进行录制 +export class AudioRecorderDemo { + private testFdNumber; // 用于保存fd地址 + + // 设置音频录制相关回调函数 + setCallBack(audioRecorder) { + audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 + console.log('prepare success'); + audioRecorder.start(); // 调用start方法开始录制,并触发start回调 }); - audioRecorder.on('start', () => { // 设置'start'事件回调 - console.log('audio recorder start success'); - // 将录制按钮切换至可暂停状态 - }); - audioRecorder.on('stop', () => { // 设置'stop'事件回调 - console.log('audio recorder stop success'); - }); - audioRecorder.on('release', () => { // 设置'release'事件回调 - console.log('audio recorder release success'); - }); -} + audioRecorder.on('start', () => { // 设置'start'事件回调 + console.log('audio recorder start success'); + audioRecorder.stop(); // 调用stop方法停止录制,并触发stop回调 + }); + audioRecorder.on('stop', () => { // 设置'stop'事件回调 + console.log('audio recorder stop success'); + audioRecorder.release(); // 调用release方法,释放资源,并触发release回调 + }); + audioRecorder.on('release', () => { // 设置'release'事件回调 + console.log('audio recorder release success'); + audioRecorder = undefined; + }); + audioRecorder.on('error', (error) => { // 设置'error'事件回调 + console.info(`audio error called, errName is ${error.name}`); + console.info(`audio error called, errCode is ${error.code}`); + console.info(`audio error called, errMessage is ${error.message}`); + }); + } -// pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Movies/01.mp3 -// 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA -async function getFd(pathName) { + // pathName是传入的录制文件名,例如:01.mp3,生成后的文件地址:/storage/media/100/local/files/Video/01.mp3 + // 使用mediaLibrary需要添加以下权限, ohos.permission.MEDIA_LOCATION、ohos.permission.WRITE_MEDIA、ohos.permission.READ_MEDIA + async getFd(pathName) { let displayName = pathName; const mediaTest = mediaLibrary.getMediaLibrary(); let fileKeyObj = mediaLibrary.FileKey; @@ -154,43 +153,37 @@ async function getFd(pathName) { let publicPath = await mediaTest.getPublicDirectory(mediaLibrary.DirectoryType.DIR_VIDEO); let dataUri = await mediaTest.createAsset(mediaType, displayName, publicPath); if (dataUri != undefined) { - let args = dataUri.id.toString(); - let fetchOp = { - selections : fileKeyObj.ID + "=?", - selectionArgs : [args], - } - let fetchFileResult = await mediaTest.getFileAssets(fetchOp); - let fileAsset = await fetchFileResult.getAllObject(); - let fdNumber = await fileAsset[0].open('Rw'); - fdNumber = "fd://" + fdNumber.toString(); - testFdNumber = fdNumber; + let args = dataUri.id.toString(); + let fetchOp = { + selections : fileKeyObj.ID + "=?", + selectionArgs : [args], + } + let fetchFileResult = await mediaTest.getFileAssets(fetchOp); + let fileAsset = await fetchFileResult.getAllObject(); + let fdNumber = await fileAsset[0].open('Rw'); + this.testFdNumber = "fd://" + fdNumber.toString(); } + } + + async audioRecorderDemo() { + // 1.创建实例 + let audioRecorder = media.createAudioRecorder(); + // 2.设置回调 + this.setCallBack(audioRecorder); + await this.getFd('01.mp3'); // 调用getFd方法获取需要录制文件的fd地址 + // 3.设置录制参数 + let audioRecorderConfig = { + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + uri : this.testFdNumber, // testFdNumber由getFd生成 + location : { latitude : 30, longitude : 130}, + audioEncoderMime : media.CodecMimeType.AUDIO_AAC, + fileFormat : media.ContainerFormatType.CFT_MPEG_4A, + } + audioRecorder.prepare(audioRecorderConfig); // 调用prepare方法,触发prepare回调函数 + } } - -await getFd('01.mp3'); - -// 1.创建实例 -let audioRecorder = media.createAudioRecorder(); -// 2.设置回调 -SetCallBack(audioRecorder); -// 3.设置录制参数 -let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC , - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : testFdNumber, // testFdNumber由getFd生成 - location : { latitude : 30, longitude : 130}, -} -audioRecorder.prepare(audioRecorderConfig) -// 4.开始录制 -audioRecorder.start(); // 需等待'prepare'事件回调完成后,才可调用start进行录制,触发'start'事件回调 -// 5.停止录制 -audioRecorder.stop(); // 需等待'start'或'resume'事件回调完成后,才可调用stop进行暂停,触发'stop'事件回调 -// 6.释放资源 -audioRecorder.release(); // audioRecorder资源被销毁 -audioRecorder = undefined; ``` ## 相关实例 @@ -198,5 +191,5 @@ audioRecorder = undefined; 针对音频录制开发,有以下相关实例可供参考: - [`Recorder`:录音机(eTS)(API8)](https://gitee.com/openharmony/app_samples/tree/master/media/Recorder) - -- [音频播放器](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) \ No newline at end of file +- [`eTsAudioPlayer`: 音频播放器(eTS)](https://gitee.com/openharmony/app_samples/blob/master/media/Recorder/entry/src/main/ets/MainAbility/pages/Play.ets) +- [音频播放器](https://gitee.com/openharmony/codelabs/tree/master/Media/Audio_OH_ETS) diff --git a/zh-cn/application-dev/media/image.md b/zh-cn/application-dev/media/image.md index 749bcf03fe58ca3de75ab91976eb9a65788b4c29..9a9d03e87ec97d020090a9d6e984697e10012ea7 100644 --- a/zh-cn/application-dev/media/image.md +++ b/zh-cn/application-dev/media/image.md @@ -4,10 +4,12 @@ 图片开发的主要工作是将获取到的图片进行解码,将解码后的pixelmap编码成支持的格式,本文将对图片的解码、编码等场景开发进行介绍说明。 -## 开发步骤 +## 接口说明 详细API含义请参考:[图片处理API文档](../reference/apis/js-apis-image.md) +## 开发步骤 + ### 全流程场景 包含流程:创建实例,读取图片信息,读写pixelmap,更新数据,打包像素,释放资源等流程。 diff --git a/zh-cn/application-dev/media/video-playback.md b/zh-cn/application-dev/media/video-playback.md index 6cef265938cb3311f38ee90a467fd8b53ce167c3..198b33914a07297f1278285ea5da1b9c5d53b26c 100644 --- a/zh-cn/application-dev/media/video-playback.md +++ b/zh-cn/application-dev/media/video-playback.md @@ -43,138 +43,135 @@ VideoPlayer支持的url媒体源输入类型可参考:[url属性说明](../reference/apis/js-apis-media.md#videoplayer_属性) -Xcomponent创建方法可参考:[Xcomponent创建方法](#Xcomponent创建方法) +Xcomponent创建方法可参考:[Xcomponent创建方法](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-xcomponent.md) + +*注意:SetSurface需要在设置url和Prepare之间 ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 -let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID - -// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 -LoadXcomponent() { - surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); - console.info('LoadXcomponent surfaceID is' + surfaceID); -} - -// 函数调用发生错误时用于上报错误信息 -function failureCallback(error) { +export class VideoPlayerDemo { + // 函数调用发生错误时用于上报错误信息 + failureCallback(error) { console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Message is ${error.message}`); -} + } -// 当函数调用发生异常时用于上报错误信息 -function catchCallback(error) { + // 当函数调用发生异常时用于上报错误信息 + catchCallback(error) { console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Message is ${error.message}`); -} + } -// 用于打印视频轨道信息 -function printfDescription(obj) { + // 用于打印视频轨道信息 + printfDescription(obj) { for (let item in obj) { - let property = obj[item]; - console.info('key is ' + item); - console.info('value is ' + property); + let property = obj[item]; + console.info('key is ' + item); + console.info('value is ' + property); } -} - -// 调用createVideoPlayer接口返回videoPlayer实例对象 -await media.createVideoPlayer().then((video) => { - if (typeof (video) != 'undefined') { + } + + async videoPlayerDemo() { + let videoPlayer = undefined; + let surfaceID = 'test' // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接见上面Xcomponent创建方法 + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); + }); + // 调用createVideoPlayer接口返回videoPlayer实例对象 + await media.createVideoPlayer().then((video) => { + if (typeof (video) != 'undefined') { console.info('createVideoPlayer success!'); videoPlayer = video; - } else { + } else { console.info('createVideoPlayer fail!'); - } -}, failureCallback).catch(catchCallback); - -// 用户选择视频设置fd(本地播放) -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -videoPlayer.url = fdPath; - -// 设置surfaceID用于显示视频画面 -await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); - -// 调用prepare完成播放前准备工作 -await videoPlayer.prepare().then(() => { - console.info('prepare success'); -}, failureCallback).catch(catchCallback); - -// 调用play接口正式开始播放 -await videoPlayer.play().then(() => { - console.info('play success'); -}, failureCallback).catch(catchCallback); - -// 暂停播放 -await videoPlayer.pause().then(() => { - console.info('pause success'); -}, failureCallback).catch(catchCallback); - -// 通过promise回调方式获取视频轨道信息 -let arrayDescription; -await videoPlayer.getTrackDescription().then((arrlist) => { - if (typeof (arrlist) != 'undefined') { + } + }, this.failureCallback).catch(this.catchCallback); + // 设置播放源 + videoPlayer.url = fdPath; + + // 设置surfaceID用于显示视频画面 + await videoPlayer.setDisplaySurface(surfaceID).then(() => { + console.info('setDisplaySurface success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用prepare完成播放前准备工作 + await videoPlayer.prepare().then(() => { + console.info('prepare success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用play接口正式开始播放 + await videoPlayer.play().then(() => { + console.info('play success'); + }, this.failureCallback).catch(this.catchCallback); + + // 暂停播放 + await videoPlayer.pause().then(() => { + console.info('pause success'); + }, this.failureCallback).catch(this.catchCallback); + + // 通过promise回调方式获取视频轨道信息 + let arrayDescription; + await videoPlayer.getTrackDescription().then((arrlist) => { + if (typeof (arrlist) != 'undefined') { arrayDescription = arrlist; - } else { + } else { console.log('video getTrackDescription fail'); + } + }, this.failureCallback).catch(this.catchCallback); + + for (let i = 0; i < arrayDescription.length; i++) { + this.printfDescription(arrayDescription[i]); } -}, failureCallback).catch(catchCallback); -for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + // 跳转播放时间到50s位置,具体入参意义请参考接口文档 + let seekTime = 50000; + await videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { + console.info('seek success'); + }, this.failureCallback).catch(this.catchCallback); + + // 音量设置接口,具体入参意义请参考接口文档 + let volume = 0.5; + await videoPlayer.setVolume(volume).then(() => { + console.info('setVolume success'); + }, this.failureCallback).catch(this.catchCallback); + + // 倍速设置接口,具体入参意义请参考接口文档 + let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; + await videoPlayer.setSpeed(speed).then(() => { + console.info('setSpeed success'); + }, this.failureCallback).catch(this.catchCallback); + + // 结束播放 + await videoPlayer.stop().then(() => { + console.info('stop success'); + }, this.failureCallback).catch(this.catchCallback); + + // 重置播放配置 + await videoPlayer.reset().then(() => { + console.info('reset success'); + }, this.failureCallback).catch(this.catchCallback); + + // 释放播放资源 + await videoPlayer.release().then(() => { + console.info('release success'); + }, this.failureCallback).catch(this.catchCallback); + + // 相关对象置undefined + videoPlayer = undefined; + surfaceID = undefined; + } } - -// 跳转播放时间到50s位置,具体入参意义请参考接口文档 -let seekTime = 50000; -await videoPlayer.seek(seekTime, media.SeekMode._NEXT_SYNC).then((seekDoneTime) => { - console.info('seek success'); -}, failureCallback).catch(catchCallback); - -// 音量设置接口,具体入参意义请参考接口文档 -let volume = 0.5; -await videoPlayer.setVolume(volume).then(() => { - console.info('setVolume success'); -}, failureCallback).catch(catchCallback); - -// 倍速设置接口,具体入参意义请参考接口文档 -let speed = media.PlaybackRateMode.SPEED_FORWARD_2_00_X; -await videoPlayer.setSpeed(speed).then(() => { - console.info('setSpeed success'); -}, failureCallback).catch(catchCallback); - -// 结束播放 -await videoPlayer.stop().then(() => { - console.info('stop success'); -}, failureCallback).catch(catchCallback); - -// 重置播放配置 -await videoPlayer.reset().then(() => { - console.info('reset success'); -}, failureCallback).catch(catchCallback); - -// 释放播放资源 -await videoPlayer.release().then(() => { - console.info('release success'); -}, failureCallback).catch(catchCallback); - -// 相关对象置undefined -videoPlayer = undefined; -surfaceID = undefined; ``` ### 正常播放场景 @@ -182,85 +179,86 @@ surfaceID = undefined; ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 -let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID - -// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 -LoadXcomponent() { - surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); - console.info('LoadXcomponent surfaceID is' + surfaceID); -} - -// 函数调用发生错误时用于上报错误信息 -function failureCallback(error) { +export class VideoPlayerDemo { + // 函数调用发生错误时用于上报错误信息 + failureCallback(error) { console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Message is ${error.message}`); -} + } -// 当函数调用发生异常时用于上报错误信息 -function catchCallback(error) { + // 当函数调用发生异常时用于上报错误信息 + catchCallback(error) { console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Message is ${error.message}`); -} + } -// 设置'playbackCompleted'事件回调,播放完成触发 -function SetCallBack(videoPlayer) { - videoPlayer.on('playbackCompleted', () => { - console.info('video play finish'); - - await videoPlayer.release().then(() => { - console.info('release success'); - }, failureCallback).catch(catchCallback); - - videoPlayer = undefined; - surfaceID = undefined; + // 用于打印视频轨道信息 + printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('key is ' + item); + console.info('value is ' + property); + } + } + + async videoPlayerDemo() { + let videoPlayer = undefined; + let surfaceID = 'test' // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接: + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); }); -} - -// 调用createVideoPlayer接口返回videoPlayer实例对象 -await media.createVideoPlayer().then((video) => { - if (typeof (video) != 'undefined') { + // 调用createVideoPlayer接口返回videoPlayer实例对象 + await media.createVideoPlayer().then((video) => { + if (typeof (video) != 'undefined') { console.info('createVideoPlayer success!'); videoPlayer = video; - } else { + } else { console.info('createVideoPlayer fail!'); - } -}, failureCallback).catch(catchCallback); - -// 设置事件回调 -SetCallBack(videoPlayer); - -// 用户选择视频设置fd(本地播放) -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -videoPlayer.url = fdPath; - -// 设置surfaceID用于显示视频画面 -await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); - -// 调用prepare完成播放前准备工作 -await videoPlayer.prepare().then(() => { - console.info('prepare success'); -}, failureCallback).catch(catchCallback); - -// 调用play接口正式开始播放 -await videoPlayer.play().then(() => { - console.info('play success'); -}, failureCallback).catch(catchCallback); + } + }, this.failureCallback).catch(this.catchCallback); + // 设置播放源 + videoPlayer.url = fdPath; + + // 设置surfaceID用于显示视频画面 + await videoPlayer.setDisplaySurface(surfaceID).then(() => { + console.info('setDisplaySurface success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用prepare完成播放前准备工作 + await videoPlayer.prepare().then(() => { + console.info('prepare success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用play接口正式开始播放 + await videoPlayer.play().then(() => { + console.info('play success'); + }, this.failureCallback).catch(this.catchCallback); + + // 结束播放 + await videoPlayer.stop().then(() => { + console.info('stop success'); + }, this.failureCallback).catch(this.catchCallback); + + // 释放播放资源 + await videoPlayer.release().then(() => { + console.info('release success'); + }, this.failureCallback).catch(this.catchCallback); + + // 相关对象置undefined + videoPlayer = undefined; + surfaceID = undefined; + } +} ``` ### 切视频场景 @@ -268,120 +266,110 @@ await videoPlayer.play().then(() => { ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 -let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID - -// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 -LoadXcomponent() { - surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); - console.info('LoadXcomponent surfaceID is' + surfaceID); -} - -// 函数调用发生错误时用于上报错误信息 -function failureCallback(error) { +export class VideoPlayerDemo { + // 函数调用发生错误时用于上报错误信息 + failureCallback(error) { console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Message is ${error.message}`); -} + } -// 当函数调用发生异常时用于上报错误信息 -function catchCallback(error) { + // 当函数调用发生异常时用于上报错误信息 + catchCallback(error) { console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Message is ${error.message}`); -} + } -// 设置'playbackCompleted'事件回调,播放完成触发 -function SetCallBack(videoPlayer) { - videoPlayer.on('playbackCompleted', () => { - console.info('video play finish'); - - await videoPlayer.release().then(() => { - console.info('release success'); - }, failureCallback).catch(catchCallback); - - videoPlayer = undefined; - surfaceID = undefined; + // 用于打印视频轨道信息 + printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('key is ' + item); + console.info('value is ' + property); + } + } + + async videoPlayerDemo() { + let videoPlayer = undefined; + let surfaceID = 'test' // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接: + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4'; + let nextPath = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/MP4_AAC.mp4'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); }); -} - -// 调用createVideoPlayer接口返回videoPlayer实例对象 -await media.createVideoPlayer().then((video) => { - if (typeof (video) != 'undefined') { + // 调用createVideoPlayer接口返回videoPlayer实例对象 + await media.createVideoPlayer().then((video) => { + if (typeof (video) != 'undefined') { console.info('createVideoPlayer success!'); videoPlayer = video; - } else { + } else { console.info('createVideoPlayer fail!'); - } -}, failureCallback).catch(catchCallback); - -// 设置事件回调 -SetCallBack(videoPlayer); - -// 用户选择视频设置fd(本地播放) -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -videoPlayer.url = fdPath; - -// 设置surfaceID用于显示视频画面 -await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); - -// 调用prepare完成播放前准备工作 -await videoPlayer.prepare().then(() => { - console.info('prepare success'); -}, failureCallback).catch(catchCallback); - -// 调用play接口正式开始播放 -await videoPlayer.play().then(() => { - console.info('play success'); -}, failureCallback).catch(catchCallback); - -// 播放一段时间后,下发切视频指令 -// 重置播放配置 -await videoPlayer.reset().then(() => { - console.info('reset success'); -}, failureCallback).catch(catchCallback); - -// 用户选择视频设置fd(本地播放) -let fdNextPath = 'fd://' -let nextPath = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/02.mp4'; -await fileIO.open(nextPath).then(fdNumber) => { - fdNextPath = fdNextPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdNextPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -videoPlayer.url = fdNextPath; - -// 设置surfaceID用于显示视频画面 -await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); - -// 调用prepare完成播放前准备工作 -await videoPlayer.prepare().then(() => { - console.info('prepare success'); -}, failureCallback).catch(catchCallback); - -// 调用play接口正式开始播放 -await videoPlayer.play().then(() => { - console.info('play success'); -}, failureCallback).catch(catchCallback); + } + }, this.failureCallback).catch(this.catchCallback); + // 设置播放源 + videoPlayer.url = fdPath; + + // 设置surfaceID用于显示视频画面 + await videoPlayer.setDisplaySurface(surfaceID).then(() => { + console.info('setDisplaySurface success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用prepare完成播放前准备工作 + await videoPlayer.prepare().then(() => { + console.info('prepare success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用play接口正式开始播放 + await videoPlayer.play().then(() => { + console.info('play success'); + }, this.failureCallback).catch(this.catchCallback); + + // 重置播放配置 + await videoPlayer.reset().then(() => { + console.info('reset success'); + }, this.failureCallback).catch(this.catchCallback); + + // 获取下一个视频fd地址 + fdPath = 'fd://' + await fileIO.open(nextPath).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); + }); + // 设置第二个视频播放源 + videoPlayer.url = fdPath; + + // 调用prepare完成播放前准备工作 + await videoPlayer.prepare().then(() => { + console.info('prepare success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用play接口正式开始播放 + await videoPlayer.play().then(() => { + console.info('play success'); + }, this.failureCallback).catch(this.catchCallback); + + // 释放播放资源 + await videoPlayer.release().then(() => { + console.info('release success'); + }, this.failureCallback).catch(this.catchCallback); + + // 相关对象置undefined + videoPlayer = undefined; + surfaceID = undefined; + } +} ``` ### 单个视频循环场景 @@ -389,99 +377,88 @@ await videoPlayer.play().then(() => { ```js import media from '@ohos.multimedia.media' import fileIO from '@ohos.fileio' - -let videoPlayer = undefined; // 用于保存createVideoPlayer创建的对象 -let surfaceID = undefined; // 用于保存Xcomponent接口返回的surfaceID - -// 调用Xcomponent的接口用于获取surfaceID,并保存在surfaceID变量中,该接口由XComponent组件默认加载,非主动调用 -LoadXcomponent() { - surfaceID = this.$element('Xcomponent').getXComponentSurfaceId(); - console.info('LoadXcomponent surfaceID is' + surfaceID); -} - -// 函数调用发生错误时用于上报错误信息 -function failureCallback(error) { +export class VideoPlayerDemo { + // 函数调用发生错误时用于上报错误信息 + failureCallback(error) { console.info(`error happened,error Name is ${error.name}`); console.info(`error happened,error Code is ${error.code}`); console.info(`error happened,error Message is ${error.message}`); -} + } -// 当函数调用发生异常时用于上报错误信息 -function catchCallback(error) { + // 当函数调用发生异常时用于上报错误信息 + catchCallback(error) { console.info(`catch error happened,error Name is ${error.name}`); console.info(`catch error happened,error Code is ${error.code}`); console.info(`catch error happened,error Message is ${error.message}`); -} + } -// 设置'playbackCompleted'事件回调,播放完成触发 -function SetCallBack(videoPlayer) { - videoPlayer.on('playbackCompleted', () => { - console.info('video play finish'); - - await videoPlayer.release().then(() => { - console.info('release success'); - }, failureCallback).catch(catchCallback); - - videoPlayer = undefined; - surfaceID = undefined; + // 用于打印视频轨道信息 + printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('key is ' + item); + console.info('value is ' + property); + } + } + + sleep(time) { + for(let t = Date.now(); Date.now() - t <= time;); + } + + async videoPlayerDemo() { + let videoPlayer = undefined; + let surfaceID = 'test' // surfaceID用于播放画面显示,具体的值需要通过Xcomponent接口获取,相关文档链接: + let fdPath = 'fd://' + // path路径的码流可通过"hdc file send D:\xxx\H264_AAC.mp4 /data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile" 命令,将其推送到设备上 + let path = '/data/app/el1/bundle/public/ohos.acts.multimedia.video.videoplayer/ohos.acts.multimedia.video.videoplayer/assets/entry/resources/rawfile/H264_AAC.mp4'; + await fileIO.open(path).then((fdNumber) => { + fdPath = fdPath + '' + fdNumber; + console.info('open fd sucess fd is' + fdPath); + }, (err) => { + console.info('open fd failed err is' + err); + }).catch((err) => { + console.info('open fd failed err is' + err); }); -} - -// 调用createVideoPlayer接口返回videoPlayer实例对象 -await media.createVideoPlayer().then((video) => { - if (typeof (video) != 'undefined') { + // 调用createVideoPlayer接口返回videoPlayer实例对象 + await media.createVideoPlayer().then((video) => { + if (typeof (video) != 'undefined') { console.info('createVideoPlayer success!'); videoPlayer = video; - } else { + } else { console.info('createVideoPlayer fail!'); - } -}, failureCallback).catch(catchCallback); - -// 设置事件回调 -SetCallBack(videoPlayer); - -// 用户选择视频设置fd(本地播放) -let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp4'; -await fileIO.open(path).then(fdNumber) => { - fdPath = fdPath + '' + fdNumber; - console.info('open fd sucess fd is' + fdPath); -}, (err) => { - console.info('open fd failed err is' + err); -}),catch((err) => { - console.info('open fd failed err is' + err); -}); - -videoPlayer.url = fdPath; - -// 设置surfaceID用于显示视频画面 -await videoPlayer.setDisplaySurface(surfaceID).then(() => { - console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); - -// 调用prepare完成播放前准备工作 -await videoPlayer.prepare().then(() => { - console.info('prepare success'); -}, failureCallback).catch(catchCallback); - -// 设置循环播放属性 -videoPlayer.loop = true; - -// 调用play接口正式开始播放 -await videoPlayer.play().then(() => { - console.info('play success'); -}, failureCallback).catch(catchCallback); -``` - -### Xcomponent创建方法 - -播放视频中获取surfaceID依赖了Xcomponent,需要创建一个和xxx.js同名的xxx.hml文件,xxx.hml里面需要添加如下代码: - -```js - // 设置窗口宽高等属性 - + } + }, this.failureCallback).catch(this.catchCallback); + // 设置播放源 + videoPlayer.url = fdPath; + + // 设置surfaceID用于显示视频画面 + await videoPlayer.setDisplaySurface(surfaceID).then(() => { + console.info('setDisplaySurface success'); + }, this.failureCallback).catch(this.catchCallback); + + // 调用prepare完成播放前准备工作 + await videoPlayer.prepare().then(() => { + console.info('prepare success'); + }, this.failureCallback).catch(this.catchCallback); + // 设置循环播放属性 + videoPlayer.loop = true; + // 调用play接口正式开始播放 + await videoPlayer.play().then(() => { + console.info('play success'); + }, this.failureCallback).catch(this.catchCallback); + // 进度条执行到末尾后,在播放放3秒钟,因为设置了循环播放,所以当进度条执行到末尾后会从头开始播放 + await videoPlayer.seek(videoPlayer.duration, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { + console.info('seek duration success'); + }, this.failureCallback).catch(this.catchCallback); + this.sleep(3000); + // 释放播放资源 + await videoPlayer.release().then(() => { + console.info('release success'); + }, this.failureCallback).catch(this.catchCallback); + + // 相关对象置undefined + videoPlayer = undefined; + surfaceID = undefined; + } +} ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-audio.md b/zh-cn/application-dev/reference/apis/js-apis-audio.md index e54f2d0d04bb3e4c5a6d3eea36dc0131fb87478d..b955f38382df4e70781b8991551aa8e8721cca30 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-audio.md +++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md @@ -2,6 +2,8 @@ > **说明:** > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 该模块提供以下音频相关的常用功能: @@ -435,6 +437,17 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => { | INTERRUPT_TYPE_BEGIN | 1 | 音频播放中断事件开始。 | | INTERRUPT_TYPE_END | 2 | 音频播放中断事件结束。 | +## InterruptForceType9+ + +枚举,强制打断类型。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer + +| 名称 | 默认值 | 描述 | +| --------------- | ------ | ------------------------------------ | +| INTERRUPT_FORCE | 0 | 由系统进行操作,强制打断音频播放。 | +| INTERRUPT_SHARE | 1 | 由应用进行操作,可以选择打断或忽略。 | + ## InterruptHint 枚举,中断提示。 @@ -499,6 +512,18 @@ audio.createAudioRenderer(audioCapturerOptions).then((data) => { | streamInfo | [AudioStreamInfo](#audiostreaminfo8) | 是 | 表示音频流信息。 | | rendererInfo | [AudioRendererInfo](#audiorendererinfo8) | 是 | 表示渲染器信息。 | +## InterruptEvent9+ + +播放中断时,应用接收的中断事件。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Audio.Renderer + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------------------------------------------ | ---- | ------------------------------------ | +| eventType | [InterruptType](#interrupttype) | 是 | 中断事件类型,开始或是结束。 | +| forceType | [InterruptForceType](#interruptforcetype9) | 是 | 操作是由系统执行或是由应用程序执行。 | +| hintType | [InterruptHint](#interrupthint) | 是 | 中断提示。 | + ## AudioInterrupt 音频监听事件传入的参数。 @@ -2475,6 +2500,51 @@ audioRenderer.getRenderRate().then((renderRate) => { }); ``` +### on('interrupt')9+ + +on(type: 'interrupt', callback: Callback\): void + +监听音频中断事件。使用callback获取中断事件。 + +**系统能力**: SystemCapability.Multimedia.Audio.Renderer + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持的事件为:'interrupt'(中断事件被触发,音频播放被中断。) | +| callback | Callback<[InterruptEvent](#interruptevent9)> | 是 | 被监听的中断事件的回调。 | + +**示例:** + +``` +audioRenderer.on('interrupt', (interruptEvent) => { + if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { + switch (interruptEvent.hintType) { + case audio.InterruptHint.INTERRUPT_HINT_PAUSE: + console.log('Force paused. Stop writing'); + isPlay = false; + break; + case audio.InterruptHint.INTERRUPT_HINT_STOP: + console.log('Force stopped. Stop writing'); + isPlay = false; + break; + } + } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) { + switch (interruptEvent.hintType) { + case audio.InterruptHint.INTERRUPT_HINT_RESUME: + console.log('Resume force paused renderer or ignore'); + startRenderer(); + break; + case audio.InterruptHint.INTERRUPT_HINT_PAUSE: + console.log('Choose to pause or ignore'); + pauseRenderer(); + break; + } + } +}); +``` + ### on('markReach')8+ on(type: 'markReach', frame: number, callback: (position: number) => {}): void diff --git a/zh-cn/application-dev/reference/apis/js-apis-camera.md b/zh-cn/application-dev/reference/apis/js-apis-camera.md new file mode 100644 index 0000000000000000000000000000000000000000..b05df124e755dcd94122988fd5a34ae74fb98e48 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-camera.md @@ -0,0 +1,2611 @@ +# 相机管理 + +> **说明:** +> 本模块首批接口从API version 9开始支持。API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 + +## 导入模块 + +``` +import camera from '@ohos.multimedia.camera'; +``` + +## 权限 + +ohos.permission.CAMERA + +## camera.getCameraManager + +getCameraManager(context: Context, callback: AsyncCallback): void + +获取相机管理器实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------- | ---- | ---------------------------------- | +| context | Context | 是 | 应用上下文。 | +| callback | AsyncCallback<[CameraManager](#cameramanager)\> | 是 | 回调函数,用于获取相机管理器实例。 | + +**示例:** + +``` +camera.getCameraManager(context, (err, cameraManager) => { + if (err) { + console.error('Failed to get the CameraManager instance ${err.message}'); + return; + } + console.log('Callback returned with the CameraManager instance'); +}); +``` + +## camera.getCameraManager + +getCameraManager(context: Context): Promise + +获取相机管理器实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------- | ------- | ---- | ------------ | +| context | Context | 是 | 应用上下文。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | ----------------------------------------- | +| Promise<[CameraManager](#cameramanager)\> | 使用Promise的方式获取一个相机管理器实例。 | + +**示例:** + +``` +camera.getCameraManager(context).then((cameraManager) => { + console.log('Promise returned with the CameraManager instance.'); +}) +``` + +## CameraStatus + +枚举,相机状态。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| ------------------------- | ------ | ------------ | +| CAMERA_STATUS_APPEAR | 0 | 相机存在。 | +| CAMERA_STATUS_DISAPPEAR | 1 | 相机不存在。 | +| CAMERA_STATUS_AVAILABLE | 2 | 相机就绪。 | +| CAMERA_STATUS_UNAVAILABLE | 3 | 相机未就绪。 | + + +## CameraPosition + +枚举,相机方向。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| --------------------------- | ------ | ---------------- | +| CAMERA_POSITION_UNSPECIFIED | 0 | 未指定方向相机。 | +| CAMERA_POSITION_BACK | 1 | 后置相机。 | +| CAMERA_POSITION_FRONT | 2 | 前置相机。 | + +## CameraType + +枚举,相机类型。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| ----------------------- | ------ | ---------------- | +| CAMERA_TYPE_UNSPECIFIED | 0 | 未指定相机类型。 | +| CAMERA_TYPE_WIDE_ANGLE | 1 | 广角相机。 | +| CAMERA_TYPE_ULTRA_WIDE | 2 | 超级广角相机。 | +| CAMERA_TYPE_TELEPHOTO | 3 | 长焦相机。 | +| CAMERA_TYPE_TRUE_DEPTH | 4 | 深度相机。 | + + +## ConnectionType + +枚举,相机连接类型。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| ---------------------------- | ------ | ------------- | +| CAMERA_CONNECTION_BUILT_IN | 0 | 内置相机。 | +| CAMERA_CONNECTION_USB_PLUGIN | 1 | 外置USB相机。 | +| CAMERA_CONNECTION_REMOTE | 2 | 分布式相机。 | + + +## CameraManager + +相机管理器类,使用前需要通过getCameraManager获取相机管理实例。 + +### getCameras + +getCameras(callback: AsyncCallback\>): void + +异步获取设备支持的相机列表,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------- | ---- | ------------------------------------ | +| callback | AsyncCallback\> | 是 | 使用callback方式获取支持的相机列表。 | + +**示例:** + +``` +cameraManager.getCameras((err, cameras) => { + if (err) { + console.error('Failed to get the cameras. ${err.message}'); + return; + } + console.log('Callback returned with an array of supported cameras: ' + cameras.length); +}) +``` + +### getCameras + +getCameras(): Promise\> + +异步获取设备支持的相机列表,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------- | ----------------------------- | +| Promise\> | 使用promise获取支持相机列表。 | + + +**示例:** + +``` +cameraManager.getCameras().then((cameraArray) => { + console.log('Promise returned with an array of supported cameras: ' + cameraArray.length); +}) +``` + +### createCameraInput + +createCameraInput(cameraId: string, callback: AsyncCallback): void + +使用相机ID异步创建CameraInput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 默认值 | 必填 | 说明 | +| -------- | ------------------------------------------- | ---- | ----------------------------------- | +| cameraId | string | 是 | 指定相机ID。 | +| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 | + +**示例:** + +``` +cameraManager.createCameraInput(cameraId, (err, cameraInput) => { + if (err) { + console.error('Failed to create the CameraInput instance. ${err.message}'); + return; + } + console.log('Callback returned with the CameraInput instance.'); +}) +``` + +### createCameraInput + +createCameraInput(cameraId: string): Promise + +使用相机ID异步创建CameraInput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 默认值 | 必填 | 说明 | +| -------- | ------ | ---- | ------------ | +| cameraId | string | 是 | 指定相机ID。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------- | ---------------------------------------- | +| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | + +**示例:** + +``` +cameraManager.createCameraInput(cameraId).then((cameraInput) => { + console.log('Promise returned with the CameraInput instance'); +}) +``` + +### createCameraInput + +createCameraInput(position: CameraPosition, type: CameraType, callback: AsyncCallback): void + +使用相机位置和相机类型异步创建CameraInput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------- | ---- | ----------------------------------- | +| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 | +| type | [CameraType](#cameratype) | 是 | 相机类型。 | +| callback | AsyncCallback<[CameraInput](#camerainput)\> | 是 | 回调函数,用于获取CameraInput实例。 | + +**示例:** + +``` +cameraManager.createCameraInput(cameraPosition, cameraType, (err, cameraInput) => { + if (err) { + console.error('Failed to create the CameraInput instance. ${err.message}'); + return; + } + console.log('Callback returned with the CameraInput instance'); +}) +``` + +### createCameraInput + +createCameraInput(position: CameraPosition, type: CameraType): Promise + +使用相机位置和相机类型异步创建CameraInput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | --------------------------------- | ---- | ---------- | +| position | [CameraPosition](#cameraposition) | 是 | 相机位置。 | +| type | [CameraType](#cameratype) | 是 | 相机类型。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------- | ---------------------------------------- | +| Promise<[CameraInput](#camerainput)\> | 使用Promise的方式获取CameraInput的实例。 | + +**示例:** + +``` +cameraManager.createCameraInput(cameraPosition, cameraType).then((cameraInput) => { + console.log('Promise returned with the CameraInput instance.'); +}) +``` + +### on('cameraStatus') + +on(type: 'cameraStatus', callback: AsyncCallback): void + +监听相机的状态变化,通过注册回调函数获取相机的状态变化。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------------------------- | :--- | :--------------------------------------------------- | +| type | string | 是 | 监听事件,固定为'cameraStatus',即相机状态变化事件。 | +| callback | AsyncCallback<[CameraStatusInfo](#camerastatusinfo)\> | 是 | 回调函数,用于获取相机状态变化信息。 | + +**示例:** + +``` +cameraManager.on('cameraStatus', (cameraStatusInfo) => { + console.log('camera : ' + cameraStatusInfo.camera.cameraId); + console.log('status: ' + cameraStatusInfo.status); +}) +``` + +## Camera + +调用[camera.getCameraManager](#cameragetcameramanager)后,将返回Camera实例,包括相机ID、位置、类型、连接类型等相机相关的元数据。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 类型 | 只读 | 说明 | +| -------------- | --------------------------------- | ---- | -------------- | +| cameraId | string | 是 | 相机ID。 | +| cameraPosition | [CameraPosition](#cameraposition) | 是 | 相机位置。 | +| cameraType | [CameraType](#cameratype) | 是 | 相机类型。 | +| connectionType | [ConnectionType](#connectiontype) | 是 | 相机连接类型。 | + +**示例:** + +``` +async function getCameraInfo() { + var cameraManager = await camera.getCameraManager(); + var cameras = await cameraManager.getCameras(); + var cameraObj = cameras[0]; + var cameraId = cameraObj.cameraId; + var cameraPosition = cameraObj.cameraPosition; + var cameraType = cameraObj.cameraType; + var cameraId = cameraObj.connectionType; +} + +``` + +## CameraStatusInfo + +相机管理器回调返回的接口实例,表示相机状态信息。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 类型 | 说明 | +| ------ | ----------------------------- | ---------- | +| camera | [Camera](#camera) | 相机信息。 | +| status | [CameraStatus](#camerastatus) | 相机状态。 | + + +## CameraInput + +相机输入类。在使用该类的方法前,需要先构建一个CameraInput实例。 + +### getCameraId + +getCameraId(callback: AsyncCallback\): void + +异步获取该CameraInput实例的相机ID,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | -------------------------- | +| callback | AsyncCallback | 是 | 回调函数,用于获取相机ID。 | + +**示例:** + +``` +cameraInput.getCameraId((err, cameraId) => { + if (err) { + console.error('Failed to get the camera ID. ${err.message}'); + return; + } + console.log('Callback returned with the camera ID: ' + cameraId); +}) +``` + +### getCameraId + +getCameraId(): Promise + +异步获取该CameraInput实例的相机ID,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ---------------- | ----------------------------- | +| Promise | 使用Promise的方式获取相机ID。 | + +**示例:** + +``` +cameraInput.getCameraId().then((cameraId) => { + console.log('Promise returned with the camera ID:' + cameraId); +}) +``` + + +### hasFlash + +hasFlash(callback: AsyncCallback): void + +判断设备是否支持闪光灯,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback | 是 | 回调函数,返回true表示设备支持闪光灯。 | + +**示例:** + +``` +cameraInput.hasFlash((err, status) => { + if (err) { + console.error('Failed to check whether the device has flash light. ${err.message}'); + return; + } + console.log('Callback returned with flash light support status: ' + status); +}) +``` + +### hasFlash + +hasFlash(): Promise + +判断设备是否支持闪光灯,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ------------------------------------------------------- | +| Promise | 使用Promise的方式获取结果,返回true表示设备支持闪光灯。 | + +**示例:** + +``` +cameraInput.hasFlash().then((status) => { + console.log('Promise returned with the flash light support status:' + status); +}) +``` + +### isFlashModeSupported + +isFlashModeSupported(flashMode: FlashMode, callback: AsyncCallback): void + +判断设备是否支持指定闪光灯模式,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ---------------------------------------- | +| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | +| callback | AsyncCallback | 是 | 回调函数,返回true表示支持该闪光灯模式。 | + +**示例:** + +``` +cameraInput.isFlashModeSupported(flashMode, (err, status) => { + if (err) { + console.error('Failed to check whether the flash mode is supported. ${err.message}'); + return; + } + console.log('Callback returned with the flash mode support status: ' + status); +}) +``` + +### isFlashModeSupported + +isFlashModeSupported(flashMode: FlashMode): Promise + +判断设备是否支持指定闪光灯模式,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ---------------- | +| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ------------------------------------------------------------ | +| Promise | 使用Promise的方式获取结果,返回true表示设备支持该闪光灯模式。 | + +**示例:** + +``` +cameraInput.isFlashModeSupported(flashMode).then((status) => { + console.log('Promise returned with flash mode support status.' + status); +}) +``` + +### setFlashMode + +setFlashMode(flashMode: FlashMode, callback: AsyncCallback): void + +设置闪光灯模式,通过注册回调函数获取结果。 + +进行设置之前,需要先检查: + +1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)。 +2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ------------------------ | +| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.setFlashMode(flashMode, (err) => { + if (err) { + console.error('Failed to set the flash mode ${err.message}'); + return; + } + console.log('Callback returned with the successful execution of setFlashMode.'); +}) +``` + +### setFlashMode + +setFlashMode(flashMode: FlashMode): Promise + +设置闪光灯模式,通过Promise获取结果。 + +进行设置之前,需要先检查: + +1. 设备是否支持闪光灯,可使用方法[hasFlash](#hasflash)。 +2. 设备是否支持指定的闪光灯模式,可使用方法[isFlashModeSupported](#isflashmodesupported)。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ----------------------- | ---- | ---------------- | +| flashMode | [FlashMode](#flashmode) | 是 | 指定闪光灯模式。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +cameraInput.setFlashMode(flashMode).then(() => { + console.log('Promise returned with the successful execution of setFlashMode.'); +}) +``` + +### getFlashMode + +getFlashMode(callback: AsyncCallback): void + +获取当前设备的闪光灯模式,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------- | ---- | ---------------------------------------- | +| callback | AsyncCallback<[FlashMode](#flashmode)\> | 是 | 回调函数,用于获取当前设备的闪光灯模式。 | + +**示例:** + +``` +cameraInput.getFlashMode((err, flashMode) => { + if (err) { + console.error('Failed to get the flash mode ${err.message}'); + return; + } + console.log('Callback returned with current flash mode: ' + flashMode); +}) +``` + +### getFlashMode + +getFlashMode(): Promise + +获取当前设备的闪光灯模式,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| --------------------------------- | --------------------------------------- | +| Promise<[FlashMode](#flashmode)\> | 使用Promise的方式获取当前的闪光灯模式。 | + +**示例:** + +``` +cameraInput.getFlashMode().then((flashMode) => { + console.log('Promise returned with current flash mode : ' + flashMode); +}) +``` + +### isFocusModeSupported + +isFocusModeSupported(afMode: FocusMode, callback: AsyncCallback): void + +判断设备是否支持指定的焦距模式,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | -------------------------------------- | +| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | +| callback | AsyncCallback | 是 | 回调函数,返回true表示支持该焦距模式。 | + +**示例:** + +``` +cameraInput.isFocusModeSupported(afMode, (err, status) => { + if (err) { + console.error('Failed to check whether the focus mode is supported. ${err.message}'); + return; + } + console.log('Callback returned with the focus mode support status: ' + status); +}) +``` + +### isFocusModeSupported + +isFocusModeSupported(afMode: FocusMode): Promise + +判断设备是否支持指定的焦距模式,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------- | ----------------------------------------------------------- | +| Promise | 使用Promise的方式获取结果,返回true表示设备支持该焦距模式。 | + +**示例:** + +``` +cameraInput.isFocusModeSupported(afMode).then((status) => { + console.log('Promise returned with focus mode support status.' + status); +}) +``` + +### setFocusMode + +setFocusMode(afMode: FocusMode, callback: AsyncCallback): void + +设置焦距模式,通过注册回调函数获取结果。 + +进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | ------------------------ | +| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.setFocusMode(afMode, (err) => { + if (err) { + console.error('Failed to set the focus mode ${err.message}'); + return; + } + console.log('Callback returned with the successful execution of setFocusMode.'); +}) +``` + +### setFocusMode + +setFocusMode(afMode: FocusMode): Promise + +设置焦距模式,通过Promise获取结果。 + +进行设置之前,需要先检查设备是否支持指定的焦距模式,可使用方法[isFocusModeSupported](#isfocusmodesupported)。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------ | ----------------------- | ---- | ---------------- | +| afMode | [FocusMode](#focusmode) | 是 | 指定的焦距模式。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +cameraInput.setFocusMode(afMode).then(() => { + console.log('Promise returned with the successful execution of setFocusMode.'); +}) +``` + +### getFocusMode + +getFocusMode(callback: AsyncCallback): void + +获取当前设备的焦距模式,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------- | ---- | -------------------------------------- | +| callback | AsyncCallback<[FocusMode](#focusmode)\> | 是 | 回调函数,用于获取当前设备的焦距模式。 | + +**示例:** + +``` +cameraInput.getFocusMode((err, afMode) => { + if (err) { + console.error('Failed to get the focus mode ${err.message}'); + return; + } + console.log('Callback returned with current focus mode: ' + afMode); +}) +``` + +### getFocusMode + +getFocusMode(): Promise + +获取当前设备的焦距模式,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ------------------------------------- | +| Promise | 使用Promise的方式获取当前的焦距模式。 | + +**示例:** + +``` +cameraInput.getFocusMode().then((afMode) => { + console.log('Promise returned with current focus mode : ' + afMode); +}) +``` + +### getZoomRatioRange + +getZoomRatioRange\(callback: AsyncCallback\>\): void + +获取可变焦距比范围,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------ | ---- | ------------------------ | +| callback | AsyncCallback\> | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.getZoomRatioRange((err, zoomRatioRange) => { + if (err) { + console.error('Failed to get the zoom ratio range. ${err.message}'); + return; + } + console.log('Callback returned with zoom ratio range: ' + zoomRatioRange.length); +}) +``` + +### getZoomRatioRange + +getZoomRatioRange\(\): Promise\> + +获取可变焦距比范围,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ------------------------ | ------------------------------------------- | +| Promise\> | 使用Promise的方式获取当前的可变焦距比范围。 | + +**示例:** + +``` +cameraInput.getZoomRatioRange().then((zoomRatioRange) => { + console.log('Promise returned with zoom ratio range: ' + zoomRatioRange.length); +}) +``` + +### setZoomRatio + +setZoomRatio(zoomRatio: number, callback: AsyncCallback): void + +设置可变焦距比,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | -------------------- | ---- | ------------------------ | +| zoomRatio | number | 是 | 可变焦距比。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.setZoomRatio(zoomRatio, (err) => { + if (err) { + console.error('Failed to set the zoom ratio value ${err.message}'); + return; + } + console.log('Callback returned with the successful execution of setZoomRatio.'); +}) +``` + +### setZoomRatio + +setZoomRatio(zoomRatio: number): Promise + +设置可变焦距比,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | ------------ | +| zoomRatio | number | 是 | 可变焦距比。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +cameraInput.setZoomRatio(zoomRatio).then(() => { + console.log('Promise returned with the successful execution of setZoomRatio.'); +}) +``` + +### getZoomRatio + +getZoomRatio(callback: AsyncCallback): void + +获取当前的可变焦距比,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.getZoomRatio((err, zoomRatio) => { + if (err) { + console.error('Failed to get the zoom ratio ${err.message}'); + return; + } + console.log('Callback returned with current zoom ratio: ' + zoomRatio); +}) +``` + +### getZoomRatio + +getZoomRatio(): Promise + +获取当前的可变焦距比,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| ---------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +cameraInput.getZoomRatio().then((zoomRatio) => { + console.log('Promise returned with current zoom ratio : ' + zoomRatio); +}) +``` + +### release + +release\(callback: AsyncCallback\): void + +释放相机实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +camera.release((err) => { + if (err) { + console.error('Failed to release the CameraInput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the CameraInput instance is released successfully.'); +}); +``` + +### release + +release(): Promise + +释放相机实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +cameraInput.release().then(() => { + console.log('Promise returned to indicate that the CameraInput instance is released successfully.'); +}) +``` + +### on('focusStateChange') + +on(type: 'focusStateChange', callback: AsyncCallback): void + +监听焦距的状态变化,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------------- | :--- | :------------------------------------------------------- | +| type | string | 是 | 监听事件,固定为'focusStateChange',即焦距状态变化事件。 | +| callback | AsyncCallback<[FocusState](#focusstate)\> | 是 | 回调函数,用于获取焦距状态。 | + +**示例:** + +``` +cameraInput.on('focusStateChange', (focusState) => { + console.log('Focus state : ' + focusState); +}) +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +监听CameraInput的错误事件,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------------------- | :--- | :---------------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即CamerInput错误事件。 | +| callback | ErrorCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +cameraInput.on('error', (cameraInputError) => { + console.log('Camera input error code: ' + cameraInputError.code); +}) +``` + + +## FlashMode + +枚举,闪光灯模式。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| ---------------------- | ------ | ------------ | +| FLASH_MODE_CLOSE | 0 | 闪光灯关闭。 | +| FLASH_MODE_OPEN | 1 | 闪光灯开启。 | +| FLASH_MODE_AUTO | 2 | 自动闪光灯。 | +| FLASH_MODE_ALWAYS_OPEN | 3 | 闪光灯常亮。 | + +## FocusMode + +枚举,焦距模式。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| -------------------------- | ------ | ------------------ | +| FOCUS_MODE_MANUAL | 0 | 手动变焦模式。 | +| FOCUS_MODE_CONTINUOUS_AUTO | 1 | 连续自动变焦模式。 | +| FOCUS_MODE_AUTO | 2 | 自动变焦模式。 | +| FOCUS_MODE_LOCKED | 3 | 定焦模式。 | + +## FocusState + +枚举,焦距状态。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| --------------------- | ------ | ------------ | +| FOCUS_STATE_SCAN | 0 | 扫描状态。 | +| FOCUS_STATE_FOCUSED | 1 | 相机已对焦。 | +| FOCUS_STATE_UNFOCUSED | 2 | 相机未对焦。 | + +## camera.createCaptureSession + +createCaptureSession\(context: Context, callback: AsyncCallback\): void + +获取CaptureSession实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------- | ---- | -------------------------------------- | +| context | Context | 是 | 应用上下文。 | +| callback | AsyncCallback<[CaptureSession](#capturesession)\> | 是 | 回调函数,用于获取CaptureSession实例。 | + +**示例:** + +``` +camera.createCaptureSession((context), (err, captureSession) => { + if (err) { + console.error('Failed to create the CaptureSession instance. ${err.message}'); + return; + } + console.log('Callback returned with the CaptureSession instance.' + captureSession); +}); +``` + +## camera.createCaptureSession + +createCaptureSession(context: Context\): Promise; + +获取CaptureSession实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------- | ------- | ---- | ------------ | +| context | Context | 是 | 应用上下文。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------- | ----------------------------------------- | +| Promise<[CaptureSession](#capturesession)\> | 使用Promise的方式获取CaptureSession实例。 | + +**示例:** + +``` +camera.createCaptureSession(context).then((captureSession) => { + console.log('Promise returned with the CaptureSession instance'); +}) +``` + +## CaptureSession + +拍照会话类。 + +### beginConfig + +beginConfig\(callback: AsyncCallback\): void + +开始配置会话,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.beginConfig((err) => { + if (err) { + console.error('Failed to start the configuration. ${err.message}'); + return; + } + console.log('Callback invoked to indicate the begin config success.'); +}); +``` + +### beginConfig + +beginConfig\(\): Promise + +开始配置会话,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +captureSession.beginConfig().then(() => { + console.log('Promise returned to indicate the begin config success.'); +}) +``` + +### commitConfig + +commitConfig\(callback: AsyncCallback\): void + +提交会话配置,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.commitConfig((err) => { + if (err) { + console.error('Failed to commit the configuration. ${err.message}'); + return; + } + console.log('Callback invoked to indicate the commit config success.'); +}); +``` + +### commitConfig + +commitConfig\(\): Promise + +提交会话配置,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.commitConfig().then(() => { + console.log('Promise returned to indicate the commit config success.'); +}) +``` + +### addInput + +addInput\(cameraInput: CameraInput, callback: AsyncCallback\): void + +在当前会话中,添加一个CameraInput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.addInput(cameraInput, (err) => { + if (err) { + console.error('Failed to add the CameraInput instance. ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the CameraInput instance is added.'); +}); +``` + +### addInput + +addInput\(cameraInput: CameraInput\): Promise + +在当前会话中,添加一个CameraInput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | 是 | 需要添加的CameraInput实例。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.addInput(cameraInput).then(() => { + console.log('Promise used to indicate that the CameraInput instance is added.'); +}) +``` + +### addOutput + +addOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void + +在当前会话中,添加一个PreviewOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.addOutput(previewOutput, (err) => { + if (err) { + console.error('Failed to add the PreviewOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PreviewOutput instance is added.'); +}); +``` + +### addOutput + +addOutput\(previewOutput: PreviewOutput\): Promise + +在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要添加的PreviewOutput实例。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.addOutput(previewOutput).then(() => { + console.log('Promise used to indicate that the PreviewOutput instance is added.'); +}) +``` + +### addOutput + +addOutput\(photoOutput: PhotoOutput, callback: AsyncCallback\): void + +在当前会话中,添加一个PhotoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.addOutput(photoOutput, (err) => { + if (err) { + console.error('Failed to add the PhotoOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PhotoOutput instance is added.'); +}); +``` + +### addOutput + +addOutput\(photoOutput: PhotoOutput\): Promise + +在当前会话中,添加一个PreviewOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise\ | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.addOutput(photoOutput).then(() => { + console.log('Promise used to indicate that the PhotoOutput instance is added.'); +}) +``` + +### addOutput + +addOutput\(videoOutput: VideoOutput, callback: AsyncCallback\): void + +在当前会话中,添加一个VideoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.addOutput(videoOutput, (err) => { + if (err) { + console.error('Failed to add the VideoOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the VideoOutput instance is added.'); +}); +``` + +### addOutput + +addOutput\(videoOutput: VideoOutput\): Promise + +在当前会话中,添加一个VideoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise\ | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.addOutput(videoOutput).then(() => { + console.log('Promise used to indicate that the VideoOutput instance is added.'); +}) +``` + +### removeInput + +removeInput\(cameraInput: CameraInput, callback: AsyncCallback\): void + +在当前会话中,移除一个CameraInput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.removeInput(cameraInput, (err) => { + if (err) { + console.error('Failed to remove the CameraInput instance. ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the cameraInput instance is removed.'); +}); +``` + +### removeInput + +removeInput\(cameraInput: CameraInput\): Promise + +在当前会话中,移除一个CameraInput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| cameraInput | [CameraInput](#camerainput) | 是 | 需要移除的CameraInput实例。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise\ | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.removeInput(cameraInput).then(() => { + console.log('Promise returned to indicate that the cameraInput instance is removed.'); +}) +``` + +### removeOutput + +removeOutput\(previewOutput: PreviewOutput, callback: AsyncCallback\): void + +在当前会话中,移除一个PreviewOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.removeOutput(previewOutput, (err) => { + if (err) { + console.error('Failed to remove the PreviewOutput instance. ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PreviewOutput instance is removed.'); +}); +``` + +### removeOutput + +removeOutput(previewOutput: PreviewOutput): Promise + +在当前会话中,移除一个PreviewOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------------- | ------------------------------- | ---- | ----------------------------- | +| previewOutput | [PreviewOutput](#previewoutput) | 是 | 需要移除的PreviewOutput实例。 | + + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +captureSession.removeOutput(previewOutput).then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is removed.'); +}) +``` + +### removeOutput + +removeOutput(photoOutput: PhotoOutput, callback: AsyncCallback): void + +在当前会话中,移除一个PhotoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.removeOutput(photoOutput, (err) => { + if (err) { + console.error('Failed to remove the PhotoOutput instance. ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PhotoOutput instance is removed.'); +}); +``` + +### removeOutput + +removeOutput(photoOutput: PhotoOutput): Promise + +在当前会话中,移除一个PhotoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| photoOutput | [PhotoOutput](#photooutput) | 是 | 需要添加的PhotoOutput实例。 | + + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +captureSession.removeOutput(photoOutput).then(() => { + console.log('Promise returned to indicate that the PhotoOutput instance is removed.'); +}) +``` + +### removeOutput + +removeOutput(videoOutput: VideoOutput, callback: AsyncCallback): void + +在当前会话中,移除一个VideoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.removeOutput(videoOutput, (err) => { + if (err) { + console.error('Failed to remove the VideoOutput instance. ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the VideoOutput instance is removed.'); +}); +``` + +### removeOutput + +removeOutput(videoOutput: VideoOutput): Promise + +在当前会话中,移除一个VideoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ----------- | --------------------------- | ---- | --------------------------- | +| videoOutput | [VideoOutput](#videooutput) | 是 | 需要添加的VideoOutput实例。 | + + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +captureSession.removeOutput(videoOutput).then(() => { + console.log('Promise returned to indicate that the VideoOutput instance is removed.'); +}) +``` + +### start + +start\(callback: AsyncCallback\): void + +启动拍照会话,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.start((err) => { + if (err) { + console.error('Failed to start the session ${err.message}'); + return; + } + console.log('Callback invoked to indicate the session start success.'); +}); +``` + +### start + +start\(\): Promise + +启动拍照会话,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.start().then(() => { + console.log('Promise returned to indicate the session start success.'); +}) +``` + +### stop + +stop\(callback: AsyncCallback\): void + +停止拍照会话,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.stop((err) => { + if (err) { + console.error('Failed to stop the session ${err.message}'); + return; + } + console.log('Callback invoked to indicate the session stop success.'); +}); +``` + +### stop + +stop(): Promise + +停止拍照会话,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.stop().then(() => { + console.log('Promise returned to indicate the session stop success.'); +}) +``` + +### release + +release\(callback: AsyncCallback\): void + +释放CaptureSession实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +captureSession.release((err) => { + if (err) { + console.error('Failed to release the CaptureSession instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the CaptureSession instance is released successfully.'); +}); +``` + +### release + +release(): Promise + +释放CaptureSession实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +captureSession.release().then(() => { + console.log('Promise returned to indicate that the CaptureSession instance is released successfully.'); +}) +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +监听拍照会话的错误事件,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :---------------------------------- | :--- | :-------------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即拍照会话错误事件。 | +| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | + +**示例:** + +``` +captureSession.on('error', (captureSessionError) => { + console.log('Capture session error code: ' + captureSessionError.code); +}) +``` + +## camera.createPreviewOutput + +createPreviewOutput(surfaceId: string, callback: AsyncCallback): void + +获取PreviewOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ----------------------------------------------- | ---- | ------------------------------------- | +| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 | +| callback | AsyncCallback<[PreviewOutput](#previewoutput)\> | 是 | 回调函数,用于获取PreviewOutput实例。 | + +**示例:** + +``` +camera.createPreviewOutput((surfaceId), (err, previewOutput) => { + if (err) { + console.error('Failed to create the PreviewOutput instance. ${err.message}'); + return; + } + console.log('Callback returned with previewOutput instance'); +}); +``` + +## camera.createPreviewOutput + +createPreviewOutput(surfaceId: string): Promise\ + +获取PreviewOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | ---------------------------------- | +| surfaceId | string | 是 | 从XComponent组件获取的Surface ID。 | + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | --------------------------- | +| Promise<[PreviewOutput](#previewoutput)\> | 使用Promise的方式获取结果。 | + +**示例:** + +``` +camera.createPreviewOutput(surfaceId).then((previewOutput) => { + console.log('Promise returned with the PreviewOutput instance'); +}) +``` + +## PreviewOutput + +预览输出类。 + +### release + +release(callback: AsyncCallback): void + +释放PreviewOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +previewOutput.release((err) => { + if (err) { + console.error('Failed to release the PreviewOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PreviewOutput instance is released successfully.'); +}); +``` + +### release + +release(): Promise + +释放PreviewOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +previewOutput.release().then(() => { + console.log('Promise returned to indicate that the PreviewOutput instance is released successfully.'); +}) +``` + +### on('frameStart') + +on(type: 'frameStart', callback: AsyncCallback): void + +监听预览帧启动,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------- | :--- | :------------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameStart',即帧启动事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +previewOutput.on('frameStart', () => { + console.log('Preview frame started'); +}) +``` + +### on('frameEnd') + +on(type: 'frameEnd', callback: AsyncCallback): void + +监听预览帧结束,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------- | :--- | :----------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameEnd',即帧结束事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +previewOutput.on('frameEnd', () => { + console.log('Preview frame ended'); +}) +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +监听预览输出的错误事件,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :--------------------------------- | :--- | :-------------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即预览输出错误事件。 | +| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | + +**示例:** + +``` +previewOutput.on('error', (previewOutputError) => { + console.log('Preview output error code: ' + previewOutputError.code); +}) +``` + +## camera.createPhotoOutput + +createPhotoOutput(surfaceId: string, callback: AsyncCallback): void + +获取PhotoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 | +| callback | AsyncCallback<[PhotoOutput](#photooutput)\> | 是 | 回调函数,用于获取PhotoOutput实例。 | + +**示例:** + +``` +camera.createPhotoOutput((surfaceId), (err, photoOutput) => { + if (err) { + console.error('Failed to create the PhotoOutput instance. ${err.message}'); + return; + } + console.log('Callback returned with the PhotoOutput instance.'); +}); +``` + +## camera.createPhotoOutput + +createPhotoOutput(surfaceId: string): Promise + +获取PhotoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | 是 | 从ImageReceiver获取的Surface ID。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------- | -------------------------------------- | +| Promise<[PhotoOutput](#photooutput)\> | 使用Promise的方式获取PhotoOutput实例。 | + +**示例:** + +``` +camera.createPhotoOutput(surfaceId).then((photoOutput) => { + console.log('Promise returned with PhotoOutput instance'); +}) +``` +## ImageRotation + +枚举,图片旋转角度。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| ------------ | ------ | --------------- | +| ROTATION_0 | 0 | 图片旋转0度。 | +| ROTATION_90 | 90 | 图片旋转90度。 | +| ROTATION_180 | 180 | 图片旋转180度。 | +| ROTATION_270 | 270 | 图片旋转270度。 | + + + +## QualityLevel + +枚举,图片质量。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 默认值 | 说明 | +| -------------------- | ------ | -------------- | +| QUALITY_LEVEL_HIGH | 0 | 图片质量高。 | +| QUALITY_LEVEL_MEDIUM | 1 | 图片质量中等。 | +| QUALITY_LEVEL_LOW | 2 | 图片质量差。 | + + +## PhotoCaptureSetting + +拍摄照片的设置。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Camera.Core。 + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------- | ---- | -------------- | +| quality | [QualityLevel](#qualitylevel) | 否 | 图片质量。 | +| rotation | [ImageRotation](#imagerotation) | 否 | 图片旋转角度。 | + + +## PhotoOutput + +照片输出类。 + +### capture + +capture(callback: AsyncCallback): void + +拍照,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +photoOutput.capture((err) => { + if (err) { + console.error('Failed to capture the photo ${err.message}'); + return; + } + console.log('Callback invoked to indicate the photo capture request success.'); +}); +``` + +### capture + +capture(setting: PhotoCaptureSetting, callback: AsyncCallback): void + +根据拍照设置拍照,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------- | ---- | ------------------------ | +| setting | [PhotoCaptureSetting](#photocapturesetting) | 是 | 拍照设置。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +photoOutput.capture(settings, (err) => { + if (err) { + console.error('Failed to capture the photo ${err.message}'); + return; + } + console.log('Callback invoked to indicate the photo capture request success.'); +}); +``` + +### capture + +capture(setting?: PhotoCaptureSetting): Promise + +根据拍照设置拍照,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------------- | ---- | ---------- | +| setting | [PhotoCaptureSetting](#photocapturesetting) | 否 | 拍照设置。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +photoOutput.capture().then(() => { + console.log('Promise returned to indicate that photo capture request success.'); +}) +``` + +### release + +release(callback: AsyncCallback): void + +释放PhotoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +photoOutput.release((err) => { + if (err) { + console.error('Failed to release the PhotoOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the PhotoOutput instance is released successfully.'); +}); +``` + +### release + +release(): Promise + +释放PhotoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +photoOutput.release().then(() => { + console.log('Promise returned to indicate that the PhotoOutput instance is released successfully.'); +}) +``` + +### on('captureStart') + +on(type: 'captureStart', callback: AsyncCallback): void + +监听拍照启动,通过注册回调函数获取Capture ID。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :--------------------- | :--- | :----------------------------------------------- | +| type | string | 是 | 监听事件,固定为'captureStart',即拍照启动事件。 | +| callback | AsyncCallback | 是 | 使用callback的方式获取Capture ID。 | + +**示例:** + +``` +photoOutput.on('captureStart', (captureId) => { + console.log('photo capture stated, captureId : ' + captureId); +}) +``` + +### on('frameShutter') + +on(type: 'frameShutter', callback: AsyncCallback): void + +监听帧刷新,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------------------- | :--- | :--------------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameShutter',即帧刷新事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取相关信息。 | + +**示例:** + +``` +photoOutput.on('frameShutter', (frameShutterInfo) => { + console.log('photo capture end, captureId : ' + frameShutterInfo.captureId); + console.log('Timestamp for frame : ' + frameShutterInfo.timestamp); +}) +``` + +### on('captureEnd') + +on(type: 'captureEnd', callback: AsyncCallback): void + +监听拍照停止,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :----------------------------- | :--- | :--------------------------------------------- | +| type | string | 是 | 监听事件,固定为'captureEnd',即拍照停止事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取相关信息。 | + +**示例:** + +``` +photoOutput.on('captureEnd', (captureEndInfo) => { + console.log('photo capture end, captureId : ' + captureEndInfo.captureId); + console.log('frameCount : ' + captureEndInfo.frameCount); +}) +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +监听拍照的错误事件,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------------------- | :--- | :---------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即拍照错误事件。 | +| callback | ErrorCallback | 是 | 回调函数,用于获取错误信息。 | + +**示例:** + +``` +photoOutput.on('error', (photoOutputError) => { + console.log('Photo output error code: ' + photoOutputError.code); +}) +``` + +## camera.createVideoOutput + +createVideoOutput(surfaceId: string, callback: AsyncCallback): void + +获取VideoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------------------------------------------- | ---- | ----------------------------------- | +| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 | +| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 | + +**示例:** + +``` +camera.createVideoOutput((surfaceId), (err, videoOutput) => { + if (err) { + console.error('Failed to create the VideoOutput instance. ${err.message}'); + return; + } + console.log('Callback returned with the VideoOutput instance'); +}); +``` + +## camera.createVideoOutput + +createVideoOutput(surfaceId: string): Promise + +获取VideoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------ | ---- | --------------------------------- | +| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------------------------- | -------------------------------------- | +| Promise<[VideoOutput](#videooutput)\> | 使用Promise的方式获取VideoOutput实例。 | + +**示例:** + +``` +camera.createVideoOutput(surfaceId).then((videoOutput) => { + console.log('Promise returned with the VideoOutput instance'); +}) +``` + +## VideoOutput + +视频输出类。 + +### start + +start(callback: AsyncCallback): void + +开始拍摄视频,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +videoOutput.start((err) => { + if (err) { + console.error('Failed to start the video output ${err.message}'); + return; + } + console.log('Callback invoked to indicate the video output start success.'); +}); +``` + +### start + +start(): Promise + +开始拍摄视频,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +videoOutput.start().then(() => { + console.log('Promise returned to indicate that start method execution success.'); +}) +``` + +### stop + +stop(callback: AsyncCallback): void + +停止拍摄视频,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +videoOutput.stop((err) => { + if (err) { + console.error('Failed to stop the video output ${err.message}'); + return; + } + console.log('Callback invoked to indicate the video output stop success.'); +}); +``` + +### stop + +stop(): Promise + +停止拍摄视频,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + +**示例:** + +``` +videoOutput.start().then(() => { + console.log('Promise returned to indicate that stop method execution success.'); +}) +``` + +### release + +release(callback: AsyncCallback): void + +释放VideoOutput实例,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------ | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +videoOutput.release((err) => { + if (err) { + console.error('Failed to release the VideoOutput instance ${err.message}'); + return; + } + console.log('Callback invoked to indicate that the VideoOutput instance is released successfully.'); +}); +``` + +### release + +release(): Promise + +释放VideoOutput实例,通过Promise获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------- | +| Promise | 使用Promise的方式获取结果。 | + + +**示例:** + +``` +videoOutput.release().then(() => { + console.log('Promise returned to indicate that the VideoOutput instance is released successfully.'); +}) +``` + +### on('frameStart') + +on(type: 'frameStart', callback: AsyncCallback): void + +监听视频帧开启,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------- | :--- | :----------------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameStart',即视频帧开启事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +videoOutput.on('frameStart', () => { + console.log('Video frame started'); +}) +``` + +### on('frameEnd') + +on(type: 'frameEnd', callback: AsyncCallback): void + +监听视频帧结束,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :------------------- | :--- | :--------------------------------------------- | +| type | string | 是 | 监听事件,固定为'frameEnd',即视频帧结束事件。 | +| callback | AsyncCallback | 是 | 回调函数,用于获取结果。 | + +**示例:** + +``` +videoOutput.on('frameEnd', () => { + console.log('Video frame ended'); +}) +``` + +### on('error') + +on(type: 'error', callback: ErrorCallback): void + +监听视频输出的错误事件,通过注册回调函数获取结果。 + +**系统能力:** SystemCapability.Multimedia.Camera.Core + +**参数:** + +| 名称 | 类型 | 必填 | 说明 | +| :------- | :-------------------------- | :--- | :-------------------------------------------- | +| type | string | 是 | 监听事件,固定为'error',即视频输出错误事件。 | +| callback | Callback | 是 | 回调函数,用于获取错误信息。 | + +**示例:** + +``` +videoOutput.on('error', (VideoOutputError) => { + console.log('Video output error code: ' + VideoOutputError.code); +}) +``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-image.md b/zh-cn/application-dev/reference/apis/js-apis-image.md index 288224034f0ceb866bc5f3d979bd0bf40c2a4471..ebeb82fce7c58a8115e4c06e734cb557a4603ed5 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-image.md +++ b/zh-cn/application-dev/reference/apis/js-apis-image.md @@ -2,6 +2,8 @@ > **说明:** > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 ## 导入模块 @@ -990,14 +992,40 @@ release(): Promise\ | RGBA_8888 | 3 | 格式为RGBA_8888。 | | RGB_565 | 2 | 格式为RGB_565。 | +## AlphaType9+ + +枚举,透明度。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image + +| 名称 | 默认值 | 描述 | +| -------- | ------ | ----------------------- | +| UNKNOWN | 0 | 未知透明度。 | +| OPAQUE | 1 | 没有alpha或图片全透明。 | +| PREMUL | 2 | RGB前乘alpha。 | +| UNPREMUL | 3 | RGB不前乘alpha。 | + +## ScaleMode9+ + +枚举,缩略值。 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image + +| 名称 | 默认值 | 描述 | +| --------------- | ------ | -------------------------------------------------- | +| CENTER_CROP | 1 | 缩放图像以填充目标图像区域并居中裁剪区域外的效果。 | +| FIT_TARGET_SIZE | 2 | 图像适合目标尺寸的效果。 | + ## InitializationOptions8+ **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image | 名称 | 类型 | 可读 | 可写 | 说明 | | ----------- | ---------------------------------- | ---- | ---- | -------------- | +| alphaType9+ | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | | editable | boolean | 是 | 是 | 是否可编辑。 | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | +| scaleMode9+ | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | | size | [Size](#size) | 是 | 是 | 创建图片大小。 | ## DecodingOptions7+ @@ -1058,7 +1086,7 @@ release(): Promise\ | 名称 | 默认值 | 说明 | | ----------------- | ----------------- | -------------------- | -| BITS_PER_SAMPLE | "BitsPerSample" | 每个像素字节数。 | +| BITS_PER_SAMPLE | "BitsPerSample" | 每个像素比特数。 | | ORIENTATION | "Orientation" | 图片方向。 | | IMAGE_LENGTH | "ImageLength" | 图片长度。 | | IMAGE_WIDTH | "ImageWidth" | 图片宽度。 | diff --git a/zh-cn/application-dev/reference/apis/js-apis-media.md b/zh-cn/application-dev/reference/apis/js-apis-media.md index 62e11d63a3733f805b5d2511a4ea708e56d73f5d..7310381a79df34e456f1a216a655655f872ccf86 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-media.md +++ b/zh-cn/application-dev/reference/apis/js-apis-media.md @@ -2,6 +2,8 @@ > **说明:** > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +> +> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 媒体子系统为开发者提供一套简单且易于理解的接口,使得开发者能够方便接入系统并使用系统的媒体资源。 @@ -10,6 +12,7 @@ - 音频播放([AudioPlayer](#audioplayer)) - 视频播放([VideoPlayer](#videoplayer8)) - 音频录制([AudioRecorder](#audiorecorder)) +- 视频录制([VideoRecorder](#videorecorder9)) 后续将提供以下功能:DataSource音视频播放、音视频编解码、容器封装解封装、媒体能力查询等功能。 @@ -87,21 +90,16 @@ createVideoPlayer(): Promise<[VideoPlayer](#videoplayer8)> ```js let videoPlayer -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} - -await media.createVideoPlayer.then((video) => { - if (typeof(video) != 'undefined') { +media.createVideoPlayer().then((video) => { + if (typeof(video) != 'undefined') { videoPlayer = video; console.info('video createVideoPlayer success'); } else { console.info('video createVideoPlayer fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ## media.createAudioRecorder @@ -124,6 +122,68 @@ createAudioRecorder(): AudioRecorder let audiorecorder = media.createAudioRecorder(); ``` +## media.createVideoRecorder9+ + +createVideoRecorder(callback: AsyncCallback\<[VideoRecorder](#videorecorder9)>): void + +异步方式创建视频录制实例。通过注册回调函数获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------- | ---- | ------------------------------ | +| callback | AsyncCallback<[VideoRecorder](#videorecorder9)> | 是 | 异步创建视频录制实例回调方法。 | + +**示例:** + +```js +let videoRecorder + +media.createVideoRecorder((error, video) => { + if (typeof(video) != 'undefined') { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.info(`video createVideoRecorder fail, error:${error.message}`); + } +}); +``` + +## media.createVideoRecorder9+ + +createVideoRecorder(): Promise<[VideoRecorder](#videorecorder9)> + +异步方式创建视频录制实例。通过Promise获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| ----------------------------------------- | ----------------------------------- | +| Promise<[VideoRecorder](#videorecorder9)> | 异步创建视频录制实例Promise返回值。 | + +**示例:** + +```js +let videoRecorder + +media.createVideoRecorder().then((video) => { + if (typeof(video) != 'undefined') { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.info('video createVideoRecorder fail'); + } +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); +``` + + + ## MediaErrorCode8+ 媒体服务错误类型枚举。 @@ -225,7 +285,7 @@ Codec MIME类型枚举。 play(): void -开始播放音频资源,需在[dataLoad](#audioplayer_on)事件成功触发后,才能调用play方法。 +开始播放音频资源,需在[dataLoad](#audioplayer_on)事件成功触发后,才能调用。 **系统能力:** SystemCapability.Multimedia.Media.AudioPlayer @@ -358,7 +418,7 @@ audioPlayer = undefined; getTrackDescription(callback: AsyncCallback>): void -通过回调方式获取音频轨道信息。 +通过回调方式获取音频轨道信息。需在[dataLoad](#audioplayer_on)事件成功触发后,才能调用。 **系统能力:** SystemCapability.Multimedia.Media.AudioPlayer @@ -394,7 +454,7 @@ audioPlayer.getTrackDescription((error, arrlist) => { getTrackDescription(): Promise> -通过Promise方式获取音频轨道信息。 +通过Promise方式获取音频轨道信息。需在[dataLoad](#audioplayer_on)事件成功触发后,才能调用 **系统能力:** SystemCapability.Multimedia.Media.AudioPlayer @@ -414,20 +474,17 @@ function printfDescription(obj) { console.info('audio value is ' + property); } } -function failureCallback(error) { - console.info(`audio failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`audio catchCallback, error:${error.message}`); -} -await audioPlayer.getTrackDescription.then((arrlist) => { +audioPlayer.getTrackDescription().then((arrlist) => { if (typeof (arrlist) != 'undefined') { arrayDescription = arrlist; } else { console.log('audio getTrackDescription fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`audio catchCallback, error:${error.message}`); +}); + for (let i = 0; i < arrayDescription.length; i++) { printfDescription(arrayDescription[i]); } @@ -517,13 +574,14 @@ audioPlayer.on('error', (error) => { //设置'error'事件回调 // 用户选择视频设置fd(本地播放) let fdPath = 'fd://' -let path = 'data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; -await fileIO.open(path).then(fdNumber) => { +// path路径的码流可通过"hdc file send D:\xxx\01.mp3 /data/accounts/account_0/appdata" 命令,将其推送到设备上 +let path = '/data/accounts/account_0/appdata/ohos.xxx.xxx.xxx/01.mp3'; +fileIO.open(path).then(fdNumber) => { fdPath = fdPath + '' + fdNumber; console.info('open fd sucess fd is' + fdPath); }, (err) => { console.info('open fd failed err is' + err); -}),catch((err) => { +}).catch((err) => { console.info('open fd failed err is' + err); }); audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 @@ -667,15 +725,11 @@ setDisplaySurface(surfaceId: string): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setDisplaySurface(surfaceId).then(() => { +videoPlayer.setDisplaySurface(surfaceId).then(() => { console.info('setDisplaySurface success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### prepare8+ @@ -721,15 +775,11 @@ prepare(): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.prepare().then(() => { +videoPlayer.prepare().then(() => { console.info('prepare success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### play8+ @@ -775,15 +825,11 @@ play(): Promise\; **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.play().then(() => { +videoPlayer.play().then(() => { console.info('play success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### pause8+ @@ -829,15 +875,11 @@ pause(): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.pause().then(() => { +videoPlayer.pause().then(() => { console.info('pause success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### stop8+ @@ -883,15 +925,11 @@ stop(): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.stop().then(() => { +videoPlayer.stop().then(() => { console.info('stop success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### reset8+ @@ -937,15 +975,11 @@ reset(): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.reset().then(() => { +videoPlayer.reset().then(() => { console.info('reset success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### seek8+ @@ -1027,19 +1061,17 @@ seek(timeMs: number, mode?:SeekMode): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点 +videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点 console.info('seek success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); -await videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { +videoPlayer.seek(seekTime, seekMode).then((seekDoneTime) => { console.info('seek success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### setVolume8+ @@ -1092,15 +1124,11 @@ setVolume(vol: number): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setVolume(vol).then() => { +videoPlayer.setVolume(vol).then() => { console.info('setVolume success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### release8+ @@ -1146,15 +1174,11 @@ release(): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.release().then() => { +videoPlayer.release().then() => { console.info('release success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### getTrackDescription8+ @@ -1217,21 +1241,17 @@ function printfDescription(obj) { console.info('video value is ' + property); } } -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} let arrayDescription; -await videoPlayer.getTrackDescription().then((arrlist) => { +videoPlayer.getTrackDescription().then((arrlist) => { if (typeof (arrlist) != 'undefined') { arrayDescription = arrlist; } else { console.log('video getTrackDescription fail'); } -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); for (let i = 0; i < arrayDescription.length; i++) { printfDescription(arrayDescription[i]); } @@ -1287,15 +1307,11 @@ setSpeed(speed:number): Promise\ **示例:** ```js -function failureCallback(error) { - console.info(`video failureCallback, error:${error.message}`); -} -function catchCallback(error) { - console.info(`video catchCallback, error:${error.message}`); -} -await videoPlayer.setSpeed(speed).then() => { +videoPlayer.setSpeed(speed).then() => { console.info('setSpeed success'); -}, failureCallback).catch(catchCallback); +}).catch((error) => { + console.info(`video catchCallback, error:${error.message}`); +}); ``` ### on('playbackCompleted')8+ @@ -1768,12 +1784,650 @@ audioRecorder.prepare(); // pre | 名称 | 默认值 | 说明 | | -------- | ------ | ------------------------------------------------------------ | -| DEFAULT | 0 | 默认封装格式为MPEG-4。
仅做接口定义,暂不支持使用。 | +| DEFAULT | 0 | 默认封装格式。
仅做接口定义,暂不支持使用。 | | MPEG_4 | 2 | 封装为MPEG-4格式。 | | AMR_NB | 3 | 封装为AMR_NB格式。
仅做接口定义,暂不支持使用。 | | AMR_WB | 4 | 封装为AMR_WB格式。
仅做接口定义,暂不支持使用。 | | AAC_ADTS | 6 | 封装为ADTS(Audio Data Transport Stream)格式,是AAC音频的传输流格式。 | +## VideoRecorder9+ + +视频录制管理类,用于录制视频媒体。在调用VideoRecorder的方法前,需要先通过[createVideoRecorder()](#mediacreatevideorecorder9)构建一个[VideoRecorder](#videorecorder9)实例。 + +视频录制demo可参考:[视频录制开发指导](../../media/video-recorder.md) + +### 属性 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------------------ | -------------------------------------- | ---- | ---- | ---------------- | +| state8+ | [VideoRecordState](#videorecordstate9) | 是 | 否 | 视频录制的状态。 | + +### prepare9+ + +prepare(config: VideoRecorderConfig, callback: AsyncCallback\): void; + +异步方式进行视频录制的参数设置。通过注册回调函数获取返回值。 + +**需要权限:** ohos.permission.MICROPHONE + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------------- | ---- | ----------------------------------- | +| config | [VideoRecorderConfig](#videorecorderconfig9) | 是 | 配置视频录制的相关参数。 | +| callback | AsyncCallback\ | 是 | 异步视频录制prepare方法的回调方法。 | + +**示例:** + +```js +let videoProfile = { + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 48000, + videoCodec : 'video/mp4v-es', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 +} + +let videoConfig = { + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, +} + +// asyncallback +let videoRecorder = null; +let events = require('events'); +let eventEmitter = new events.EventEmitter(); + +eventEmitter.on('prepare', () => { + videoRecorder.prepare(videoConfig, (err) => { + if (typeof (err) == 'undefined') { + console.info('prepare success'); + } else { + console.info('prepare failed and error is ' + err.message); + } + }); +}); + +media.createVideoRecorder((err, recorder) => { + if (typeof (err) == 'undefined' && typeof (recorder) != 'undefined') { + videoRecorder = recorder; + console.info('createVideoRecorder success'); + eventEmitter.emit('prepare'); // prepare事件触发 + } else { + console.info('createVideoRecorder failed and error is ' + err.message); + } +}); +``` + +### prepare9+ + +prepare(config: VideoRecorderConfig): Promise\; + +异步方式进行视频录制的参数设置。通过Promise获取返回值。 + +**需要权限:** ohos.permission.MICROPHONE,ohos.permission.CAMERA + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | -------------------------------------------- | ---- | ------------------------ | +| config | [VideoRecorderConfig](#videorecorderconfig9) | 是 | 配置视频录制的相关参数。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ---------------------------------------- | +| Promise\ | 异步视频录制prepare方法的Promise返回值。 | + +**示例:** + +```js +let videoProfile = { + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 48000, + videoCodec : 'video/mp4v-es', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 +} + +let videoConfig = { + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, +} + +// promise +let videoRecorder = null; +media.createVideoRecorder().then((recorder) => { + if (typeof (recorder) != 'undefined') { + videoRecorder = recorder; + console.info('createVideoRecorder success'); + } else { + console.info('createVideoRecorder failed'); + } +}).catch((err) => { + console.info('catch err error message is ' + err.message); +}); + +videoRecorder.prepare(videoConfig).then(() => { + console.info('prepare success'); +}).catch((err) => { + console.info('prepare failed and catch error is ' + err.message); +}); +``` + +### getInputSurface9+ + +getInputSurface(callback: AsyncCallback\): void; + +异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。 + +应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。 + +只能在[prepare()](#videorecorder_prepare1)接口调用后调用。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | --------------------------- | +| callback | AsyncCallback\ | 是 | 异步获得surface的回调方法。 | + +**示例:** + +```js +// asyncallback +let surfaceID = null; // 传递给外界的surfaceID +videoRecorder.getInputSurface((err, surfaceId) => { + if (typeof (err) == 'undefined') { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.info('getInputSurface failed and error is ' + err.message); + } +}); +``` + +### getInputSurface9+ + +getInputSurface(): Promise\; + + 异步方式获得录制需要的surface。此surface提供给调用者,调用者从此surface中获取surfaceBuffer,填入相应的数据。 + +应当注意,填入的视频数据需要携带时间戳(单位ns),buffersize。时间戳的起始时间请以系统启动时间为基准。 + +只能在[prepare()](#videorecorder_prepare1)接口调用后调用。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| ---------------- | -------------------------------- | +| Promise\ | 异步获得surface的Promise返回值。 | + +**示例:** + +```js +// promise +let surfaceID = null; // 传递给外界的surfaceID +videoRecorder.getInputSurface().then((surfaceId) => { + console.info('getInputSurface success'); + surfaceID = surfaceId; +}).catch((err) => { + console.info('getInputSurface failed and catch error is ' + err.message); +}); +``` + +### start9+ + +start(callback: AsyncCallback\): void; + +异步方式开始视频录制。通过注册回调函数获取返回值。 + +在[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 异步开始视频录制的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.start((err) => { + if (typeof (err) == 'undefined') { + console.info('start videorecorder success'); + } else { + console.info('start videorecorder failed and error is ' + err.message); + } +}); +``` + +### start9+ + +start(): Promise\; + +异步方式开始视频录制。通过Promise获取返回值。 + +在[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)后调用,需要依赖数据源先给surface传递数据。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------------------------- | +| Promise\ | 异步开始视频录制方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.start().then(() => { + console.info('start videorecorder success'); +}).catch((err) => { + console.info('start videorecorder failed and catch error is ' + err.message); +}); +``` + +### pause9+ + +pause(callback: AsyncCallback\): void; + +异步方式暂停视频录制。通过注册回调函数获取返回值。 + +在[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 异步暂停视频录制的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.pause((err) => { + if (typeof (err) == 'undefined') { + console.info('pause videorecorder success'); + } else { + console.info('pause videorecorder failed and error is ' + err.message); + } +}); +``` + +### pause9+ + +pause(): Promise\; + +异步方式暂停视频录制。通过Promise获取返回值。 + +在[start()](#videorecorder_start1)后调用。可以通过调用[resume()](#videorecorder_resume1)接口来恢复录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------------------------- | +| Promise\ | 异步暂停视频录制方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.pause().then(() => { + console.info('pause videorecorder success'); +}).catch((err) => { + console.info('pause videorecorder failed and catch error is ' + err.message); +}); +``` + +### resume9+ + +resume(callback: AsyncCallback\): void; + +异步方式恢复视频录制。通过注册回调函数获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 异步恢复视频录制的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.resume((err) => { + if (typeof (err) == 'undefined') { + console.info('resume videorecorder success'); + } else { + console.info('resume videorecorder failed and error is ' + err.message); + } +}); +``` + +### resume9+ + +resume(): Promise\; + +异步方式恢复视频录制。通过Promise获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------------------------- | +| Promise\ | 异步恢复视频录制方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.resume().then(() => { + console.info('resume videorecorder success'); +}).catch((err) => { + console.info('resume videorecorder failed and catch error is ' + err.message); +}); +``` + +### stop9+ + +stop(callback: AsyncCallback\): void; + +异步方式停止视频录制。通过注册回调函数获取返回值。 + +需要重新调用[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)接口才能重新录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 异步停止视频录制的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.stop((err) => { + if (typeof (err) == 'undefined') { + console.info('stop videorecorder success'); + } else { + console.info('stop videorecorder failed and error is ' + err.message); + } +}); +``` + +### stop9+ + +stop(): Promise\; + +异步方式停止视频录制。通过Promise获取返回值。 + +需要重新调用[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)接口才能重新录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------------------------- | +| Promise\ | 异步停止视频录制方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.stop().then(() => { + console.info('stop videorecorder success'); +}).catch((err) => { + console.info('stop videorecorder failed and catch error is ' + err.message); +}); +``` + +### release9+ + +release(callback: AsyncCallback\): void; + +异步方式释放视频录制资源。通过注册回调函数获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | -------------------------------- | +| callback | AsyncCallback\ | 是 | 异步释放视频录制资源的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.release((err) => { + if (typeof (err) == 'undefined') { + console.info('release videorecorder success'); + } else { + console.info('release videorecorder failed and error is ' + err.message); + } +}); +``` + +### release9+ + +release(): Promise\; + +异步方式释放视频录制资源。通过Promise获取返回值。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------------------- | +| Promise\ | 异步释放视频录制资源方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.release().then(() => { + console.info('release videorecorder success'); +}).catch((err) => { + console.info('release videorecorder failed and catch error is ' + err.message); +}); +``` + +### reset9+ + +reset(callback: AsyncCallback\): void; + +异步方式重置视频录制。通过注册回调函数获取返回值。 + +需要重新调用[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)接口才能重新录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 异步重置视频录制的回调方法。 | + +**示例:** + +```js +// asyncallback +videoRecorder.reset((err) => { + if (typeof (err) == 'undefined') { + console.info('reset videorecorder success'); + } else { + console.info('reset videorecorder failed and error is ' + err.message); + } +}); +``` + +### reset9+ + +reset(): Promise\; + +异步方式重置视频录制。通过Promise获取返回值。 + +需要重新调用[prepare()](#videorecorder_prepare1)和[getInputSurface()](#getinputsurface8)接口才能重新录制。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**返回值:** + +| 类型 | 说明 | +| -------------- | ------------------------------------- | +| Promise\ | 异步重置视频录制方法的Promise返回值。 | + +**示例:** + +```js +// promise +videoRecorder.reset().then(() => { + console.info('reset videorecorder success'); +}).catch((err) => { + console.info('reset videorecorder failed and catch error is ' + err.message); +}); +``` + +### on('error')9+ + +on(type: 'error', callback: ErrorCallback): void + +开始订阅视频录制错误事件。 + +**系统能力:** SystemCapability.Multimedia.Media.VideoRecorder + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 录制错误事件回调类型'error'。
- 'error':视频录制过程中发生错误,触发该事件。 | +| callback | ErrorCallback | 是 | 录制错误事件回调方法。 | + +**示例:** + +```js +videoRecorder.on('error', (error) => { // 设置'error'事件回调 + console.info(`audio error called, errName is ${error.name}`); // 打印错误类型名称 + console.info(`audio error called, errCode is ${error.code}`); // 打印错误码 + console.info(`audio error called, errMessage is ${error.message}`); // 打印错误类型详细描述 +}); +// 当获取videoRecordState接口出错时通过此订阅事件上报 +``` + +## VideoRecordState9+ + +视频录制的状态机。可通过state属性获取当前状态。 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 类型 | 描述 | +| -------- | ------ | ---------------------- | +| idle | string | 视频录制空闲。 | +| prepared | string | 视频录制参数设置完成。 | +| playing | string | 视频正在录制。 | +| paused | string | 视频暂停录制。 | +| stopped | string | 视频录制停止。 | +| error | string | 错误状态。 | + +## VideoRecorderConfig9+ + +表示视频录制的参数设置。 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 参数类型 | 必填 | 说明 | +| --------------- | ---------------------------------------------- | ---- | ------------------------------------------------------------ | +| audioSourceType | [AudioSourceType](#audiosourcetype9) | 是 | 视频录制的音频源类型。 | +| videoSourceType | [VideoSourceType](#videosourcetype9) | 是 | 视频录制的视频源类型。 | +| profile | [VideoRecorderProfile](#videorecorderprofile9) | 是 | 视频录制的profile。 | +| rotation | number | 否 | 录制视频的旋转角度。 | +| location | [Location](#location) | 否 | 录制视频的地理位置。 | +| url | string | 是 | 视频输出URL:fd://xx (fd number)
![](figures/zh-cn_image_url.png)
文件需要由调用者创建,并赋予适当的权限。 | + +## AudioSourceType9+ + +表示视频录制中音频源类型的枚举。 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 值 | 说明 | +| ------------------------- | ---- | ---------------------- | +| AUDIO_SOURCE_TYPE_DEFAULT | 0 | 默认的音频输入源类型。 | +| AUDIO_SOURCE_TYPE_MIC | 1 | 表示MIC的音频输入源。 | + +## VideoSourceType9+ + +表示视频录制中视频源类型的枚举。 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 值 | 说明 | +| ----------------------------- | ---- | ------------------------------- | +| VIDEO_SOURCE_TYPE_SURFACE_YUV | 0 | 输入surface中携带的是raw data。 | +| VIDEO_SOURCE_TYPE_SURFACE_ES | 1 | 输入surface中携带的是ES data。 | + +## VideoRecorderProfile9+ + +视频录制的配置文件。 + +**系统能力:** 以下各项对应的系统能力均为 SystemCapability.Multimedia.Media.VideoRecorder。 + +| 名称 | 参数类型 | 必填 | 说明 | +| ---------------- | -------------------------------------------- | ---- | ---------------- | +| audioBitrate | number | 是 | 音频编码比特率。 | +| audioChannels | number | 是 | 音频采集声道数。 | +| audioCodec | [CodecMimeType](#codecmimetype8) | 是 | 音频编码格式。 | +| audioSampleRate | number | 是 | 音频采样率。 | +| fileFormat | [ContainerFormatType](#containerformattype8) | 是 | 文件的容器格式。 | +| videoBitrate | number | 是 | 视频编码比特率。 | +| videoCodec | [CodecMimeType](#codecmimetype8) | 是 | 视频编码格式。 | +| videoFrameWidth | number | 是 | 录制视频帧的宽。 | +| videoFrameHeight | number | 是 | 录制视频帧的高。 | +| videoFrameRate | number | 是 | 录制视频帧率。 | + ## ContainerFormatType8+ 表示容器格式类型的枚举,缩写为CFT。