提交 e5a447e3 编写于 作者: Z zengyawen

update docs

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 98bd8197
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
- [Audio Playback Development Using AudioRenderer](audio-renderer.md) - [Audio Playback Development Using AudioRenderer](audio-renderer.md)
- [Audio Management Development](audio-management.md)
- [Audio Recording Development](audio-recorder.md) - [Audio Recording Development](audio-recorder.md)
- [Audio Recorder Development Using AudioCapturer](audio-capturer) - [Audio Recorder Development Using AudioCapturer](audio-capturer)
......
# Audio Management Development<a name="EN-US_TOPIC_0000001147178551"></a>
## When to Use<a name="section1269212236329"></a>
You use audio management APIs to set and obtain volume, and get information about input/output devices.
## Available APIs<a name="section5122103123215"></a>
**Table 1** APIs for audio management
<a name="table14861021152915"></a>
<table><thead align="left"><tr id="row1586142112297"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p12879217294"><a name="p12879217294"></a><a name="p12879217294"></a>API</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p58716212291"><a name="p58716212291"></a><a name="p58716212291"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row188719211298"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p122859462311"><a name="p122859462311"></a><a name="p122859462311"></a>getAudioManager(): AudioManager</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p587321182911"><a name="p587321182911"></a><a name="p587321182911"></a>Obtains an <strong id="b6542415195"><a name="b6542415195"></a><a name="b6542415195"></a>AudioManager</strong> instance.</p>
</td>
</tr>
<tr id="row118752119293"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1387142192917"><a name="p1387142192917"></a><a name="p1387142192917"></a>AudioManager</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p78762192915"><a name="p78762192915"></a><a name="p78762192915"></a>Manages audio volume and audio device information. For details, see <strong id="b1959135016"><a name="b1959135016"></a><a name="b1959135016"></a>AudioManager</strong>.</p>
</td>
</tr>
<tr id="row3871321172918"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p118712212292"><a name="p118712212292"></a><a name="p118712212292"></a><a href="#table5223445184315">AudioDeviceDescriptor</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p987182116295"><a name="p987182116295"></a><a name="p987182116295"></a>Describes audio devices.</p>
</td>
</tr>
<tr id="row1987172162912"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1287132152919"><a name="p1287132152919"></a><a name="p1287132152919"></a><a href="#table48202011451">AudioVolumeType</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1387221162913"><a name="p1387221162913"></a><a name="p1387221162913"></a>Enumerates audio volume types.</p>
</td>
</tr>
<tr id="row487192117299"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1287121122918"><a name="p1287121122918"></a><a name="p1287121122918"></a><a href="#table2959127489">DeviceFlag</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p787102117299"><a name="p787102117299"></a><a name="p787102117299"></a>Enumerates flags of supported devices.</p>
</td>
</tr>
<tr id="row171261911173510"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1412691112350"><a name="p1412691112350"></a><a name="p1412691112350"></a><a href="#table41106159499">DeviceRole</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p012791116358"><a name="p012791116358"></a><a name="p012791116358"></a>Enumerates device roles.</p>
</td>
</tr>
<tr id="row6530511173512"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p9530181193513"><a name="p9530181193513"></a><a name="p9530181193513"></a><a href="#table1238810503496">DeviceType</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p7530191117353"><a name="p7530191117353"></a><a name="p7530191117353"></a>Enumerates device types.</p>
</td>
</tr>
<tr id="row6530511173513"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p9530181193514"><a name="p9530181193514"></a><a name="p9530181193514"></a><a href="#audioscene">AudioScene</a></p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p7530191117354"><a name="p7530191117354"></a><a name="p7530191117354"></a>Enumerates audio scenes.</p>
</td>
</tr>
</tbody>
</table>
**Table 2** AudioManager methods
<a name="table5183104292517"></a>
<table><thead align="left"><tr id="row3183104212517"><th class="cellrowborder" valign="top" width="64.83%" id="mcps1.2.3.1.1"><p id="p950118362414"><a name="p950118362414"></a><a name="p950118362414"></a>Method</p>
</th>
<th class="cellrowborder" valign="top" width="35.17%" id="mcps1.2.3.1.2"><p id="p125017361644"><a name="p125017361644"></a><a name="p125017361644"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row0634135815263"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p102919146399"><a name="p102919146399"></a><a name="p102919146399"></a>setVolume(audioType: AudioVolumeType,volume: number,callback: AsyncCallback&lt;void&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p163555832612"><a name="p163555832612"></a><a name="p163555832612"></a>Sets the volume of a stream asynchronously and uses a callback to return the execution result.</p>
</td>
</tr>
<tr id="row574419319279"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p64791923153912"><a name="p64791923153912"></a><a name="p64791923153912"></a>setVolume(audioType: AudioVolumeType,volume: number): Promise&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p674443182715"><a name="p674443182715"></a><a name="p674443182715"></a>Sets the volume of a stream asynchronously and uses a Promise to return the execution result.</p>
</td>
</tr>
<tr id="row1348213114277"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1293542863917"><a name="p1293542863917"></a><a name="p1293542863917"></a>getVolume(audioType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p8482201142715"><a name="p8482201142715"></a><a name="p8482201142715"></a>Obtains the volume of a stream asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row872195279"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1124013343392"><a name="p1124013343392"></a><a name="p1124013343392"></a>getVolume(audioType: AudioVolumeType): Promise&lt;number&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p1273493271"><a name="p1273493271"></a><a name="p1273493271"></a>Obtains the volume of a stream asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
<tr id="row3300184416273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p14484174015396"><a name="p14484174015396"></a><a name="p14484174015396"></a>getMinVolume(audioType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p130194472719"><a name="p130194472719"></a><a name="p130194472719"></a>Obtains the minimum volume of a stream asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row747314483273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p88551509397"><a name="p88551509397"></a><a name="p88551509397"></a>getMinVolume(audioType: AudioVolumeType): Promise&lt;number&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p1747464810273"><a name="p1747464810273"></a><a name="p1747464810273"></a>Obtains the minimum volume of a stream asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
<tr id="row9417164614274"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p147247575391"><a name="p147247575391"></a><a name="p147247575391"></a>getMaxVolume(audioType: AudioVolumeType, callback: AsyncCallback&lt;number&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p1441884632714"><a name="p1441884632714"></a><a name="p1441884632714"></a>Obtains the maximum volume of a stream asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row199921350162711"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p191994474013"><a name="p191994474013"></a><a name="p191994474013"></a>getMaxVolume(audioType: AudioVolumeType): Promise&lt;number&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p1999235072718"><a name="p1999235072718"></a><a name="p1999235072718"></a>Obtains the maximum volume of a stream asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>getDevices(deviceFlag: DeviceFlag, callback: AsyncCallback&lt;AudioDeviceDescriptors&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Obtains the device list asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row1982485992714"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1242861714408"><a name="p1242861714408"></a><a name="p1242861714408"></a>getDevices(deviceFlag: DeviceFlag): Promise&lt;AudioDeviceDescriptors&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p16825195911278"><a name="p16825195911278"></a><a name="p16825195911278"></a>Obtains the device list asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback&lt;void&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Activates the device asynchronously and uses a callback to return the execution result.</p>
</td>
</tr>
<tr id="row1982485992714"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1242861714408"><a name="p1242861714408"></a><a name="p1242861714408"></a>setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p16825195911278"><a name="p16825195911278"></a><a name="p16825195911278"></a>Activates the device asynchronously and uses a Promise to return the execution result.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback&lt;boolean&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Checks whether a device is active asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row1982485992714"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1242861714408"><a name="p1242861714408"></a><a name="p1242861714408"></a>isDeviceActive(deviceType: ActiveDeviceType): Promise&lt;boolean&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p16825195911278"><a name="p16825195911278"></a><a name="p16825195911278"></a>Checks whether a device is active asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>on(type: 'deviceChange', callback: AsyncCallback&lt;DeviceChangeAction&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Subscribes to device change events. Registered clients will receieve the callback when a device is connected/disconnected.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>setAudioScene(scene: AudioScene, callback: AsyncCallback&lt;void&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Sets the audio scene mode asynchronously and uses a callback to return the execution result.</p>
</td>
</tr>
<tr id="row1982485992714"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1242861714408"><a name="p1242861714408"></a><a name="p1242861714408"></a>setAudioScene(scene: AudioScene): Promise&lt;void&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p16825195911278"><a name="p16825195911278"></a><a name="p16825195911278"></a>Sets the audio scene mode asynchronously and uses a Promise to return the execution result.</p>
</td>
</tr>
<tr id="row182815717273"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p10833698408"><a name="p10833698408"></a><a name="p10833698408"></a>getAudioScene(callback: AsyncCallback&lt;AudioScene&gt;): void</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p112818572270"><a name="p112818572270"></a><a name="p112818572270"></a>Obtains the audio scene mode asynchronously and uses a callback to return the result.</p>
</td>
</tr>
<tr id="row1982485992714"><td class="cellrowborder" valign="top" width="64.83%" headers="mcps1.2.3.1.1 "><p id="p1242861714408"><a name="p1242861714408"></a><a name="p1242861714408"></a>getAudioScene(): Promise&lt;AudioScene&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="35.17%" headers="mcps1.2.3.1.2 "><p id="p16825195911278"><a name="p16825195911278"></a><a name="p16825195911278"></a>Obtains the audio scene mode asynchronously and uses a Promise to return the result.</p>
</td>
</tr>
</tbody>
</table>
**Table 3** AudioDeviceDescriptor attributes
<a name="table5223445184315"></a>
<table><thead align="left"><tr id="row72237455433"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p82931051124313"><a name="p82931051124313"></a><a name="p82931051124313"></a>Parameter</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1229365113434"><a name="p1229365113434"></a><a name="p1229365113434"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row3223745114317"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p7416236174410"><a name="p7416236174410"></a><a name="p7416236174410"></a>deviceRole: DeviceRole</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p16223104511433"><a name="p16223104511433"></a><a name="p16223104511433"></a>Audio device role</p>
</td>
</tr>
<tr id="row6223194516430"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p622374516437"><a name="p622374516437"></a><a name="p622374516437"></a>deviceType: DeviceType</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p172237458430"><a name="p172237458430"></a><a name="p172237458430"></a>Audio device type</p>
</td>
</tr>
</tbody>
</table>
**Table 4** AudioVolumeType enums
<a name="table48202011451"></a>
<table><thead align="left"><tr id="row7872094512"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p3372527184510"><a name="p3372527184510"></a><a name="p3372527184510"></a>Enum</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1737222710450"><a name="p1737222710450"></a><a name="p1737222710450"></a>Description</p>
</th>
</tr>
</thead>
<tbody>
<tr id="row188162012454"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p764215288462"><a name="p764215288462"></a><a name="p764215288462"></a>VOICE_CALL = 0</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1596200459"><a name="p1596200459"></a><a name="p1596200459"></a>Audio streams for voice calls</p>
</td>
</tr>
<tr id="row188162012454"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p764215288462"><a name="p764215288462"></a><a name="p764215288462"></a>MEDIA = 1</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1596200459"><a name="p1596200459"></a><a name="p1596200459"></a>Audio streams for media purpose</p>
</td>
</tr>
<tr id="row1288915367468"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p51611346194614"><a name="p51611346194614"></a><a name="p51611346194614"></a>RINGTONE = 2</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9333131144712"><a name="p9333131144712"></a><a name="p9333131144712"></a>Audio streams for ring tones</p>
<tr id="row188162012454"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p764215288462"><a name="p764215288462"></a><a name="p764215288462"></a>VOICE_ASSISTANT = 9</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1596200459"><a name="p1596200459"></a><a name="p1596200459"></a>Audio streams for voice assistant</p>
</td>
</tr>
</td>
</tr>
</tbody>
</table>
**Table 5** DeviceFlag enums
<a name="table2959127489"></a>
<table><thead align="left"><tr id="row0959122483"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p10301718485"><a name="p10301718485"></a><a name="p10301718485"></a>Enum</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p8314178482"><a name="p8314178482"></a><a name="p8314178482"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row7967128484"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p149631217480"><a name="p149631217480"></a><a name="p149631217480"></a>OUTPUT_DEVICES_FLAG = 1</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p119613126489"><a name="p119613126489"></a><a name="p119613126489"></a>Output devices</p>
</td>
</tr>
<tr id="row169691220485"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1796201204814"><a name="p1796201204814"></a><a name="p1796201204814"></a>INPUT_DEVICES_FLAG = 2</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p796181254810"><a name="p796181254810"></a><a name="p796181254810"></a>Input devices</p>
</td>
</tr>
<tr id="row1696812154817"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p396191218482"><a name="p396191218482"></a><a name="p396191218482"></a>ALL_DEVICES_FLAG = 3</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p29612124485"><a name="p29612124485"></a><a name="p29612124485"></a>All devices</p>
</td>
</tr>
</tbody>
</table>
**Table 6** DeviceRole enums
<a name="table41106159499"></a>
<table><thead align="left"><tr id="row1811011515495"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p2090221774914"><a name="p2090221774914"></a><a name="p2090221774914"></a>Enum</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p99029172498"><a name="p99029172498"></a><a name="p99029172498"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row1611031534915"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p711111150497"><a name="p711111150497"></a><a name="p711111150497"></a>INPUT_DEVICE = 1</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p81111715114914"><a name="p81111715114914"></a><a name="p81111715114914"></a>Input role</p>
</td>
</tr>
<tr id="row19111171574916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p111112153492"><a name="p111112153492"></a><a name="p111112153492"></a>OUTPUT_DEVICE = 2</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p9111141504916"><a name="p9111141504916"></a><a name="p9111141504916"></a>Output role</p>
</td>
</tr>
</tbody>
</table>
**Table 7** DeviceType enums
<a name="table1238810503496"></a>
<table><thead align="left"><tr id="row1738810504498"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p973775318495"><a name="p973775318495"></a><a name="p973775318495"></a>Enum</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p17737253174912"><a name="p17737253174912"></a><a name="p17737253174912"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row2388155012491"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p2038925064917"><a name="p2038925064917"></a><a name="p2038925064917"></a>INVALID = 0</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p17389145016497"><a name="p17389145016497"></a><a name="p17389145016497"></a>Invalid device</p>
</td>
</tr>
<tr id="row938915016493"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p538925044916"><a name="p538925044916"></a><a name="p538925044916"></a>SPEAKER = 2</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p16724165865017"><a name="p16724165865017"></a><a name="p16724165865017"></a>Speaker</p>
</td>
</tr>
<tr id="row12389105084916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p538914502497"><a name="p538914502497"></a><a name="p538914502497"></a>WIRED_HEADSET = 3</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p63891850144911"><a name="p63891850144911"></a><a name="p63891850144911"></a>Wired headset</p>
</td>
</tr>
<tr id="row2389205074915"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p10389175054919"><a name="p10389175054919"></a><a name="p10389175054919"></a>BLUETOOTH_SCO = 7</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p538905016496"><a name="p538905016496"></a><a name="p538905016496"></a>Bluetooth device using the synchronous connection oriented (SCO) link</p>
</td>
</tr>
<tr id="row83891502499"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1938975015494"><a name="p1938975015494"></a><a name="p1938975015494"></a>BLUETOOTH_A2DP = 8</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p193891550134912"><a name="p193891550134912"></a><a name="p193891550134912"></a>Bluetooth device using advanced audio distribution profile (A2DP)</p>
</td>
</tr>
<tr id="row11389175014916"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1738955018497"><a name="p1738955018497"></a><a name="p1738955018497"></a>MIC = 15</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p73891250174914"><a name="p73891250174914"></a><a name="p73891250174914"></a>Microphone</p>
</td>
</tr>
</tbody>
</table>
**Table 8** AudioScene enums<a name="audioscenetable"></a>
Enumerates audio scenes.
| Name | Description |
| :----------------------------- | :---------------------------- |
| AUDIO_SCENE_DEFAULT = 0 | Default audio scene. <br/> |
| AUDIO_SCENE_RINGING = 1 | Ringing audio scene. <br/> |
| AUDIO_SCENE_PHONE_CALL = 2 | Phone call audio scene. <br/> |
| AUDIO_SCENE_VOICE_CHAT = 3 | Voice chat audio scene. <br/> |
## Development Procedure<a name="section1772415410138"></a>
1. Obtain an audio manager.
```
const audioManager = audio.getAudioManager();
```
2. Obtain the audio stream volume.
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getVolume ${value}`);
});
```
## Usage <a name="usage"></a>
**setAudioScene**
**Example**
Here's an example of how to use setAudioScene to change the audio strategy for the phone call scene.
1. Obtain an audio manager.
```
const audioManager = audio.getAudioManager();
```
2. Change the audio scene to phone call.
```
audioManager.setAudioScene(audio.AudioScene.AUDIO_SCENE_PHONE_CALL, (err) => {
if (err) {
console.error('Failed to set the audio scene mode.​ ${err.message}');
return;
}
console.log('Audio scene mode setting is successful.');
});
```
**getAudioScene**
**Example**
Here's an example of how to use getAudioScene to obtain the current audio scene.
1. Obtain an audio manager.
```
const audioManager = audio.getAudioManager();
```
2. Obtain the current audio scene.
```
audioManager.getAudioScene((err, value) => {
if (err) {
console.error('Failed to obtain the audio scene mode.​ ${err.message}');
return;
}
console.log('Audio scene mode ${value)');
})
```
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
- [音频录制开发指导](audio-recorder.md) - [音频录制开发指导](audio-recorder.md)
- [音频渲染开发指导](audio-renderer.md) - [音频渲染开发指导](audio-renderer.md)
- [音频采集开发指导](audio-capturer.md) - [音频采集开发指导](audio-capturer.md)
- [音频管理开发指导](audio-management.md)
- 视频 - 视频
- [视频播放开发指导](video-playback.md) - [视频播放开发指导](video-playback.md)
......
# 音频管理开发指导
## 场景介绍
音频管理的主要工作是音量调节与音量查询,以及输入/输出设备查询。
## 接口说明
**表1** audio的相关接口
| 接口名 | 描述 |
| -------- | -------- |
| getAudioManager():&nbsp;AudioManager | 获得音频管理器。 |
| AudioManager | 音频管理器。具体参考表&nbsp;音频管理相关的interface&nbsp;AudioManager。 |
| AudioDeviceDescriptor | 描述音频设备。 |
| AudioVolumeType | 表示音频流类型的枚举。 |
| DeviceFlag | 表示可获取的设备种类的枚举。 |
| DeviceRole | 表示设备角色的枚举。 |
| DeviceType | 表示设备类型的枚举。 |
| AudioScene | 表示音频场景的枚举。 |
**表2** 音频管理相关的interface **AudioManager**
| 接口名 | 描述 |
| -------- | -------- |
| setVolume(audioType:&nbsp;AudioVolumeType,volume:&nbsp;number,callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | 改变某个流的音量。 |
| setVolume(audioType:&nbsp;AudioVolumeType,volume:&nbsp;number):&nbsp;Promise&lt;void&gt; | 改变某个流的音量。 |
| getVolume(audioType:&nbsp;AudioVolumeType,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):&nbsp;void | 获得某个流的音量。 |
| getVolume(audioType:&nbsp;AudioVolumeType):&nbsp;Promise&lt;number&gt; | 获得某个流的音量。 |
| getMinVolume(audioType:&nbsp;AudioVolumeType,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):&nbsp;void | 获得某个流的最小音量。 |
| getMinVolume(audioType:&nbsp;AudioVolumeType):&nbsp;Promise&lt;number&gt; | 获得某个流的最小音量。 |
| getMaxVolume(audioType:&nbsp;AudioVolumeType,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):&nbsp;void | 获得某个流的最大音量。 |
| getMaxVolume(audioType:&nbsp;AudioVolumeType):&nbsp;Promise&lt;number&gt; | 获得某个流的最大音量。 |
| getDevices(deviceFlag:&nbsp;DeviceFlag,&nbsp;callback:&nbsp;AsyncCallback&lt;AudioDeviceDescriptors&gt;):&nbsp;void | 获得设备列表。 |
| getDevices(deviceFlag:&nbsp;DeviceFlag):&nbsp;Promise&lt;AudioDeviceDescriptors&gt; | 获得设备列表。 |
| setDeviceActive(deviceType: ActiveDeviceType, active: boolean, callback: AsyncCallback<void>): void | 激活设备,使用callback返回异步结果 |
| setDeviceActive(deviceType: ActiveDeviceType, active: boolean): Promise<void> | 激活设备,使用Promise返回异步结果。 |
| isDeviceActive(deviceType: ActiveDeviceType, callback: AsyncCallback<boolean>): void | 检查设备是否激活,使用callback返回异步结果。 |
| isDeviceActive(deviceType: ActiveDeviceType): Promise<boolean> | 检查设备是否激活,使用Promise返回异步结果。 |
| on(type: 'deviceChange', callback: AsyncCallback<DeviceChangeAction>): void | 订阅设备更改事件。 当设备连接或断开时,注册的客户端将收到回调。 |
| setAudioScene(scene: AudioScene, callback: AsyncCallback<void>): void | 设置音频场景模式,使用callback返回异步结果。 |
| setAudioScene(scene: AudioScene): Promise<void> | 设置音频场景模式,使用Promise返回异步结果。 |
| getAudioScene(callback: AsyncCallback<AudioScene>): void | 获取音频场景模式,使用callback返回异步结果。 |
| getAudioScene(): Promise<AudioScene> | 获取音频场景模式,使用Promise返回异步结果。 |
**表3** 表示音频设备的interface **AudioDeviceDescriptor**
| 属性 | 描述 |
| -------- | -------- |
| deviceRole:&nbsp;DeviceRole | 设备角色。 |
| deviceType:&nbsp;DeviceType | 设备类型。 |
**表4** 表示音频流类型的枚举**AudioVolumeType**
| 枚举值 | 描述 |
| -------- | -------- |
| VOICE_CALL = 0 | 语音通话。 |
| MEDIA&nbsp;=&nbsp;1 | 媒体声音。 |
| RINGTONE&nbsp;=&nbsp;2 | 铃声。 |
| VOICE_ASSISTANT = 9 | 语音助手。 |
**表5** 表示可获取的设备种类的枚举**DeviceFlag**
| 枚举值 | 描述 |
| -------- | -------- |
| OUTPUT_DEVICES_FLAG&nbsp;=&nbsp;1 | 输出设备。 |
| INPUT_DEVICES_FLAG&nbsp;=&nbsp;2 | 输入设备。 |
| ALL_DEVICES_FLAG&nbsp;=&nbsp;3 | 所有设备。 |
**表6** 表示设备角色的枚举**DeviceRole**
| 枚举值 | 描述 |
| -------- | -------- |
| INPUT_DEVICE&nbsp;=&nbsp;1 | 输入设备。 |
| OUTPUT_DEVICE&nbsp;=&nbsp;2 | 输出设备。 |
**表7** 表示设备类型的枚举**DeviceType**
| 枚举值 | 描述 |
| -------- | -------- |
| INVALID&nbsp;=&nbsp;0 | 无效。 |
| SPEAKER&nbsp;=&nbsp;2 | 扬声器。 |
| WIRED_HEADSET&nbsp;=&nbsp;3 | 有线耳机。 |
| BLUETOOTH_SCO&nbsp;=&nbsp;7 | 蓝牙设备。 |
| BLUETOOTH_A2DP&nbsp;=&nbsp;8 | 支持A2DP的蓝牙设备。 |
| MIC&nbsp;=&nbsp;15 | 麦克风。 |
**表8** 表示音频模式的枚举** **AudioScene **
| Name | Description |
| :------------------------- | :----------------------- |
| AUDIO_SCENE_DEFAULT = 0 | 默认的音频。 <br/> |
| AUDIO_SCENE_RINGING = 1 | 响铃音频场景。 <br/> |
| AUDIO_SCENE_PHONE_CALL = 2 | 电话音频场景。 <br/> |
| AUDIO_SCENE_VOICE_CHAT = 3 | 语音聊天音频场景。 <br/> |
## 开发步骤
1. 获取音频控制器。
```
const audioManager = audio.getAudioManager();
```
2. 改变媒体流的声音。
```
audioManager.getVolume(audio.AudioVolumeType.MEDIA, (err, value) => {
if (err) {
console.error(`failed to get volume ${err.message}`);
return;
}
console.log(`Media getVolume ${value}`);
});
```
## 使用方法
**setAudioScene**
**示例**
1. 获取音频管理器。
```
const audioManager = audio.getAudioManager();
```
2. 获取当前的音频场景。
```
audioManager.getAudioScene((err, value) => {
if (err) {
console.error('Failed to obtain the audio scene mode.​ ${err.message}');
return;
}
console.log('Audio scene mode ${value)');
})
```
\ No newline at end of file
# 相机管理 # 相机管理
> **说明:** > **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册