1# @ohos.bluetooth.a2dp (Bluetooth A2DP Module) 2 3The **a2dp** module provides APIs for using the Bluetooth Advanced Audio Distribution Profile (A2DP), which defines how to stream high quality audio from one device to another over a Bluetooth connection. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9 10## Modules to Import 11 12```js 13import { a2dp } from '@kit.ConnectivityKit'; 14``` 15 16## BaseProfile 17 18type BaseProfile = baseProfile.BaseProfile 19 20Defines **BaseProfile** APIs. 21 22**System capability**: SystemCapability.Communication.Bluetooth.Core 23 24| Type | Description | 25| ----------------------------- | ---------- | 26| [baseProfile.BaseProfile](js-apis-bluetooth-baseProfile.md#baseprofile) | **BaseProfile** API definition.| 27 28 29## a2dp.createA2dpSrcProfile 30 31createA2dpSrcProfile(): A2dpSourceProfile 32 33Creates an **A2dpSrcProfile** instance. 34 35**System capability**: SystemCapability.Communication.Bluetooth.Core 36 37**Return value** 38 39| Type | Description | 40| ----------------------------- | ---------- | 41| [A2dpSourceProfile](#a2dpsourceprofile) | **A2dpSrcProfile** instance created.| 42 43**Error codes** 44 45For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 46 47| ID| Error Message| 48| -------- | ---------------------------- | 49|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 50|801 | Capability not supported. | 51 52 53**Example** 54 55```js 56import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 57try { 58 let a2dpProfile = a2dp.createA2dpSrcProfile(); 59 console.info('a2dp success'); 60} catch (err) { 61 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 62} 63``` 64 65 66## A2dpSourceProfile 67 68Provides APIs for using the A2DP. Before using any API of **A2dpSourceProfile**, you need to create an instance of this class by using [createA2dpSrcProfile()](#a2dpcreatea2dpsrcprofile). 69 70 71### getPlayingState 72 73getPlayingState(deviceId: string): PlayingState 74 75Obtains the playing state of a device. 76 77**Required permissions**: ohos.permission.ACCESS_BLUETOOTH 78 79**System capability**: SystemCapability.Communication.Bluetooth.Core 80 81**Parameters** 82 83| Name | Type | Mandatory | Description | 84| ------ | ------ | ---- | ------- | 85| deviceId | string | Yes | Address of the remote device.| 86 87**Return value** 88 89| Type | Description | 90| ----------------------------- | ---------- | 91| [PlayingState](#playingstate) | Playing state of the remote device obtained.| 92 93**Error codes** 94 95For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Bluetooth Error Codes](errorcode-bluetoothManager.md). 96 97| ID| Error Message| 98| -------- | ---------------------------- | 99|201 | Permission denied. | 100|401 | Invalid parameter. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verification failed. | 101|801 | Capability not supported. | 102|2900001 | Service stopped. | 103|2900003 | Bluetooth disabled. | 104|2900004 | Profile not supported. | 105|2900099 | Operation failed. | 106 107**Example** 108 109```js 110import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; 111try { 112 let a2dpSrc = a2dp.createA2dpSrcProfile(); 113 let state = a2dpSrc.getPlayingState('XX:XX:XX:XX:XX:XX'); 114} catch (err) { 115 console.error('errCode: ' + (err as BusinessError).code + ', errMessage: ' + (err as BusinessError).message); 116} 117``` 118 119 120## PlayingState 121 122Enumerates the A2DP playing states. 123 124**System capability**: SystemCapability.Communication.Bluetooth.Core 125 126| Name | Value | Description | 127| ----------------- | ------ | ------- | 128| STATE_NOT_PLAYING | 0x0000 | Not playing. | 129| STATE_PLAYING | 0x0001 | Playing.| 130 131 132## CodecInfo<sup>11+</sup> 133 134Defines the codec information. 135 136**System capability**: SystemCapability.Communication.Bluetooth.Core 137 138| Name | Type | Readable | Writable | Description | 139| ------------------- | ----------------------- | ---- | ---- | -------------------------------------- | 140| codecType | [CodecType](#codectype11) | Yes | Yes | Codec type. The default value is **CODEC_TYPE_SBC**.| 141| codecBitsPerSample | [CodecBitsPerSample](#codecbitspersample11) | Yes | Yes | Number of bits of each sample. The default value is **SCAN_MODE_LOW_POWER**.| 142| codecChannelMode | [CodecChannelMode](#codecchannelmode11) | Yes | Yes | Channel mode of the codec. The default value is **CODEC_CHANNEL_MODE_NONE**.| 143| codecSampleRate | [CodecSampleRate](#codecsamplerate11) | Yes | Yes | Sampling rate of the codec. The default value is **CODEC_BITS_PER_SAMPLE_NONE**.| 144 145 146## CodecType<sup>11+</sup> 147 148Enumerates the Bluetooth codec types. 149 150**System capability**: SystemCapability.Communication.Bluetooth.Core 151 152| Name | Value | Description | 153| ----------------- | ------ | ------- | 154| CODEC_TYPE_INVALID | -1 | Unknown type. | 155| CODEC_TYPE_SBC | 0 | SBC.| 156| CODEC_TYPE_AAC | 1 | AAC.| 157| CODEC_TYPE_L2HC | 2 | L2HC.| 158| CODEC_TYPE_L2HCST<sup>13+</sup> | 3 | L2HCST.| 159| CODEC_TYPE_LDAC<sup>13+</sup> | 4 | LDAC.| 160 161 162## CodecChannelMode<sup>11+</sup> 163 164Enumerates the channel modes of the Bluetooth codec. 165 166**System capability**: SystemCapability.Communication.Bluetooth.Core 167 168| Name | Value | Description | 169| ----------------- | ------ | ------- | 170| CODEC_CHANNEL_MODE_NONE | 0 | Unknown.| 171| CODEC_CHANNEL_MODE_MONO | 1 | Mono. | 172| CODEC_CHANNEL_MODE_STEREO | 2 | Stereo. | 173 174 175## CodecBitsPerSample<sup>11+</sup> 176 177Enumerates the number of bits per sample for the Bluetooth codec. 178 179**System capability**: SystemCapability.Communication.Bluetooth.Core 180 181| Name | Value | Description | 182| ----------------- | ------ | ------- | 183| CODEC_BITS_PER_SAMPLE_NONE | 0 | Unknown.| 184| CODEC_BITS_PER_SAMPLE_16 | 1 | 16 bits per sample.| 185| CODEC_BITS_PER_SAMPLE_24 | 2 | 24 bits per sample.| 186| CODEC_BITS_PER_SAMPLE_32 | 3 | 32 bits per sample.| 187 188 189## CodecSampleRate<sup>11+</sup> 190 191Enumerates the sampling rates of the Bluetooth codec. 192 193**System capability**: SystemCapability.Communication.Bluetooth.Core 194 195| Name | Value | Description | 196| ----------------- | ------ | ------- | 197| CODEC_SAMPLE_RATE_NONE | 0 | Unknown.| 198| CODEC_SAMPLE_RATE_44100 | 1 | 44.1 kHz.| 199| CODEC_SAMPLE_RATE_48000 | 2 | 48 kHz.| 200| CODEC_SAMPLE_RATE_88200 | 3 | 88.2 kHz.| 201| CODEC_SAMPLE_RATE_96000 | 4 | 96 kHz.| 202| CODEC_SAMPLE_RATE_176400 | 5 | 176.4 kHz.| 203| CODEC_SAMPLE_RATE_192000 | 6 | 192 kHz.| 204