1e41f4b71Sopenharmony_ci# @ohos.multimedia.avsession (AVSession Management) (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **avSession** module provides APIs for media playback control so that applications can access the system's Media Controller. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThis module provides the following typical features related to media sessions: 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci> **NOTE** 10e41f4b71Sopenharmony_ci> 11e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 12e41f4b71Sopenharmony_ci> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.avsession (AVSession Management)](js-apis-avsession.md). 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci## Modules to Import 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci```ts 17e41f4b71Sopenharmony_ciimport { avSession } from '@kit.AVSessionKit'; 18e41f4b71Sopenharmony_ci``` 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci## Usage Guidelines 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ciThis topic describes only system APIs. Before using these APIs, you must create an instance. For details about how to create an instance, see the description and example of the public API [avSession.createAVSession](js-apis-avsession.md#avsessioncreateavsession10). 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci## avSession.getAllSessionDescriptors 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_cigetAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>> 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ciObtains the descriptors of all sessions that have set media information and registered control callbacks. This API uses a promise to return the result. 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**System API**: This is a system API. 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Return value** 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| Type | Description | 39e41f4b71Sopenharmony_ci| ------------------------------------------------------------ | --------------------------------------------- | 40e41f4b71Sopenharmony_ci| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only. | 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci**Error codes** 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci| ID | Error Message | 47e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 48e41f4b71Sopenharmony_ci| 201 | permission denied. | 49e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**Example** 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ciavSession.getAllSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => { 57e41f4b71Sopenharmony_ci console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 58e41f4b71Sopenharmony_ci if (descriptors.length > 0 ) { 59e41f4b71Sopenharmony_ci console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 60e41f4b71Sopenharmony_ci console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 61e41f4b71Sopenharmony_ci console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 62e41f4b71Sopenharmony_ci } 63e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 64e41f4b71Sopenharmony_ci console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 65e41f4b71Sopenharmony_ci}); 66e41f4b71Sopenharmony_ci``` 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci## avSession.getAllSessionDescriptors 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_cigetAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ciObtains the descriptors of all sessions that have set media information and registered control callbacks. This API uses an asynchronous callback to return the result. 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci**System API**: This is a system API. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci**Parameters** 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 83e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 84e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only. | 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**Error codes** 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci| ID | Error Message | 91e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 92e41f4b71Sopenharmony_ci| 201 | permission denied. | 93e41f4b71Sopenharmony_ci| 6600101 |Session service exception. | 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**Example** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci```ts 98e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ciavSession.getAllSessionDescriptors((err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => { 101e41f4b71Sopenharmony_ci if (err) { 102e41f4b71Sopenharmony_ci console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 103e41f4b71Sopenharmony_ci } else { 104e41f4b71Sopenharmony_ci console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 105e41f4b71Sopenharmony_ci if (descriptors.length > 0 ) { 106e41f4b71Sopenharmony_ci console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 107e41f4b71Sopenharmony_ci console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 108e41f4b71Sopenharmony_ci console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 109e41f4b71Sopenharmony_ci } 110e41f4b71Sopenharmony_ci } 111e41f4b71Sopenharmony_ci}); 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci## avSession.getHistoricalSessionDescriptors<sup>10+</sup> 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_cigetHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVSessionDescriptor>>> 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ciObtains the descriptors of all historical sessions. This API uses a promise to return the result. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci**System API**: This is a system API. 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**Parameters** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 129e41f4b71Sopenharmony_ci| -------- | ------ | ---- | -----------------------------------------------------------------| 130e41f4b71Sopenharmony_ci| maxSize | number | No | Maximum number of descriptors to obtain. The value ranges from 0 to 10. If this parameter is left blank, the default value **3** is used.| 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Return value** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci| Type | Description | 135e41f4b71Sopenharmony_ci| --------------------------------------------------------------------------- | -------------------------------------- | 136e41f4b71Sopenharmony_ci| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only. | 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Error codes** 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci| ID | Error Message | 143e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 144e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 145e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci**Example** 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci```ts 150e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ciavSession.getHistoricalSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => { 153e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 154e41f4b71Sopenharmony_ci if (descriptors.length > 0 ) { 155e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 156e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 157e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 158e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); 159e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); 160e41f4b71Sopenharmony_ci } 161e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 162e41f4b71Sopenharmony_ci console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 163e41f4b71Sopenharmony_ci}); 164e41f4b71Sopenharmony_ci``` 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci## avSession.getHistoricalSessionDescriptors<sup>10+</sup> 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_cigetHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ciObtains the descriptors of all historical sessions. This API uses an asynchronous callback to return the result. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**System API**: This is a system API. 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**Parameters** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 181e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------------------------ | ---- | -----------------------------------------------------------------| 182e41f4b71Sopenharmony_ci| maxSize | number | Yes | Maximum number of descriptors to obtain. The value ranges from 0 to 10.| 183e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only. | 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci**Error codes** 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci| ID | Error Message | 190e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 191e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 192e41f4b71Sopenharmony_ci| 6600101 |Session service exception. | 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci**Example** 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci```ts 197e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ciavSession.getHistoricalSessionDescriptors(1, (err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => { 200e41f4b71Sopenharmony_ci if (err) { 201e41f4b71Sopenharmony_ci console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 202e41f4b71Sopenharmony_ci } else { 203e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 204e41f4b71Sopenharmony_ci if (descriptors.length > 0 ) { 205e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 206e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 207e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 208e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); 209e41f4b71Sopenharmony_ci console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); 210e41f4b71Sopenharmony_ci } 211e41f4b71Sopenharmony_ci } 212e41f4b71Sopenharmony_ci}); 213e41f4b71Sopenharmony_ci``` 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci## avSession.getHistoricalAVQueueInfos<sup>11+</sup> 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_cigetHistoricalAVQueueInfos(maxSize: number, maxAppSize: number) : Promise\<Array\<Readonly\<AVQueueInfo>>> 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ciObtains all the historical playlists. This API uses a promise to return the result. 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci**System API**: This is a system API. 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Parameters** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 230e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------------------------------------------------------------| 231e41f4b71Sopenharmony_ci| maxSize | number | Yes | Maximum number of playlists that can be obtained. Currently, the maximum number is restricted by the system. | 232e41f4b71Sopenharmony_ci| maxAppSize | number | Yes | Maximum number of applications to which the playlists to be obtained belong. Currently, the maximum number is restricted by the system. | 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Return value** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci| Type | Description | 237e41f4b71Sopenharmony_ci| --------------------------------------------------------------------------- | ------------------------------------- | 238e41f4b71Sopenharmony_ci| Promise\<Array\<Readonly\<[AVQueueInfo](#avqueueinfo11)\>\>\> | Promise used to return all the read-only historical playlists. | 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci**Error codes** 241e41f4b71Sopenharmony_ci 242e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci| ID | Error Message | 245e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 246e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 247e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci**Example** 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ci```ts 252e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ciavSession.getHistoricalAVQueueInfos(3, 5).then((avQueueInfos: avSession.AVQueueInfo[]) => { 255e41f4b71Sopenharmony_ci console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`); 256e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 257e41f4b71Sopenharmony_ci console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`); 258e41f4b71Sopenharmony_ci}); 259e41f4b71Sopenharmony_ci``` 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci## avSession.getHistoricalAVQueueInfos<sup>11+</sup> 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_cigetHistoricalAVQueueInfos(maxSize: number, maxAppSize: number, callback: AsyncCallback\<Array\<Readonly\<AVQueueInfo>>>): void; 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ciObtains all the historical playlists. This API uses an asynchronous callback to return the result. 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci**System API**: This is a system API. 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci**Parameters** 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 276e41f4b71Sopenharmony_ci| -------- | ----------------------------------------------------------------------------- | ---- | ---------------------------------------------------------------| 277e41f4b71Sopenharmony_ci| maxSize | number | Yes | Maximum number of playlists that can be obtained. Currently, the maximum number is restricted by the system. | 278e41f4b71Sopenharmony_ci| maxAppSize | number | Yes | Maximum number of applications to which the playlists to be obtained belong. Currently, the maximum number is restricted by the system. | 279e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<Readonly<[AVQueueInfo](#avqueueinfo11)\>\>\> | Yes | Callback used to return all the read-only historical playlists. | 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci**Error codes** 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci| ID | Error Message | 286e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 287e41f4b71Sopenharmony_ci| 201 | permission denied. | 288e41f4b71Sopenharmony_ci| 202 | Not System App. | 289e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 290e41f4b71Sopenharmony_ci| 6600101 |Session service exception. | 291e41f4b71Sopenharmony_ci 292e41f4b71Sopenharmony_ci**Example** 293e41f4b71Sopenharmony_ci 294e41f4b71Sopenharmony_ci```ts 295e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ciavSession.getHistoricalAVQueueInfos(3, 5, (err: BusinessError, avQueueInfos: avSession.AVQueueInfo[]) => { 298e41f4b71Sopenharmony_ci if (err) { 299e41f4b71Sopenharmony_ci console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`); 300e41f4b71Sopenharmony_ci } else { 301e41f4b71Sopenharmony_ci console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`); 302e41f4b71Sopenharmony_ci } 303e41f4b71Sopenharmony_ci}); 304e41f4b71Sopenharmony_ci``` 305e41f4b71Sopenharmony_ci 306e41f4b71Sopenharmony_ci## avSession.createController 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_cicreateController(sessionId: string): Promise\<AVSessionController> 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ciCreates a session controller based on the session ID. Multiple session controllers can be created. This API uses a promise to return the result. 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**System API**: This is a system API. 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Parameters** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 321e41f4b71Sopenharmony_ci| --------- | ------ | ---- | -------- | 322e41f4b71Sopenharmony_ci| sessionId | string | Yes | Session ID. If the value is set to **'default'**, the system creates a default controller to control the system default session. | 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Return value** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| Type | Description | 327e41f4b71Sopenharmony_ci| ----------------------------------------------------- | ------------------------------------------------------------ | 328e41f4b71Sopenharmony_ci| Promise<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\> | Promise used to return the session controller created, which can be used to obtain the session ID,<br>send commands and events to sessions, and obtain metadata and playback state information.| 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**Error codes** 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci| ID | Error Message | 335e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 336e41f4b71Sopenharmony_ci| 201 | permission denied. | 337e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 338e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 339e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. | 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**Example** 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci```ts 344e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 345e41f4b71Sopenharmony_ci 346e41f4b71Sopenharmony_cilet currentAVcontroller: avSession.AVSessionController | undefined = undefined; 347e41f4b71Sopenharmony_cicurrentAvSession.createController(sessionId).then((avcontroller: avSession.AVSessionController) => { 348e41f4b71Sopenharmony_ci currentAVcontroller = avcontroller; 349e41f4b71Sopenharmony_ci console.info('CreateController : SUCCESS '); 350e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 351e41f4b71Sopenharmony_ci console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 352e41f4b71Sopenharmony_ci}); 353e41f4b71Sopenharmony_ci``` 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci## avSession.createController 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_cicreateController(sessionId: string, callback: AsyncCallback\<AVSessionController>): void 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ciCreates a session controller based on the session ID. Multiple session controllers can be created. This API uses an asynchronous callback to return the result. 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**System API**: This is a system API. 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ci**Parameters** 368e41f4b71Sopenharmony_ci 369e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 370e41f4b71Sopenharmony_ci| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 371e41f4b71Sopenharmony_ci| sessionId | string | Yes | Session ID. If the value is set to **'default'**, the system creates a default controller to control the default session. | 372e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\> | Yes | Callback used to return the session controller created, which can be used to obtain the session ID,<br>send commands and events to sessions, and obtain metadata and playback state information. | 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci**Error codes** 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci| ID | Error Message | 379e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 380e41f4b71Sopenharmony_ci| 201 | permission denied. | 381e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 382e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 383e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. | 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci**Example** 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci```ts 388e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 389e41f4b71Sopenharmony_ci 390e41f4b71Sopenharmony_cilet currentAVcontroller: avSession.AVSessionController | undefined = undefined; 391e41f4b71Sopenharmony_cicurrentAvSession.createController(sessionId, (err: BusinessError, avcontroller: avSession.AVSessionController) => { 392e41f4b71Sopenharmony_ci if (err) { 393e41f4b71Sopenharmony_ci console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 394e41f4b71Sopenharmony_ci } else { 395e41f4b71Sopenharmony_ci currentAVcontroller = avcontroller; 396e41f4b71Sopenharmony_ci console.info('CreateController : SUCCESS '); 397e41f4b71Sopenharmony_ci } 398e41f4b71Sopenharmony_ci}); 399e41f4b71Sopenharmony_ci``` 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci## avSession.castAudio 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_cicastAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise\<void> 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ciCasts a session to a list of devices. This API uses a promise to return the result. 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ciBefore calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices. 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci**System API**: This is a system API. 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**Parameters** 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 418e41f4b71Sopenharmony_ci| ------------ | -------------- |------|------| 419e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens. | 420e41f4b71Sopenharmony_ci| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices. | 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci**Return value** 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci| Type | Description | 425e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 426e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If casting is successful, no value is returned; otherwise, an error object is returned. | 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**Error codes** 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci| ID | Error Message | 433e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 434e41f4b71Sopenharmony_ci| 201 | permission denied. | 435e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 436e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 437e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. | 438e41f4b71Sopenharmony_ci| 6600104 | The remote session connection failed. | 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci**Example** 441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci```ts 443e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 444e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_cilet audioManager = audio.getAudioManager(); 447e41f4b71Sopenharmony_cilet audioRoutingManager = audioManager.getRoutingManager(); 448e41f4b71Sopenharmony_cilet audioDevices: audio.AudioDeviceDescriptors | undefined = undefined; 449e41f4b71Sopenharmony_ciaudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 450e41f4b71Sopenharmony_ci audioDevices = data; 451e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the device list is obtained.'); 452e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 453e41f4b71Sopenharmony_ci console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); 454e41f4b71Sopenharmony_ci}); 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ciif (audioDevices !== undefined) { 457e41f4b71Sopenharmony_ci avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors).then(() => { 458e41f4b71Sopenharmony_ci console.info('CreateController : SUCCESS'); 459e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 460e41f4b71Sopenharmony_ci console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 461e41f4b71Sopenharmony_ci }); 462e41f4b71Sopenharmony_ci} 463e41f4b71Sopenharmony_ci``` 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci## avSession.castAudio 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_cicastAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ciCasts a session to a list of devices. This API uses an asynchronous callback to return the result. 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ciBefore calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices. 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ci**System API**: This is a system API. 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**Parameters** 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 482e41f4b71Sopenharmony_ci| ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ | 483e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens. | 484e41f4b71Sopenharmony_ci| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/js-apis-audio.md#audiodevicedescriptor)\> | Yes | Audio devices. | 485e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If casting is successful, **err** is **undefined**; otherwise, **err** is an error object. | 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci**Error codes** 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci| ID | Error Message | 492e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 493e41f4b71Sopenharmony_ci| 201 | permission denied. | 494e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 495e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 496e41f4b71Sopenharmony_ci| 6600102 | The session does not exist. | 497e41f4b71Sopenharmony_ci| 6600104 | The remote session connection failed. | 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**Example** 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci```ts 502e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 503e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_cilet audioManager = audio.getAudioManager(); 506e41f4b71Sopenharmony_cilet audioRoutingManager = audioManager.getRoutingManager(); 507e41f4b71Sopenharmony_cilet audioDevices: audio.AudioDeviceDescriptors | undefined = undefined; 508e41f4b71Sopenharmony_ciaudioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 509e41f4b71Sopenharmony_ci audioDevices = data; 510e41f4b71Sopenharmony_ci console.info('Promise returned to indicate that the device list is obtained.'); 511e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 512e41f4b71Sopenharmony_ci console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); 513e41f4b71Sopenharmony_ci}); 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ciif (audioDevices !== undefined) { 516e41f4b71Sopenharmony_ci avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors, (err: BusinessError) => { 517e41f4b71Sopenharmony_ci if (err) { 518e41f4b71Sopenharmony_ci console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); 519e41f4b71Sopenharmony_ci } else { 520e41f4b71Sopenharmony_ci console.info('CastAudio : SUCCESS '); 521e41f4b71Sopenharmony_ci } 522e41f4b71Sopenharmony_ci }); 523e41f4b71Sopenharmony_ci} 524e41f4b71Sopenharmony_ci``` 525e41f4b71Sopenharmony_ci 526e41f4b71Sopenharmony_ci## avSession.startAVPlayback<sup>11+</sup> 527e41f4b71Sopenharmony_ci 528e41f4b71Sopenharmony_cistartAVPlayback(bundleName: string, assetId: string): Promise\<void> 529e41f4b71Sopenharmony_ci 530e41f4b71Sopenharmony_ciStarts an application to play a media asset. This API uses a promise to return the result. 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci**System API**: This is a system API. 537e41f4b71Sopenharmony_ci 538e41f4b71Sopenharmony_ci**Parameters** 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 541e41f4b71Sopenharmony_ci| ------------ | -------------- |------|------| 542e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the application. | 543e41f4b71Sopenharmony_ci| assetId |string | Yes | ID of the media asset. | 544e41f4b71Sopenharmony_ci 545e41f4b71Sopenharmony_ci**Return value** 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_ci| Type | Description | 548e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 549e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the playback is successful, no value is returned; otherwise, an error object is returned. | 550e41f4b71Sopenharmony_ci 551e41f4b71Sopenharmony_ci**Error codes** 552e41f4b71Sopenharmony_ci 553e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 554e41f4b71Sopenharmony_ci 555e41f4b71Sopenharmony_ci| ID | Error Message | 556e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 557e41f4b71Sopenharmony_ci| 201 | permission denied. | 558e41f4b71Sopenharmony_ci| 202 | Not System App. Interface caller is not a system app. | 559e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 560e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 561e41f4b71Sopenharmony_ci 562e41f4b71Sopenharmony_ci**Example** 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci```ts 565e41f4b71Sopenharmony_ciimport { audio } from '@kit.AudioKit'; 566e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ciavSession.startAVPlayback("com.example.myapplication", "121278").then(() => { 569e41f4b71Sopenharmony_ci console.info('startAVPlayback : SUCCESS'); 570e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 571e41f4b71Sopenharmony_ci console.error(`startAVPlayback BusinessError: code: ${err.code}, message: ${err.message}`); 572e41f4b71Sopenharmony_ci}); 573e41f4b71Sopenharmony_ci``` 574e41f4b71Sopenharmony_ci 575e41f4b71Sopenharmony_ci## SessionToken 576e41f4b71Sopenharmony_ci 577e41f4b71Sopenharmony_ciDescribes the information about a session token. 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci**System API**: This is a system API. 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 586e41f4b71Sopenharmony_ci| :-------- | :----- | :--- | :----------- | 587e41f4b71Sopenharmony_ci| sessionId | string | Yes | Session ID. | 588e41f4b71Sopenharmony_ci| pid | number | No | Process ID of the session. | 589e41f4b71Sopenharmony_ci| uid | number | No | User ID. | 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci## avSession.on('sessionCreate') 592e41f4b71Sopenharmony_ci 593e41f4b71Sopenharmony_cion(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ciSubscribes to session creation events. 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 600e41f4b71Sopenharmony_ci 601e41f4b71Sopenharmony_ci**System API**: This is a system API. 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci**Parameters** 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 606e41f4b71Sopenharmony_ci| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 607e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'sessionCreate'** is triggered when a session is created.| 608e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor. | 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci**Error codes** 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ci| ID | Error Message | 615e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 616e41f4b71Sopenharmony_ci| 201 | permission denied. | 617e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 618e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 619e41f4b71Sopenharmony_ci 620e41f4b71Sopenharmony_ci**Example** 621e41f4b71Sopenharmony_ci 622e41f4b71Sopenharmony_ci```ts 623e41f4b71Sopenharmony_ciavSession.on('sessionCreate', (descriptor: avSession.AVSessionDescriptor) => { 624e41f4b71Sopenharmony_ci console.info(`on sessionCreate : isActive : ${descriptor.isActive}`); 625e41f4b71Sopenharmony_ci console.info(`on sessionCreate : type : ${descriptor.type}`); 626e41f4b71Sopenharmony_ci console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`); 627e41f4b71Sopenharmony_ci}); 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci``` 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ci## avSession.on('sessionDestroy') 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_cion(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void 634e41f4b71Sopenharmony_ci 635e41f4b71Sopenharmony_ciSubscribes to session destruction events. 636e41f4b71Sopenharmony_ci 637e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 638e41f4b71Sopenharmony_ci 639e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ci**System API**: This is a system API. 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_ci**Parameters** 644e41f4b71Sopenharmony_ci 645e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 646e41f4b71Sopenharmony_ci| -------- | ---------------| ---- | ------------------------------------------------------------ | 647e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| 648e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor. | 649e41f4b71Sopenharmony_ci 650e41f4b71Sopenharmony_ci**Error codes** 651e41f4b71Sopenharmony_ci 652e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 653e41f4b71Sopenharmony_ci 654e41f4b71Sopenharmony_ci| ID | Error Message | 655e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 656e41f4b71Sopenharmony_ci| 201 | permission denied. | 657e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 658e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci**Example** 661e41f4b71Sopenharmony_ci 662e41f4b71Sopenharmony_ci```ts 663e41f4b71Sopenharmony_ciavSession.on('sessionDestroy', (descriptor: avSession.AVSessionDescriptor) => { 664e41f4b71Sopenharmony_ci console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`); 665e41f4b71Sopenharmony_ci console.info(`on sessionDestroy : type : ${descriptor.type}`); 666e41f4b71Sopenharmony_ci console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`); 667e41f4b71Sopenharmony_ci}); 668e41f4b71Sopenharmony_ci``` 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci## avSession.on('topSessionChange') 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_cion(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_ciSubscribes to top session change events. 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_ci**System API**: This is a system API. 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_ci**Parameters** 683e41f4b71Sopenharmony_ci 684e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 685e41f4b71Sopenharmony_ci| -------- | --------------------| ---- | ------------------------------------------------------------ | 686e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'topSessionChange'** is triggered when the top session is changed.| 687e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor. | 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ci**Error codes** 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci| ID | Error Message | 694e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 695e41f4b71Sopenharmony_ci| 201 | permission denied. | 696e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 697e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci**Example** 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci```ts 702e41f4b71Sopenharmony_ciavSession.on('topSessionChange', (descriptor: avSession.AVSessionDescriptor) => { 703e41f4b71Sopenharmony_ci console.info(`on topSessionChange : isActive : ${descriptor.isActive}`); 704e41f4b71Sopenharmony_ci console.info(`on topSessionChange : type : ${descriptor.type}`); 705e41f4b71Sopenharmony_ci console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`); 706e41f4b71Sopenharmony_ci}); 707e41f4b71Sopenharmony_ci``` 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci## avSession.off('sessionCreate') 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_cioff(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ciUnsubscribes from session creation events. 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci**System API**: This is a system API. 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci**Parameters** 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 724e41f4b71Sopenharmony_ci| -------- | ----------| ---- | ----------| 725e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'sessionCreate'** in this case.| 726e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 727e41f4b71Sopenharmony_ci 728e41f4b71Sopenharmony_ci**Error codes** 729e41f4b71Sopenharmony_ci 730e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_ci| ID | Error Message | 733e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 734e41f4b71Sopenharmony_ci| 201 | permission denied. | 735e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 736e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 737e41f4b71Sopenharmony_ci 738e41f4b71Sopenharmony_ci**Example** 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci```ts 741e41f4b71Sopenharmony_ciavSession.off('sessionCreate'); 742e41f4b71Sopenharmony_ci``` 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci## avSession.off('sessionDestroy') 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_cioff(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void 747e41f4b71Sopenharmony_ci 748e41f4b71Sopenharmony_ciUnsubscribes from session destruction events. 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 751e41f4b71Sopenharmony_ci 752e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci**System API**: This is a system API. 755e41f4b71Sopenharmony_ci 756e41f4b71Sopenharmony_ci**Parameters** 757e41f4b71Sopenharmony_ci 758e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 759e41f4b71Sopenharmony_ci| -------- | -----------| ---- | -------------------------| 760e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'sessionDestroy'** in this case.| 761e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| 762e41f4b71Sopenharmony_ci 763e41f4b71Sopenharmony_ci**Error codes** 764e41f4b71Sopenharmony_ci 765e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 766e41f4b71Sopenharmony_ci 767e41f4b71Sopenharmony_ci| ID | Error Message | 768e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 769e41f4b71Sopenharmony_ci| 201 | permission denied. | 770e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 771e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_ci**Example** 774e41f4b71Sopenharmony_ci 775e41f4b71Sopenharmony_ci```ts 776e41f4b71Sopenharmony_ciavSession.off('sessionDestroy'); 777e41f4b71Sopenharmony_ci``` 778e41f4b71Sopenharmony_ci 779e41f4b71Sopenharmony_ci## avSession.off('topSessionChange') 780e41f4b71Sopenharmony_ci 781e41f4b71Sopenharmony_cioff(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void 782e41f4b71Sopenharmony_ci 783e41f4b71Sopenharmony_ciUnsubscribes from top session change events. 784e41f4b71Sopenharmony_ci 785e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 786e41f4b71Sopenharmony_ci 787e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 788e41f4b71Sopenharmony_ci 789e41f4b71Sopenharmony_ci**System API**: This is a system API. 790e41f4b71Sopenharmony_ci 791e41f4b71Sopenharmony_ci**Parameters** 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 794e41f4b71Sopenharmony_ci| -------- | -----------------| ---- | ---------------------------- | 795e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'topSessionChange'** in this case.| 796e41f4b71Sopenharmony_ci| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 797e41f4b71Sopenharmony_ci 798e41f4b71Sopenharmony_ci**Error codes** 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 801e41f4b71Sopenharmony_ci 802e41f4b71Sopenharmony_ci| ID | Error Message | 803e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 804e41f4b71Sopenharmony_ci| 201 | permission denied. | 805e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 806e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 807e41f4b71Sopenharmony_ci 808e41f4b71Sopenharmony_ci**Example** 809e41f4b71Sopenharmony_ci 810e41f4b71Sopenharmony_ci```ts 811e41f4b71Sopenharmony_ciavSession.off('topSessionChange'); 812e41f4b71Sopenharmony_ci``` 813e41f4b71Sopenharmony_ci 814e41f4b71Sopenharmony_ci## avSession.on('sessionServiceDie') 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_cion(type: 'sessionServiceDie', callback: () => void): void 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ciSubscribes to session service death events. Upon receiving this event, the application can clear resources. 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci**System API**: This is a system API. 823e41f4b71Sopenharmony_ci 824e41f4b71Sopenharmony_ci**Parameters** 825e41f4b71Sopenharmony_ci 826e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 827e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ | 828e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies. | 829e41f4b71Sopenharmony_ci| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 830e41f4b71Sopenharmony_ci 831e41f4b71Sopenharmony_ci**Error codes** 832e41f4b71Sopenharmony_ci 833e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 834e41f4b71Sopenharmony_ci 835e41f4b71Sopenharmony_ci| ID | Error Message | 836e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 837e41f4b71Sopenharmony_ci| 201 | permission denied. | 838e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 839e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 840e41f4b71Sopenharmony_ci 841e41f4b71Sopenharmony_ci**Example** 842e41f4b71Sopenharmony_ci 843e41f4b71Sopenharmony_ci```ts 844e41f4b71Sopenharmony_ciavSession.on('sessionServiceDie', () => { 845e41f4b71Sopenharmony_ci console.info('on sessionServiceDie : session is Died '); 846e41f4b71Sopenharmony_ci}); 847e41f4b71Sopenharmony_ci``` 848e41f4b71Sopenharmony_ci 849e41f4b71Sopenharmony_ci## avSession.off('sessionServiceDie') 850e41f4b71Sopenharmony_ci 851e41f4b71Sopenharmony_cioff(type: 'sessionServiceDie', callback?: () => void): void 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ciUnsubscribes from session service death events. 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci**System API**: This is a system API. 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ci**Parameters** 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 862e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------- | 863e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.| 864e41f4b71Sopenharmony_ci| callback | callback: () => void | No | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 865e41f4b71Sopenharmony_ci 866e41f4b71Sopenharmony_ci**Error codes** 867e41f4b71Sopenharmony_ci 868e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 869e41f4b71Sopenharmony_ci 870e41f4b71Sopenharmony_ci| ID | Error Message | 871e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 872e41f4b71Sopenharmony_ci| 201 | permission denied. | 873e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 874e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 875e41f4b71Sopenharmony_ci 876e41f4b71Sopenharmony_ci**Example** 877e41f4b71Sopenharmony_ci 878e41f4b71Sopenharmony_ci```ts 879e41f4b71Sopenharmony_ciavSession.off('sessionServiceDie'); 880e41f4b71Sopenharmony_ci``` 881e41f4b71Sopenharmony_ci 882e41f4b71Sopenharmony_ci## avSession.sendSystemAVKeyEvent 883e41f4b71Sopenharmony_ci 884e41f4b71Sopenharmony_cisendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 885e41f4b71Sopenharmony_ci 886e41f4b71Sopenharmony_ciSends a system key event to the top session. This API uses an asynchronous callback to return the result. 887e41f4b71Sopenharmony_ci 888e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 889e41f4b71Sopenharmony_ci 890e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 891e41f4b71Sopenharmony_ci 892e41f4b71Sopenharmony_ci**System API**: This is a system API. 893e41f4b71Sopenharmony_ci 894e41f4b71Sopenharmony_ci**Parameters** 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 897e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | 898e41f4b71Sopenharmony_ci| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | Yes | Key event. | 899e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object. | 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**Error codes** 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 904e41f4b71Sopenharmony_ci 905e41f4b71Sopenharmony_ci| ID | Error Message | 906e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 907e41f4b71Sopenharmony_ci| 201 | permission denied. | 908e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 909e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 910e41f4b71Sopenharmony_ci| 6600105 | Invalid session command. | 911e41f4b71Sopenharmony_ci 912e41f4b71Sopenharmony_ci**Example** 913e41f4b71Sopenharmony_ci 914e41f4b71Sopenharmony_ci```ts 915e41f4b71Sopenharmony_ciimport { KeyEvent } from '@kit.InputKit'; 916e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 917e41f4b71Sopenharmony_ci 918e41f4b71Sopenharmony_cilet keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0}; 919e41f4b71Sopenharmony_cilet event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ciavSession.sendSystemAVKeyEvent(event, (err: BusinessError) => { 922e41f4b71Sopenharmony_ci if (err) { 923e41f4b71Sopenharmony_ci console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 924e41f4b71Sopenharmony_ci } else { 925e41f4b71Sopenharmony_ci console.info('SendSystemAVKeyEvent : SUCCESS '); 926e41f4b71Sopenharmony_ci } 927e41f4b71Sopenharmony_ci}); 928e41f4b71Sopenharmony_ci``` 929e41f4b71Sopenharmony_ci 930e41f4b71Sopenharmony_ci## avSession.sendSystemAVKeyEvent 931e41f4b71Sopenharmony_ci 932e41f4b71Sopenharmony_cisendSystemAVKeyEvent(event: KeyEvent): Promise\<void> 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ciSends a system key event to the top session. This API uses a promise to return the result. 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 937e41f4b71Sopenharmony_ci 938e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**System API**: This is a system API. 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci**Parameters** 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 945e41f4b71Sopenharmony_ci| ------ | ------------------------------- | ---- | ---------- | 946e41f4b71Sopenharmony_ci| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | Yes | Key event. | 947e41f4b71Sopenharmony_ci 948e41f4b71Sopenharmony_ci**Return value** 949e41f4b71Sopenharmony_ci 950e41f4b71Sopenharmony_ci| Type | Description | 951e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 952e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned. | 953e41f4b71Sopenharmony_ci 954e41f4b71Sopenharmony_ci**Error codes** 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci| ID | Error Message | 959e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 960e41f4b71Sopenharmony_ci| 201 | permission denied. | 961e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 962e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 963e41f4b71Sopenharmony_ci| 6600105 | Invalid session command. | 964e41f4b71Sopenharmony_ci 965e41f4b71Sopenharmony_ci**Example** 966e41f4b71Sopenharmony_ci 967e41f4b71Sopenharmony_ci```ts 968e41f4b71Sopenharmony_ciimport { KeyEvent } from '@kit.InputKit'; 969e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 970e41f4b71Sopenharmony_ci 971e41f4b71Sopenharmony_cilet keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0}; 972e41f4b71Sopenharmony_cilet event: keyEvent.KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ciavSession.sendSystemAVKeyEvent(event).then(() => { 975e41f4b71Sopenharmony_ci console.info('SendSystemAVKeyEvent Successfully'); 976e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 977e41f4b71Sopenharmony_ci console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 978e41f4b71Sopenharmony_ci}); 979e41f4b71Sopenharmony_ci``` 980e41f4b71Sopenharmony_ci 981e41f4b71Sopenharmony_ci## avSession.sendSystemControlCommand 982e41f4b71Sopenharmony_ci 983e41f4b71Sopenharmony_cisendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 984e41f4b71Sopenharmony_ci 985e41f4b71Sopenharmony_ciSends a system control command to the top session. This API uses an asynchronous callback to return the result. 986e41f4b71Sopenharmony_ci 987e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 990e41f4b71Sopenharmony_ci 991e41f4b71Sopenharmony_ci**System API**: This is a system API. 992e41f4b71Sopenharmony_ci 993e41f4b71Sopenharmony_ci**Parameters** 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 996e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 997e41f4b71Sopenharmony_ci| command | [AVControlCommand](js-apis-avsession.md#avcontrolcommand10) | Yes | Command to send. | 998e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 999e41f4b71Sopenharmony_ci 1000e41f4b71Sopenharmony_ci**Error codes** 1001e41f4b71Sopenharmony_ci 1002e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1003e41f4b71Sopenharmony_ci 1004e41f4b71Sopenharmony_ci| ID | Error Message | 1005e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1006e41f4b71Sopenharmony_ci| 201 | permission denied. | 1007e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1008e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1009e41f4b71Sopenharmony_ci| 6600105 | Invalid session command. | 1010e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events. | 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci**Example** 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci```ts 1015e41f4b71Sopenharmony_cilet cmd : avSession.AVControlCommandType = 'play'; 1016e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'pause'; 1017e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'stop'; 1018e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'playNext'; 1019e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'playPrevious'; 1020e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'fastForward'; 1021e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'rewind'; 1022e41f4b71Sopenharmony_cilet avcommand: avSession.AVControlCommand = {command:cmd}; 1023e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'seek'; 1024e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:10}; 1025e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'setSpeed'; 1026e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:2.6}; 1027e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'setLoopMode'; 1028e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; 1029e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'toggleFavorite'; 1030e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:"false"}; 1031e41f4b71Sopenharmony_ciavSession.sendSystemControlCommand(avcommand, (err) => { 1032e41f4b71Sopenharmony_ci if (err) { 1033e41f4b71Sopenharmony_ci console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 1034e41f4b71Sopenharmony_ci } else { 1035e41f4b71Sopenharmony_ci console.info('sendSystemControlCommand successfully'); 1036e41f4b71Sopenharmony_ci } 1037e41f4b71Sopenharmony_ci}); 1038e41f4b71Sopenharmony_ci``` 1039e41f4b71Sopenharmony_ci 1040e41f4b71Sopenharmony_ci## avSession.sendSystemControlCommand 1041e41f4b71Sopenharmony_ci 1042e41f4b71Sopenharmony_cisendSystemControlCommand(command: AVControlCommand): Promise\<void> 1043e41f4b71Sopenharmony_ci 1044e41f4b71Sopenharmony_ciSends a system control command to the top session. This API uses a promise to return the result. 1045e41f4b71Sopenharmony_ci 1046e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1047e41f4b71Sopenharmony_ci 1048e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 1049e41f4b71Sopenharmony_ci 1050e41f4b71Sopenharmony_ci**System API**: This is a system API. 1051e41f4b71Sopenharmony_ci 1052e41f4b71Sopenharmony_ci**Parameters** 1053e41f4b71Sopenharmony_ci 1054e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1055e41f4b71Sopenharmony_ci| ------- | ------------------------------------- | ---- | ----------------------------------- | 1056e41f4b71Sopenharmony_ci| command | [AVControlCommand](js-apis-avsession.md#avcontrolcommand10) | Yes | Command to send. | 1057e41f4b71Sopenharmony_ci 1058e41f4b71Sopenharmony_ci**Return value** 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_ci| Type | Description | 1061e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1062e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned. | 1063e41f4b71Sopenharmony_ci 1064e41f4b71Sopenharmony_ci**Error codes** 1065e41f4b71Sopenharmony_ci 1066e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1067e41f4b71Sopenharmony_ci 1068e41f4b71Sopenharmony_ci| ID | Error Message | 1069e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1070e41f4b71Sopenharmony_ci| 201 | permission denied. | 1071e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1072e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1073e41f4b71Sopenharmony_ci| 6600105 | Invalid session command. | 1074e41f4b71Sopenharmony_ci| 6600107 | Too many commands or events. | 1075e41f4b71Sopenharmony_ci 1076e41f4b71Sopenharmony_ci**Example** 1077e41f4b71Sopenharmony_ci 1078e41f4b71Sopenharmony_ci```ts 1079e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_cilet cmd : avSession.AVControlCommandType = 'play'; 1082e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'pause'; 1083e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'stop'; 1084e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'playNext'; 1085e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'playPrevious'; 1086e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'fastForward'; 1087e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'rewind'; 1088e41f4b71Sopenharmony_cilet avcommand: avSession.AVControlCommand = {command:cmd}; 1089e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'seek'; 1090e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:10}; 1091e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'setSpeed'; 1092e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:2.6}; 1093e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'setLoopMode'; 1094e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; 1095e41f4b71Sopenharmony_ci// let cmd : avSession.AVControlCommandType = 'toggleFavorite'; 1096e41f4b71Sopenharmony_ci// let avcommand = {command:cmd, parameter:"false"}; 1097e41f4b71Sopenharmony_ciavSession.sendSystemControlCommand(avcommand).then(() => { 1098e41f4b71Sopenharmony_ci console.info('SendSystemControlCommand successfully'); 1099e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1100e41f4b71Sopenharmony_ci console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 1101e41f4b71Sopenharmony_ci}); 1102e41f4b71Sopenharmony_ci``` 1103e41f4b71Sopenharmony_ci 1104e41f4b71Sopenharmony_ci## ProtocolType<sup>10+</sup> 1105e41f4b71Sopenharmony_ci 1106e41f4b71Sopenharmony_ciEnumerates the protocol types supported by the remote device. 1107e41f4b71Sopenharmony_ci 1108e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1109e41f4b71Sopenharmony_ci 1110e41f4b71Sopenharmony_ci| Name | Value | Description | 1111e41f4b71Sopenharmony_ci| --------------------------- | ---- | ----------- | 1112e41f4b71Sopenharmony_ci| TYPE_CAST_PLUS_MIRROR | 1 | Cast+ mirror mode.<br> **System API**: This is a system API. | 1113e41f4b71Sopenharmony_ci 1114e41f4b71Sopenharmony_ci## avSession.startCastDeviceDiscovery<sup>10+</sup> 1115e41f4b71Sopenharmony_ci 1116e41f4b71Sopenharmony_cistartCastDeviceDiscovery(callback: AsyncCallback\<void>): void 1117e41f4b71Sopenharmony_ci 1118e41f4b71Sopenharmony_ciStarts cast-enabled device discovery. This API uses an asynchronous callback to return the result. 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1121e41f4b71Sopenharmony_ci 1122e41f4b71Sopenharmony_ci**System API**: This is a system API. 1123e41f4b71Sopenharmony_ci 1124e41f4b71Sopenharmony_ci**Parameters** 1125e41f4b71Sopenharmony_ci 1126e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1127e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1128e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object. | 1129e41f4b71Sopenharmony_ci 1130e41f4b71Sopenharmony_ci 1131e41f4b71Sopenharmony_ci**Example** 1132e41f4b71Sopenharmony_ci 1133e41f4b71Sopenharmony_ci```ts 1134e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_ciavSession.startCastDeviceDiscovery((err: BusinessError) => { 1137e41f4b71Sopenharmony_ci if (err) { 1138e41f4b71Sopenharmony_ci console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1139e41f4b71Sopenharmony_ci } else { 1140e41f4b71Sopenharmony_ci console.info('startCastDeviceDiscovery successfully'); 1141e41f4b71Sopenharmony_ci } 1142e41f4b71Sopenharmony_ci}); 1143e41f4b71Sopenharmony_ci``` 1144e41f4b71Sopenharmony_ci 1145e41f4b71Sopenharmony_ci## avSession.startCastDeviceDiscovery<sup>10+</sup> 1146e41f4b71Sopenharmony_ci 1147e41f4b71Sopenharmony_cistartCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void 1148e41f4b71Sopenharmony_ci 1149e41f4b71Sopenharmony_ciStarts cast-enabled device discovery with filter criteria specified. This API uses an asynchronous callback to return the result. 1150e41f4b71Sopenharmony_ci 1151e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1152e41f4b71Sopenharmony_ci 1153e41f4b71Sopenharmony_ci**System API**: This is a system API. 1154e41f4b71Sopenharmony_ci 1155e41f4b71Sopenharmony_ci**Parameters** 1156e41f4b71Sopenharmony_ci 1157e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1158e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1159e41f4b71Sopenharmony_ci| filter | number | Yes | Filter criteria for device discovery. The value consists of **ProtocolType**s. | 1160e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object. | 1161e41f4b71Sopenharmony_ci 1162e41f4b71Sopenharmony_ci**Error codes** 1163e41f4b71Sopenharmony_ci 1164e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1165e41f4b71Sopenharmony_ci 1166e41f4b71Sopenharmony_ci| ID | Error Message | 1167e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1168e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1169e41f4b71Sopenharmony_ci 1170e41f4b71Sopenharmony_ci**Example** 1171e41f4b71Sopenharmony_ci 1172e41f4b71Sopenharmony_ci```ts 1173e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1174e41f4b71Sopenharmony_ci 1175e41f4b71Sopenharmony_cilet filter = 2; 1176e41f4b71Sopenharmony_ciavSession.startCastDeviceDiscovery(filter, (err: BusinessError) => { 1177e41f4b71Sopenharmony_ci if (err) { 1178e41f4b71Sopenharmony_ci console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1179e41f4b71Sopenharmony_ci } else { 1180e41f4b71Sopenharmony_ci console.info('startCastDeviceDiscovery successfully'); 1181e41f4b71Sopenharmony_ci } 1182e41f4b71Sopenharmony_ci}); 1183e41f4b71Sopenharmony_ci``` 1184e41f4b71Sopenharmony_ci 1185e41f4b71Sopenharmony_ci## avSession.startCastDeviceDiscovery<sup>10+</sup> 1186e41f4b71Sopenharmony_ci 1187e41f4b71Sopenharmony_cistartCastDeviceDiscovery(filter?: number, drmSchemes?: Array\<string>): Promise\<void> 1188e41f4b71Sopenharmony_ci 1189e41f4b71Sopenharmony_ciStarts cast-enabled device discovery. This API uses a promise to return the result. 1190e41f4b71Sopenharmony_ci 1191e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1192e41f4b71Sopenharmony_ci 1193e41f4b71Sopenharmony_ci**System API**: This is a system API. 1194e41f4b71Sopenharmony_ci 1195e41f4b71Sopenharmony_ci**Parameters** 1196e41f4b71Sopenharmony_ci 1197e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1198e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1199e41f4b71Sopenharmony_ci| filter | number | No | Filter criteria for device discovery. The value consists of **ProtocolType**s. | 1200e41f4b71Sopenharmony_ci| drmSchemes | Array\<string> | No | Filter criteria for discovering devices that support DRM resource playback. The value consists of DRM UUIDs.<br>This parameter is supported since API version 12.| 1201e41f4b71Sopenharmony_ci 1202e41f4b71Sopenharmony_ci**Return value** 1203e41f4b71Sopenharmony_ci 1204e41f4b71Sopenharmony_ci| Type | Description | 1205e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1206e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent and device discovery starts, no value is returned; otherwise, an error object is returned. | 1207e41f4b71Sopenharmony_ci 1208e41f4b71Sopenharmony_ci**Error codes** 1209e41f4b71Sopenharmony_ci 1210e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1211e41f4b71Sopenharmony_ci 1212e41f4b71Sopenharmony_ci| ID | Error Message | 1213e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1214e41f4b71Sopenharmony_ci| 202 | Not System App. | 1215e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1216e41f4b71Sopenharmony_ci 1217e41f4b71Sopenharmony_ci**Example** 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_ci```ts 1220e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1221e41f4b71Sopenharmony_ci 1222e41f4b71Sopenharmony_cilet filter = 2; 1223e41f4b71Sopenharmony_cilet drmSchemes = ['3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c']; 1224e41f4b71Sopenharmony_ciavSession.startCastDeviceDiscovery(filter, drmSchemes).then(() => { 1225e41f4b71Sopenharmony_ci console.info('startCastDeviceDiscovery successfully'); 1226e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1227e41f4b71Sopenharmony_ci console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1228e41f4b71Sopenharmony_ci}); 1229e41f4b71Sopenharmony_ci``` 1230e41f4b71Sopenharmony_ci 1231e41f4b71Sopenharmony_ci## avSession.stopCastDeviceDiscovery<sup>10+</sup> 1232e41f4b71Sopenharmony_ci 1233e41f4b71Sopenharmony_cistopCastDeviceDiscovery(callback: AsyncCallback\<void>): void 1234e41f4b71Sopenharmony_ci 1235e41f4b71Sopenharmony_ciStops cast-enabled device discovery. This API uses an asynchronous callback to return the result. 1236e41f4b71Sopenharmony_ci 1237e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1238e41f4b71Sopenharmony_ci 1239e41f4b71Sopenharmony_ci**System API**: This is a system API. 1240e41f4b71Sopenharmony_ci 1241e41f4b71Sopenharmony_ci**Parameters** 1242e41f4b71Sopenharmony_ci 1243e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1244e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1245e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If device discovery stops, **err** is **undefined**; otherwise, **err** is an error object. | 1246e41f4b71Sopenharmony_ci 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci**Example** 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci```ts 1251e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1252e41f4b71Sopenharmony_ci 1253e41f4b71Sopenharmony_ciavSession.stopCastDeviceDiscovery((err: BusinessError) => { 1254e41f4b71Sopenharmony_ci if (err) { 1255e41f4b71Sopenharmony_ci console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1256e41f4b71Sopenharmony_ci } else { 1257e41f4b71Sopenharmony_ci console.info('stopCastDeviceDiscovery successfully'); 1258e41f4b71Sopenharmony_ci } 1259e41f4b71Sopenharmony_ci}); 1260e41f4b71Sopenharmony_ci``` 1261e41f4b71Sopenharmony_ci 1262e41f4b71Sopenharmony_ci## avSession.stopCastDeviceDiscovery<sup>10+</sup> 1263e41f4b71Sopenharmony_ci 1264e41f4b71Sopenharmony_cistopCastDeviceDiscovery(): Promise\<void> 1265e41f4b71Sopenharmony_ci 1266e41f4b71Sopenharmony_ciStops cast-enabled device discovery. This API uses a promise to return the result. 1267e41f4b71Sopenharmony_ci 1268e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1269e41f4b71Sopenharmony_ci 1270e41f4b71Sopenharmony_ci**System API**: This is a system API. 1271e41f4b71Sopenharmony_ci 1272e41f4b71Sopenharmony_ci**Return value** 1273e41f4b71Sopenharmony_ci 1274e41f4b71Sopenharmony_ci| Type | Description | 1275e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1276e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If device discovery stops, no value is returned; otherwise, an error object is returned. | 1277e41f4b71Sopenharmony_ci 1278e41f4b71Sopenharmony_ci**Example** 1279e41f4b71Sopenharmony_ci 1280e41f4b71Sopenharmony_ci```ts 1281e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ciavSession.stopCastDeviceDiscovery().then(() => { 1284e41f4b71Sopenharmony_ci console.info('stopCastDeviceDiscovery successfully'); 1285e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1286e41f4b71Sopenharmony_ci console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1287e41f4b71Sopenharmony_ci}); 1288e41f4b71Sopenharmony_ci``` 1289e41f4b71Sopenharmony_ci 1290e41f4b71Sopenharmony_ci## avSession.setDiscoverable<sup>10+</sup> 1291e41f4b71Sopenharmony_ci 1292e41f4b71Sopenharmony_cisetDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void 1293e41f4b71Sopenharmony_ci 1294e41f4b71Sopenharmony_ciSets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses an asynchronous callback to return the result. 1295e41f4b71Sopenharmony_ci 1296e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1297e41f4b71Sopenharmony_ci 1298e41f4b71Sopenharmony_ci**System API**: This is a system API. 1299e41f4b71Sopenharmony_ci 1300e41f4b71Sopenharmony_ci**Parameters** 1301e41f4b71Sopenharmony_ci 1302e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1303e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1304e41f4b71Sopenharmony_ci| enable | boolean | Yes | Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite. | 1305e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1306e41f4b71Sopenharmony_ci 1307e41f4b71Sopenharmony_ci**Error codes** 1308e41f4b71Sopenharmony_ci 1309e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1310e41f4b71Sopenharmony_ci 1311e41f4b71Sopenharmony_ci| ID | Error Message | 1312e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1313e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1314e41f4b71Sopenharmony_ci 1315e41f4b71Sopenharmony_ci**Example** 1316e41f4b71Sopenharmony_ci 1317e41f4b71Sopenharmony_ci```ts 1318e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1319e41f4b71Sopenharmony_ci 1320e41f4b71Sopenharmony_ciavSession.setDiscoverable(true, (err: BusinessError) => { 1321e41f4b71Sopenharmony_ci if (err) { 1322e41f4b71Sopenharmony_ci console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); 1323e41f4b71Sopenharmony_ci } else { 1324e41f4b71Sopenharmony_ci console.info('setDiscoverable successfully'); 1325e41f4b71Sopenharmony_ci } 1326e41f4b71Sopenharmony_ci}); 1327e41f4b71Sopenharmony_ci``` 1328e41f4b71Sopenharmony_ci 1329e41f4b71Sopenharmony_ci## avSession.setDiscoverable<sup>10+</sup> 1330e41f4b71Sopenharmony_ci 1331e41f4b71Sopenharmony_cisetDiscoverable(enable: boolean): Promise\<void> 1332e41f4b71Sopenharmony_ci 1333e41f4b71Sopenharmony_ciSets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses a promise to return the result. 1334e41f4b71Sopenharmony_ci 1335e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1336e41f4b71Sopenharmony_ci 1337e41f4b71Sopenharmony_ci**System API**: This is a system API. 1338e41f4b71Sopenharmony_ci 1339e41f4b71Sopenharmony_ci**Parameters** 1340e41f4b71Sopenharmony_ci 1341e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1342e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1343e41f4b71Sopenharmony_ci| enable | boolean | Yes | Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite. | 1344e41f4b71Sopenharmony_ci 1345e41f4b71Sopenharmony_ci**Error codes** 1346e41f4b71Sopenharmony_ci 1347e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci| ID | Error Message | 1350e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1351e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_ci**Return value** 1354e41f4b71Sopenharmony_ci 1355e41f4b71Sopenharmony_ci| Type | Description | 1356e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1357e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned. | 1358e41f4b71Sopenharmony_ci 1359e41f4b71Sopenharmony_ci**Example** 1360e41f4b71Sopenharmony_ci 1361e41f4b71Sopenharmony_ci```ts 1362e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1363e41f4b71Sopenharmony_ci 1364e41f4b71Sopenharmony_ciavSession.setDiscoverable(true).then(() => { 1365e41f4b71Sopenharmony_ci console.info('setDiscoverable successfully'); 1366e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1367e41f4b71Sopenharmony_ci console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); 1368e41f4b71Sopenharmony_ci}); 1369e41f4b71Sopenharmony_ci``` 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ci## avSession.on('deviceAvailable')<sup>10+</sup> 1372e41f4b71Sopenharmony_ci 1373e41f4b71Sopenharmony_cion(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void 1374e41f4b71Sopenharmony_ci 1375e41f4b71Sopenharmony_ciSubscribes to device discovery events. 1376e41f4b71Sopenharmony_ci 1377e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1378e41f4b71Sopenharmony_ci 1379e41f4b71Sopenharmony_ci**System API**: This is a system API. 1380e41f4b71Sopenharmony_ci 1381e41f4b71Sopenharmony_ci**Parameters** 1382e41f4b71Sopenharmony_ci 1383e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1384e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1385e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered. | 1386e41f4b71Sopenharmony_ci| callback | (device: [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)) => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_ci**Error codes** 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci| ID | Error Message | 1393e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1394e41f4b71Sopenharmony_ci| 201 | permission denied. | 1395e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1396e41f4b71Sopenharmony_ci 1397e41f4b71Sopenharmony_ci**Example** 1398e41f4b71Sopenharmony_ci 1399e41f4b71Sopenharmony_ci```ts 1400e41f4b71Sopenharmony_cilet castDevice: avSession.OutputDeviceInfo; 1401e41f4b71Sopenharmony_ciavSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1402e41f4b71Sopenharmony_ci castDevice = device; 1403e41f4b71Sopenharmony_ci console.info(`on deviceAvailable : ${device} `); 1404e41f4b71Sopenharmony_ci}); 1405e41f4b71Sopenharmony_ci``` 1406e41f4b71Sopenharmony_ci 1407e41f4b71Sopenharmony_ci## avSession.off('deviceAvailable')<sup>10+</sup> 1408e41f4b71Sopenharmony_ci 1409e41f4b71Sopenharmony_cioff(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void 1410e41f4b71Sopenharmony_ci 1411e41f4b71Sopenharmony_ciUnsubscribes from device discovery events. 1412e41f4b71Sopenharmony_ci 1413e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1414e41f4b71Sopenharmony_ci 1415e41f4b71Sopenharmony_ci**System API**: This is a system API. 1416e41f4b71Sopenharmony_ci 1417e41f4b71Sopenharmony_ci**Parameters** 1418e41f4b71Sopenharmony_ci 1419e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1420e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------- | 1421e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.| 1422e41f4b71Sopenharmony_ci| callback | (device: [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)) => void | No | Callback used to return the device information.| 1423e41f4b71Sopenharmony_ci 1424e41f4b71Sopenharmony_ci**Error codes** 1425e41f4b71Sopenharmony_ci 1426e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1427e41f4b71Sopenharmony_ci 1428e41f4b71Sopenharmony_ci| ID | Error Message | 1429e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1430e41f4b71Sopenharmony_ci| 201 | permission denied. | 1431e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1432e41f4b71Sopenharmony_ci 1433e41f4b71Sopenharmony_ci**Example** 1434e41f4b71Sopenharmony_ci 1435e41f4b71Sopenharmony_ci```ts 1436e41f4b71Sopenharmony_ciavSession.off('deviceAvailable'); 1437e41f4b71Sopenharmony_ci``` 1438e41f4b71Sopenharmony_ci 1439e41f4b71Sopenharmony_ci## avSession.on('deviceOffline')<sup>11+</sup> 1440e41f4b71Sopenharmony_ci 1441e41f4b71Sopenharmony_cion(type: 'deviceOffline', callback: (deviceId: string) => void): void 1442e41f4b71Sopenharmony_ci 1443e41f4b71Sopenharmony_ciSubscribes to device offline events. 1444e41f4b71Sopenharmony_ci 1445e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci**System API**: This is a system API. 1448e41f4b71Sopenharmony_ci 1449e41f4b71Sopenharmony_ci**Parameters** 1450e41f4b71Sopenharmony_ci 1451e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1452e41f4b71Sopenharmony_ci| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1453e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'deviceOffline'** is triggered when a device gets offline. | 1454e41f4b71Sopenharmony_ci| callback | (deviceId: string) => void | Yes | Callback used to return the result. The **deviceId** parameter in the callback indicates the device ID. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1455e41f4b71Sopenharmony_ci 1456e41f4b71Sopenharmony_ci**Error codes** 1457e41f4b71Sopenharmony_ci 1458e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci| ID | Error Message | 1461e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1462e41f4b71Sopenharmony_ci| 201 | permission denied. | 1463e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1464e41f4b71Sopenharmony_ci 1465e41f4b71Sopenharmony_ci**Example** 1466e41f4b71Sopenharmony_ci 1467e41f4b71Sopenharmony_ci```ts 1468e41f4b71Sopenharmony_cilet castDeviceId: string; 1469e41f4b71Sopenharmony_ciavSession.on('deviceOffline', (deviceId: string) => { 1470e41f4b71Sopenharmony_ci castDeviceId = deviceId; 1471e41f4b71Sopenharmony_ci console.info(`on deviceOffline : ${deviceId} `); 1472e41f4b71Sopenharmony_ci}); 1473e41f4b71Sopenharmony_ci``` 1474e41f4b71Sopenharmony_ci 1475e41f4b71Sopenharmony_ci## avSession.off('deviceOffline')<sup>11+</sup> 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_cioff(type: 'deviceOffline', callback?: (deviceId: string) => void): void 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ciUnsubscribes from device offline events. 1480e41f4b71Sopenharmony_ci 1481e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1482e41f4b71Sopenharmony_ci 1483e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1484e41f4b71Sopenharmony_ci 1485e41f4b71Sopenharmony_ci**System API**: This is a system API. 1486e41f4b71Sopenharmony_ci 1487e41f4b71Sopenharmony_ci**Parameters** 1488e41f4b71Sopenharmony_ci 1489e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1490e41f4b71Sopenharmony_ci| ------ | ---------------------- | ---- | ------------------------------------------------------- | 1491e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'deviceOffline'** in this case.| 1492e41f4b71Sopenharmony_ci| callback | (deviceId: string) => void | No | Callback used to return the result. The **deviceId** parameter in the callback indicates the device ID. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| 1493e41f4b71Sopenharmony_ci 1494e41f4b71Sopenharmony_ci**Error codes** 1495e41f4b71Sopenharmony_ci 1496e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1497e41f4b71Sopenharmony_ci 1498e41f4b71Sopenharmony_ci| ID | Error Message | 1499e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1500e41f4b71Sopenharmony_ci| 201 | permission denied. | 1501e41f4b71Sopenharmony_ci| 202 | Not System App. | 1502e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1503e41f4b71Sopenharmony_ci 1504e41f4b71Sopenharmony_ci**Example** 1505e41f4b71Sopenharmony_ci 1506e41f4b71Sopenharmony_ci```ts 1507e41f4b71Sopenharmony_ciavSession.off('deviceOffline'); 1508e41f4b71Sopenharmony_ci``` 1509e41f4b71Sopenharmony_ci 1510e41f4b71Sopenharmony_ci## avSession.getAVCastController<sup>10+</sup> 1511e41f4b71Sopenharmony_ci 1512e41f4b71Sopenharmony_cigetAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController>): void 1513e41f4b71Sopenharmony_ci 1514e41f4b71Sopenharmony_ciObtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. 1515e41f4b71Sopenharmony_ci 1516e41f4b71Sopenharmony_ciThis API can be called on both the local and remote devices. You can use the API to obtain the same controller to control audio playback after cast. 1517e41f4b71Sopenharmony_ci 1518e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1519e41f4b71Sopenharmony_ci 1520e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1521e41f4b71Sopenharmony_ci 1522e41f4b71Sopenharmony_ci**System API**: This is a system API. 1523e41f4b71Sopenharmony_ci 1524e41f4b71Sopenharmony_ci**Parameters** 1525e41f4b71Sopenharmony_ci 1526e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1527e41f4b71Sopenharmony_ci| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1528e41f4b71Sopenharmony_ci| sessionId | string | Yes |Session ID. | 1529e41f4b71Sopenharmony_ci| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller. | 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci**Error codes** 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1534e41f4b71Sopenharmony_ci 1535e41f4b71Sopenharmony_ci| ID | Error Message | 1536e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1537e41f4b71Sopenharmony_ci| 201 | permission denied. | 1538e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1539e41f4b71Sopenharmony_ci| 6600101 | Session service exception | 1540e41f4b71Sopenharmony_ci| 6600102 | session does not exist | 1541e41f4b71Sopenharmony_ci 1542e41f4b71Sopenharmony_ci**Example** 1543e41f4b71Sopenharmony_ci 1544e41f4b71Sopenharmony_ci```ts 1545e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1546e41f4b71Sopenharmony_ci 1547e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined; 1548e41f4b71Sopenharmony_cilet tag = "createNewSession"; 1549e41f4b71Sopenharmony_cilet context: Context = getContext(this); 1550e41f4b71Sopenharmony_cilet sessionId: string = ""; // Used as an input parameter of subsequent functions. 1551e41f4b71Sopenharmony_ci 1552e41f4b71Sopenharmony_cilet aVCastController: avSession.AVCastController; 1553e41f4b71Sopenharmony_ciavSession.getAVCastController(sessionId , (err: BusinessError, avcontroller: avSession.AVCastController) => { 1554e41f4b71Sopenharmony_ci if (err) { 1555e41f4b71Sopenharmony_ci console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1556e41f4b71Sopenharmony_ci } else { 1557e41f4b71Sopenharmony_ci aVCastController = avcontroller; 1558e41f4b71Sopenharmony_ci console.info('getAVCastController : SUCCESS '); 1559e41f4b71Sopenharmony_ci } 1560e41f4b71Sopenharmony_ci}); 1561e41f4b71Sopenharmony_ci``` 1562e41f4b71Sopenharmony_ci 1563e41f4b71Sopenharmony_ci## avSession.getAVCastController<sup>10+</sup> 1564e41f4b71Sopenharmony_ci 1565e41f4b71Sopenharmony_cigetAVCastController(sessionId: string): Promise\<AVCastController> 1566e41f4b71Sopenharmony_ci 1567e41f4b71Sopenharmony_ciObtains the cast controller when a casting connection is set up. This API uses a promise to return the result. 1568e41f4b71Sopenharmony_ci 1569e41f4b71Sopenharmony_ciThis API can be called on both the local and remote devices. You can use the API to obtain the same controller to control audio playback after cast. 1570e41f4b71Sopenharmony_ci 1571e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1572e41f4b71Sopenharmony_ci 1573e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1574e41f4b71Sopenharmony_ci 1575e41f4b71Sopenharmony_ci**System API**: This is a system API. 1576e41f4b71Sopenharmony_ci 1577e41f4b71Sopenharmony_ci**Parameters** 1578e41f4b71Sopenharmony_ci 1579e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1580e41f4b71Sopenharmony_ci| --------- | ------------------------- | ---- | ------------------------------------------------------------ | 1581e41f4b71Sopenharmony_ci| sessionId | string | Yes |Session ID. | 1582e41f4b71Sopenharmony_ci 1583e41f4b71Sopenharmony_ci**Return value** 1584e41f4b71Sopenharmony_ci 1585e41f4b71Sopenharmony_ci| Type | Description | 1586e41f4b71Sopenharmony_ci| --------- | ------------------------------------------------------------ | 1587e41f4b71Sopenharmony_ci| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller. | 1588e41f4b71Sopenharmony_ci 1589e41f4b71Sopenharmony_ci**Error codes** 1590e41f4b71Sopenharmony_ci 1591e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1592e41f4b71Sopenharmony_ci 1593e41f4b71Sopenharmony_ci| ID | Error Message | 1594e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1595e41f4b71Sopenharmony_ci| 201 | permission denied. | 1596e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1597e41f4b71Sopenharmony_ci| 6600101 | server exception | 1598e41f4b71Sopenharmony_ci| 6600102 | The session does not exist | 1599e41f4b71Sopenharmony_ci 1600e41f4b71Sopenharmony_ci**Example** 1601e41f4b71Sopenharmony_ci 1602e41f4b71Sopenharmony_ci```ts 1603e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1604e41f4b71Sopenharmony_ci 1605e41f4b71Sopenharmony_cilet currentAVSession: avSession.AVSession | undefined = undefined; 1606e41f4b71Sopenharmony_cilet tag = "createNewSession"; 1607e41f4b71Sopenharmony_cilet context: Context = getContext(this); 1608e41f4b71Sopenharmony_cilet sessionId: string = ""; // Used as an input parameter of subsequent functions. 1609e41f4b71Sopenharmony_ci 1610e41f4b71Sopenharmony_cilet aVCastController: avSession.AVCastController; 1611e41f4b71Sopenharmony_ciavSession.getAVCastController(sessionId).then((avcontroller: avSession.AVCastController) => { 1612e41f4b71Sopenharmony_ci aVCastController = avcontroller; 1613e41f4b71Sopenharmony_ci console.info('getAVCastController : SUCCESS'); 1614e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1615e41f4b71Sopenharmony_ci console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1616e41f4b71Sopenharmony_ci}); 1617e41f4b71Sopenharmony_ci``` 1618e41f4b71Sopenharmony_ci 1619e41f4b71Sopenharmony_ci## avSession.startCasting<sup>10+</sup> 1620e41f4b71Sopenharmony_ci 1621e41f4b71Sopenharmony_cistartCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\<void>): void 1622e41f4b71Sopenharmony_ci 1623e41f4b71Sopenharmony_ciStarts casting. This API uses an asynchronous callback to return the result. 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1626e41f4b71Sopenharmony_ci 1627e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1628e41f4b71Sopenharmony_ci 1629e41f4b71Sopenharmony_ci**System API**: This is a system API. 1630e41f4b71Sopenharmony_ci 1631e41f4b71Sopenharmony_ci**Parameters** 1632e41f4b71Sopenharmony_ci 1633e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1634e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1635e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1636e41f4b71Sopenharmony_ci| device | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10) | Yes | Device-related information. | 1637e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent and casting starts, **err** is **undefined**; otherwise, **err** is an error object. | 1638e41f4b71Sopenharmony_ci 1639e41f4b71Sopenharmony_ci**Error codes** 1640e41f4b71Sopenharmony_ci 1641e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1642e41f4b71Sopenharmony_ci 1643e41f4b71Sopenharmony_ci| ID | Error Message | 1644e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1645e41f4b71Sopenharmony_ci| 201 | permission denied. | 1646e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1647e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1648e41f4b71Sopenharmony_ci| 6600108 | Device connection failed. | 1649e41f4b71Sopenharmony_ci 1650e41f4b71Sopenharmony_ci**Example** 1651e41f4b71Sopenharmony_ci 1652e41f4b71Sopenharmony_ci```ts 1653e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1654e41f4b71Sopenharmony_ci 1655e41f4b71Sopenharmony_cilet myToken: avSession.SessionToken = { 1656e41f4b71Sopenharmony_ci sessionId: sessionId, 1657e41f4b71Sopenharmony_ci} 1658e41f4b71Sopenharmony_cilet castDevice: avSession.OutputDeviceInfo | undefined = undefined; 1659e41f4b71Sopenharmony_ciavSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1660e41f4b71Sopenharmony_ci castDevice = device; 1661e41f4b71Sopenharmony_ci console.info(`on deviceAvailable : ${device} `); 1662e41f4b71Sopenharmony_ci}); 1663e41f4b71Sopenharmony_ciif (castDevice !== undefined) { 1664e41f4b71Sopenharmony_ci avSession.startCasting(myToken, castDevice, (err: BusinessError) => { 1665e41f4b71Sopenharmony_ci if (err) { 1666e41f4b71Sopenharmony_ci console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1667e41f4b71Sopenharmony_ci } else { 1668e41f4b71Sopenharmony_ci console.info('startCasting successfully'); 1669e41f4b71Sopenharmony_ci } 1670e41f4b71Sopenharmony_ci }); 1671e41f4b71Sopenharmony_ci} 1672e41f4b71Sopenharmony_ci``` 1673e41f4b71Sopenharmony_ci 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci## avSession.startCasting<sup>10+</sup> 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_cistartCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void> 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ciStarts casting. This API uses a promise to return the result. 1680e41f4b71Sopenharmony_ci 1681e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1682e41f4b71Sopenharmony_ci 1683e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1684e41f4b71Sopenharmony_ci 1685e41f4b71Sopenharmony_ci**System API**: This is a system API. 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci**Parameters** 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1690e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1691e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1692e41f4b71Sopenharmony_ci| device | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10) | Yes | Device-related information. | 1693e41f4b71Sopenharmony_ci 1694e41f4b71Sopenharmony_ci**Return value** 1695e41f4b71Sopenharmony_ci 1696e41f4b71Sopenharmony_ci| Type | Description | 1697e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1698e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If the command is sent and casting starts, no value is returned; otherwise, an error object is returned. | 1699e41f4b71Sopenharmony_ci 1700e41f4b71Sopenharmony_ci**Error codes** 1701e41f4b71Sopenharmony_ci 1702e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1703e41f4b71Sopenharmony_ci 1704e41f4b71Sopenharmony_ci| ID | Error Message | 1705e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1706e41f4b71Sopenharmony_ci| 201 | permission denied. | 1707e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1708e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1709e41f4b71Sopenharmony_ci| 6600108 | Device connection failed. | 1710e41f4b71Sopenharmony_ci 1711e41f4b71Sopenharmony_ci**Example** 1712e41f4b71Sopenharmony_ci 1713e41f4b71Sopenharmony_ci```ts 1714e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1715e41f4b71Sopenharmony_ci 1716e41f4b71Sopenharmony_cilet myToken: avSession.SessionToken = { 1717e41f4b71Sopenharmony_ci sessionId: sessionId, 1718e41f4b71Sopenharmony_ci} 1719e41f4b71Sopenharmony_cilet castDevice: avSession.OutputDeviceInfo | undefined = undefined; 1720e41f4b71Sopenharmony_ciavSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1721e41f4b71Sopenharmony_ci castDevice = device; 1722e41f4b71Sopenharmony_ci console.info(`on deviceAvailable : ${device} `); 1723e41f4b71Sopenharmony_ci}); 1724e41f4b71Sopenharmony_ciif (castDevice !== undefined) { 1725e41f4b71Sopenharmony_ci avSession.startCasting(myToken, castDevice).then(() => { 1726e41f4b71Sopenharmony_ci console.info('startCasting successfully'); 1727e41f4b71Sopenharmony_ci }).catch((err: BusinessError) => { 1728e41f4b71Sopenharmony_ci console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1729e41f4b71Sopenharmony_ci }); 1730e41f4b71Sopenharmony_ci} 1731e41f4b71Sopenharmony_ci``` 1732e41f4b71Sopenharmony_ci 1733e41f4b71Sopenharmony_ci## avSession.stopCasting<sup>10+</sup> 1734e41f4b71Sopenharmony_ci 1735e41f4b71Sopenharmony_cistopCasting(session: SessionToken, callback: AsyncCallback\<void>): void 1736e41f4b71Sopenharmony_ci 1737e41f4b71Sopenharmony_ciStops castings. This API uses an asynchronous callback to return the result. 1738e41f4b71Sopenharmony_ci 1739e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1740e41f4b71Sopenharmony_ci 1741e41f4b71Sopenharmony_ci**System API**: This is a system API. 1742e41f4b71Sopenharmony_ci 1743e41f4b71Sopenharmony_ci**Parameters** 1744e41f4b71Sopenharmony_ci 1745e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1746e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1747e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1748e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If casting stops, **err** is **undefined**; otherwise, **err** is an error object. | 1749e41f4b71Sopenharmony_ci 1750e41f4b71Sopenharmony_ci**Error codes** 1751e41f4b71Sopenharmony_ci 1752e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1753e41f4b71Sopenharmony_ci 1754e41f4b71Sopenharmony_ci| ID | Error Message | 1755e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1756e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1757e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established. | 1758e41f4b71Sopenharmony_ci 1759e41f4b71Sopenharmony_ci**Example** 1760e41f4b71Sopenharmony_ci 1761e41f4b71Sopenharmony_ci```ts 1762e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1763e41f4b71Sopenharmony_ci 1764e41f4b71Sopenharmony_cilet myToken: avSession.SessionToken = { 1765e41f4b71Sopenharmony_ci sessionId: sessionId, 1766e41f4b71Sopenharmony_ci} 1767e41f4b71Sopenharmony_ciavSession.stopCasting(myToken, (err: BusinessError) => { 1768e41f4b71Sopenharmony_ci if (err) { 1769e41f4b71Sopenharmony_ci console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1770e41f4b71Sopenharmony_ci } else { 1771e41f4b71Sopenharmony_ci console.info('stopCasting successfully'); 1772e41f4b71Sopenharmony_ci } 1773e41f4b71Sopenharmony_ci}); 1774e41f4b71Sopenharmony_ci``` 1775e41f4b71Sopenharmony_ci 1776e41f4b71Sopenharmony_ci## avSession.stopCasting<sup>10+</sup> 1777e41f4b71Sopenharmony_ci 1778e41f4b71Sopenharmony_cistopCasting(session: SessionToken): Promise\<void> 1779e41f4b71Sopenharmony_ci 1780e41f4b71Sopenharmony_ciStops castings. This API uses a promise to return the result. 1781e41f4b71Sopenharmony_ci 1782e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1783e41f4b71Sopenharmony_ci 1784e41f4b71Sopenharmony_ci**System API**: This is a system API. 1785e41f4b71Sopenharmony_ci 1786e41f4b71Sopenharmony_ci**Parameters** 1787e41f4b71Sopenharmony_ci 1788e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1789e41f4b71Sopenharmony_ci| -------- | ------------------------------------- | ---- | ------------------------------------- | 1790e41f4b71Sopenharmony_ci| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1791e41f4b71Sopenharmony_ci 1792e41f4b71Sopenharmony_ci**Return value** 1793e41f4b71Sopenharmony_ci 1794e41f4b71Sopenharmony_ci| Type | Description | 1795e41f4b71Sopenharmony_ci| -------------- | ----------------------------- | 1796e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned. | 1797e41f4b71Sopenharmony_ci 1798e41f4b71Sopenharmony_ci**Error codes** 1799e41f4b71Sopenharmony_ci 1800e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1801e41f4b71Sopenharmony_ci 1802e41f4b71Sopenharmony_ci| ID | Error Message | 1803e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1804e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1805e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established. | 1806e41f4b71Sopenharmony_ci 1807e41f4b71Sopenharmony_ci**Example** 1808e41f4b71Sopenharmony_ci 1809e41f4b71Sopenharmony_ci```ts 1810e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1811e41f4b71Sopenharmony_ci 1812e41f4b71Sopenharmony_cilet myToken: avSession.SessionToken = { 1813e41f4b71Sopenharmony_ci sessionId: sessionId, 1814e41f4b71Sopenharmony_ci} 1815e41f4b71Sopenharmony_ciavSession.stopCasting(myToken).then(() => { 1816e41f4b71Sopenharmony_ci console.info('stopCasting successfully'); 1817e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1818e41f4b71Sopenharmony_ci console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1819e41f4b71Sopenharmony_ci}); 1820e41f4b71Sopenharmony_ci``` 1821e41f4b71Sopenharmony_ci 1822e41f4b71Sopenharmony_ci## AVCastController<sup>10+</sup> 1823e41f4b71Sopenharmony_ci 1824e41f4b71Sopenharmony_ciAfter a casting connection is set up, you can call [avSession.getAVCastController](js-apis-avsession.md#getavcastcontroller10) to obtain the cast controller. Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information. 1825e41f4b71Sopenharmony_ci 1826e41f4b71Sopenharmony_ci### setDisplaySurface<sup>10+</sup> 1827e41f4b71Sopenharmony_ci 1828e41f4b71Sopenharmony_cisetDisplaySurface(surfaceId: string): Promise\<void> 1829e41f4b71Sopenharmony_ci 1830e41f4b71Sopenharmony_ciSets the surface ID for playback, which is used at the cast receiver (sink). This API uses a promise to return the result. 1831e41f4b71Sopenharmony_ci 1832e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1833e41f4b71Sopenharmony_ci 1834e41f4b71Sopenharmony_ci**System API**: This is a system API. 1835e41f4b71Sopenharmony_ci 1836e41f4b71Sopenharmony_ci**Return value** 1837e41f4b71Sopenharmony_ci 1838e41f4b71Sopenharmony_ci| Type | Description | 1839e41f4b71Sopenharmony_ci| --------------------------------------------- | --------------------------- | 1840e41f4b71Sopenharmony_ci| Promise\<void> | Promise used to return the result. | 1841e41f4b71Sopenharmony_ci 1842e41f4b71Sopenharmony_ci**Error codes** 1843e41f4b71Sopenharmony_ci 1844e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1845e41f4b71Sopenharmony_ci 1846e41f4b71Sopenharmony_ci| ID | Error Message | 1847e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1848e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1849e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established. | 1850e41f4b71Sopenharmony_ci 1851e41f4b71Sopenharmony_ci**Example** 1852e41f4b71Sopenharmony_ci 1853e41f4b71Sopenharmony_ci```ts 1854e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 1855e41f4b71Sopenharmony_cilet surfaceID: string = ''; 1856e41f4b71Sopenharmony_cimedia.createAVRecorder().then((avRecorder) => { 1857e41f4b71Sopenharmony_ci avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 1858e41f4b71Sopenharmony_ci if (err == null) { 1859e41f4b71Sopenharmony_ci console.info('getInputSurface success'); 1860e41f4b71Sopenharmony_ci surfaceID = surfaceId; 1861e41f4b71Sopenharmony_ci } else { 1862e41f4b71Sopenharmony_ci console.error('getInputSurface failed and error is ' + err.message); 1863e41f4b71Sopenharmony_ci } 1864e41f4b71Sopenharmony_ci }); 1865e41f4b71Sopenharmony_ci}) 1866e41f4b71Sopenharmony_ciaVCastController.setDisplaySurface(surfaceID).then(() => { 1867e41f4b71Sopenharmony_ci console.info('setDisplaySurface : SUCCESS'); 1868e41f4b71Sopenharmony_ci}); 1869e41f4b71Sopenharmony_ci``` 1870e41f4b71Sopenharmony_ci 1871e41f4b71Sopenharmony_ci### setDisplaySurface<sup>10+</sup> 1872e41f4b71Sopenharmony_ci 1873e41f4b71Sopenharmony_cisetDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void 1874e41f4b71Sopenharmony_ci 1875e41f4b71Sopenharmony_ciSets the surface ID for playback, which is used at the cast receiver (sink). This API uses an asynchronous callback to return the result. 1876e41f4b71Sopenharmony_ci 1877e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1878e41f4b71Sopenharmony_ci 1879e41f4b71Sopenharmony_ci**System API**: This is a system API. 1880e41f4b71Sopenharmony_ci 1881e41f4b71Sopenharmony_ci**Parameters** 1882e41f4b71Sopenharmony_ci 1883e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1884e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------- | ---- | ---------------------------- | 1885e41f4b71Sopenharmony_ci| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 1886e41f4b71Sopenharmony_ci| surfaceId | string | Yes | Surface ID. | 1887e41f4b71Sopenharmony_ci 1888e41f4b71Sopenharmony_ci 1889e41f4b71Sopenharmony_ci**Error codes** 1890e41f4b71Sopenharmony_ci 1891e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1892e41f4b71Sopenharmony_ci 1893e41f4b71Sopenharmony_ci| ID | Error Message | 1894e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | 1895e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1896e41f4b71Sopenharmony_ci| 6600109 | The remote connection is not established. | 1897e41f4b71Sopenharmony_ci 1898e41f4b71Sopenharmony_ci**Example** 1899e41f4b71Sopenharmony_ci 1900e41f4b71Sopenharmony_ci```ts 1901e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1902e41f4b71Sopenharmony_ciimport { media } from '@kit.MediaKit'; 1903e41f4b71Sopenharmony_cilet surfaceID: string = ''; 1904e41f4b71Sopenharmony_cimedia.createAVRecorder().then((avRecorder) => { 1905e41f4b71Sopenharmony_ci avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 1906e41f4b71Sopenharmony_ci if (err == null) { 1907e41f4b71Sopenharmony_ci console.info('getInputSurface success'); 1908e41f4b71Sopenharmony_ci surfaceID = surfaceId; 1909e41f4b71Sopenharmony_ci } else { 1910e41f4b71Sopenharmony_ci console.error('getInputSurface failed and error is ' + err.message); 1911e41f4b71Sopenharmony_ci } 1912e41f4b71Sopenharmony_ci }); 1913e41f4b71Sopenharmony_ci}) 1914e41f4b71Sopenharmony_ciaVCastController.setDisplaySurface(surfaceID, (err: BusinessError) => { 1915e41f4b71Sopenharmony_ci if (err) { 1916e41f4b71Sopenharmony_ci console.error(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`); 1917e41f4b71Sopenharmony_ci } else { 1918e41f4b71Sopenharmony_ci console.info('setDisplaySurface : SUCCESS'); 1919e41f4b71Sopenharmony_ci } 1920e41f4b71Sopenharmony_ci}); 1921e41f4b71Sopenharmony_ci``` 1922e41f4b71Sopenharmony_ci 1923e41f4b71Sopenharmony_ci### on('videoSizeChange')<sup>10+</sup> 1924e41f4b71Sopenharmony_ci 1925e41f4b71Sopenharmony_cion(type: 'videoSizeChange', callback: (width:number, height:number) => void): void 1926e41f4b71Sopenharmony_ci 1927e41f4b71Sopenharmony_ciSubscribes to video size change events. 1928e41f4b71Sopenharmony_ci 1929e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1930e41f4b71Sopenharmony_ci 1931e41f4b71Sopenharmony_ci**System API**: This is a system API. 1932e41f4b71Sopenharmony_ci 1933e41f4b71Sopenharmony_ci**Parameters** 1934e41f4b71Sopenharmony_ci 1935e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1936e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 1937e41f4b71Sopenharmony_ci| type | string | Yes | Event type. The event **'videoSizeChange'** is triggered when the video size changes. | 1938e41f4b71Sopenharmony_ci| callback | (width:number, height:number) => void | Yes | Callback used to return the video width and height. | 1939e41f4b71Sopenharmony_ci 1940e41f4b71Sopenharmony_ci**Error codes** 1941e41f4b71Sopenharmony_ci 1942e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1943e41f4b71Sopenharmony_ci 1944e41f4b71Sopenharmony_ci| ID | Error Message | 1945e41f4b71Sopenharmony_ci| -------- | ---------------- | 1946e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1947e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1948e41f4b71Sopenharmony_ci 1949e41f4b71Sopenharmony_ci**Example** 1950e41f4b71Sopenharmony_ci 1951e41f4b71Sopenharmony_ci```ts 1952e41f4b71Sopenharmony_ciaVCastController.on('videoSizeChange', (width: number, height: number) => { 1953e41f4b71Sopenharmony_ci console.info(`width : ${width} `); 1954e41f4b71Sopenharmony_ci console.info(`height: ${height} `); 1955e41f4b71Sopenharmony_ci}); 1956e41f4b71Sopenharmony_ci``` 1957e41f4b71Sopenharmony_ci 1958e41f4b71Sopenharmony_ci### off('videoSizeChange')<sup>10+</sup> 1959e41f4b71Sopenharmony_ci 1960e41f4b71Sopenharmony_cioff(type: 'videoSizeChange'): void 1961e41f4b71Sopenharmony_ci 1962e41f4b71Sopenharmony_ciUnsubscribes from video size changes. 1963e41f4b71Sopenharmony_ci 1964e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1965e41f4b71Sopenharmony_ci 1966e41f4b71Sopenharmony_ci**System API**: This is a system API. 1967e41f4b71Sopenharmony_ci 1968e41f4b71Sopenharmony_ci**Parameters** 1969e41f4b71Sopenharmony_ci 1970e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1971e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 1972e41f4b71Sopenharmony_ci| type | string | Yes | Event type, which is **'videoSizeChange'** in this case. | 1973e41f4b71Sopenharmony_ci 1974e41f4b71Sopenharmony_ci**Error codes** 1975e41f4b71Sopenharmony_ci 1976e41f4b71Sopenharmony_ciFor details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1977e41f4b71Sopenharmony_ci 1978e41f4b71Sopenharmony_ci| ID | Error Message | 1979e41f4b71Sopenharmony_ci| -------- | ---------------- | 1980e41f4b71Sopenharmony_ci| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1981e41f4b71Sopenharmony_ci| 6600101 | Session service exception. | 1982e41f4b71Sopenharmony_ci 1983e41f4b71Sopenharmony_ci**Example** 1984e41f4b71Sopenharmony_ci 1985e41f4b71Sopenharmony_ci```ts 1986e41f4b71Sopenharmony_ciaVCastController.off('videoSizeChange'); 1987e41f4b71Sopenharmony_ci``` 1988e41f4b71Sopenharmony_ci 1989e41f4b71Sopenharmony_ci## AVMetadata<sup>10+</sup> 1990e41f4b71Sopenharmony_ci 1991e41f4b71Sopenharmony_ciDescribes the media metadata. 1992e41f4b71Sopenharmony_ci 1993e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core 1994e41f4b71Sopenharmony_ci 1995e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 1996e41f4b71Sopenharmony_ci| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 1997e41f4b71Sopenharmony_ci| avQueueName<sup>11+</sup> | string | No | Playlist name.<br>This is a system API. | 1998e41f4b71Sopenharmony_ci 1999e41f4b71Sopenharmony_ci## AVQueueInfo<sup>11+</sup> 2000e41f4b71Sopenharmony_ci 2001e41f4b71Sopenharmony_ciDefines the attributes of a playlist. 2002e41f4b71Sopenharmony_ci 2003e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core 2004e41f4b71Sopenharmony_ci 2005e41f4b71Sopenharmony_ci**System API**: This is a system API. 2006e41f4b71Sopenharmony_ci 2007e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 2008e41f4b71Sopenharmony_ci| --------------- |-------------------------| ---- |--------------------------------------------------------------------- | 2009e41f4b71Sopenharmony_ci| bundleName | string | Yes | Bundle name of the application to which the playlist belongs. | 2010e41f4b71Sopenharmony_ci| avQueueName | string | Yes | Playlist name. | 2011e41f4b71Sopenharmony_ci| avQueueId | string | Yes | Unique ID of the playlist. | 2012e41f4b71Sopenharmony_ci| avQueueImage | image.PixelMap | string |Yes | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path). | 2013e41f4b71Sopenharmony_ci| lastPlayedTime | number | No | Last time when the playlist is played. | 2014e41f4b71Sopenharmony_ci 2015e41f4b71Sopenharmony_ci## DeviceInfo<sup>10+</sup> 2016e41f4b71Sopenharmony_ci 2017e41f4b71Sopenharmony_ciDescribes the information related to the output device. 2018e41f4b71Sopenharmony_ci 2019e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Core 2020e41f4b71Sopenharmony_ci 2021e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 2022e41f4b71Sopenharmony_ci| ---------- | -------------- | ---- | ---------------------- | 2023e41f4b71Sopenharmony_ci| ipAddress | string | No | IP address of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast | 2024e41f4b71Sopenharmony_ci| providerId | number | No | Vendor of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast | 2025e41f4b71Sopenharmony_ci| authenticationStatus<sup>11+</sup> | number | No | Whether the output device is trusted. The default value is **0**, indicating that the device is untrusted. The value **1** means that the device is trusted.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast | 2026e41f4b71Sopenharmony_ci 2027e41f4b71Sopenharmony_ci## AVSessionDescriptor 2028e41f4b71Sopenharmony_ci 2029e41f4b71Sopenharmony_ciDeclares the session descriptor. 2030e41f4b71Sopenharmony_ci 2031e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Multimedia.AVSession.Manager 2032e41f4b71Sopenharmony_ci 2033e41f4b71Sopenharmony_ci**System API**: This is a system API. 2034e41f4b71Sopenharmony_ci 2035e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 2036e41f4b71Sopenharmony_ci| --------------| ---------------- | ---------------- | ---------------- |------| 2037e41f4b71Sopenharmony_ci| sessionId | string | Yes | Yes | Session ID. | 2038e41f4b71Sopenharmony_ci| type | [AVSessionType](js-apis-avsession.md#avsessiontype10) | Yes | Yes | Session type. | 2039e41f4b71Sopenharmony_ci| sessionTag | string | Yes | Yes | Custom session name. | 2040e41f4b71Sopenharmony_ci| elementName | [ElementName](../apis-ability-kit/js-apis-bundle-ElementName.md) | Yes | Yes | Information about the application to which the session belongs, including the bundle name and ability name. | 2041e41f4b71Sopenharmony_ci| isActive | boolean | Yes | Yes | Whether the session is activated.<br>**true**: The session is activated.<br>**false**: The service is not activated. | 2042e41f4b71Sopenharmony_ci| isTopSession | boolean | Yes | Yes | Whether the session is the top session.<br>**true**: The session is the top session.<br>**false**: The session is not the top session. | 2043e41f4b71Sopenharmony_ci| outputDevice | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10) | Yes | Yes | Information about the output device. | 2044