1# @ohos.multimedia.avsession (AVSession Management) (System API) 2 3The AVSession module provides APIs for media playback control so that applications can access the system's Media Controller. 4 5This module provides the following typical features related to media sessions: 6 7- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios. 8 9> **NOTE** 10> 11> - 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. 12> - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.multimedia.avsession (AVSession Management)](arkts-apis-avsession.md). 13 14## Modules to Import 15 16```ts 17import { avSession } from '@kit.AVSessionKit'; 18``` 19 20## Usage Guidelines 21 22This 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](arkts-apis-avsession-f.md#avsessioncreateavsession10). 23 24## avSession.getAllSessionDescriptors 25 26getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>> 27 28Obtains the descriptors of all sessions that have set media information and registered control callbacks. This API uses a promise to return the result. 29 30**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 31 32**System capability**: SystemCapability.Multimedia.AVSession.Manager 33 34**System API**: This is a system API. 35 36**Return value** 37 38| Type | Description | 39| ------------------------------------------------------------ | --------------------------------------------- | 40| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of AVSessionDescriptor objects, each of which is read only.| 41 42**Error codes** 43 44For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 45 46| ID| Error Message| 47| -------- | ---------------------------------------- | 48| 201 | permission denied. | 49| 6600101 | Session service exception. | 50 51**Example** 52 53```ts 54import { BusinessError } from '@kit.BasicServicesKit'; 55 56avSession.getAllSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => { 57 console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 58 if (descriptors.length > 0 ) { 59 console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 60 console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 61 console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 62 } 63}).catch((err: BusinessError) => { 64 console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 65}); 66``` 67 68## avSession.getAllSessionDescriptors 69 70getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void 71 72Obtains the descriptors of all sessions that have set media information and registered control callbacks. This API uses an asynchronous callback to return the result. 73 74**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 75 76**System capability**: SystemCapability.Multimedia.AVSession.Manager 77 78**System API**: This is a system API. 79 80**Parameters** 81 82| Name | Type | Mandatory| Description | 83| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 84| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes | Callback used to return an array of AVSessionDescriptor objects, each of which is read only.| 85 86**Error codes** 87 88For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 89 90| ID| Error Message| 91| -------- | ---------------------------------------- | 92| 201 | permission denied. | 93| 6600101 |Session service exception. | 94 95**Example** 96 97```ts 98import { BusinessError } from '@kit.BasicServicesKit'; 99 100avSession.getAllSessionDescriptors((err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => { 101 if (err) { 102 console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 103 } else { 104 console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 105 if (descriptors.length > 0 ) { 106 console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 107 console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 108 console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 109 } 110 } 111}); 112``` 113 114## avSession.getHistoricalSessionDescriptors<sup>10+</sup> 115 116getHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVSessionDescriptor>>> 117 118Obtains the descriptors of all historical sessions. This API uses a promise to return the result. 119 120**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 121 122**System capability**: SystemCapability.Multimedia.AVSession.Manager 123 124**System API**: This is a system API. 125 126**Parameters** 127 128| Name | Type | Mandatory| Description | 129| -------- | ------ | ---- | -----------------------------------------------------------------| 130| 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.| 131 132**Return value** 133 134| Type | Description | 135| --------------------------------------------------------------------------- | -------------------------------------- | 136| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of AVSessionDescriptor objects, each of which is read only.| 137 138**Error codes** 139 140For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 141 142| ID| Error Message| 143| -------- | ---------------------------------------- | 144| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 145| 6600101 | Session service exception. | 146 147**Example** 148 149```ts 150import { BusinessError } from '@kit.BasicServicesKit'; 151 152avSession.getHistoricalSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => { 153 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 154 if (descriptors.length > 0 ) { 155 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 156 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 157 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 158 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); 159 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); 160 } 161}).catch((err: BusinessError) => { 162 console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 163}); 164``` 165 166## avSession.getHistoricalSessionDescriptors<sup>10+</sup> 167 168getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void 169 170Obtains the descriptors of all historical sessions. This API uses an asynchronous callback to return the result. 171 172**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 173 174**System capability**: SystemCapability.Multimedia.AVSession.Manager 175 176**System API**: This is a system API. 177 178**Parameters** 179 180| Name | Type | Mandatory| Description | 181| -------- | ------------------------------------------------------------------------------ | ---- | -----------------------------------------------------------------| 182| maxSize | number | Yes | Maximum number of descriptors to obtain. The value ranges from 0 to 10.| 183| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes | Callback used to return an array of AVSessionDescriptor objects, each of which is read only. | 184 185**Error codes** 186 187For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 188 189| ID| Error Message| 190| -------- | ---------------------------------------- | 191| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 192| 6600101 |Session service exception. | 193 194**Example** 195 196```ts 197import { BusinessError } from '@kit.BasicServicesKit'; 198 199avSession.getHistoricalSessionDescriptors(1, (err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => { 200 if (err) { 201 console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); 202 } else { 203 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`); 204 if (descriptors.length > 0 ) { 205 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`); 206 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`); 207 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); 208 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`); 209 console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); 210 } 211 } 212}); 213``` 214 215## avSession.getHistoricalAVQueueInfos<sup>11+</sup> 216 217getHistoricalAVQueueInfos(maxSize: number, maxAppSize: number) : Promise\<Array\<Readonly\<AVQueueInfo>>> 218 219Obtains all the historical playlists. This API uses a promise to return the result. 220 221**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 222 223**System capability**: SystemCapability.Multimedia.AVSession.Manager 224 225**System API**: This is a system API. 226 227**Parameters** 228 229| Name | Type | Mandatory| Description | 230| -------- | ------ | ---- | ---------------------------------------------------------------| 231| maxSize | number | Yes | Maximum number of playlists that can be obtained. Currently, the maximum number is restricted by the system. | 232| maxAppSize | number | Yes | Maximum number of applications to which the playlists to be obtained belong. Currently, the maximum number is restricted by the system. | 233 234**Return value** 235 236| Type | Description | 237| --------------------------------------------------------------------------- | ------------------------------------- | 238| Promise\<Array\<Readonly\<[AVQueueInfo](#avqueueinfo11)\>\>\> | Promise used to return all the read-only historical playlists. | 239 240**Error codes** 241 242For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 243 244| ID| Error Message| 245| -------- | ---------------------------------------- | 246| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 247| 6600101 | Session service exception. | 248 249**Example** 250 251```ts 252import { BusinessError } from '@kit.BasicServicesKit'; 253 254avSession.getHistoricalAVQueueInfos(3, 5).then((avQueueInfos: avSession.AVQueueInfo[]) => { 255 console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`); 256}).catch((err: BusinessError) => { 257 console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`); 258}); 259``` 260 261## avSession.getHistoricalAVQueueInfos<sup>11+</sup> 262 263getHistoricalAVQueueInfos(maxSize: number, maxAppSize: number, callback: AsyncCallback\<Array\<Readonly\<AVQueueInfo>>>): void; 264 265Obtains all the historical playlists. This API uses an asynchronous callback to return the result. 266 267**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 268 269**System capability**: SystemCapability.Multimedia.AVSession.Manager 270 271**System API**: This is a system API. 272 273**Parameters** 274 275| Name | Type | Mandatory| Description | 276| -------- | ----------------------------------------------------------------------------- | ---- | ---------------------------------------------------------------| 277| maxSize | number | Yes | Maximum number of playlists that can be obtained. Currently, the maximum number is restricted by the system. | 278| maxAppSize | number | Yes | Maximum number of applications to which the playlists to be obtained belong. Currently, the maximum number is restricted by the system. | 279| callback | AsyncCallback<Array<Readonly<[AVQueueInfo](#avqueueinfo11)\>\>\> | Yes | Callback used to return all the read-only historical playlists. | 280 281**Error codes** 282 283For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 284 285| ID| Error Message| 286| -------- | ---------------------------------------- | 287| 201 | permission denied. | 288| 202 | Not System App. | 289| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 290| 6600101 |Session service exception. | 291 292**Example** 293 294```ts 295import { BusinessError } from '@kit.BasicServicesKit'; 296 297avSession.getHistoricalAVQueueInfos(3, 5, (err: BusinessError, avQueueInfos: avSession.AVQueueInfo[]) => { 298 if (err) { 299 console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`); 300 } else { 301 console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`); 302 } 303}); 304``` 305 306## avSession.createController 307 308createController(sessionId: string): Promise\<AVSessionController> 309 310Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses a promise to return the result. 311 312**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 313 314**System capability**: SystemCapability.Multimedia.AVSession.Manager 315 316**System API**: This is a system API. 317 318**Parameters** 319 320| Name | Type | Mandatory| Description | 321| --------- | ------ | ---- | -------- | 322| sessionId | string | Yes | Session ID. If the value is set to **'default'**, the system creates a default controller to control the system default session.| 323 324**Return value** 325 326| Type | Description | 327| ----------------------------------------------------- | ------------------------------------------------------------ | 328| Promise<[AVSessionController](arkts-apis-avsession-AVSessionController.md)\> | Promise used to return the session controller created, which can be used to obtain the session ID, send commands and events to sessions, and obtain metadata and playback state information.| 329 330**Error codes** 331 332For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 333 334| ID| Error Message| 335| -------- | ---------------------------------------- | 336| 201 | permission denied. | 337| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 338| 6600101 | Session service exception. | 339| 6600102 | The session does not exist. | 340 341**Example** 342 343```ts 344import { BusinessError } from '@kit.BasicServicesKit'; 345 346let currentAVcontroller: avSession.AVSessionController | undefined = undefined; 347currentAvSession.createController(sessionId).then((avcontroller: avSession.AVSessionController) => { 348 currentAVcontroller = avcontroller; 349 console.info('CreateController : SUCCESS '); 350}).catch((err: BusinessError) => { 351 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 352}); 353``` 354 355## avSession.createController 356 357createController(sessionId: string, callback: AsyncCallback\<AVSessionController>): void 358 359Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses an asynchronous callback to return the result. 360 361**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 362 363**System capability**: SystemCapability.Multimedia.AVSession.Manager 364 365**System API**: This is a system API. 366 367**Parameters** 368 369| Name | Type | Mandatory| Description | 370| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 371| sessionId | string | Yes | Session ID. If the value is set to **'default'**, the system creates a default controller to control the system default session. | 372| callback | AsyncCallback<[AVSessionController](arkts-apis-avsession-AVSessionController.md)\> | Yes | Callback used to return the session controller created, which can be used to obtain the session ID, send commands and events to sessions, and obtain metadata and playback state information.| 373 374**Error codes** 375 376For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 377 378| ID| Error Message| 379| -------- | ---------------------------------------- | 380| 201 | permission denied. | 381| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 382| 6600101 | Session service exception. | 383| 6600102 | The session does not exist. | 384 385**Example** 386 387```ts 388import { BusinessError } from '@kit.BasicServicesKit'; 389 390let currentAVcontroller: avSession.AVSessionController | undefined = undefined; 391currentAvSession.createController(sessionId, (err: BusinessError, avcontroller: avSession.AVSessionController) => { 392 if (err) { 393 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 394 } else { 395 currentAVcontroller = avcontroller; 396 console.info('CreateController : SUCCESS '); 397 } 398}); 399``` 400 401## avSession.castAudio 402 403castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise\<void> 404 405Casts a session to a list of devices. This API uses a promise to return the result. 406 407Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices. 408 409**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 410 411**System capability**: SystemCapability.Multimedia.AVSession.Manager 412 413**System API**: This is a system API. 414 415**Parameters** 416 417| Name | Type | Mandatory| Description| 418| ------------ | -------------- |------|------| 419| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.| 420| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/arkts-apis-audio-i.md#audiodevicedescriptor)\> | Yes | Audio devices. | 421 422**Return value** 423 424| Type | Description | 425| -------------- | ----------------------------- | 426| Promise\<void> | Promise used to return the result. If casting is successful, no value is returned; otherwise, an error object is returned.| 427 428**Error codes** 429 430For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 431 432| ID| Error Message| 433| -------- | ---------------------------------------- | 434| 201 | permission denied. | 435| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 436| 6600101 | Session service exception. | 437| 6600102 | The session does not exist. | 438| 6600104 | The remote session connection failed. | 439 440**Example** 441 442```ts 443import { audio } from '@kit.AudioKit'; 444import { BusinessError } from '@kit.BasicServicesKit'; 445 446let audioManager = audio.getAudioManager(); 447let audioRoutingManager = audioManager.getRoutingManager(); 448let audioDevices: audio.AudioDeviceDescriptors | undefined = undefined; 449audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 450 audioDevices = data; 451 console.info('Promise returned to indicate that the device list is obtained.'); 452}).catch((err: BusinessError) => { 453 console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); 454}); 455 456if (audioDevices !== undefined) { 457 avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors).then(() => { 458 console.info('CreateController : SUCCESS'); 459 }).catch((err: BusinessError) => { 460 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 461 }); 462} 463``` 464 465## avSession.castAudio 466 467castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void 468 469Casts a session to a list of devices. This API uses an asynchronous callback to return the result. 470 471Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices. 472 473**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 474 475**System capability**: SystemCapability.Multimedia.AVSession.Manager 476 477**System API**: This is a system API. 478 479**Parameters** 480 481| Name | Type | Mandatory| Description | 482| ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ | 483| session | [SessionToken](#sessiontoken) | 'all' | Yes | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.| 484| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/arkts-apis-audio-i.md#audiodevicedescriptor)\> | Yes | Audio devices.| 485| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If casting is successful, **err** is **undefined**; otherwise, **err** is an error object. | 486 487**Error codes** 488 489For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 490 491| ID| Error Message| 492| -------- | ---------------------------------------- | 493| 201 | permission denied. | 494| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 495| 6600101 | Session service exception. | 496| 6600102 | The session does not exist. | 497| 6600104 | The remote session connection failed. | 498 499**Example** 500 501```ts 502import { audio } from '@kit.AudioKit'; 503import { BusinessError } from '@kit.BasicServicesKit'; 504 505let audioManager = audio.getAudioManager(); 506let audioRoutingManager = audioManager.getRoutingManager(); 507let audioDevices: audio.AudioDeviceDescriptors | undefined = undefined; 508audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => { 509 audioDevices = data; 510 console.info('Promise returned to indicate that the device list is obtained.'); 511}).catch((err: BusinessError) => { 512 console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); 513}); 514 515if (audioDevices !== undefined) { 516 avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors, (err: BusinessError) => { 517 if (err) { 518 console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); 519 } else { 520 console.info('CastAudio : SUCCESS '); 521 } 522 }); 523} 524``` 525 526## avSession.startAVPlayback<sup>11+</sup> 527 528startAVPlayback(bundleName: string, assetId: string): Promise\<void> 529 530Starts an application to play a media asset. This API uses a promise to return the result. 531 532**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 533 534**System capability**: SystemCapability.Multimedia.AVSession.Manager 535 536**System API**: This is a system API. 537 538**Parameters** 539 540| Name | Type | Mandatory| Description| 541| ------------ | -------------- |------|------| 542| bundleName | string | Yes | Bundle name of the application.| 543| assetId |string | Yes | ID of the media asset. | 544 545**Return value** 546 547| Type | Description | 548| -------------- | ----------------------------- | 549| Promise\<void> | Promise used to return the result. If the playback is successful, no value is returned; otherwise, an error object is returned.| 550 551**Error codes** 552 553For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 554 555| ID| Error Message| 556| -------- | ---------------------------------------- | 557| 201 | permission denied. | 558| 202 | Not System App. Interface caller is not a system app. | 559| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 560| 6600101 | Session service exception. | 561 562**Example** 563 564```ts 565import { audio } from '@kit.AudioKit'; 566import { BusinessError } from '@kit.BasicServicesKit'; 567 568avSession.startAVPlayback("com.example.myapplication", "121278").then(() => { 569 console.info('startAVPlayback : SUCCESS'); 570}).catch((err: BusinessError) => { 571 console.error(`startAVPlayback BusinessError: code: ${err.code}, message: ${err.message}`); 572}); 573``` 574 575## avSession.getDistributedSessionController<sup>18+</sup> 576 577getDistributedSessionController(distributedSessionType: DistributedSessionType): Promise<Array\<AVSessionController>> 578 579Obtains remote distributed session controllers based on the remote session type. This API uses a promise to return the result. 580 581**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 582 583**System capability**: SystemCapability.Multimedia.AVSession.Manager 584 585**System API**: This is a system API. 586 587**Parameters** 588 589| Name | Type | Mandatory| Description | 590| --------- |-------------------------------------------------------------------------| ---- |---------| 591| distributedSessionType | [DistributedSessionType](#distributedsessiontype18) | Yes | Remote session type.| 592 593**Return value** 594 595| Type | Description | 596|------------------------------------------------------------------------------------|-----------------------------------------------------------------------| 597| Promise<Array<[AVSessionController](arkts-apis-avsession-AVSessionController.md)\>> | Promise used to return an array of session controller instances of the corresponding type. You can view the session ID, send commands and events to the session, and obtain metadata and playback status information.| 598 599**Error codes** 600 601For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 602 603| ID | Error Message | 604|---------|-------------------------------------------------------------------------------------------------------| 605| 201 | permission denied. | 606| 202 | Not System App. Interface caller is not a system app. | 607| 6600101 | Session service exception. | 608| 6600109 | The remote connection is not established. | 609 610**Example** 611 612```ts 613import { BusinessError } from '@kit.BasicServicesKit'; 614 615avSession.getDistributedSessionController(avSession.DistributedSessionType.TYPE_SESSION_REMOTE).then((sessionControllers: Array<avSession.AVSessionController>) => { 616 console.info(`getDistributedSessionController : SUCCESS : sessionControllers.length : ${sessionControllers.length}`); 617}).catch((err: BusinessError) => { 618 console.error(`getDistributedSessionController BusinessError: code: ${err.code}, message: ${err.message}`); 619}); 620``` 621 622 623## SessionToken 624 625Describes the information about a session token. 626 627**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 628 629**System capability**: SystemCapability.Multimedia.AVSession.Manager 630 631**System API**: This is a system API. 632 633| Name | Type | Mandatory| Description | 634| :-------- | :----- | :--- | :----------- | 635| sessionId | string | Yes | Session ID. | 636| pid | number | No | Process ID of the session.| 637| uid | number | No | User ID. | 638 639## avSession.on('sessionCreate') 640 641on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void 642 643Subscribes to session creation events. 644 645**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 646 647**System capability**: SystemCapability.Multimedia.AVSession.Manager 648 649**System API**: This is a system API. 650 651**Parameters** 652 653| Name | Type | Mandatory| Description | 654| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 655| type | string | Yes | Event type. The event **'sessionCreate'** is triggered when a session is created.| 656| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| 657 658**Error codes** 659 660For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 661 662| ID| Error Message| 663| -------- | ---------------------------------------- | 664| 201 | permission denied. | 665| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 666| 6600101 | Session service exception. | 667 668**Example** 669 670```ts 671avSession.on('sessionCreate', (descriptor: avSession.AVSessionDescriptor) => { 672 console.info(`on sessionCreate : isActive : ${descriptor.isActive}`); 673 console.info(`on sessionCreate : type : ${descriptor.type}`); 674 console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`); 675}); 676 677``` 678 679## avSession.on('sessionDestroy') 680 681on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void 682 683Subscribes to session destruction events. 684 685**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 686 687**System capability**: SystemCapability.Multimedia.AVSession.Manager 688 689**System API**: This is a system API. 690 691**Parameters** 692 693| Name | Type | Mandatory| Description | 694| -------- | ---------------| ---- | ------------------------------------------------------------ | 695| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| 696| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| 697 698**Error codes** 699 700For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 701 702| ID| Error Message| 703| -------- | ---------------------------------------- | 704| 201 | permission denied. | 705| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 706| 6600101 | Session service exception. | 707 708**Example** 709 710```ts 711avSession.on('sessionDestroy', (descriptor: avSession.AVSessionDescriptor) => { 712 console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`); 713 console.info(`on sessionDestroy : type : ${descriptor.type}`); 714 console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`); 715}); 716``` 717 718## avSession.on('topSessionChange') 719 720on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void 721 722Subscribes to top session change events. 723 724**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 725 726**System capability**: SystemCapability.Multimedia.AVSession.Manager 727 728**System API**: This is a system API. 729 730**Parameters** 731 732| Name | Type | Mandatory| Description | 733| -------- | --------------------| ---- | ------------------------------------------------------------ | 734| type | string | Yes | Event type. The event **'topSessionChange'** is triggered when the top session is changed.| 735| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes | Callback used to report the session descriptor.| 736 737**Error codes** 738 739For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 740 741| ID| Error Message| 742| -------- | ---------------------------------------- | 743| 201 | permission denied. | 744| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 745| 6600101 | Session service exception. | 746 747**Example** 748 749```ts 750avSession.on('topSessionChange', (descriptor: avSession.AVSessionDescriptor) => { 751 console.info(`on topSessionChange : isActive : ${descriptor.isActive}`); 752 console.info(`on topSessionChange : type : ${descriptor.type}`); 753 console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`); 754}); 755``` 756 757## avSession.off('sessionCreate') 758 759off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void 760 761Unsubscribes from session creation events. 762 763**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 764 765**System capability**: SystemCapability.Multimedia.AVSession.Manager 766 767**System API**: This is a system API. 768 769**Parameters** 770 771| Name | Type | Mandatory| Description | 772| -------- | ----------| ---- | ----------| 773| type | string | Yes | Event type, which is **'sessionCreate'** in this case.| 774| 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. | 775 776**Error codes** 777 778For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 779 780| ID| Error Message| 781| -------- | ---------------------------------------- | 782| 201 | permission denied. | 783| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 784| 6600101 | Session service exception. | 785 786**Example** 787 788```ts 789avSession.off('sessionCreate'); 790``` 791 792## avSession.off('sessionDestroy') 793 794off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void 795 796Unsubscribes from session destruction events. 797 798**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 799 800**System capability**: SystemCapability.Multimedia.AVSession.Manager 801 802**System API**: This is a system API. 803 804**Parameters** 805 806| Name | Type | Mandatory| Description | 807| -------- | -----------| ---- | -------------------------| 808| type | string | Yes | Event type, which is **'sessionDestroy'** in this case.| 809| 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.| 810 811**Error codes** 812 813For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 814 815| ID| Error Message| 816| -------- | ---------------------------------------- | 817| 201 | permission denied. | 818| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 819| 6600101 | Session service exception. | 820 821**Example** 822 823```ts 824avSession.off('sessionDestroy'); 825``` 826 827## avSession.off('topSessionChange') 828 829off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void 830 831Unsubscribes from top session change events. 832 833**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 834 835**System capability**: SystemCapability.Multimedia.AVSession.Manager 836 837**System API**: This is a system API. 838 839**Parameters** 840 841| Name | Type | Mandatory| Description | 842| -------- | -----------------| ---- | ---------------------------- | 843| type | string | Yes | Event type, which is **'topSessionChange'** in this case.| 844| 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.| 845 846**Error codes** 847 848For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 849 850| ID| Error Message| 851| -------- | ---------------------------------------- | 852| 201 | permission denied. | 853| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 854| 6600101 | Session service exception. | 855 856**Example** 857 858```ts 859avSession.off('topSessionChange'); 860``` 861 862## avSession.on('sessionServiceDie') 863 864on(type: 'sessionServiceDie', callback: () => void): void 865 866Subscribes to session service death events. Upon receiving this event, the application can clear resources. 867 868**System capability**: SystemCapability.Multimedia.AVSession.Core 869 870**System API**: This is a system API. 871 872**Parameters** 873 874| Name | Type | Mandatory| Description | 875| -------- | -------------------- | ---- | ------------------------------------------------------------ | 876| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.| 877| callback | callback: () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 878 879**Error codes** 880 881For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 882 883| ID| Error Message| 884| -------- | ---------------------------------------- | 885| 201 | permission denied. | 886| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 887| 6600101 | Session service exception. | 888 889**Example** 890 891```ts 892avSession.on('sessionServiceDie', () => { 893 console.info('on sessionServiceDie : session is Died '); 894}); 895``` 896 897## avSession.off('sessionServiceDie') 898 899off(type: 'sessionServiceDie', callback?: () => void): void 900 901Unsubscribes from session service death events. 902 903**System capability**: SystemCapability.Multimedia.AVSession.Core 904 905**System API**: This is a system API. 906 907**Parameters** 908 909| Name | Type | Mandatory | Description | 910| ------ | ---------------------- | ---- | ------------------------------------------------------- | 911| type | string | Yes | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.| 912| 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. | 913 914**Error codes** 915 916For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 917 918| ID| Error Message| 919| -------- | ---------------------------------------- | 920| 201 | permission denied. | 921| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 922| 6600101 | Session service exception. | 923 924**Example** 925 926```ts 927avSession.off('sessionServiceDie'); 928``` 929 930 931## avSession.on('distributedSessionChange')<sup>18+</sup> 932 933on(type: 'distributedSessionChange', distributedSessionType: DistributedSessionType, callback: Callback<Array\<AVSessionController>>): void 934 935Subscribes to the latest distributed remote session change events. 936 937**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 938 939**System capability**: SystemCapability.Multimedia.AVSession.Manager 940 941**System API**: This is a system API. 942 943**Parameters** 944 945| Name | Type | Mandatory| Description | 946| -------- |-------------------------------------------------------------------------------------| ---- |--------------------------------------------------------------------------| 947| type | string | Yes | Event type. The event **'distributedSessionChange'** is triggered when the latest distributed session is changed.| 948| distributedSessionType | [DistributedSessionType](#distributedsessiontype18) | Yes | Remote session type. | 949| callback | Callback<Array<[AVSessionController](arkts-apis-avsession-AVSessionController.md)\>> | Yes | Callback used to return an array of session controller instances of the corresponding type. You can view the session ID, send commands and events to the session, and obtain metadata and playback status information. | 950 951**Error codes** 952 953For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 954 955| ID | Error Message | 956|---------|---------------------------------------------------------------------------------------------------| 957| 202 | Not System App. Interface caller is not a system app. | 958| 6600101 | Session service exception. | 959 960**Example** 961 962```ts 963avSession.on('distributedSessionChange', avSession.DistributedSessionType.TYPE_SESSION_REMOTE, (sessionControllers: Array<avSession.AVSessionController>) => { 964 console.info(`on distributedSessionChange size: ${sessionControllers.length}`); 965}); 966``` 967 968 969## avSession.off('distributedSessionChange')<sup>18+</sup> 970 971off(type: 'distributedSessionChange', distributedSessionType: DistributedSessionType, callback?: Callback<Array\<AVSessionController>>): void 972 973Unsubscribes from the latest distributed remote session change events. 974 975**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 976 977**System capability**: SystemCapability.Multimedia.AVSession.Manager 978 979**System API**: This is a system API. 980 981**Parameters** 982 983| Name | Type | Mandatory| Description | 984| -------- |-------------------------------------------------------------------------------------|----|---------------------------------------------------------------| 985| type | string | Yes | Event type. The event **'distributedSessionChange'** is triggered when the latest distributed session is changed. | 986| distributedSessionType | [DistributedSessionType](#distributedsessiontype18) | Yes | Remote session type. | 987| callback | Callback<Array<[AVSessionController](arkts-apis-avsession-AVSessionController.md)\>> | No | Callback used to return an array of session controller instances of the corresponding type. You can view the session ID, send commands and events to the session, and obtain metadata and playback status information.| 988 989**Error codes** 990 991For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 992 993| ID | Error Message | 994|---------|---------------------------------------------------------------------------------------------------| 995| 202 | Not System App. Interface caller is not a system app. | 996| 6600101 | Session service exception. | 997 998**Example** 999 1000```ts 1001avSession.off('distributedSessionChange', avSession.DistributedSessionType.TYPE_SESSION_REMOTE); 1002``` 1003 1004## avSession.sendSystemAVKeyEvent 1005 1006sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 1007 1008Sends a system key event to the top session. This API uses an asynchronous callback to return the result. 1009 1010**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1011 1012**System capability**: SystemCapability.Multimedia.AVSession.Manager 1013 1014**System API**: This is a system API. 1015 1016**Parameters** 1017 1018| Name | Type | Mandatory| Description | 1019| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | 1020| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | Yes | Key event. | 1021| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.| 1022 1023**Error codes** 1024 1025For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1026 1027| ID| Error Message| 1028| -------- | ---------------------------------------- | 1029| 201 | permission denied. | 1030| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1031| 6600101 | Session service exception. | 1032| 6600105 | Invalid session command. | 1033 1034**Example** 1035 1036```ts 1037import { KeyEvent } from '@kit.InputKit'; 1038import { BusinessError } from '@kit.BasicServicesKit'; 1039 1040let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0}; 1041let 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}; 1042 1043avSession.sendSystemAVKeyEvent(event, (err: BusinessError) => { 1044 if (err) { 1045 console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 1046 } else { 1047 console.info('SendSystemAVKeyEvent : SUCCESS '); 1048 } 1049}); 1050``` 1051 1052## avSession.sendSystemAVKeyEvent 1053 1054sendSystemAVKeyEvent(event: KeyEvent): Promise\<void> 1055 1056Sends a system key event to the top session. This API uses a promise to return the result. 1057 1058**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1059 1060**System capability**: SystemCapability.Multimedia.AVSession.Manager 1061 1062**System API**: This is a system API. 1063 1064**Parameters** 1065 1066| Name| Type | Mandatory| Description | 1067| ------ | ------------------------------- | ---- | ---------- | 1068| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | Yes | Key event.| 1069 1070**Return value** 1071 1072| Type | Description | 1073| -------------- | ----------------------------- | 1074| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.| 1075 1076**Error codes** 1077 1078For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1079 1080| ID| Error Message| 1081| -------- | ---------------------------------------- | 1082| 201 | permission denied. | 1083| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1084| 6600101 | Session service exception. | 1085| 6600105 | Invalid session command. | 1086 1087**Example** 1088 1089```ts 1090import { KeyEvent } from '@kit.InputKit'; 1091import { BusinessError } from '@kit.BasicServicesKit'; 1092 1093let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0}; 1094let 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}; 1095 1096avSession.sendSystemAVKeyEvent(event).then(() => { 1097 console.info('SendSystemAVKeyEvent Successfully'); 1098}).catch((err: BusinessError) => { 1099 console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 1100}); 1101``` 1102 1103## avSession.sendSystemControlCommand 1104 1105sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 1106 1107Sends a system control command to the top session. This API uses an asynchronous callback to return the result. 1108 1109**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1110 1111**System capability**: SystemCapability.Multimedia.AVSession.Manager 1112 1113**System API**: This is a system API. 1114 1115**Parameters** 1116 1117| Name | Type | Mandatory| Description | 1118| -------- | ------------------------------------- | ---- | ------------------------------------- | 1119| command | [AVControlCommand](arkts-apis-avsession-i.md#avcontrolcommand10) | Yes | Command to send. | 1120| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 1121 1122**Error codes** 1123 1124For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1125 1126| ID| Error Message| 1127| -------- | ---------------------------------------- | 1128| 201 | permission denied. | 1129| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1130| 6600101 | Session service exception. | 1131| 6600105 | Invalid session command. | 1132| 6600107 | Too many commands or events. | 1133 1134**Example** 1135 1136```ts 1137let cmd : avSession.AVControlCommandType = 'play'; 1138// let cmd : avSession.AVControlCommandType = 'pause'; 1139// let cmd : avSession.AVControlCommandType = 'stop'; 1140// let cmd : avSession.AVControlCommandType = 'playNext'; 1141// let cmd : avSession.AVControlCommandType = 'playPrevious'; 1142// let cmd : avSession.AVControlCommandType = 'fastForward'; 1143// let cmd : avSession.AVControlCommandType = 'rewind'; 1144let avcommand: avSession.AVControlCommand = {command:cmd}; 1145// let cmd : avSession.AVControlCommandType = 'seek'; 1146// let avcommand = {command:cmd, parameter:10}; 1147// let cmd : avSession.AVControlCommandType = 'setSpeed'; 1148// let avcommand = {command:cmd, parameter:2.6}; 1149// let cmd : avSession.AVControlCommandType = 'setLoopMode'; 1150// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; 1151// let cmd : avSession.AVControlCommandType = 'toggleFavorite'; 1152// let avcommand = {command:cmd, parameter:"false"}; 1153avSession.sendSystemControlCommand(avcommand, (err) => { 1154 if (err) { 1155 console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 1156 } else { 1157 console.info('sendSystemControlCommand successfully'); 1158 } 1159}); 1160``` 1161 1162## avSession.sendSystemControlCommand 1163 1164sendSystemControlCommand(command: AVControlCommand): Promise\<void> 1165 1166Sends a system control command to the top session. This API uses a promise to return the result. 1167 1168**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1169 1170**System capability**: SystemCapability.Multimedia.AVSession.Manager 1171 1172**System API**: This is a system API. 1173 1174**Parameters** 1175 1176| Name | Type | Mandatory| Description | 1177| ------- | ------------------------------------- | ---- | ----------------------------------- | 1178| command | [AVControlCommand](arkts-apis-avsession-i.md#avcontrolcommand10) | Yes | Command to send.| 1179 1180**Return value** 1181 1182| Type | Description | 1183| -------------- | ----------------------------- | 1184| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 1185 1186**Error codes** 1187 1188For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1189 1190| ID| Error Message| 1191| -------- | ---------------------------------------- | 1192| 201 | permission denied. | 1193| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1194| 6600101 | Session service exception. | 1195| 6600105 | Invalid session command. | 1196| 6600107 | Too many commands or events. | 1197 1198**Example** 1199 1200```ts 1201import { BusinessError } from '@kit.BasicServicesKit'; 1202 1203let cmd : avSession.AVControlCommandType = 'play'; 1204// let cmd : avSession.AVControlCommandType = 'pause'; 1205// let cmd : avSession.AVControlCommandType = 'stop'; 1206// let cmd : avSession.AVControlCommandType = 'playNext'; 1207// let cmd : avSession.AVControlCommandType = 'playPrevious'; 1208// let cmd : avSession.AVControlCommandType = 'fastForward'; 1209// let cmd : avSession.AVControlCommandType = 'rewind'; 1210let avcommand: avSession.AVControlCommand = {command:cmd}; 1211// let cmd : avSession.AVControlCommandType = 'seek'; 1212// let avcommand = {command:cmd, parameter:10}; 1213// let cmd : avSession.AVControlCommandType = 'setSpeed'; 1214// let avcommand = {command:cmd, parameter:2.6}; 1215// let cmd : avSession.AVControlCommandType = 'setLoopMode'; 1216// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; 1217// let cmd : avSession.AVControlCommandType = 'toggleFavorite'; 1218// let avcommand = {command:cmd, parameter:"false"}; 1219avSession.sendSystemControlCommand(avcommand).then(() => { 1220 console.info('SendSystemControlCommand successfully'); 1221}).catch((err: BusinessError) => { 1222 console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 1223}); 1224``` 1225 1226## ProtocolType<sup>10+</sup> 1227 1228Enumerates the protocol types supported by the remote device. 1229 1230**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1231 1232| Name | Value | Description | 1233| --------------------------- | ---- | ----------- | 1234| TYPE_CAST_PLUS_MIRROR | 1 | Cast+ mirror mode.<br> **System API**: This is a system API.| 1235 1236## avSession.startCastDeviceDiscovery<sup>10+</sup> 1237 1238startCastDeviceDiscovery(callback: AsyncCallback\<void>): void 1239 1240Starts cast-enabled device discovery. This API uses an asynchronous callback to return the result. 1241 1242**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1243 1244**System API**: This is a system API. 1245 1246**Parameters** 1247 1248| Name | Type | Mandatory| Description | 1249| -------- | ------------------------------------- | ---- | ------------------------------------- | 1250| 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.| 1251 1252 1253**Example** 1254 1255```ts 1256import { BusinessError } from '@kit.BasicServicesKit'; 1257 1258avSession.startCastDeviceDiscovery((err: BusinessError) => { 1259 if (err) { 1260 console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1261 } else { 1262 console.info('startCastDeviceDiscovery successfully'); 1263 } 1264}); 1265``` 1266 1267## DistributedSessionType<sup>18+</sup> 1268 1269Enumerates the session types supported by the remote distributed device. 1270 1271**Atomic service API**: This API can be used in atomic services since API version 18. 1272 1273**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1274 1275| Name | Value| Description | 1276|----------------------------------------|---|---------------------------| 1277| TYPE_SESSION_REMOTE | 0 | Session on the remote device. | 1278| TYPE_SESSION_MIGRATE_IN | 1 | Session migrated to the local device.| 1279| TYPE_SESSION_MIGRATE_OUT | 2 | Session migrated to the remote device.| 1280 1281## avSession.startCastDeviceDiscovery<sup>10+</sup> 1282 1283startCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void 1284 1285Starts cast-enabled device discovery with filter criteria specified. This API uses an asynchronous callback to return the result. 1286 1287**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1288 1289**System API**: This is a system API. 1290 1291**Parameters** 1292 1293| Name | Type | Mandatory| Description | 1294| -------- | ------------------------------------- | ---- | ------------------------------------- | 1295| filter | number | Yes| Filter criteria for device discovery. The value consists of **ProtocolType**s.| 1296| 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.| 1297 1298**Error codes** 1299 1300For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1301 1302| ID| Error Message| 1303| -------- | ---------------------------------------- | 1304| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1305 1306**Example** 1307 1308```ts 1309import { BusinessError } from '@kit.BasicServicesKit'; 1310 1311let filter = 2; 1312avSession.startCastDeviceDiscovery(filter, (err: BusinessError) => { 1313 if (err) { 1314 console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1315 } else { 1316 console.info('startCastDeviceDiscovery successfully'); 1317 } 1318}); 1319``` 1320 1321## avSession.startCastDeviceDiscovery<sup>10+</sup> 1322 1323startCastDeviceDiscovery(filter?: number, drmSchemes?: Array\<string>): Promise\<void> 1324 1325Starts cast-enabled device discovery. This API uses a promise to return the result. 1326 1327**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1328 1329**System API**: This is a system API. 1330 1331**Parameters** 1332 1333| Name | Type | Mandatory| Description | 1334| -------- | ------------------------------------- | ---- | ------------------------------------- | 1335| filter | number | No| Filter criteria for device discovery. The value consists of **ProtocolType**s.| 1336| 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.| 1337 1338**Return value** 1339 1340| Type | Description | 1341| -------------- | ----------------------------- | 1342| 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.| 1343 1344**Error codes** 1345 1346For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1347 1348| ID| Error Message| 1349| -------- | ---------------------------------------- | 1350| 202 | Not System App. | 1351| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1352 1353**Example** 1354 1355```ts 1356import { BusinessError } from '@kit.BasicServicesKit'; 1357 1358let filter = 2; 1359let drmSchemes = ['3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c']; 1360avSession.startCastDeviceDiscovery(filter, drmSchemes).then(() => { 1361 console.info('startCastDeviceDiscovery successfully'); 1362}).catch((err: BusinessError) => { 1363 console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1364}); 1365``` 1366 1367## avSession.stopCastDeviceDiscovery<sup>10+</sup> 1368 1369stopCastDeviceDiscovery(callback: AsyncCallback\<void>): void 1370 1371Stops cast-enabled device discovery. This API uses an asynchronous callback to return the result. 1372 1373**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1374 1375**System API**: This is a system API. 1376 1377**Parameters** 1378 1379| Name | Type | Mandatory| Description | 1380| -------- | ------------------------------------- | ---- | ------------------------------------- | 1381| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If device discovery stops, **err** is **undefined**; otherwise, **err** is an error object.| 1382 1383 1384**Example** 1385 1386```ts 1387import { BusinessError } from '@kit.BasicServicesKit'; 1388 1389avSession.stopCastDeviceDiscovery((err: BusinessError) => { 1390 if (err) { 1391 console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1392 } else { 1393 console.info('stopCastDeviceDiscovery successfully'); 1394 } 1395}); 1396``` 1397 1398## avSession.stopCastDeviceDiscovery<sup>10+</sup> 1399 1400stopCastDeviceDiscovery(): Promise\<void> 1401 1402Stops cast-enabled device discovery. This API uses a promise to return the result. 1403 1404**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1405 1406**System API**: This is a system API. 1407 1408**Return value** 1409 1410| Type | Description | 1411| -------------- | ----------------------------- | 1412| Promise\<void> | Promise used to return the result. If device discovery stops, no value is returned; otherwise, an error object is returned.| 1413 1414**Example** 1415 1416```ts 1417import { BusinessError } from '@kit.BasicServicesKit'; 1418 1419avSession.stopCastDeviceDiscovery().then(() => { 1420 console.info('stopCastDeviceDiscovery successfully'); 1421}).catch((err: BusinessError) => { 1422 console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); 1423}); 1424``` 1425 1426## avSession.setDiscoverable<sup>10+</sup> 1427 1428setDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void 1429 1430Sets 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. 1431 1432**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1433 1434**System API**: This is a system API. 1435 1436**Parameters** 1437 1438| Name | Type | Mandatory| Description | 1439| -------- | ------------------------------------- | ---- | ------------------------------------- | 1440| enable | boolean | Yes| Whether to allow the device discoverable. **true** if discoverable, **false** otherwise.| 1441| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1442 1443**Error codes** 1444 1445For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1446 1447| ID| Error Message| 1448| -------- | ---------------------------------------- | 1449| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1450 1451**Example** 1452 1453```ts 1454import { BusinessError } from '@kit.BasicServicesKit'; 1455 1456avSession.setDiscoverable(true, (err: BusinessError) => { 1457 if (err) { 1458 console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); 1459 } else { 1460 console.info('setDiscoverable successfully'); 1461 } 1462}); 1463``` 1464 1465## avSession.setDiscoverable<sup>10+</sup> 1466 1467setDiscoverable(enable: boolean): Promise\<void> 1468 1469Sets 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. 1470 1471**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1472 1473**System API**: This is a system API. 1474 1475**Parameters** 1476 1477| Name | Type | Mandatory| Description | 1478| -------- | ------------------------------------- | ---- | ------------------------------------- | 1479| enable | boolean | Yes| Whether to allow the device discoverable. **true** if discoverable, **false** otherwise.| 1480 1481**Error codes** 1482 1483For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1484 1485| ID| Error Message| 1486| -------- | ---------------------------------------- | 1487| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1488 1489**Return value** 1490 1491| Type | Description | 1492| -------------- | ----------------------------- | 1493| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 1494 1495**Example** 1496 1497```ts 1498import { BusinessError } from '@kit.BasicServicesKit'; 1499 1500avSession.setDiscoverable(true).then(() => { 1501 console.info('setDiscoverable successfully'); 1502}).catch((err: BusinessError) => { 1503 console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); 1504}); 1505``` 1506 1507## avSession.on('deviceAvailable')<sup>10+</sup> 1508 1509on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void 1510 1511Subscribes to device discovery events. 1512 1513**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1514 1515**System API**: This is a system API. 1516 1517**Parameters** 1518 1519| Name | Type | Mandatory| Description | 1520| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1521| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.| 1522| callback | (device: [OutputDeviceInfo](arkts-apis-avsession-i.md#outputdeviceinfo10)) => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1523 1524**Error codes** 1525 1526For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1527 1528| ID| Error Message| 1529| -------- | ---------------------------------------- | 1530| 201 | permission denied. | 1531| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1532 1533**Example** 1534 1535```ts 1536let castDevice: avSession.OutputDeviceInfo; 1537avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1538 castDevice = device; 1539 console.info(`on deviceAvailable : ${device} `); 1540}); 1541``` 1542 1543## avSession.off('deviceAvailable')<sup>10+</sup> 1544 1545off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void 1546 1547Unsubscribes from device discovery events. 1548 1549**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1550 1551**System API**: This is a system API. 1552 1553**Parameters** 1554 1555| Name | Type | Mandatory | Description | 1556| ------ | ---------------------- | ---- | ------------------------------------------------------- | 1557| type | string | Yes | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.| 1558| callback | (device: [OutputDeviceInfo](arkts-apis-avsession-i.md#outputdeviceinfo10)) => void | No | Callback used to return the device information.| 1559 1560**Error codes** 1561 1562For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1563 1564| ID| Error Message| 1565| -------- | ---------------------------------------- | 1566| 201 | permission denied. | 1567| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1568 1569**Example** 1570 1571```ts 1572avSession.off('deviceAvailable'); 1573``` 1574 1575## avSession.on('deviceOffline')<sup>11+</sup> 1576 1577on(type: 'deviceOffline', callback: (deviceId: string) => void): void 1578 1579Subscribes to device offline events. 1580 1581**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1582 1583**System API**: This is a system API. 1584 1585**Parameters** 1586 1587| Name | Type | Mandatory| Description | 1588| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1589| type | string | Yes | Event type. The event **'deviceOffline'** is triggered when a device gets offline.| 1590| 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. | 1591 1592**Error codes** 1593 1594For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1595 1596| ID| Error Message| 1597| -------- | ---------------------------------------- | 1598| 201 | permission denied. | 1599| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1600 1601**Example** 1602 1603```ts 1604let castDeviceId: string; 1605avSession.on('deviceOffline', (deviceId: string) => { 1606 castDeviceId = deviceId; 1607 console.info(`on deviceOffline : ${deviceId} `); 1608}); 1609``` 1610 1611## avSession.off('deviceOffline')<sup>11+</sup> 1612 1613off(type: 'deviceOffline', callback?: (deviceId: string) => void): void 1614 1615Unsubscribes from device offline events. 1616 1617**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1618 1619**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1620 1621**System API**: This is a system API. 1622 1623**Parameters** 1624 1625| Name | Type | Mandatory | Description | 1626| ------ | ---------------------- | ---- | ------------------------------------------------------- | 1627| type | string | Yes | Event type, which is **'deviceOffline'** in this case.| 1628| 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.| 1629 1630**Error codes** 1631 1632For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1633 1634| ID| Error Message| 1635| -------- | ---------------------------------------- | 1636| 201 | permission denied. | 1637| 202 | Not System App. | 1638| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1639 1640**Example** 1641 1642```ts 1643avSession.off('deviceOffline'); 1644``` 1645 1646## avSession.getAVCastController<sup>10+</sup> 1647 1648getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController>): void 1649 1650Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. 1651 1652This 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. 1653 1654**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1655 1656**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1657 1658**System API**: This is a system API. 1659 1660**Parameters** 1661 1662| Name | Type | Mandatory| Description | 1663| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1664| sessionId | string | Yes |Session ID.| 1665| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller.| 1666 1667**Error codes** 1668 1669For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1670 1671| ID| Error Message| 1672| -------- | ---------------------------------------- | 1673| 201 | permission denied. | 1674| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1675| 6600101 | Session service exception | 1676| 6600102 | session does not exist | 1677 1678**Example** 1679 1680```ts 1681import { BusinessError } from '@kit.BasicServicesKit'; 1682import { avSession } from '@kit.AVSessionKit'; 1683@Entry 1684@Component 1685struct Index { 1686 @State message: string = 'hello world'; 1687 1688 build() { 1689 Column() { 1690 Text(this.message) 1691 .onClick(()=>{ 1692 let currentAVSession: avSession.AVSession | undefined = undefined; 1693 let tag = "createNewSession"; 1694 let context = this.getUIContext().getHostContext() as Context; 1695 let sessionId: string = ""; // Used as an input parameter of subsequent functions. 1696 1697 let aVCastController: avSession.AVCastController; 1698 avSession.getAVCastController(sessionId , (err: BusinessError, avcontroller: avSession.AVCastController) => { 1699 if (err) { 1700 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1701 } else { 1702 aVCastController = avcontroller; 1703 console.info('getAVCastController : SUCCESS '); 1704 } 1705 }); 1706 }) 1707 } 1708 .width('100%') 1709 .height('100%') 1710 } 1711} 1712``` 1713 1714## avSession.getAVCastController<sup>10+</sup> 1715 1716getAVCastController(sessionId: string): Promise\<AVCastController> 1717 1718Obtains the cast controller when a casting connection is set up. This API uses a promise to return the result. 1719 1720This 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. 1721 1722**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1723 1724**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 1725 1726**System API**: This is a system API. 1727 1728**Parameters** 1729 1730| Name | Type | Mandatory| Description | 1731| --------- | ------------------------- | ---- | ------------------------------------------------------------ | 1732| sessionId | string | Yes |Session ID.| 1733 1734**Return value** 1735 1736| Type | Description | 1737| --------- | ------------------------------------------------------------ | 1738| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller.| 1739 1740**Error codes** 1741 1742For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1743 1744| ID| Error Message| 1745| -------- | ---------------------------------------- | 1746| 201 | permission denied. | 1747| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1748| 6600101 | server exception | 1749| 6600102 | The session does not exist | 1750 1751**Example** 1752 1753```ts 1754import { BusinessError } from '@kit.BasicServicesKit'; 1755import { avSession } from '@kit.AVSessionKit'; 1756@Entry 1757@Component 1758struct Index { 1759 @State message: string = 'hello world'; 1760 1761 build() { 1762 Column() { 1763 Text(this.message) 1764 .onClick(()=>{ 1765 let currentAVSession: avSession.AVSession | undefined = undefined; 1766 let tag = "createNewSession"; 1767 let context = this.getUIContext().getHostContext() as Context; 1768 let sessionId: string = ""; // Used as an input parameter of subsequent functions. 1769 1770 let aVCastController: avSession.AVCastController; 1771 avSession.getAVCastController(sessionId).then((avcontroller: avSession.AVCastController) => { 1772 aVCastController = avcontroller; 1773 console.info('getAVCastController : SUCCESS'); 1774 }).catch((err: BusinessError) => { 1775 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1776 }); 1777 }) 1778 } 1779 .width('100%') 1780 .height('100%') 1781 } 1782} 1783``` 1784 1785## avSession.startCasting<sup>10+</sup> 1786 1787startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\<void>): void 1788 1789Starts casting. This API uses an asynchronous callback to return the result. 1790 1791**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1792 1793**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1794 1795**System API**: This is a system API. 1796 1797**Parameters** 1798 1799| Name | Type | Mandatory| Description | 1800| -------- | ------------------------------------- | ---- | ------------------------------------- | 1801| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1802| device | [OutputDeviceInfo](arkts-apis-avsession-i.md#outputdeviceinfo10) | Yes | Device-related information.| 1803| 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.| 1804 1805**Error codes** 1806 1807For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1808 1809| ID| Error Message| 1810| -------- | ---------------------------------------- | 1811| 201 | permission denied. | 1812| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1813| 6600101 | Session service exception. | 1814| 6600108 | Device connection failed. | 1815 1816**Example** 1817 1818```ts 1819import { BusinessError } from '@kit.BasicServicesKit'; 1820 1821let myToken: avSession.SessionToken = { 1822 sessionId: sessionId, 1823} 1824let castDevice: avSession.OutputDeviceInfo | undefined = undefined; 1825avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1826 castDevice = device; 1827 console.info(`on deviceAvailable : ${device} `); 1828}); 1829if (castDevice !== undefined) { 1830 avSession.startCasting(myToken, castDevice, (err: BusinessError) => { 1831 if (err) { 1832 console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1833 } else { 1834 console.info('startCasting successfully'); 1835 } 1836 }); 1837} 1838``` 1839 1840 1841## avSession.startCasting<sup>10+</sup> 1842 1843startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void> 1844 1845Starts casting. This API uses a promise to return the result. 1846 1847**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications) 1848 1849**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1850 1851**System API**: This is a system API. 1852 1853**Parameters** 1854 1855| Name | Type | Mandatory| Description | 1856| -------- | ------------------------------------- | ---- | ------------------------------------- | 1857| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1858| device | [OutputDeviceInfo](arkts-apis-avsession-i.md#outputdeviceinfo10) | Yes | Device-related information.| 1859 1860**Return value** 1861 1862| Type | Description | 1863| -------------- | ----------------------------- | 1864| 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.| 1865 1866**Error codes** 1867 1868For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1869 1870| ID| Error Message| 1871| -------- | ---------------------------------------- | 1872| 201 | permission denied. | 1873| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1874| 6600101 | Session service exception. | 1875| 6600108 | Device connection failed. | 1876 1877**Example** 1878 1879```ts 1880import { BusinessError } from '@kit.BasicServicesKit'; 1881 1882let myToken: avSession.SessionToken = { 1883 sessionId: sessionId, 1884} 1885let castDevice: avSession.OutputDeviceInfo | undefined = undefined; 1886avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => { 1887 castDevice = device; 1888 console.info(`on deviceAvailable : ${device} `); 1889}); 1890if (castDevice !== undefined) { 1891 avSession.startCasting(myToken, castDevice).then(() => { 1892 console.info('startCasting successfully'); 1893 }).catch((err: BusinessError) => { 1894 console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1895 }); 1896} 1897``` 1898 1899## avSession.stopCasting<sup>10+</sup> 1900 1901stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void 1902 1903Stops castings. This API uses an asynchronous callback to return the result. 1904 1905**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1906 1907**System API**: This is a system API. 1908 1909**Parameters** 1910 1911| Name | Type | Mandatory| Description | 1912| -------- | ------------------------------------- | ---- | ------------------------------------- | 1913| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1914| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If casting stops, **err** is **undefined**; otherwise, **err** is an error object.| 1915 1916**Error codes** 1917 1918For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1919 1920| ID| Error Message| 1921| -------- | ---------------------------------------- | 1922| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1923| 6600109 | The remote connection is not established. | 1924 1925**Example** 1926 1927```ts 1928import { BusinessError } from '@kit.BasicServicesKit'; 1929 1930let myToken: avSession.SessionToken = { 1931 sessionId: sessionId, 1932} 1933avSession.stopCasting(myToken, (err: BusinessError) => { 1934 if (err) { 1935 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1936 } else { 1937 console.info('stopCasting successfully'); 1938 } 1939}); 1940``` 1941 1942## avSession.stopCasting<sup>10+</sup> 1943 1944stopCasting(session: SessionToken): Promise\<void> 1945 1946Stops castings. This API uses a promise to return the result. 1947 1948**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1949 1950**System API**: This is a system API. 1951 1952**Parameters** 1953 1954| Name | Type | Mandatory| Description | 1955| -------- | ------------------------------------- | ---- | ------------------------------------- | 1956| session | [SessionToken](#sessiontoken) | Yes | Session token. | 1957 1958**Return value** 1959 1960| Type | Description | 1961| -------------- | ----------------------------- | 1962| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.| 1963 1964**Error codes** 1965 1966For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1967 1968| ID| Error Message| 1969| -------- | ---------------------------------------- | 1970| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 1971| 6600109 | The remote connection is not established. | 1972 1973**Example** 1974 1975```ts 1976import { BusinessError } from '@kit.BasicServicesKit'; 1977 1978let myToken: avSession.SessionToken = { 1979 sessionId: sessionId, 1980} 1981avSession.stopCasting(myToken).then(() => { 1982 console.info('stopCasting successfully'); 1983}).catch((err: BusinessError) => { 1984 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 1985}); 1986``` 1987 1988## avSession.startDeviceLogging<sup>13+</sup> 1989 1990startDeviceLogging(url: string, maxSize?: number): Promise\<void> 1991 1992Starts to write device logs to a file. This API uses a promise to return the result. 1993 1994**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1995 1996**System API**: This is a system API. 1997 1998**Parameters** 1999 2000| Name | Type | Mandatory| Description | 2001| -------- | ------------------------------------- | ---- | ------------------------------------- | 2002| url | string | Yes | Target file descriptor (unique identifier used to open a file).| 2003| maxSize | number | No | Maximum size of the log file, in KB.| 2004 2005**Return value** 2006 2007| Type | Description | 2008| -------------- | ----------------------------- | 2009| Promise\<void> | Promise used to return the result. If the device logs are written to the file successfully, no result is returned; otherwise, an error object is returned.| 2010 2011**Error codes** 2012 2013For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2014 2015| ID| Error Message| 2016| -------- | ---------------------------------------- | 2017| 202 | Not System App. | 2018| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2019| 6600101 | Session service exception. | 2020| 6600102 | The session does not exist. | 2021 2022**Example** 2023 2024```ts 2025import { BusinessError } from '@kit.BasicServicesKit'; 2026import { fileIo } from '@kit.CoreFileKit'; 2027 2028let file = await fileIo.open("filePath"); 2029let url = file.fd.toString(); 2030avSession.startDeviceLogging(url, 2048).then(() => { 2031 console.info('startDeviceLogging successfully'); 2032}).catch((err: BusinessError) => { 2033 console.error(`startDeviceLogging BusinessError: code: ${err.code}, message: ${err.message}`); 2034}) 2035``` 2036 2037## avSession.stopDeviceLogging<sup>13+</sup> 2038 2039stopDeviceLogging(): Promise\<void> 2040 2041Stops device logging. This API uses a promise to return the result. 2042 2043**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2044 2045**System API**: This is a system API. 2046 2047**Return value** 2048 2049| Type | Description | 2050| -------------- | ----------------------------- | 2051| Promise\<void> | Promise used to return the result. If device logging is stopped, no result is returned; otherwise, an error object is returned.| 2052 2053**Error codes** 2054 2055For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2056 2057| ID| Error Message| 2058| -------- | ---------------------------------------- | 2059| 202 | Not System App. | 2060| 6600101 | Session service exception. | 2061| 6600102 | The session does not exist. | 2062 2063**Example** 2064 2065```ts 2066import { BusinessError } from '@kit.BasicServicesKit'; 2067 2068avSession.stopDeviceLogging().then(() => { 2069 console.info('stopCasting successfully'); 2070}).catch((err: BusinessError) => { 2071 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 2072}); 2073``` 2074 2075## avSession.on('deviceLogEvent')<sup>13+</sup> 2076 2077on(type: 'deviceLogEvent', callback: Callback\<DeviceLogEventCode>): void 2078 2079Subscribes to device log events. 2080 2081**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2082 2083**System API**: This is a system API. 2084 2085**Parameters** 2086 2087| Name | Type | Mandatory| Description | 2088| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2089| type | string | Yes | Event type, which is **'deviceLogEvent'** in this case.| 2090| callback | (callback: [DeviceLogEventCode](#devicelogeventcode13)) => void | Yes | Callback function, in which **DeviceLogEventCode** is the return value of the current device log event. | 2091 2092**Error codes** 2093 2094For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2095 2096| ID| Error Message| 2097| -------- | ---------------------------------------- | 2098| 202 | Not System App. | 2099| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2100| 6600101 | Session service exception. | 2101| 6600102 | The session does not exist. | 2102 2103**Example** 2104 2105```ts 2106avSession.on('deviceLogEvent', (eventCode: avSession.DeviceLogEventCode) => { 2107 console.info(`on deviceLogEvent code : ${eventCode}`); 2108}); 2109``` 2110 2111## avSession.off('deviceLogEvent')<sup>13+</sup> 2112 2113off(type: 'deviceLogEvent', callback?: Callback\<DeviceLogEventCode>): void 2114 2115Unsubscribes from device log events. 2116 2117**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2118 2119**System API**: This is a system API. 2120 2121**Parameters** 2122 2123| Name | Type | Mandatory| Description | 2124| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2125| type | string | Yes | Event type, which is **'deviceLogEvent'** in this case.| 2126| callback | (callback: [DeviceLogEventCode](#devicelogeventcode13)) => void | No | Callback used for unsubscription. 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. | 2127 2128**Error codes** 2129 2130For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2131 2132| ID| Error Message| 2133| -------- | ---------------------------------------- | 2134| 202 | Not System App. | 2135| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2136| 6600101 | Session service exception. | 2137| 6600102 | The session does not exist. | 2138 2139**Example** 2140 2141```ts 2142avSession.off('deviceLogEvent'); 2143``` 2144 2145## DeviceState<sup>20+</sup> 2146 2147Describes the connection state of the casting device. 2148 2149**System API**: This is a system API. 2150 2151**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2152 2153| Name | Type | Read-Only| Optional| Description | 2154| :------------- | :----- | :--- | :--- | :----------- | 2155| deviceId | string | Yes | No | ID of the casting device. | 2156| deviceState | number | Yes | No | Connection status code of the casting device.| 2157| reasonCode | number | Yes | No | Connection error code of the casting device.| 2158| radarErrorCode | number | Yes | No | System radar error code.| 2159 2160## avSession.on('deviceStateChanged')<sup>20+</sup> 2161 2162on(type: 'deviceStateChanged', callback: Callback\<DeviceState\>): void 2163 2164Subscribes to casting device connection state events. 2165 2166**System API**: This is a system API. 2167 2168**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 2169 2170**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2171 2172**Parameters** 2173 2174| Name | Type | Mandatory | Description | 2175| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2176| type | string | Yes | Event type, which is **'deviceStateChanged'** in this case. This event is triggered when the connection state of the casting device changes.| 2177| callback | (callback: [DeviceState](#devicestate20)) => void | Yes | Callback function, in which **DeviceState** contains the casting device ID, connection status code, connection error code, and system radar error code.| 2178 2179**Error codes** 2180 2181For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2182 2183| ID| Error Message| 2184| -------- | ---------------------------------------- | 2185| 201 | Permission denied. | 2186| 202 | Not System App. | 2187 2188**Example** 2189 2190```ts 2191avSession.on('deviceStateChanged', (state: avSession.DeviceState) => { 2192 console.info(`on deviceStateChanged state, deviceId=${state.deviceId}, connect status=${state.deviceState}, 2193 reasonCode=${state.reasonCode}, radarErrorCode=${state.radarErrorCode}`) 2194}) 2195``` 2196 2197## avSession.off('deviceStateChanged')<sup>20+</sup> 2198 2199off(type: 'deviceStateChanged', callback?: Callback\<DeviceState>): void 2200 2201Unsubscribes from casting device connection state events. 2202 2203**System API**: This is a system API. 2204 2205**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES 2206 2207**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2208 2209**Parameters** 2210 2211| Name | Type | Mandatory | Description | 2212| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2213| type | string | Yes | Event type, which is **'deviceStateChanged'** in this case. This event is triggered when the connection state of the casting device changes.| 2214| callback | (callback: [DeviceState](#devicestate20)) => void | No | Callback used to return the result. If the operation 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.| 2215 2216**Error codes** 2217 2218For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 2219 2220| ID| Error Message| 2221| -------- | ---------------------------------------- | 2222| 201 | Permission denied. | 2223| 202 | Not System App. | 2224 2225**Example** 2226 2227```ts 2228avSession.off('deviceStateChanged'); 2229``` 2230 2231## AVCastController<sup>10+</sup> 2232 2233After a casting connection is set up, you can call [avSession.getAVCastController](arkts-apis-avsession-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. 2234 2235### setDisplaySurface<sup>10+</sup> 2236 2237setDisplaySurface(surfaceId: string): Promise\<void> 2238 2239Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses a promise to return the result. 2240 2241**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2242 2243**System API**: This is a system API. 2244 2245**Parameters** 2246 2247| Name | Type | Mandatory| Description | 2248| -------- | --------------------------------------------------- | ---- | ---------------------------- | 2249| surfaceId | string | Yes | Surface ID.| 2250 2251**Return value** 2252 2253| Type | Description | 2254| --------------------------------------------- | --------------------------- | 2255| Promise\<void> | Promise used to return the result.| 2256 2257**Error codes** 2258 2259For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2260 2261| ID| Error Message| 2262| -------- | ---------------------------------------- | 2263| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 2264| 6600109 | The remote connection is not established. | 2265 2266**Example** 2267 2268```ts 2269import { media } from '@kit.MediaKit'; 2270let surfaceID: string = ''; 2271media.createAVRecorder().then((avRecorder) => { 2272 avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 2273 if (err == null) { 2274 console.info('getInputSurface success'); 2275 surfaceID = surfaceId; 2276 } else { 2277 console.error('getInputSurface failed and error is ' + err.message); 2278 } 2279 }); 2280}) 2281aVCastController.setDisplaySurface(surfaceID).then(() => { 2282 console.info('setDisplaySurface : SUCCESS'); 2283}); 2284``` 2285 2286### setDisplaySurface<sup>10+</sup> 2287 2288setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void 2289 2290Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses an asynchronous callback to return the result. 2291 2292**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2293 2294**System API**: This is a system API. 2295 2296**Parameters** 2297 2298| Name | Type | Mandatory| Description | 2299| -------- | --------------------------------------------------- | ---- | ---------------------------- | 2300| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| 2301| surfaceId | string | Yes | Surface ID.| 2302 2303 2304**Error codes** 2305 2306For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2307 2308| ID| Error Message| 2309| -------- | ---------------------------------------- | 2310| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 2311| 6600109 | The remote connection is not established. | 2312 2313**Example** 2314 2315```ts 2316import { BusinessError } from '@kit.BasicServicesKit'; 2317import { media } from '@kit.MediaKit'; 2318let surfaceID: string = ''; 2319media.createAVRecorder().then((avRecorder) => { 2320 avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => { 2321 if (err == null) { 2322 console.info('getInputSurface success'); 2323 surfaceID = surfaceId; 2324 } else { 2325 console.error('getInputSurface failed and error is ' + err.message); 2326 } 2327 }); 2328}) 2329aVCastController.setDisplaySurface(surfaceID, (err: BusinessError) => { 2330 if (err) { 2331 console.error(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`); 2332 } else { 2333 console.info('setDisplaySurface : SUCCESS'); 2334 } 2335}); 2336``` 2337 2338### on('videoSizeChange')<sup>12+</sup> 2339 2340on(type: 'videoSizeChange', callback: (width:number, height:number) => void): void 2341 2342Subscribes to video size change events. 2343 2344**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2345 2346**System API**: This is a system API. 2347 2348**Parameters** 2349 2350| Name | Type | Mandatory| Description | 2351| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 2352| type | string | Yes | Event type. The event **'videoSizeChange'** is triggered when the video size changes.| 2353| callback | (width:number, height:number) => void | Yes | Callback used to return the video width and height. | 2354 2355**Error codes** 2356 2357For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2358 2359| ID| Error Message| 2360| -------- | ---------------- | 2361| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2362| 6600101 | Session service exception. | 2363 2364**Example** 2365 2366```ts 2367aVCastController.on('videoSizeChange', (width: number, height: number) => { 2368 console.info(`width : ${width} `); 2369 console.info(`height: ${height} `); 2370}); 2371``` 2372 2373### off('videoSizeChange')<sup>12+</sup> 2374 2375off(type: 'videoSizeChange'): void 2376 2377Unsubscribes from video size changes. 2378 2379**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2380 2381**System API**: This is a system API. 2382 2383**Parameters** 2384 2385| Name | Type | Mandatory| Description | 2386| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 2387| type | string | Yes | Event type, which is **'videoSizeChange'** in this case. | 2388 2389**Error codes** 2390 2391For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2392 2393| ID| Error Message| 2394| -------- | ---------------- | 2395| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2396| 6600101 | Session service exception. | 2397 2398**Example** 2399 2400```ts 2401aVCastController.off('videoSizeChange'); 2402``` 2403 2404## AVMetadata<sup>10+</sup> 2405 2406Describes the media metadata. 2407 2408**System capability**: SystemCapability.Multimedia.AVSession.Core 2409 2410| Name | Type | Mandatory| Description | 2411| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 2412| avQueueName<sup>12+</sup> | string | No | Playlist name.<br>This is a system API.| 2413 2414## AVQueueInfo<sup>11+</sup> 2415 2416Defines the attributes of a playlist. 2417 2418**System capability**: SystemCapability.Multimedia.AVSession.Core 2419 2420**System API**: This is a system API. 2421 2422| Name | Type | Mandatory| Description | 2423| --------------- |-------------------------| ---- |--------------------------------------------------------------------- | 2424| bundleName | string | Yes | Bundle name of the application to which the playlist belongs. | 2425| avQueueName | string | Yes | Playlist name. | 2426| avQueueId | string | Yes | Unique ID of the playlist. | 2427| 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). | 2428| lastPlayedTime | number | No | Last time when the playlist is played. | 2429 2430## DeviceInfo<sup>10+</sup> 2431 2432Describes the information related to the output device. 2433 2434| Name | Type | Mandatory| Description | 2435| ---------- | -------------- | ---- | ---------------------- | 2436| ipAddress | string | No | IP address of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast | 2437| providerId | number | No | Vendor of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast | 2438| 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 | 2439| networkId<sup>13+</sup> | string | No | Network ID of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 2440 2441## AVSessionDescriptor 2442 2443Declares the session descriptor. 2444 2445**System capability**: SystemCapability.Multimedia.AVSession.Manager 2446 2447**System API**: This is a system API. 2448 2449| Name | Type | Read-Only| Optional| Description | 2450| --------------| ---------------- | ---------------- | ---------------- |------| 2451| sessionId | string | No| No | Session ID. | 2452| type | [AVSessionType](arkts-apis-avsession-t.md#avsessiontype10) | No| No| Session type. | 2453| sessionTag | string | No| No| Custom session name. | 2454| elementName | [ElementName](../apis-ability-kit/js-apis-bundle-ElementName.md) | No| No| Information about the application to which the session belongs, including the bundle name and ability name.| 2455| isActive | boolean | No| No| Whether the session is activated.<br>**true**: The session is activated.<br>**false**: The session is not activated. | 2456| isTopSession | boolean | No| No| Whether the session is the top session.<br>**true**: The session is the top session.<br>**false**: The session is not the top session. | 2457| outputDevice | [OutputDeviceInfo](arkts-apis-avsession-i.md#outputdeviceinfo10) | No| No| Information about the output device. | 2458 2459## DeviceLogEventCode<sup>13+</sup> 2460 2461Enumerates the return values of device log events. 2462 2463**System capability**: SystemCapability.Multimedia.AVSession.AVCast 2464 2465**System API**: This is a system API. 2466 2467| Name | Value | Description | 2468| --------------------------- | ---- | ----------- | 2469| DEVICE_LOG_FULL | 1 | The log file is full. | 2470| DEVICE_LOG_EXCEPTION | 2 | An exception occurs during device logging.| 2471