提交 93258ede 编写于 作者: W wusongqing

updated audio api

Signed-off-by: Nwusongqing <wusongqing@huawei.com>
上级 9e64c0ff
...@@ -224,7 +224,7 @@ var audioCapturerOptions = { ...@@ -224,7 +224,7 @@ var audioCapturerOptions = {
} }
var audioCapturer; var audioCapturer;
audio.createAudioRenderer(audioCapturerOptions).then((data) => { audio.createAudioCapturer(audioCapturerOptions).then((data) => {
audioCapturer = data; audioCapturer = data;
console.info('AudioCapturer Created : Success : Stream Type: SUCCESS'); console.info('AudioCapturer Created : Success : Stream Type: SUCCESS');
}).catch((err) => { }).catch((err) => {
...@@ -567,8 +567,8 @@ Describes the device connection status and device information. ...@@ -567,8 +567,8 @@ Describes the device connection status and device information.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :---------------- | :------------------------------------------------ | :--- | :----------------- | | :---------------- | :------------------------------------------------ | :--- | :----------------- |
| type | [DeviceChangeType](#DeviceChangeType) | Yes | Device connection status.| | type | [DeviceChangeType](#devicechangetype) | Yes | Device connection status.|
| deviceDescriptors | [AudioDeviceDescriptors](#AudioDeviceDescriptors) | Yes | Device information. | | deviceDescriptors | [AudioDeviceDescriptors](#audiodevicedescriptors) | Yes | Device information. |
## DeviceChangeType ## DeviceChangeType
...@@ -646,7 +646,7 @@ Sets the volume for a stream. This API uses an asynchronous callback to return t ...@@ -646,7 +646,7 @@ Sets the volume for a stream. This API uses an asynchronous callback to return t
| ---------- | ----------------------------------- | ---- | -------------------------------------------------------- | | ---------- | ----------------------------------- | ---- | -------------------------------------------------------- |
| volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. | | volumeType | [AudioVolumeType](#audiovolumetype) | Yes | Audio stream type. |
| volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.| | volume | number | Yes | Volume to set. The value range can be obtained by calling **getMinVolume** and **getMaxVolume**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. | | callback | AsyncCallback&lt;void\> | Yes | Callback used to return the result. |
**Example** **Example**
...@@ -1314,7 +1314,7 @@ Sets a device to the active state. This API uses an asynchronous callback to ret ...@@ -1314,7 +1314,7 @@ Sets a device to the active state. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true, (err) => { audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true, (err) => {
if (err) { if (err) {
console.error('Failed to set the active status of the device. ${err.message}'); console.error('Failed to set the active status of the device. ${err.message}');
return; return;
...@@ -1348,7 +1348,7 @@ Sets a device to the active state. This API uses a promise to return the result. ...@@ -1348,7 +1348,7 @@ Sets a device to the active state. This API uses a promise to return the result.
``` ```
audioManager.setDeviceActive(audio.DeviceType.SPEAKER, true).then(() => { audioManager.setDeviceActive(audio.ActiveDeviceType.SPEAKER, true).then(() => {
console.log('Promise returned to indicate that the device is set to the active status.'); console.log('Promise returned to indicate that the device is set to the active status.');
}); });
``` ```
...@@ -1371,7 +1371,7 @@ Checks whether a device is active. This API uses an asynchronous callback to ret ...@@ -1371,7 +1371,7 @@ Checks whether a device is active. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER, (err, value) => { audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER, (err, value) => {
if (err) { if (err) {
console.error('Failed to obtain the active status of the device. ${err.message}'); console.error('Failed to obtain the active status of the device. ${err.message}');
return; return;
...@@ -1404,7 +1404,7 @@ Checks whether a device is active. This API uses a promise to return the result. ...@@ -1404,7 +1404,7 @@ Checks whether a device is active. This API uses a promise to return the result.
**Example** **Example**
``` ```
audioManager.isDeviceActive(audio.DeviceType.SPEAKER).then((value) => { audioManager.isDeviceActive(audio.ActiveDeviceType.SPEAKER).then((value) => {
console.log('Promise returned to indicate that the active status of the device is obtained.' + value); console.log('Promise returned to indicate that the active status of the device is obtained.' + value);
}); });
``` ```
...@@ -1638,7 +1638,7 @@ var interAudioInterrupt = { ...@@ -1638,7 +1638,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
this.audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => { audioManager.on('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to gain the audio focus starts."); console.log("An event to gain the audio focus starts.");
console.log("Focus gain event:" + JSON.stringify(InterruptAction)); console.log("Focus gain event:" + JSON.stringify(InterruptAction));
...@@ -1674,7 +1674,7 @@ var interAudioInterrupt = { ...@@ -1674,7 +1674,7 @@ var interAudioInterrupt = {
contentType:0, contentType:0,
pauseWhenDucked:true pauseWhenDucked:true
}; };
this.audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => { audioManager.off('interrupt', interAudioInterrupt, (InterruptAction) => {
if (InterruptAction.actionType === 0) { if (InterruptAction.actionType === 0) {
console.log("An event to release the audio focus starts."); console.log("An event to release the audio focus starts.");
console.log("Focus release event:" + JSON.stringify(InterruptAction)); console.log("Focus release event:" + JSON.stringify(InterruptAction));
...@@ -1736,7 +1736,7 @@ This is a system API and cannot be called by third-party applications. ...@@ -1736,7 +1736,7 @@ This is a system API and cannot be called by third-party applications.
**Example** **Example**
``` ```
audioManager.setAudioScene(audio.AudioSceneMode.AUDIO_SCENE_PHONE_CALL).then(() => { audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL).then(() => {
console.log('Promise returned to indicate a successful setting of the audio scene mode.'); console.log('Promise returned to indicate a successful setting of the audio scene mode.');
}).catch ((err) => { }).catch ((err) => {
console.log('Failed to set the audio scene mode'); console.log('Failed to set the audio scene mode');
...@@ -1895,6 +1895,7 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us ...@@ -1895,6 +1895,7 @@ Obtains the renderer information of this **AudioRenderer** instance. This API us
**Example** **Example**
``` ```
var resultFlag = true;
audioRenderer.getRendererInfo().then((rendererInfo) => { audioRenderer.getRendererInfo().then((rendererInfo) => {
console.log('Renderer GetRendererInfo:'); console.log('Renderer GetRendererInfo:');
console.log('Renderer content:' + rendererInfo.content); console.log('Renderer content:' + rendererInfo.content);
...@@ -2341,13 +2342,11 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -2341,13 +2342,11 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Example** **Example**
``` ```
audioRenderer.getBufferSize((err, bufferSize) => { var bufferSize = audioRenderer.getBufferSize(async(err, bufferSize) => {
if (err) { if (err) {
console.error('getBufferSize error'); console.error('getBufferSize error');
} }
}); });
let buf = new ArrayBuffer(bufferSize);
ss.readSync(buf);
``` ```
### getBufferSize<sup>8+</sup> ### getBufferSize<sup>8+</sup>
...@@ -2367,11 +2366,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a ...@@ -2367,11 +2366,12 @@ Obtains a reasonable minimum buffer size in bytes for rendering. This API uses a
**Example** **Example**
``` ```
audioRenderer.getBufferSize().then((bufferSize) => { var bufferSize;
let buf = new ArrayBuffer(bufferSize); await audioRenderer.getBufferSize().then(async function (data) => {
ss.readSync(buf); console.info('AudioFrameworkRenderLog: getBufferSize :SUCCESS '+data);
bufferSize=data;
}).catch((err) => { }).catch((err) => {
console.log('ERROR: '+err.message); console.info('AudioFrameworkRenderLog: getBufferSize :ERROR : '+err.message);
}); });
``` ```
...@@ -2496,7 +2496,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru ...@@ -2496,7 +2496,9 @@ Subscribes to audio interruption events. This API uses a callback to get interru
**Example** **Example**
``` ```
audioRenderer.on('interrupt', (interruptEvent) => { var isPlay;
var started;
audioRenderer.on('interrupt', async(interruptEvent) => {
if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) { if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_FORCE) {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
...@@ -2509,14 +2511,33 @@ audioRenderer.on('interrupt', (interruptEvent) => { ...@@ -2509,14 +2511,33 @@ audioRenderer.on('interrupt', (interruptEvent) => {
break; break;
} }
} else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) { } else if (interruptEvent.forceType == audio.InterruptForceType.INTERRUPT_SHARE) {
switch (interruptEvent.hintType) { switch (interruptEvent.hintType) {
case audio.InterruptHint.INTERRUPT_HINT_RESUME: case audio.InterruptHint.INTERRUPT_HINT_RESUME:
console.log('Resume force paused renderer or ignore'); console.log('Resume force paused renderer or ignore');
startRenderer(); await audioRenderer.start().then(async function () {
console.info('AudioInterruptMusic: renderInstant started :SUCCESS ');
started = true;
}).catch((err) => {
console.info('AudioInterruptMusic: renderInstant start :ERROR : '+err.message);
started = false;
});
if (started) {
isPlay = true;
console.info('AudioInterruptMusic Renderer started : isPlay : '+isPlay);
} else {
console.error('AudioInterruptMusic Renderer start failed');
}
break; break;
case audio.InterruptHint.INTERRUPT_HINT_PAUSE: case audio.InterruptHint.INTERRUPT_HINT_PAUSE:
console.log('Choose to pause or ignore'); console.log('Choose to pause or ignore');
pauseRenderer(); if (isPlay == true) {
isPlay == false;
console.info('AudioInterruptMusic: Media PAUSE : TRUE');
}
else {
isPlay = true;
console.info('AudioInterruptMusic: Media PLAY : TRUE');
}
break; break;
} }
} }
...@@ -2885,7 +2906,7 @@ Stops capturing. This API uses a promise to return the result. ...@@ -2885,7 +2906,7 @@ Stops capturing. This API uses a promise to return the result.
audioCapturer.stop().then(() => { audioCapturer.stop().then(() => {
console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------'); console.info('AudioFrameworkRecLog: ---------RELEASE RECORD---------');
console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS'); console.info('AudioFrameworkRecLog: Capturer stopped : SUCCESS');
if ((audioCapturer.state == audioCapturer.AudioState.STATE_STOPPED)){ if ((audioCapturer.state == audio.AudioState.STATE_STOPPED)){
stateFlag=true; stateFlag=true;
console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag); console.info('AudioFrameworkRecLog: resultFlag : '+stateFlag);
} }
...@@ -2945,8 +2966,6 @@ audioCapturer.release().then(() => { ...@@ -2945,8 +2966,6 @@ audioCapturer.release().then(() => {
console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state); console.info('AudioFrameworkRecLog: AudioCapturer : STATE : '+audioCapturer.state);
stateFlag=true; stateFlag=true;
console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag); console.info('AudioFrameworkRecLog: stateFlag : '+stateFlag);
expect(stateFlag).assertTrue();
done();
}).catch((err) => { }).catch((err) => {
console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message); console.info('AudioFrameworkRecLog: Capturer stop:ERROR : '+err.message);
stateFlag=false stateFlag=false
...@@ -3108,15 +3127,12 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a ...@@ -3108,15 +3127,12 @@ Obtains a reasonable minimum buffer size in bytes for capturing. This API uses a
**Example** **Example**
``` ```
audioCapturer.getBufferSize().then((bufferSize) => { await audioCapturer.getBufferSize().then(async function (bufferSize) {
if (!err) { console.info('AudioFrameworkRecordLog: getBufferSize :SUCCESS '+ bufferSize);
console.log('BufferSize : ' + bufferSize); var buffer = await audioCapturer.read(bufferSize, true);
audioCapturer.read(bufferSize, true).then((buffer) => { console.info('Buffer read is ' + buffer );
console.info('Buffer read is ' + buffer ); }).catch((err) => {
}).catch((err) => { console.info('AudioFrameworkRecordLog: getBufferSize :ERROR : '+err.message);
console.info('ERROR : '+err.message);
});
}
}); });
``` ```
...@@ -3180,7 +3196,7 @@ Subscribes to mark reached events. When the period of frame capturing reaches th ...@@ -3180,7 +3196,7 @@ Subscribes to mark reached events. When the period of frame capturing reaches th
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| :------- | :----------------------- | :--- | :------------------------------------------ | | :------- | :----------------------- | :--- | :------------------------------------------ |
| type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.| | type | string | Yes | Type of event to subscribe to. The value **periodReach** means the period reached event, which is triggered when the period of frame capturing reaches the value of the **frame** parameter.|
| frame | number | Yes | Period during which frame rendering is listened. The value must be greater than **0**. | | frame | number | Yes | Period during which frame capturing is listened. The value must be greater than **0**. |
| callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. | | callback | (position: number) => {} | Yes | Callback invoked when the event is triggered. |
**Example** **Example**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册