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 bb377864a18274fd47c1ed8a52e6cb89861f2db2..8c816b559d8c79eefba7b10b68fef070c0a57c5d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-media.md +++ b/zh-cn/application-dev/reference/apis/js-apis-media.md @@ -45,15 +45,15 @@ createAVPlayer(callback: AsyncCallback\): void **示例:** ```js -let avPlayer +let avPlayer; media.createAVPlayer((error, video) => { - if (video != null) { - avPlayer = video; - console.info('createAVPlayer success'); - } else { - console.info(`createAVPlayer fail, error:${error}`); - } + if (video != null) { + avPlayer = video; + console.info('createAVPlayer success'); + } else { + console.error(`createAVPlayer fail, error message:${error.message}`); + } }); ``` @@ -82,17 +82,17 @@ createAVPlayer(): Promise\ **示例:** ```js -let avPlayer +let avPlayer; media.createAVPlayer().then((video) => { - if (video != null) { - avPlayer = video; - console.info('createAVPlayer success'); - } else { - console.info('createAVPlayer fail'); - } + if (video != null) { + avPlayer = video; + console.info('createAVPlayer success'); + } else { + console.error('createAVPlayer fail'); + } }).catch((error) => { - console.info(`AVPlayer catchCallback, error:${error}`); + console.error(`AVPlayer catchCallback, error message:${error.message}`); }); ``` @@ -124,15 +124,15 @@ createAVRecorder(callback: AsyncCallback\): void **示例:** ```js -let avRecorder +let avRecorder; media.createAVRecorder((error, recorder) => { - if (recorder != null) { - avRecorder = recorder; - console.info('createAVRecorder success'); - } else { - console.info(`createAVRecorder fail, error:${error}`); - } + if (recorder != null) { + avRecorder = recorder; + console.info('createAVRecorder success'); + } else { + console.error(`createAVRecorder fail, error message:${error.message}`); + } }); ``` @@ -164,17 +164,17 @@ createAVRecorder(): Promise\ **示例:** ```js -let avRecorder +let avRecorder; media.createAVRecorder().then((recorder) => { - if (recorder != null) { - avRecorder = recorder; - console.info('createAVRecorder success'); - } else { - console.info('createAVRecorder fail'); - } + if (recorder != null) { + avRecorder = recorder; + console.info('createAVRecorder success'); + } else { + console.error('createAVRecorder fail'); + } }).catch((error) => { - console.info(`createAVRecorder catchCallback, error:${error}`); + console.error(`createAVRecorder catchCallback, error message:${error.message}`); }); ``` @@ -206,15 +206,15 @@ createVideoRecorder(callback: AsyncCallback\): void **示例:** ```js -let videoRecorder +let videoRecorder; media.createVideoRecorder((error, video) => { - if (video != null) { - videoRecorder = video; - console.info('video createVideoRecorder success'); - } else { - console.info(`video createVideoRecorder fail, error:${error}`); - } + if (video != null) { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.error(`video createVideoRecorder fail, error message:${error.message}`); + } }); ``` @@ -246,17 +246,17 @@ createVideoRecorder(): Promise\ **示例:** ```js -let videoRecorder +let videoRecorder; media.createVideoRecorder().then((video) => { - if (video != null) { - videoRecorder = video; - console.info('video createVideoRecorder success'); - } else { - console.info('video createVideoRecorder fail'); - } + if (video != null) { + videoRecorder = video; + console.info('video createVideoRecorder success'); + } else { + console.error('video createVideoRecorder fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error message:${error.message}`); }); ``` @@ -397,38 +397,38 @@ on(type: 'stateChange', callback: (state: AVPlayerState, reason: StateChangeReas ```js avPlayer.on('stateChange', async (state, reason) => { - switch (state) { - case 'idle': - console.info('state idle called') - break; - case 'initialized': - console.info('initialized prepared called') - break; - case 'prepared': - console.info('state prepared called') - break; - case 'playing': - console.info('state playing called') - break; - case 'paused': - console.info('state paused called') - break; - case 'completed': - console.info('state completed called') - break; - case 'stopped': - console.info('state stopped called') - break; - case 'released': - console.info('state released called') - break; - case 'error': - console.info('state error called') - break; - default: - console.info('unkown state :' + state) - break; - } + switch (state) { + case 'idle': + console.info('state idle called') + break; + case 'initialized': + console.info('initialized prepared called') + break; + case 'prepared': + console.info('state prepared called') + break; + case 'playing': + console.info('state playing called') + break; + case 'paused': + console.info('state paused called') + break; + case 'completed': + console.info('state completed called') + break; + case 'stopped': + console.info('state stopped called') + break; + case 'released': + console.info('state released called') + break; + case 'error': + console.info('state error called') + break; + default: + console.info('unkown state :' + state) + break; + } }) ``` @@ -485,8 +485,8 @@ AVPlayer回调的**错误分类**可以分为以下几 ```js avPlayer.on('error', (error) => { - console.info('error happened,and error message is :' + error.message) - console.info('error happened,and error code is :' + error.code) + console.error('error happened,and error message is :' + error.message) + console.error('error happened,and error code is :' + error.code) }) ``` @@ -537,11 +537,11 @@ prepare(callback: AsyncCallback\): void ```js avPlayer.prepare((err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.error('prepare filed,error message is :' + err.message) - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare filed,error message is :' + err.message) + } }) ``` @@ -572,9 +572,9 @@ prepare(): Promise\ ```js avPlayer.prepare().then(() => { - console.info('prepare success'); + console.info('prepare success'); }, (err) => { - console.error('prepare filed,error message is :' + err.message) + console.error('prepare filed,error message is :' + err.message) }) ``` @@ -604,11 +604,11 @@ play(callback: AsyncCallback\): void ```js avPlayer.play((err) => { - if (err == null) { - console.info('play success'); - } else { - console.error('play filed,error message is :' + err.message) - } + if (err == null) { + console.info('play success'); + } else { + console.error('play filed,error message is :' + err.message) + } }) ``` @@ -638,9 +638,9 @@ play(): Promise\ ```js avPlayer.play().then(() => { - console.info('play success'); + console.info('play success'); }, (err) => { - console.error('play filed,error message is :' + err.message) + console.error('play filed,error message is :' + err.message) }) ``` @@ -670,11 +670,11 @@ pause(callback: AsyncCallback\): void ```js avPlayer.pause((err) => { - if (err == null) { - console.info('pause success'); - } else { - console.error('pause filed,error message is :' + err.message) - } + if (err == null) { + console.info('pause success'); + } else { + console.error('pause filed,error message is :' + err.message) + } }) ``` @@ -704,9 +704,9 @@ pause(): Promise\ ```js avPlayer.pause().then(() => { - console.info('pause success'); + console.info('pause success'); }, (err) => { - console.error('pause filed,error message is :' + err.message) + console.error('pause filed,error message is :' + err.message) }) ``` @@ -736,11 +736,11 @@ stop(callback: AsyncCallback\): void ```js avPlayer.stop((err) => { - if (err == null) { - console.info('stop success'); - } else { - console.error('stop filed,error message is :' + err.message) - } + if (err == null) { + console.info('stop success'); + } else { + console.error('stop filed,error message is :' + err.message) + } }) ``` @@ -770,9 +770,9 @@ stop(): Promise\ ```js avPlayer.stop().then(() => { - console.info('stop success'); + console.info('stop success'); }, (err) => { - console.error('stop filed,error message is :' + err.message) + console.error('stop filed,error message is :' + err.message) }) ``` @@ -802,11 +802,11 @@ reset(callback: AsyncCallback\): void ```js avPlayer.reset((err) => { - if (err == null) { - console.info('reset success'); - } else { - console.error('reset filed,error message is :' + err.message) - } + if (err == null) { + console.info('reset success'); + } else { + console.error('reset filed,error message is :' + err.message) + } }) ``` @@ -836,9 +836,9 @@ reset(): Promise\ ```js avPlayer.reset().then(() => { - console.info('reset success'); + console.info('reset success'); }, (err) => { - console.error('reset filed,error message is :' + err.message) + console.error('reset filed,error message is :' + err.message) }) ``` @@ -868,11 +868,11 @@ release(callback: AsyncCallback\): void ```js avPlayer.release((err) => { - if (err == null) { - console.info('reset success'); - } else { - console.error('release filed,error message is :' + err.message) - } + if (err == null) { + console.info('reset success'); + } else { + console.error('release filed,error message is :' + err.message) + } }) ``` @@ -902,9 +902,9 @@ release(): Promise\ ```js avPlayer.release().then(() => { - console.info('release success'); + console.info('release success'); }, (err) => { - console.error('release filed,error message is :' + err.message) + console.error('release filed,error message is :' + err.message) }) ``` @@ -933,22 +933,22 @@ getTrackDescription(callback: AsyncCallback\>): void **示例:** ```js -printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } +function printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } avPlayer.getTrackDescription((error, arrList) => { - if ((arrList) != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`video getTrackDescription fail, error:${error}`); + if ((arrList) != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`video getTrackDescription fail, error:${error}`); + } }); ``` @@ -979,24 +979,24 @@ getTrackDescription(): Promise\> ```js let arrayDescription; -printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } +function printfDescription(obj) { + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } avPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('video getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('video getTrackDescription fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.info(`video catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -1041,7 +1041,7 @@ on(type: 'seekDone', callback: Callback\): void ```js avPlayer.on('seekDone', (seekDoneTime:number) => { - console.info('seekDone success,and seek time is:' + seekDoneTime) + console.info('seekDone success,and seek time is:' + seekDoneTime) }) ``` @@ -1104,7 +1104,7 @@ on(type: 'speedDone', callback: Callback\): void ```js avPlayer.on('speedDone', (speed:number) => { - console.info('speedDone success,and speed value is:' + speed) + console.info('speedDone success,and speed value is:' + speed) }) ``` @@ -1140,7 +1140,7 @@ setBitrate(bitrate: number): void | 参数名 | 类型 | 必填 | 说明 | | ------- | ------ | ---- | ------------------------------------------------------------ | -| bitrate | number | 是 | 指定比特率,可以通过[availableBitrates](#availableBitrates_on)事件获得当前HLS协议流可用的比特率,如果用户指定的比特率不在此列表中,则播放器将从可用比特率列表中选择最小和最接近的比特率。如果通过availableBitrates时间获得的比特率列表长度为0,则不支持指定比特率,也不会产生bitrateDone回调。 | +| bitrate | number | 是 | 指定比特率,可以通过[availableBitrates](#availableBitrates_on)事件获得当前HLS协议流可用的比特率,如果用户指定的比特率不在此列表中,则播放器将从可用比特率列表中选择最小和最接近的比特率。如果通过availableBitrates事件获得的比特率列表长度为0,则不支持指定比特率,也不会产生bitrateDone回调。 | **示例:** @@ -1168,7 +1168,7 @@ on(type: 'bitrateDone', callback: Callback\): void ```js avPlayer.on('bitrateDone', (bitrate:number) => { - console.info('bitrateDone success,and bitrate value is:' + bitrate) + console.info('bitrateDone success,and bitrate value is:' + bitrate) }) ``` @@ -1211,7 +1211,7 @@ on(type: 'availableBitrates', callback: (bitrates: Array\) => void): voi ```js avPlayer.on('availableBitrates', (bitrates: Array) => { - console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length) + console.info('availableBitrates success,and availableBitrates length is:' + bitrates.length) }) ``` @@ -1275,7 +1275,7 @@ on(type: 'volumeChange', callback: Callback\): void ```js avPlayer.on('volumeChange', (vol:number) => { - console.info('volumeChange success,and new volume is :' + vol) + console.info('volumeChange success,and new volume is :' + vol) }) ``` @@ -1291,7 +1291,7 @@ off(type: 'volumeChange'): void | 参数名 | 类型 | 必填 | 说明 | | ------ | ------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | setVolume生效的事件回调类型,取消注册的事件:'availableBitrates'。 | +| type | string | 是 | setVolume生效的事件回调类型,取消注册的事件:'volumeChange'。 | **示例:** @@ -1318,7 +1318,7 @@ on(type: 'endOfStream', callback: Callback\): void ```js avPlayer.on('endOfStream', () => { - console.info('endOfStream success') + console.info('endOfStream success') }) ``` @@ -1361,7 +1361,7 @@ on(type: 'timeUpdate', callback: Callback\): void ```js avPlayer.on('timeUpdate', (time:number) => { - console.info('timeUpdate success,and new time is :' + time) + console.info('timeUpdate success,and new time is :' + time) }) ``` @@ -1404,7 +1404,7 @@ on(type: 'durationUpdate', callback: Callback\): void ```js avPlayer.on('durationUpdate', (duration) => { - console.info('durationUpdate success,new duration is :' + duration) + console.info('durationUpdate success,new duration is :' + duration) }) ``` @@ -1447,7 +1447,7 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ```js avPlayer.on('bufferingUpdate', (infoType: media.BufferingInfoType, value: number) => { - console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value) + console.info('bufferingUpdate success,and infoType value is:' + infoType + ', value is :' + value) }) ``` @@ -1490,7 +1490,7 @@ on(type: 'startRenderFrame', callback: Callback\): void ```js avPlayer.on('startRenderFrame', () => { - console.info('startRenderFrame success') + console.info('startRenderFrame success') }) ``` @@ -1533,7 +1533,7 @@ on(type: 'videoSizeChange', callback: (width: number, height: number) => void): ```js avPlayer.on('videoSizeChange', (width: number, height: number) => { - console.info('videoSizeChange success,and width is:' + width + ', height is :' + height) + console.info('videoSizeChange success,and width is:' + width + ', height is :' + height) }) ``` @@ -1578,7 +1578,7 @@ on(type: 'audioInterrupt', callback: (info: audio.InterruptEvent) => void): void import audio from '@ohos.multimedia.audio'; avPlayer.on('audioInterrupt', (info: audio.InterruptEvent) => { - console.info('audioInterrupt success,and InterruptEvent info is:' + info) + console.info('audioInterrupt success,and InterruptEvent info is:' + info) }) ``` @@ -1679,19 +1679,19 @@ avPlayer.off('audioInterrupt') ```js import media from '@ohos.multimedia.media' function printfItemDescription(obj, key) { - let property = obj[key]; - console.info('audio key is ' + key); // 通过key值获取对应的value。key值具体可见[MediaDescriptionKey] - console.info('audio value is ' + property); //对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey] + let property = obj[key]; + console.info('audio key is ' + key); // 通过key值获取对应的value。key值具体可见[MediaDescriptionKey] + console.info('audio value is ' + property); //对应key值得value。其类型可为任意类型,具体key对应value的类型可参考[MediaDescriptionKey] } let audioPlayer = media.createAudioPlayer(); audioPlayer.getTrackDescription((error, arrList) => { - if (arrList != null) { - for (let i = 0; i < arrList.length; i++) { - printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值 - } - } else { - console.log(`audio getTrackDescription fail, error:${error}`); + if (arrList != null) { + for (let i = 0; i < arrList.length; i++) { + printfItemDescription(arrList[i], media.MediaDescriptionKey.MD_KEY_TRACK_TYPE); //打印出每条轨道MD_KEY_TRACK_TYPE的值 } + } else { + console.log(`audio getTrackDescription fail, error:${error}`); + } }); ``` @@ -1748,32 +1748,32 @@ prepare(config: AVRecorderConfig, callback: AsyncCallback\): void ```js // 配置参数以实际硬件设备支持的范围为准 let AVRecorderProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : media.CodecMimeType.AUDIO_AAC, - audioSampleRate : 48000, - fileFormat : media.ContainerFormatType.CFT_MPEG_4, - videoBitrate : 2000000, - videoCodec : media.CodecMimeType.VIDEO_AVC, - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : media.CodecMimeType.AUDIO_AAC, + audioSampleRate : 48000, + fileFormat : media.ContainerFormatType.CFT_MPEG_4, + videoBitrate : 2000000, + videoCodec : media.CodecMimeType.VIDEO_AVC, + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let AVRecorderConfig = { - audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, - videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, - profile : AVRecorderProfile, - url : 'fd://', // 文件需先由调用者创建,赋予读写权限,将文件fd传给此参数,eg.fd://45 - rotation : 0, // 合理值0、90、180、270,非合理值prepare接口将报错 - location : { latitude : 30, longitude : 130 } + audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, + profile : AVRecorderProfile, + url : 'fd://', // 文件需先由调用者创建,赋予读写权限,将文件fd传给此参数,eg.fd://45 + rotation : 0, // 合理值0、90、180、270,非合理值prepare接口将报错 + location : { latitude : 30, longitude : 130 } } avRecorder.prepare(AVRecorderConfig, (err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.info('prepare failed and error is ' + err.message); - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare failed and error is ' + err.message); + } }) ``` @@ -1817,30 +1817,30 @@ prepare(config: AVRecorderConfig): Promise\ ```js // 配置参数以实际硬件设备支持的范围为准 let AVRecorderProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : media.CodecMimeType.AUDIO_AAC, - audioSampleRate : 48000, - fileFormat : media.ContainerFormatType.CFT_MPEG_4, - videoBitrate : 2000000, - videoCodec : media.CodecMimeType.VIDEO_AVC, - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : media.CodecMimeType.AUDIO_AAC, + audioSampleRate : 48000, + fileFormat : media.ContainerFormatType.CFT_MPEG_4, + videoBitrate : 2000000, + videoCodec : media.CodecMimeType.VIDEO_AVC, + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let AVRecorderConfig = { - audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, - videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, - profile : AVRecorderProfile, - url : 'fd://', // 文件需先由调用者创建,赋予读写权限,将文件fd传给此参数,eg.fd://45 - rotation : 0, // 合理值0、90、180、270,非合理值prepare接口报错 - location : { latitude : 30, longitude : 130 } + audioSourceType : media.AudioSourceType.AUDIO_SOURCE_TYPE_MIC, + videoSourceType : media.VideoSourceType.VIDEO_SOURCE_TYPE_SURFACE_YUV, + profile : AVRecorderProfile, + url : 'fd://', // 文件需先由调用者创建,赋予读写权限,将文件fd传给此参数,eg.fd://45 + rotation : 0, // 合理值0、90、180、270,非合理值prepare接口报错 + location : { latitude : 30, longitude : 130 } } avRecorder.prepare(AVRecorderConfig).then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); + console.error('prepare failed and catch error is ' + err.message); }); ``` @@ -1879,12 +1879,12 @@ getInputSurface(callback: AsyncCallback\): void let surfaceID = null; // 该surfaceID用于传递给相机接口创造videoOutput avRecorder.getInputSurface((err, surfaceId) => { - if (err == null) { - console.info('getInputSurface success'); - surfaceID = surfaceId; - } else { - console.info('getInputSurface failed and error is ' + err.message); - } + if (err == null) { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.error('getInputSurface failed and error is ' + err.message); + } }); ``` @@ -1923,10 +1923,10 @@ getInputSurface(): Promise\ let surfaceID = null; // 该surfaceID用于传递给相机接口创造videoOutput avRecorder.getInputSurface().then((surfaceId) => { - console.info('getInputSurface success'); - surfaceID = surfaceId; + console.info('getInputSurface success'); + surfaceID = surfaceId; }).catch((err) => { - console.info('getInputSurface failed and catch error is ' + err.message); + console.error('getInputSurface failed and catch error is ' + err.message); }); ``` @@ -1960,11 +1960,11 @@ start(callback: AsyncCallback\): void ```js avRecorder.start((err) => { - if (err == null) { - console.info('start AVRecorder success'); - } else { - console.info('start AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('start AVRecorder success'); + } else { + console.error('start AVRecorder failed and error is ' + err.message); + } }); ``` @@ -1998,9 +1998,9 @@ start(): Promise\ ```js avRecorder.start().then(() => { - console.info('start AVRecorder success'); + console.info('start AVRecorder success'); }).catch((err) => { - console.info('start AVRecorder failed and catch error is ' + err.message); + console.error('start AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2034,11 +2034,11 @@ pause(callback: AsyncCallback\): void ```js avRecorder.pause((err) => { - if (err == null) { - console.info('pause AVRecorder success'); - } else { - console.info('pause AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('pause AVRecorder success'); + } else { + console.error('pause AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2072,9 +2072,9 @@ pause(): Promise\ ```js avRecorder.pause().then(() => { - console.info('pause AVRecorder success'); + console.info('pause AVRecorder success'); }).catch((err) => { - console.info('pause AVRecorder failed and catch error is ' + err.message); + console.error('pause AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2108,11 +2108,11 @@ resume(callback: AsyncCallback\): void ```js avRecorder.resume((err) => { - if (err == null) { - console.info('resume AVRecorder success'); - } else { - console.info('resume AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('resume AVRecorder success'); + } else { + console.error('resume AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2146,9 +2146,9 @@ resume(): Promise\ ```js avRecorder.resume().then(() => { - console.info('resume AVRecorder success'); + console.info('resume AVRecorder success'); }).catch((err) => { - console.info('resume AVRecorder failed and catch error is ' + err.message); + console.error('resume AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2184,11 +2184,11 @@ stop(callback: AsyncCallback\): void ```js avRecorder.stop((err) => { - if (err == null) { - console.info('stop AVRecorder success'); - } else { - console.info('stop AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('stop AVRecorder success'); + } else { + console.error('stop AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2224,9 +2224,9 @@ stop(): Promise\ ```js avRecorder.stop().then(() => { - console.info('stop AVRecorder success'); + console.info('stop AVRecorder success'); }).catch((err) => { - console.info('stop AVRecorder failed and catch error is ' + err.message); + console.error('stop AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2259,11 +2259,11 @@ reset(callback: AsyncCallback\): void ```js avRecorder.reset((err) => { - if (err == null) { - console.info('reset AVRecorder success'); - } else { - console.info('reset AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('reset AVRecorder success'); + } else { + console.error('reset AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2296,9 +2296,9 @@ reset(): Promise\ ```js avRecorder.reset().then(() => { - console.info('reset AVRecorder success'); + console.info('reset AVRecorder success'); }).catch((err) => { - console.info('reset AVRecorder failed and catch error is ' + err.message); + console.error('reset AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2330,11 +2330,11 @@ release(callback: AsyncCallback\): void ```js avRecorder.release((err) => { - if (err == null) { - console.info('release AVRecorder success'); - } else { - console.info('release AVRecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('release AVRecorder success'); + } else { + console.error('release AVRecorder failed and error is ' + err.message); + } }); ``` @@ -2366,9 +2366,9 @@ release(): Promise\ ```js avRecorder.release().then(() => { - console.info('release AVRecorder success'); + console.info('release AVRecorder success'); }).catch((err) => { - console.info('release AVRecorder failed and catch error is ' + err.message); + console.error('release AVRecorder failed and catch error is ' + err.message); }); ``` @@ -2391,7 +2391,7 @@ on(type: 'stateChange', callback: (state: AVRecorderState, reason: StateChangeRe ```js avRecorder.on('stateChange', async (state, reason) => { - console.info('case state has changed, new state is :' + state + ',and new reason is : ' + reason); + console.info('case state has changed, new state is :' + state + ',and new reason is : ' + reason); }); ``` @@ -2445,7 +2445,7 @@ on(type: 'error', callback: ErrorCallback): void ```js avRecorder.on('error', (err) => { - console.info('case avRecorder.on(error) called, errMessage is ' + err.message); + console.error('case avRecorder.on(error) called, errMessage is ' + err.message); }); ``` @@ -2626,34 +2626,34 @@ prepare(config: VideoRecorderConfig, callback: AsyncCallback\): void; ```js // 配置参数以实际硬件设备支持的范围为准 let videoProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : 'audio/mp4a-latm', - audioSampleRate : 48000, - fileFormat : 'mp4', - videoBitrate : 2000000, - videoCodec : 'video/avc', - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 2000000, + videoCodec : 'video/avc', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let videoConfig = { - audioSourceType : 1, - videoSourceType : 0, - profile : videoProfile, - url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 - orientationHint : 0, - location : { latitude : 30, longitude : 130 }, + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, } // asyncallback videoRecorder.prepare(videoConfig, (err) => { - if (err == null) { - console.info('prepare success'); - } else { - console.info('prepare failed and error is ' + err.message); - } + if (err == null) { + console.info('prepare success'); + } else { + console.error('prepare failed and error is ' + err.message); + } }) ``` @@ -2697,32 +2697,32 @@ prepare(config: VideoRecorderConfig): Promise\; ```js // 配置参数以实际硬件设备支持的范围为准 let videoProfile = { - audioBitrate : 48000, - audioChannels : 2, - audioCodec : 'audio/mp4a-latm', - audioSampleRate : 48000, - fileFormat : 'mp4', - videoBitrate : 2000000, - videoCodec : 'video/avc', - videoFrameWidth : 640, - videoFrameHeight : 480, - videoFrameRate : 30 + audioBitrate : 48000, + audioChannels : 2, + audioCodec : 'audio/mp4a-latm', + audioSampleRate : 48000, + fileFormat : 'mp4', + videoBitrate : 2000000, + videoCodec : 'video/avc', + videoFrameWidth : 640, + videoFrameHeight : 480, + videoFrameRate : 30 } let videoConfig = { - audioSourceType : 1, - videoSourceType : 0, - profile : videoProfile, - url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 - orientationHint : 0, - location : { latitude : 30, longitude : 130 }, + audioSourceType : 1, + videoSourceType : 0, + profile : videoProfile, + url : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + orientationHint : 0, + location : { latitude : 30, longitude : 130 }, } // promise videoRecorder.prepare(videoConfig).then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((err) => { - console.info('prepare failed and catch error is ' + err.message); + console.error('prepare failed and catch error is ' + err.message); }); ``` @@ -2762,12 +2762,12 @@ getInputSurface(callback: AsyncCallback\): void; // asyncallback let surfaceID = null; // 传递给外界的surfaceID videoRecorder.getInputSurface((err, surfaceId) => { - if (err == null) { - console.info('getInputSurface success'); - surfaceID = surfaceId; - } else { - console.info('getInputSurface failed and error is ' + err.message); - } + if (err == null) { + console.info('getInputSurface success'); + surfaceID = surfaceId; + } else { + console.error('getInputSurface failed and error is ' + err.message); + } }); ``` @@ -2807,10 +2807,10 @@ getInputSurface(): Promise\; // promise let surfaceID = null; // 传递给外界的surfaceID videoRecorder.getInputSurface().then((surfaceId) => { - console.info('getInputSurface success'); - surfaceID = surfaceId; + console.info('getInputSurface success'); + surfaceID = surfaceId; }).catch((err) => { - console.info('getInputSurface failed and catch error is ' + err.message); + console.error('getInputSurface failed and catch error is ' + err.message); }); ``` @@ -2847,11 +2847,11 @@ start(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.start((err) => { - if (err == null) { - console.info('start videorecorder success'); - } else { - console.info('start videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('start videorecorder success'); + } else { + console.error('start videorecorder failed and error is ' + err.message); + } }); ``` @@ -2888,9 +2888,9 @@ start(): Promise\; ```js // promise videoRecorder.start().then(() => { - console.info('start videorecorder success'); + console.info('start videorecorder success'); }).catch((err) => { - console.info('start videorecorder failed and catch error is ' + err.message); + console.error('start videorecorder failed and catch error is ' + err.message); }); ``` @@ -2927,11 +2927,11 @@ pause(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.pause((err) => { - if (err == null) { - console.info('pause videorecorder success'); - } else { - console.info('pause videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('pause videorecorder success'); + } else { + console.error('pause videorecorder failed and error is ' + err.message); + } }); ``` @@ -2968,9 +2968,9 @@ pause(): Promise\; ```js // promise videoRecorder.pause().then(() => { - console.info('pause videorecorder success'); + console.info('pause videorecorder success'); }).catch((err) => { - console.info('pause videorecorder failed and catch error is ' + err.message); + console.error('pause videorecorder failed and catch error is ' + err.message); }); ``` @@ -3005,11 +3005,11 @@ resume(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.resume((err) => { - if (err == null) { - console.info('resume videorecorder success'); - } else { - console.info('resume videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('resume videorecorder success'); + } else { + console.error('resume videorecorder failed and error is ' + err.message); + } }); ``` @@ -3044,9 +3044,9 @@ resume(): Promise\; ```js // promise videoRecorder.resume().then(() => { - console.info('resume videorecorder success'); + console.info('resume videorecorder success'); }).catch((err) => { - console.info('resume videorecorder failed and catch error is ' + err.message); + console.error('resume videorecorder failed and catch error is ' + err.message); }); ``` @@ -3083,11 +3083,11 @@ stop(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.stop((err) => { - if (err == null) { - console.info('stop videorecorder success'); - } else { - console.info('stop videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('stop videorecorder success'); + } else { + console.error('stop videorecorder failed and error is ' + err.message); + } }); ``` @@ -3124,9 +3124,9 @@ stop(): Promise\; ```js // promise videoRecorder.stop().then(() => { - console.info('stop videorecorder success'); + console.info('stop videorecorder success'); }).catch((err) => { - console.info('stop videorecorder failed and catch error is ' + err.message); + console.error('stop videorecorder failed and catch error is ' + err.message); }); ``` @@ -3159,11 +3159,11 @@ release(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.release((err) => { - if (err == null) { - console.info('release videorecorder success'); - } else { - console.info('release videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('release videorecorder success'); + } else { + console.error('release videorecorder failed and error is ' + err.message); + } }); ``` @@ -3196,9 +3196,9 @@ release(): Promise\; ```js // promise videoRecorder.release().then(() => { - console.info('release videorecorder success'); + console.info('release videorecorder success'); }).catch((err) => { - console.info('release videorecorder failed and catch error is ' + err.message); + console.error('release videorecorder failed and catch error is ' + err.message); }); ``` @@ -3234,11 +3234,11 @@ reset(callback: AsyncCallback\): void; ```js // asyncallback videoRecorder.reset((err) => { - if (err == null) { - console.info('reset videorecorder success'); - } else { - console.info('reset videorecorder failed and error is ' + err.message); - } + if (err == null) { + console.info('reset videorecorder success'); + } else { + console.error('reset videorecorder failed and error is ' + err.message); + } }); ``` @@ -3274,9 +3274,9 @@ reset(): Promise\; ```js // promise videoRecorder.reset().then(() => { - console.info('reset videorecorder success'); + console.info('reset videorecorder success'); }).catch((err) => { - console.info('reset videorecorder failed and catch error is ' + err.message); + console.error('reset videorecorder failed and catch error is ' + err.message); }); ``` @@ -3309,7 +3309,7 @@ on(type: 'error', callback: ErrorCallback): void ```js // 当获取videoRecordState接口出错时通过此订阅事件上报 videoRecorder.on('error', (error) => { // 设置'error'事件回调 - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }) ``` @@ -3411,15 +3411,15 @@ createVideoPlayer(callback: AsyncCallback\): void **示例:** ```js -let videoPlayer +let videoPlayer; media.createVideoPlayer((error, video) => { - if (video != null) { - videoPlayer = video; - console.info('video createVideoPlayer success'); - } else { - console.info(`video createVideoPlayer fail, error:${error}`); - } + if (video != null) { + videoPlayer = video; + console.info('video createVideoPlayer success'); + } else { + console.error(`video createVideoPlayer fail, error:${error}`); + } }); ``` @@ -3443,17 +3443,17 @@ createVideoPlayer(): Promise\ **示例:** ```js -let videoPlayer +let videoPlayer; media.createVideoPlayer().then((video) => { - if (video != null) { - videoPlayer = video; - console.info('video createVideoPlayer success'); - } else { - console.info('video createVideoPlayer fail'); - } + if (video != null) { + videoPlayer = video; + console.info('video createVideoPlayer success'); + } else { + console.error('video createVideoPlayer fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -3536,7 +3536,7 @@ play(): void ```js audioPlayer.on('play', () => { //设置'play'事件回调 - console.log('audio play success'); + console.log('audio play success'); }); audioPlayer.play(); ``` @@ -3553,7 +3553,7 @@ pause(): void ```js audioPlayer.on('pause', () => { //设置'pause'事件回调 - console.log('audio pause success'); + console.log('audio pause success'); }); audioPlayer.pause(); ``` @@ -3570,7 +3570,7 @@ stop(): void ```js audioPlayer.on('stop', () => { //设置'stop'事件回调 - console.log('audio stop success'); + console.log('audio stop success'); }); audioPlayer.stop(); ``` @@ -3587,7 +3587,7 @@ reset(): void ```js audioPlayer.on('reset', () => { //设置'reset'事件回调 - console.log('audio reset success'); + console.log('audio reset success'); }); audioPlayer.reset(); ``` @@ -3610,11 +3610,11 @@ seek(timeMs: number): void ```js audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 - if (seekDoneTime == null) { - console.info('audio seek fail'); - return; - } - console.log('audio seek success. seekDoneTime: ' + seekDoneTime); + if (seekDoneTime == null) { + console.info('audio seek fail'); + return; + } + console.log('audio seek success. seekDoneTime: ' + seekDoneTime); }); audioPlayer.seek(30000); //seek到30000ms的位置 ``` @@ -3637,7 +3637,7 @@ setVolume(vol: number): void ```js audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 - console.log('audio volumeChange success'); + console.log('audio volumeChange success'); }); audioPlayer.setVolume(1); //设置音量到100% ``` @@ -3675,21 +3675,21 @@ getTrackDescription(callback: AsyncCallback\>): void ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } audioPlayer.getTrackDescription((error, arrList) => { - if (arrList != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`audio getTrackDescription fail, error:${error}`); + if (arrList != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`audio getTrackDescription fail, error:${error}`); + } }); ``` @@ -3711,25 +3711,25 @@ getTrackDescription(): Promise\> ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('audio key is ' + item); - console.info('audio value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('audio key is ' + item); + console.info('audio value is ' + property); + } } let arrayDescription = null audioPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('audio getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('audio getTrackDescription fail'); + } }).catch((error) => { - console.info(`audio catchCallback, error:${error}`); + console.info(`audio catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -3752,8 +3752,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ```js audioPlayer.on('bufferingUpdate', (infoType, value) => { - console.log('audio bufferingInfo type: ' + infoType); - console.log('audio bufferingInfo value: ' + value); + console.log('audio bufferingInfo type: ' + infoType); + console.log('audio bufferingInfo value: ' + value); }); ``` @@ -3779,40 +3779,40 @@ import fs from '@ohos.file.fs'; let audioPlayer = media.createAudioPlayer(); //创建一个音频播放实例 audioPlayer.on('dataLoad', () => { //设置'dataLoad'事件回调,src属性设置成功后,触发此回调 - console.info('audio set source success'); - audioPlayer.play(); //开始播放,并触发'play'事件回调 + console.info('audio set source success'); + audioPlayer.play(); //开始播放,并触发'play'事件回调 }); audioPlayer.on('play', () => { //设置'play'事件回调 - console.info('audio play success'); - audioPlayer.seek(30000); //调用seek方法,并触发'timeUpdate'事件回调 + console.info('audio play success'); + audioPlayer.seek(30000); //调用seek方法,并触发'timeUpdate'事件回调 }); audioPlayer.on('pause', () => { //设置'pause'事件回调 - console.info('audio pause success'); - audioPlayer.stop(); //停止播放,并触发'stop'事件回调 + console.info('audio pause success'); + audioPlayer.stop(); //停止播放,并触发'stop'事件回调 }); audioPlayer.on('reset', () => { //设置'reset'事件回调 - console.info('audio reset success'); - audioPlayer.release(); //释放播放实例资源 - audioPlayer = undefined; + console.info('audio reset success'); + audioPlayer.release(); //释放播放实例资源 + audioPlayer = undefined; }); audioPlayer.on('timeUpdate', (seekDoneTime) => { //设置'timeUpdate'事件回调 - if (seekDoneTime == null) { - console.info('audio seek fail'); - return; - } - console.info('audio seek success, and seek time is ' + seekDoneTime); - audioPlayer.setVolume(0.5); //设置音量为50%,并触发'volumeChange'事件回调 + if (seekDoneTime == null) { + console.info('audio seek fail'); + return; + } + console.info('audio seek success, and seek time is ' + seekDoneTime); + audioPlayer.setVolume(0.5); //设置音量为50%,并触发'volumeChange'事件回调 }); audioPlayer.on('volumeChange', () => { //设置'volumeChange'事件回调 - console.info('audio volumeChange success'); - audioPlayer.pause(); //暂停播放,并触发'pause'事件回调 + console.info('audio volumeChange success'); + audioPlayer.pause(); //暂停播放,并触发'pause'事件回调 }); audioPlayer.on('finish', () => { //设置'finish'事件回调 - console.info('audio play finish'); - audioPlayer.stop(); //停止播放,并触发'stop'事件回调 + console.info('audio play finish'); + audioPlayer.stop(); //停止播放,并触发'stop'事件回调 }); audioPlayer.on('error', (error) => { //设置'error'事件回调 - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); // 用户选择音频设置fd(本地播放) @@ -3820,13 +3820,13 @@ let fdPath = 'fd://'; // 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'; fs.open(path).then((file) => { - fdPath = fdPath + '' + file.fd; - console.info('open fd success fd is' + fdPath); - audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 + fdPath = fdPath + '' + file.fd; + console.info('open fd success fd is' + fdPath); + audioPlayer.src = fdPath; //设置src属性,并触发'dataLoad'事件回调 }, (err) => { - console.info('open fd failed err is' + err); + console.info('open fd failed err is' + err); }).catch((err) => { - console.info('open fd failed err is' + err); + console.info('open fd failed err is' + err); }); ``` @@ -3849,11 +3849,11 @@ on(type: 'timeUpdate', callback: Callback\): void ```js audioPlayer.on('timeUpdate', (newTime) => { //设置'timeUpdate'事件回调 - if (newTime == null) { - console.info('audio timeUpadate fail'); - return; - } - console.log('audio timeUpadate success. seekDoneTime: ' + newTime); + if (newTime == null) { + console.info('audio timeUpadate fail'); + return; + } + console.log('audio timeUpadate success. seekDoneTime: ' + newTime); }); audioPlayer.play(); //开始播放后,自动触发时间戳更新事件 ``` @@ -3877,7 +3877,7 @@ on(type: 'error', callback: ErrorCallback): void ```js audioPlayer.on('error', (error) => { //设置'error'事件回调 - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); audioPlayer.setVolume(3); //设置volume为无效值,触发'error'事件 ``` @@ -3945,11 +3945,11 @@ setDisplaySurface(surfaceId: string, callback: AsyncCallback\): void ```js let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId, (err) => { - if (err == null) { - console.info('setDisplaySurface success!'); - } else { - console.info('setDisplaySurface fail!'); - } + if (err == null) { + console.info('setDisplaySurface success!'); + } else { + console.error('setDisplaySurface fail!'); + } }); ``` @@ -3980,9 +3980,9 @@ setDisplaySurface(surfaceId: string): Promise\ ```js let surfaceId = null; videoPlayer.setDisplaySurface(surfaceId).then(() => { - console.info('setDisplaySurface success'); + console.info('setDisplaySurface success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4004,11 +4004,11 @@ prepare(callback: AsyncCallback\): void ```js videoPlayer.prepare((err) => { - if (err == null) { - console.info('prepare success!'); - } else { - console.info('prepare fail!'); - } + if (err == null) { + console.info('prepare success!'); + } else { + console.error('prepare fail!'); + } }); ``` @@ -4030,9 +4030,9 @@ prepare(): Promise\ ```js videoPlayer.prepare().then(() => { - console.info('prepare success'); + console.info('prepare success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4054,11 +4054,11 @@ play(callback: AsyncCallback\): void; ```js videoPlayer.play((err) => { - if (err == null) { - console.info('play success!'); - } else { - console.info('play fail!'); - } + if (err == null) { + console.info('play success!'); + } else { + console.error('play fail!'); + } }); ``` @@ -4080,9 +4080,9 @@ play(): Promise\; ```js videoPlayer.play().then(() => { - console.info('play success'); + console.info('play success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4104,11 +4104,11 @@ pause(callback: AsyncCallback\): void ```js videoPlayer.pause((err) => { - if (err == null) { - console.info('pause success!'); - } else { - console.info('pause fail!'); - } + if (err == null) { + console.info('pause success!'); + } else { + console.info('pause fail!'); + } }); ``` @@ -4130,9 +4130,9 @@ pause(): Promise\ ```js videoPlayer.pause().then(() => { - console.info('pause success'); + console.info('pause success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4154,11 +4154,11 @@ stop(callback: AsyncCallback\): void ```js videoPlayer.stop((err) => { - if (err == null) { - console.info('stop success!'); - } else { - console.info('stop fail!'); - } + if (err == null) { + console.info('stop success!'); + } else { + console.error('stop fail!'); + } }); ``` @@ -4180,9 +4180,9 @@ stop(): Promise\ ```js videoPlayer.stop().then(() => { - console.info('stop success'); + console.info('stop success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4204,11 +4204,11 @@ reset(callback: AsyncCallback\): void ```js videoPlayer.reset((err) => { - if (err == null) { - console.info('reset success!'); - } else { - console.info('reset fail!'); - } + if (err == null) { + console.info('reset success!'); + } else { + console.error('reset fail!'); + } }); ``` @@ -4230,9 +4230,9 @@ reset(): Promise\ ```js videoPlayer.reset().then(() => { - console.info('reset success'); + console.info('reset success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4256,11 +4256,11 @@ seek(timeMs: number, callback: AsyncCallback\): void ```js let seekTime = 5000; videoPlayer.seek(seekTime, (err, result) => { - if (err == null) { - console.info('seek success!'); - } else { - console.info('seek fail!'); - } + if (err == null) { + console.info('seek success!'); + } else { + console.error('seek fail!'); + } }); ``` @@ -4286,11 +4286,11 @@ seek(timeMs: number, mode:SeekMode, callback: AsyncCallback\): void import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC, (err, result) => { - if (err == null) { - console.info('seek success!'); - } else { - console.info('seek fail!'); - } + if (err == null) { + console.info('seek success!'); + } else { + console.error('seek fail!'); + } }); ``` @@ -4321,15 +4321,15 @@ seek(timeMs: number, mode?:SeekMode): Promise\ import media from '@ohos.multimedia.media' let seekTime = 5000; videoPlayer.seek(seekTime).then((seekDoneTime) => { // seekDoneTime表示seek完成后的时间点 - console.info('seek success'); + console.info('seek success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); videoPlayer.seek(seekTime, media.SeekMode.SEEK_NEXT_SYNC).then((seekDoneTime) => { - console.info('seek success'); + console.info('seek success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4353,11 +4353,11 @@ setVolume(vol: number, callback: AsyncCallback\): void ```js let vol = 0.5; videoPlayer.setVolume(vol, (err, result) => { - if (err == null) { - console.info('setVolume success!'); - } else { - console.info('setVolume fail!'); - } + if (err == null) { + console.info('setVolume success!'); + } else { + console.error('setVolume fail!'); + } }); ``` @@ -4386,9 +4386,9 @@ setVolume(vol: number): Promise\ ```js let vol = 0.5; videoPlayer.setVolume(vol).then(() => { - console.info('setVolume success'); + console.info('setVolume success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4410,11 +4410,11 @@ release(callback: AsyncCallback\): void ```js videoPlayer.release((err) => { - if (err == null) { - console.info('release success!'); - } else { - console.info('release fail!'); - } + if (err == null) { + console.info('release success!'); + } else { + console.error('release fail!'); + } }); ``` @@ -4436,9 +4436,9 @@ release(): Promise\ ```js videoPlayer.release().then(() => { - console.info('release success'); + console.info('release success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4460,21 +4460,21 @@ getTrackDescription(callback: AsyncCallback\>): void ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('video key is ' + item); - console.info('video value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('video key is ' + item); + console.info('video value is ' + property); + } } videoPlayer.getTrackDescription((error, arrList) => { - if ((arrList) != null) { - for (let i = 0; i < arrList.length; i++) { - printfDescription(arrList[i]); - } - } else { - console.log(`video getTrackDescription fail, error:${error}`); + if ((arrList) != null) { + for (let i = 0; i < arrList.length; i++) { + printfDescription(arrList[i]); } + } else { + console.log(`video getTrackDescription fail, error:${error}`); + } }); ``` @@ -4496,25 +4496,25 @@ getTrackDescription(): Promise\> ```js function printfDescription(obj) { - for (let item in obj) { - let property = obj[item]; - console.info('video key is ' + item); - console.info('video value is ' + property); - } + for (let item in obj) { + let property = obj[item]; + console.info('video key is ' + item); + console.info('video value is ' + property); + } } let arrayDescription; videoPlayer.getTrackDescription().then((arrList) => { - if (arrList != null) { - arrayDescription = arrList; - } else { - console.log('video getTrackDescription fail'); - } + if (arrList != null) { + arrayDescription = arrList; + } else { + console.log('video getTrackDescription fail'); + } }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.info(`video catchCallback, error:${error}`); }); for (let i = 0; i < arrayDescription.length; i++) { - printfDescription(arrayDescription[i]); + printfDescription(arrayDescription[i]); } ``` @@ -4540,11 +4540,11 @@ import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; videoPlayer.setSpeed(speed, (err, result) => { - if (err == null) { - console.info('setSpeed success!'); - } else { - console.info('setSpeed fail!'); - } + if (err == null) { + console.info('setSpeed success!'); + } else { + console.error('setSpeed fail!'); + } }); ``` @@ -4575,9 +4575,9 @@ import media from '@ohos.multimedia.media' let speed = media.PlaybackSpeed.SPEED_FORWARD_2_00_X; videoPlayer.setSpeed(speed).then(() => { - console.info('setSpeed success'); + console.info('setSpeed success'); }).catch((error) => { - console.info(`video catchCallback, error:${error}`); + console.error(`video catchCallback, error:${error}`); }); ``` @@ -4600,7 +4600,7 @@ on(type: 'playbackCompleted', callback: Callback\): void ```js videoPlayer.on('playbackCompleted', () => { - console.info('playbackCompleted success!'); + console.info('playbackCompleted success!'); }); ``` @@ -4623,8 +4623,8 @@ on(type: 'bufferingUpdate', callback: (infoType: BufferingInfoType, value: numbe ```js videoPlayer.on('bufferingUpdate', (infoType, value) => { - console.log('video bufferingInfo type: ' + infoType); - console.log('video bufferingInfo value: ' + value); + console.log('video bufferingInfo type: ' + infoType); + console.log('video bufferingInfo value: ' + value); }); ``` @@ -4647,7 +4647,7 @@ on(type: 'startRenderFrame', callback: Callback\): void ```js videoPlayer.on('startRenderFrame', () => { - console.info('startRenderFrame success!'); + console.info('startRenderFrame success!'); }); ``` @@ -4670,8 +4670,8 @@ on(type: 'videoSizeChanged', callback: (width: number, height: number) => void): ```js videoPlayer.on('videoSizeChanged', (width, height) => { - console.log('video width is: ' + width); - console.log('video height is: ' + height); + console.log('video width is: ' + width); + console.log('video height is: ' + height); }); ``` @@ -4694,7 +4694,7 @@ on(type: 'error', callback: ErrorCallback): void ```js videoPlayer.on('error', (error) => { // 设置'error'事件回调 - console.info(`video error called, error: ${error}`); + console.error(`video error called, error: ${error}`); }); videoPlayer.url = 'fd://error'; //设置错误的播放地址,触发'error'事件 ``` @@ -4744,16 +4744,16 @@ prepare(config: AudioRecorderConfig): void ```js let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://1', // 文件需先由调用者创建,并给予适当的权限 - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://1', // 文件需先由调用者创建,并给予适当的权限 + location : { latitude : 30, longitude : 130}, } audioRecorder.on('prepare', () => { //设置'prepare'事件回调 - console.log('prepare success'); + console.log('prepare success'); }); audioRecorder.prepare(audioRecorderConfig); ``` @@ -4771,7 +4771,7 @@ start(): void ```js audioRecorder.on('start', () => { //设置'start'事件回调 - console.log('audio recorder start success'); + console.log('audio recorder start success'); }); audioRecorder.start(); ``` @@ -4788,7 +4788,7 @@ pause():void ```js audioRecorder.on('pause', () => { //设置'pause'事件回调 - console.log('audio recorder pause success'); + console.log('audio recorder pause success'); }); audioRecorder.pause(); ``` @@ -4805,7 +4805,7 @@ resume():void ```js audioRecorder.on('resume', () => { //设置'resume'事件回调 - console.log('audio recorder resume success'); + console.log('audio recorder resume success'); }); audioRecorder.resume(); ``` @@ -4822,7 +4822,7 @@ stop(): void ```js audioRecorder.on('stop', () => { //设置'stop'事件回调 - console.log('audio recorder stop success'); + console.log('audio recorder stop success'); }); audioRecorder.stop(); ``` @@ -4839,7 +4839,7 @@ release(): void ```js audioRecorder.on('release', () => { //设置'release'事件回调 - console.log('audio recorder release success'); + console.log('audio recorder release success'); }); audioRecorder.release(); audioRecorder = undefined; @@ -4859,7 +4859,7 @@ reset(): void ```js audioRecorder.on('reset', () => { //设置'reset'事件回调 - console.log('audio recorder reset success'); + console.log('audio recorder reset success'); }); audioRecorder.reset(); ``` @@ -4884,38 +4884,38 @@ on(type: 'prepare' | 'start' | 'pause' | 'resume' | 'stop' | 'release' | 'reset' ```js let audioRecorder = media.createAudioRecorder(); // 创建一个音频录制实例 let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + location : { latitude : 30, longitude : 130}, } audioRecorder.on('error', (error) => { // 设置'error'事件回调 - console.info(`audio error called, error: ${error}`); + console.info(`audio error called, error: ${error}`); }); audioRecorder.on('prepare', () => { // 设置'prepare'事件回调 - console.log('prepare success'); - audioRecorder.start(); // 开始录制,并触发'start'事件回调 + console.log('prepare success'); + audioRecorder.start(); // 开始录制,并触发'start'事件回调 }); audioRecorder.on('start', () => { // 设置'start'事件回调 - console.log('audio recorder start success'); + console.log('audio recorder start success'); }); audioRecorder.on('pause', () => { // 设置'pause'事件回调 - console.log('audio recorder pause success'); + console.log('audio recorder pause success'); }); audioRecorder.on('resume', () => { // 设置'resume'事件回调 - console.log('audio recorder resume success'); + console.log('audio recorder resume success'); }); audioRecorder.on('stop', () => { // 设置'stop'事件回调 - console.log('audio recorder stop success'); + console.log('audio recorder stop success'); }); audioRecorder.on('release', () => { // 设置'release'事件回调 - console.log('audio recorder release success'); + console.log('audio recorder release success'); }); audioRecorder.on('reset', () => { // 设置'reset'事件回调 - console.log('audio recorder reset success'); + console.log('audio recorder reset success'); }); audioRecorder.prepare(audioRecorderConfig) // 设置录制参数 ,并触发'prepare'事件回调 ``` @@ -4939,16 +4939,16 @@ on(type: 'error', callback: ErrorCallback): void ```js let audioRecorderConfig = { - audioEncoder : media.AudioEncoder.AAC_LC, - audioEncodeBitRate : 22050, - audioSampleRate : 22050, - numberOfChannels : 2, - format : media.AudioOutputFormat.AAC_ADTS, - uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 - location : { latitude : 30, longitude : 130}, + audioEncoder : media.AudioEncoder.AAC_LC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : 2, + format : media.AudioOutputFormat.AAC_ADTS, + uri : 'fd://xx', // 文件需先由调用者创建,并给予适当的权限 + location : { latitude : 30, longitude : 130}, } audioRecorder.on('error', (error) => { // 设置'error'事件回调 - console.info(`audio error called, error: ${error}`); + console.error(`audio error called, error: ${error}`); }); audioRecorder.prepare(audioRecorderConfig); // prepare不设置参数,触发'error'事件 ```