1# @ohos.multimedia.avsession (AVSession Management) 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- [AVSession](#avsession10): used to set session metadata, playback state information, and more. 8- [AVSessionController](#avsessioncontroller10): used to obtain session IDs, send commands and events to sessions, and obtain the session metadata and playback state information. 9- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios. 10 11> **NOTE** 12> 13> 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. 14 15## Modules to Import 16 17```ts 18import { avSession } from '@kit.AVSessionKit'; 19``` 20 21## avSession.createAVSession<sup>10+</sup> 22 23createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession> 24 25Creates a media session. This API uses a promise to return the result. An ability can have only one session, and repeated calling of this API fails. 26 27**Atomic service API**: This API can be used in atomic services since API version 12. 28 29**System capability**: SystemCapability.Multimedia.AVSession.Core 30 31**Parameters** 32 33| Name| Type | Mandatory| Description | 34| ------ | ------------------------------- | ---- | ------------------------------ | 35| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | Yes| Context of the UIAbility, which is used to obtain information about the application component.| 36| tag | string | Yes | Custom session name. | 37| type | [AVSessionType](#avsessiontype10) | Yes | Session type.| 38 39**Return value** 40 41| Type | Description | 42| --------------------------------- | ------------------------------------------------------------ | 43| Promise<[AVSession](#avsession10)\> | Promise used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.| 44 45**Error codes** 46 47For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 48 49| ID| Error Message| 50| -------- | ---------------------------------------- | 51| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 52| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 53 54**Example** 55 56```ts 57import { BusinessError } from '@kit.BasicServicesKit'; 58import { avSession } from '@kit.AVSessionKit'; 59@Entry 60@Component 61struct Index { 62 @State message: string = 'hello world'; 63 64 build() { 65 Column() { 66 Text(this.message) 67 .onClick(()=>{ 68 let currentAVSession: avSession.AVSession; 69 let tag = "createNewSession"; 70 let context: Context = this.getUIContext().getHostContext() as Context; 71 let sessionId: string; // Used as an input parameter of subsequent functions. 72 73 avSession.createAVSession(context, tag, "audio").then(async (data: avSession.AVSession) => { 74 currentAVSession = data; 75 sessionId = currentAVSession.sessionId; 76 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 77 }).catch((err: BusinessError) => { 78 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 79 }); 80 }) 81 } 82 .width('100%') 83 .height('100%') 84 } 85} 86``` 87 88## avSession.createAVSession<sup>10+</sup> 89 90createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void 91 92Creates a media session. This API uses an asynchronous callback to return the result. An ability can have only one session, and repeated calling of this API fails. 93 94**System capability**: SystemCapability.Multimedia.AVSession.Core 95 96**Parameters** 97 98| Name | Type | Mandatory| Description | 99| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 100| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | Yes| Context of the UIAbility, which is used to obtain information about the application component. | 101| tag | string | Yes | Custom session name. | 102| type | [AVSessionType](#avsessiontype10) | Yes | Session type. | 103| callback | AsyncCallback<[AVSession](#avsession10)\> | Yes | Callback used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.| 104 105**Error codes** 106 107For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 108 109| ID| Error Message| 110| -------- | ---------------------------------------- | 111| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 112| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 113 114**Example** 115 116```ts 117import { BusinessError } from '@kit.BasicServicesKit'; 118import { avSession } from '@kit.AVSessionKit'; 119@Entry 120@Component 121struct Index { 122 @State message: string = 'hello world'; 123 124 build() { 125 Column() { 126 Text(this.message) 127 .onClick(()=>{ 128 let currentAVSession: avSession.AVSession; 129 let tag = "createNewSession"; 130 let context: Context = this.getUIContext().getHostContext() as Context; 131 let sessionId: string; // Used as an input parameter of subsequent functions. 132 133 avSession.createAVSession(context, tag, "audio", async (err: BusinessError, data: avSession.AVSession) => { 134 if (err) { 135 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 136 } else { 137 currentAVSession = data; 138 sessionId = currentAVSession.sessionId; 139 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 140 } 141 }); 142 }) 143 } 144 .width('100%') 145 .height('100%') 146 } 147} 148``` 149 150## ProtocolType<sup>11+</sup> 151 152Enumerates the protocol types supported by the remote device. 153 154**System capability**: SystemCapability.Multimedia.AVSession.AVCast 155 156| Name | Value | Description | 157| --------------------------- | ---- | ----------- | 158| TYPE_LOCAL<sup>11+</sup> | 0 | Local device, which can be the built-in speaker or audio jack of the device, or an A2DP device.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 159| TYPE_CAST_PLUS_STREAM<sup>11+</sup> | 2 | Cast+ stream mode, indicating that the media asset is being displayed on another device.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 160| TYPE_DLNA<sup>12+</sup> | 4 | DLNA protocol, indicating that the media asset is being displayed on another device.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 161| TYPE_CAST_PLUS_AUDIO<sup>20+</sup> | 8 | PCM mode, indicating that the media asset is being displayed on another device.<br>**Atomic service API**: This API can be used in atomic services since API version 20.| 162 163## AVSessionType<sup>10+<sup> 164 165type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call' 166 167Defines the session type supported by the session. 168 169You can use the strings listed in the following table. 170 171**Atomic service API**: This API can be used in atomic services since API version 12. 172 173**System capability**: SystemCapability.Multimedia.AVSession.Core 174 175| Type | Description| 176| ----- | ---- | 177| 'audio' | Audio session.| 178| 'video' | Video session.| 179| 'voice_call'<sup>11+<sup> | Voice call.| 180| 'video_call'<sup>12+<sup> | Video call.| 181 182## AVSession<sup>10+</sup> 183 184An AVSession object is created by calling [avSession.createAVSession](#avsessioncreateavsession10). The object enables you to obtain the session ID and set the metadata and playback state. 185 186### Properties 187 188**Atomic service API**: This API can be used in atomic services since API version 12. 189 190**System capability**: SystemCapability.Multimedia.AVSession.Core 191 192| Name | Type | Read-Only| Optional| Description | 193| :-------- | :----- | :--- | :--- | :---------------------------- | 194| sessionId | string | Yes | No | Unique session ID of the AVSession object.| 195| sessionType| [AVSessionType](#avsessiontype10) | Yes | No | AVSession type.| 196 197**Example** 198 199```ts 200let sessionId: string = currentAVSession.sessionId; 201let sessionType: avSession.AVSessionType = currentAVSession.sessionType; 202``` 203 204### setAVMetadata<sup>10+</sup> 205 206setAVMetadata(data: AVMetadata): Promise\<void> 207 208Sets session metadata. This API uses a promise to return the result. 209 210**Atomic service API**: This API can be used in atomic services since API version 12. 211 212**System capability**: SystemCapability.Multimedia.AVSession.Core 213 214**Parameters** 215 216| Name| Type | Mandatory| Description | 217| ------ | ------------------------- | ---- | ------------ | 218| data | [AVMetadata](#avmetadata10) | Yes | Session metadata.| 219 220**Return value** 221 222| Type | Description | 223| -------------- | ----------------------------- | 224| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 225 226**Error codes** 227 228For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 229 230| ID| Error Message| 231| -------- | ---------------------------------------- | 232| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 233| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 234| 6600102 | The session does not exist. | 235 236**Example** 237 238```ts 239import { BusinessError } from '@kit.BasicServicesKit'; 240 241let metadata: avSession.AVMetadata = { 242 assetId: "121278", 243 title: "lose yourself", 244 artist: "Eminem", 245 author: "ST", 246 album: "Slim shady", 247 writer: "ST", 248 composer: "ST", 249 duration: 2222, 250 mediaImage: "https://www.example.com/example.jpg", 251 subtitle: "8 Mile", 252 description: "Rap", 253 // The LRC contains two types of elements: time tag + lyrics, and ID tag. 254 // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n 255 lyric: "Lyrics in LRC format", 256 // The singleLyricText field stores a single line of lyric text without timestamps. 257 // Example: "Content of a single lyric line" 258 singleLyricText: "Content of a single lyric line", 259 previousAssetId: "121277", 260 nextAssetId: "121279" 261}; 262currentAVSession.setAVMetadata(metadata).then(() => { 263 console.info('SetAVMetadata successfully'); 264}).catch((err: BusinessError) => { 265 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 266}); 267``` 268 269### setAVMetadata<sup>10+</sup> 270 271setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void 272 273Sets session metadata. This API uses an asynchronous callback to return the result. 274 275**System capability**: SystemCapability.Multimedia.AVSession.Core 276 277**Parameters** 278 279| Name | Type | Mandatory| Description | 280| -------- | ------------------------- | ---- | ------------------------------------- | 281| data | [AVMetadata](#avmetadata10) | Yes | Session metadata. | 282| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 283 284**Error codes** 285 286For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 287 288| ID| Error Message| 289| -------- | ---------------------------------------- | 290| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 291| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 292| 6600102 | The session does not exist. | 293 294**Example** 295 296```ts 297import { BusinessError } from '@kit.BasicServicesKit'; 298 299let metadata: avSession.AVMetadata = { 300 assetId: "121278", 301 title: "lose yourself", 302 artist: "Eminem", 303 author: "ST", 304 album: "Slim shady", 305 writer: "ST", 306 composer: "ST", 307 duration: 2222, 308 mediaImage: "https://www.example.com/example.jpg", 309 subtitle: "8 Mile", 310 description: "Rap", 311 // The LRC contains two types of elements: time tag + lyrics, and ID tag. 312 // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n 313 lyric: "Lyrics in LRC format", 314 // The singleLyricText field stores a single line of lyric text without timestamps. 315 // Example: "Content of a single lyric line" 316 singleLyricText: "Content of a single lyric line", 317 previousAssetId: "121277", 318 nextAssetId: "121279" 319}; 320currentAVSession.setAVMetadata(metadata, (err: BusinessError) => { 321 if (err) { 322 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 323 } else { 324 console.info('SetAVMetadata successfully'); 325 } 326}); 327``` 328 329### setCallMetadata<sup>11+</sup> 330 331setCallMetadata(data: CallMetadata): Promise\<void> 332 333Sets call metadata. This API uses a promise to return the result. 334 335**System capability**: SystemCapability.Multimedia.AVSession.Core 336 337**Parameters** 338 339| Name| Type | Mandatory| Description | 340| ------ | ------------------------- | ---- | ------------ | 341| data | [CallMetadata](#callmetadata11) | Yes | Call metadata.| 342 343**Return value** 344 345| Type | Description | 346| -------------- | ----------------------------- | 347| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 348 349**Error codes** 350 351For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 352 353| ID| Error Message| 354| -------- | ---------------------------------------- | 355| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 356| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 357| 6600102 | The session does not exist. | 358 359**Example** 360 361```ts 362import { image } from '@kit.ImageKit'; 363import { resourceManager } from '@kit.LocalizationKit'; 364import { BusinessError } from '@kit.BasicServicesKit'; 365 366let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 367 let imageSource = await image.createImageSource(value.buffer); 368 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 369 let calldata: avSession.CallMetadata = { 370 name: "xiaoming", 371 phoneNumber: "111xxxxxxxx", 372 avatar: imagePixel 373 }; 374currentAVSession.setCallMetadata(calldata).then(() => { 375 console.info('setCallMetadata successfully'); 376}).catch((err: BusinessError) => { 377 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 378}); 379``` 380 381### setCallMetadata<sup>11+</sup> 382 383setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void 384 385Sets call metadata. This API uses an asynchronous callback to return the result. 386 387**System capability**: SystemCapability.Multimedia.AVSession.Core 388 389**Parameters** 390 391| Name | Type | Mandatory| Description | 392| -------- | ------------------------- | ---- | ------------------------------------- | 393| data | [CallMetadata](#callmetadata11) | Yes | Call metadata. | 394| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 395 396**Error codes** 397 398For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 399 400| ID| Error Message| 401| -------- | ---------------------------------------- | 402| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 403| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 404| 6600102 | The session does not exist. | 405 406**Example** 407 408```ts 409import { image } from '@kit.ImageKit'; 410import { resourceManager } from '@kit.LocalizationKit'; 411import { BusinessError } from '@kit.BasicServicesKit'; 412 413async function setCallMetadata() { 414 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 415 let imageSource = await image.createImageSource(value.buffer); 416 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 417 let calldata: avSession.CallMetadata = { 418 name: "xiaoming", 419 phoneNumber: "111xxxxxxxx", 420 avatar: imagePixel 421 }; 422 currentAVSession.setCallMetadata(calldata, (err: BusinessError) => { 423 if (err) { 424 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 425 } else { 426 console.info('setCallMetadata successfully'); 427 } 428 }); 429} 430``` 431 432### setAVCallState<sup>11+</sup> 433 434setAVCallState(state: AVCallState): Promise\<void> 435 436Sets the call state. This API uses a promise to return the result. 437 438**System capability**: SystemCapability.Multimedia.AVSession.Core 439 440**Parameters** 441 442| Name| Type | Mandatory| Description | 443| ------ | ------------------------- | ---- | ------------ | 444| state | [AVCallState](#avcallstate11) | Yes | Call state.| 445 446**Return value** 447 448| Type | Description | 449| -------------- | ----------------------------- | 450| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 451 452**Error codes** 453 454For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 455 456| ID| Error Message| 457| -------- | ---------------------------------------- | 458| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 459| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 460| 6600102 | The session does not exist. | 461 462**Example** 463 464```ts 465import { BusinessError } from '@kit.BasicServicesKit'; 466 467let calldata: avSession.AVCallState = { 468 state: avSession.CallState.CALL_STATE_ACTIVE, 469 muted: false 470}; 471currentAVSession.setAVCallState(calldata).then(() => { 472 console.info('setAVCallState successfully'); 473}).catch((err: BusinessError) => { 474 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 475}); 476``` 477 478### setAVCallState<sup>11+</sup> 479 480setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void 481 482Sets the call state. This API uses an asynchronous callback to return the result. 483 484**System capability**: SystemCapability.Multimedia.AVSession.Core 485 486**Parameters** 487 488| Name | Type | Mandatory| Description | 489| -------- | ------------------------- | ---- | ------------------------------------- | 490| state | [AVCallState](#avcallstate11) | Yes | Call state. | 491| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 492 493**Error codes** 494 495For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 496 497| ID| Error Message| 498| -------- | ---------------------------------------- | 499| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 500| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 501| 6600102 | The session does not exist. | 502 503**Example** 504 505```ts 506import { BusinessError } from '@kit.BasicServicesKit'; 507 508let avcalldata: avSession.AVCallState = { 509 state: avSession.CallState.CALL_STATE_ACTIVE, 510 muted: false 511}; 512currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => { 513 if (err) { 514 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 515 } else { 516 console.info('setAVCallState successfully'); 517 } 518}); 519``` 520 521### setAVPlaybackState<sup>10+</sup> 522 523setAVPlaybackState(state: AVPlaybackState): Promise\<void> 524 525Sets information related to the session playback state. This API uses a promise to return the result. 526 527**Atomic service API**: This API can be used in atomic services since API version 12. 528 529**System capability**: SystemCapability.Multimedia.AVSession.Core 530 531**Parameters** 532 533| Name| Type | Mandatory| Description | 534| ------ | ----------------------------------- | ---- | ---------------------------------------------- | 535| state | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| 536 537**Return value** 538 539| Type | Description | 540| -------------- | ----------------------------- | 541| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 542 543**Error codes** 544 545For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 546 547| ID| Error Message| 548| -------- | ---------------------------------------- | 549| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 550| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 551| 6600102 | The session does not exist. | 552 553**Example** 554 555```ts 556import { BusinessError } from '@kit.BasicServicesKit'; 557 558let playbackState: avSession.AVPlaybackState = { 559 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 560 speed: 1.0, 561 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 562 bufferedTime:1000, 563 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 564 isFavorite:true 565}; 566currentAVSession.setAVPlaybackState(playbackState).then(() => { 567 console.info('SetAVPlaybackState successfully'); 568}).catch((err: BusinessError) => { 569 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 570}); 571``` 572 573### setAVPlaybackState<sup>10+</sup> 574 575setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void 576 577Sets information related to the session playback state. This API uses an asynchronous callback to return the result. 578 579**System capability**: SystemCapability.Multimedia.AVSession.Core 580 581**Parameters** 582 583| Name | Type | Mandatory| Description | 584| -------- | ----------------------------------- | ---- | ---------------------------------------------- | 585| state | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| 586| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. | 587 588**Error codes** 589 590For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 591 592| ID| Error Message| 593| -------- | ---------------------------------------- | 594| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 595| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 596| 6600102 | The session does not exist. | 597 598**Example** 599 600```ts 601import { BusinessError } from '@kit.BasicServicesKit'; 602 603let PlaybackState: avSession.AVPlaybackState = { 604 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 605 speed: 1.0, 606 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 607 bufferedTime:1000, 608 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 609 isFavorite:true 610}; 611currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => { 612 if (err) { 613 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 614 } else { 615 console.info('SetAVPlaybackState successfully'); 616 } 617}); 618``` 619 620### setLaunchAbility<sup>10+</sup> 621 622setLaunchAbility(ability: WantAgent): Promise\<void> 623 624Sets a launcher ability. This API uses a promise to return the result. 625 626**Atomic service API**: This API can be used in atomic services since API version 12. 627 628**System capability**: SystemCapability.Multimedia.AVSession.Core 629 630**Parameters** 631 632| Name | Type | Mandatory| Description | 633| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 634| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes | Application properties, such as the bundle name, ability name, and deviceID.| 635 636**Return value** 637 638| Type | Description | 639| -------------- | ----------------------------- | 640| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 641 642**Error codes** 643 644For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 645 646| ID| Error Message| 647| -------- | ---------------------------------------- | 648| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 649| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 650| 6600102 | The session does not exist. | 651 652**Example** 653 654```ts 655import { wantAgent } from '@kit.AbilityKit'; 656import { BusinessError } from '@kit.BasicServicesKit'; 657 658// WantAgentInfo object. 659let wantAgentInfo: wantAgent.WantAgentInfo = { 660 wants: [ 661 { 662 deviceId: "deviceId", 663 bundleName: "com.example.myapplication", 664 abilityName: "EntryAbility", 665 action: "action1", 666 entities: ["entity1"], 667 type: "MIMETYPE", 668 uri: "key = {true,true,false}", 669 parameters: 670 { 671 mykey0: 2222, 672 mykey1: [1, 2, 3], 673 mykey2: "[1, 2, 3]", 674 mykey3: "ssssssssssssssssssssssssss", 675 mykey4: [false, true, false], 676 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 677 mykey6: true 678 } 679 } 680 ], 681 operationType: wantAgent.OperationType.START_ABILITIES, 682 requestCode: 0, 683 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 684} 685 686wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 687 currentAVSession.setLaunchAbility(agent).then(() => { 688 console.info('SetLaunchAbility successfully'); 689 }).catch((err: BusinessError) => { 690 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 691 }); 692}); 693``` 694 695### setLaunchAbility<sup>10+</sup> 696 697setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void 698 699Sets a launcher ability. This API uses an asynchronous callback to return the result. 700 701**System capability**: SystemCapability.Multimedia.AVSession.Core 702 703**Parameters** 704 705| Name | Type | Mandatory| Description | 706| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 707| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes | Application properties, such as the bundle name, ability name, and deviceID. | 708| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 709 710**Error codes** 711 712For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 713 714| ID| Error Message| 715| -------- | ---------------------------------------- | 716| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 717| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 718| 6600102 | The session does not exist. | 719 720**Example** 721 722```ts 723import { wantAgent } from '@kit.AbilityKit'; 724import { BusinessError } from '@kit.BasicServicesKit'; 725 726// WantAgentInfo object. 727let wantAgentInfo: wantAgent.WantAgentInfo = { 728 wants: [ 729 { 730 deviceId: "deviceId", 731 bundleName: "com.example.myapplication", 732 abilityName: "EntryAbility", 733 action: "action1", 734 entities: ["entity1"], 735 type: "MIMETYPE", 736 uri: "key = {true,true,false}", 737 parameters: 738 { 739 mykey0: 2222, 740 mykey1: [1, 2, 3], 741 mykey2: "[1, 2, 3]", 742 mykey3: "ssssssssssssssssssssssssss", 743 mykey4: [false, true, false], 744 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 745 mykey6: true 746 } 747 } 748 ], 749 operationType: wantAgent.OperationType.START_ABILITIES, 750 requestCode: 0, 751 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 752} 753 754wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 755 currentAVSession.setLaunchAbility(agent, (err: BusinessError) => { 756 if (err) { 757 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 758 } else { 759 console.info('SetLaunchAbility successfully'); 760 } 761 }); 762}); 763``` 764 765### dispatchSessionEvent<sup>10+</sup> 766 767dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void> 768 769Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses a promise to return the result. It is called by the provider. 770 771**Atomic service API**: This API can be used in atomic services since API version 12. 772 773**System capability**: SystemCapability.Multimedia.AVSession.Core 774 775**Parameters** 776 777| Name | Type | Mandatory| Description | 778| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 779| event | string | Yes | Name of the session event.| 780| args | {[key: string]: Object} | Yes | Content of the session event.| 781 782> **NOTE** 783> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 784 785**Return value** 786 787| Type | Description | 788| -------------- | ----------------------------- | 789| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 790 791**Error codes** 792 793For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 794 795| ID| Error Message| 796| -------- | ---------------------------------------- | 797| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 798| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 799| 6600102 | The session does not exist. | 800 801**Example** 802 803```ts 804import { BusinessError } from '@kit.BasicServicesKit'; 805import { avSession } from '@kit.AVSessionKit'; 806@Entry 807@Component 808struct Index { 809 @State message: string = 'hello world'; 810 811 build() { 812 Column() { 813 Text(this.message) 814 .onClick(()=>{ 815 let currentAVSession: avSession.AVSession | undefined = undefined; 816 let tag = "createNewSession"; 817 let context: Context = this.getUIContext().getHostContext() as Context; 818 819 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 820 if (err) { 821 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 822 } else { 823 currentAVSession = data; 824 } 825 }); 826 let eventName = "dynamic_lyric"; 827 if (currentAVSession !== undefined) { 828 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => { 829 console.info('dispatchSessionEvent successfully'); 830 }).catch((err: BusinessError) => { 831 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 832 }) 833 } 834 }) 835 } 836 .width('100%') 837 .height('100%') 838 } 839} 840``` 841 842### dispatchSessionEvent<sup>10+</sup> 843 844dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 845 846Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses an asynchronous callback to return the result. It is called by the provider. 847 848**System capability**: SystemCapability.Multimedia.AVSession.Core 849 850**Parameters** 851 852| Name | Type | Mandatory| Description | 853| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 854| event | string | Yes | Name of the session event.| 855| args | {[key: string]: Object} | Yes | Content of the session event.| 856| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 857 858> **NOTE** 859 860> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 861 862**Error codes** 863 864For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 865 866| ID| Error Message| 867| -------- | ---------------------------------------- | 868| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 869| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 870| 6600102 | The session does not exist. | 871 872**Example** 873 874```ts 875import { BusinessError } from '@kit.BasicServicesKit'; 876import { avSession } from '@kit.AVSessionKit'; 877@Entry 878@Component 879struct Index { 880 @State message: string = 'hello world'; 881 882 build() { 883 Column() { 884 Text(this.message) 885 .onClick(()=>{ 886 let currentAVSession: avSession.AVSession | undefined = undefined; 887 let tag = "createNewSession"; 888 let context: Context = this.getUIContext().getHostContext() as Context; 889 890 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 891 if (err) { 892 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 893 } else { 894 currentAVSession = data; 895 } 896 }); 897 let eventName: string = "dynamic_lyric"; 898 if (currentAVSession !== undefined) { 899 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => { 900 if (err) { 901 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 902 } 903 }) 904 } 905 }) 906 } 907 .width('100%') 908 .height('100%') 909 } 910} 911``` 912 913### setAVQueueItems<sup>10+</sup> 914 915setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void> 916 917Sets a playlist. This API uses a promise to return the result. 918 919**Atomic service API**: This API can be used in atomic services since API version 12. 920 921**System capability**: SystemCapability.Multimedia.AVSession.Core 922 923**Parameters** 924 925| Name | Type | Mandatory| Description | 926| ------ | ------------------------------------ | ---- | ---------------------------------- | 927| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set.| 928 929**Return value** 930 931| Type | Description | 932| -------------- | ----------------------------- | 933| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 934 935**Error codes** 936 937For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 938 939| ID| Error Message| 940| -------- | ---------------------------------------- | 941| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 942| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 943| 6600102 | The session does not exist. | 944 945**Example** 946 947```ts 948import { image } from '@kit.ImageKit'; 949import { resourceManager } from '@kit.LocalizationKit'; 950import { BusinessError } from '@kit.BasicServicesKit'; 951 952async function setAVQueueItems() { 953 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 954 let imageSource = await image.createImageSource(value.buffer); 955 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 956 let queueItemDescription_1: avSession.AVMediaDescription = { 957 assetId: '001', 958 title: 'music_name', 959 subtitle: 'music_sub_name', 960 description: 'music_description', 961 mediaImage : imagePixel, 962 extras: {extras:'any'} 963 }; 964 let queueItem_1: avSession.AVQueueItem = { 965 itemId: 1, 966 description: queueItemDescription_1 967 }; 968 let queueItemDescription_2: avSession.AVMediaDescription = { 969 assetId: '002', 970 title: 'music_name', 971 subtitle: 'music_sub_name', 972 description: 'music_description', 973 mediaImage: imagePixel, 974 extras: {extras:'any'} 975 }; 976 let queueItem_2: avSession.AVQueueItem = { 977 itemId: 2, 978 description: queueItemDescription_2 979 }; 980 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 981 currentAVSession.setAVQueueItems(queueItemsArray).then(() => { 982 console.info('SetAVQueueItems successfully'); 983 }).catch((err: BusinessError) => { 984 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 985 }); 986} 987``` 988 989### setAVQueueItems<sup>10+</sup> 990 991setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void 992 993Sets a playlist. This API uses an asynchronous callback to return the result. 994 995**System capability**: SystemCapability.Multimedia.AVSession.Core 996 997**Parameters** 998 999| Name | Type | Mandatory| Description | 1000| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | 1001| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set. | 1002| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1003 1004**Error codes** 1005 1006For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1007 1008| ID| Error Message| 1009| -------- | ---------------------------------------- | 1010| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1011| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1012| 6600102 | The session does not exist. | 1013 1014**Example** 1015 1016```ts 1017import { image } from '@kit.ImageKit'; 1018import { resourceManager } from '@kit.LocalizationKit'; 1019import { BusinessError } from '@kit.BasicServicesKit'; 1020 1021async function setAVQueueItems() { 1022 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 1023 let imageSource = await image.createImageSource(value.buffer); 1024 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 1025 let queueItemDescription_1: avSession.AVMediaDescription = { 1026 assetId: '001', 1027 title: 'music_name', 1028 subtitle: 'music_sub_name', 1029 description: 'music_description', 1030 mediaImage : imagePixel, 1031 extras: {extras:'any'} 1032 }; 1033 let queueItem_1: avSession.AVQueueItem = { 1034 itemId: 1, 1035 description: queueItemDescription_1 1036 }; 1037 let queueItemDescription_2: avSession.AVMediaDescription = { 1038 assetId: '002', 1039 title: 'music_name', 1040 subtitle: 'music_sub_name', 1041 description: 'music_description', 1042 mediaImage: imagePixel, 1043 extras: {extras:'any'} 1044 }; 1045 let queueItem_2: avSession.AVQueueItem = { 1046 itemId: 2, 1047 description: queueItemDescription_2 1048 }; 1049 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 1050 currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => { 1051 if (err) { 1052 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 1053 } else { 1054 console.info('SetAVQueueItems successfully'); 1055 } 1056 }); 1057} 1058``` 1059 1060### setAVQueueTitle<sup>10+</sup> 1061 1062setAVQueueTitle(title: string): Promise\<void> 1063 1064Sets a name for the playlist. This API uses a promise to return the result. 1065 1066**Atomic service API**: This API can be used in atomic services since API version 12. 1067 1068**System capability**: SystemCapability.Multimedia.AVSession.Core 1069 1070**Parameters** 1071 1072| Name | Type | Mandatory| Description | 1073| ------ | ------ | ---- | -------------- | 1074| title | string | Yes | Name of the playlist.| 1075 1076**Return value** 1077 1078| Type | Description | 1079| -------------- | ----------------------------- | 1080| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 1081 1082**Error codes** 1083 1084For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1085 1086| ID| Error Message| 1087| -------- | ---------------------------------------- | 1088| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1089| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1090| 6600102 | The session does not exist. | 1091 1092**Example** 1093 1094```ts 1095import { BusinessError } from '@kit.BasicServicesKit'; 1096 1097let queueTitle = 'QUEUE_TITLE'; 1098currentAVSession.setAVQueueTitle(queueTitle).then(() => { 1099 console.info('SetAVQueueTitle successfully'); 1100}).catch((err: BusinessError) => { 1101 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1102}); 1103``` 1104 1105### setAVQueueTitle<sup>10+</sup> 1106 1107setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void 1108 1109Sets a name for the playlist. This API uses an asynchronous callback to return the result. 1110 1111**System capability**: SystemCapability.Multimedia.AVSession.Core 1112 1113**Parameters** 1114 1115| Name | Type | Mandatory| Description | 1116| -------- | --------------------- | ---- | ----------------------------------------------------------- | 1117| title | string | Yes | Name of the playlist. | 1118| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1119 1120**Error codes** 1121 1122For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1123 1124| ID| Error Message| 1125| -------- | ---------------------------------------- | 1126| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1127| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1128| 6600102 | The session does not exist. | 1129 1130**Example** 1131 1132```ts 1133import { BusinessError } from '@kit.BasicServicesKit'; 1134 1135let queueTitle = 'QUEUE_TITLE'; 1136currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => { 1137 if (err) { 1138 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1139 } else { 1140 console.info('SetAVQueueTitle successfully'); 1141 } 1142}); 1143``` 1144 1145### setExtras<sup>10+</sup> 1146 1147setExtras(extras: {[key: string]: Object}): Promise\<void> 1148 1149Sets a custom media packet in the form of key-value pairs. This API uses a promise to return the result. It is called by the provider. 1150 1151**Atomic service API**: This API can be used in atomic services since API version 12. 1152 1153**System capability**: SystemCapability.Multimedia.AVSession.Core 1154 1155**Parameters** 1156 1157| Name | Type | Mandatory| Description | 1158| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1159| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| 1160 1161> **NOTE** 1162 1163> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 1164 1165**Return value** 1166 1167| Type | Description | 1168| -------------- | ----------------------------- | 1169| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 1170 1171**Error codes** 1172 1173For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1174 1175| ID| Error Message| 1176| -------- | ---------------------------------------- | 1177| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1178| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1179| 6600102 | The session does not exist. | 1180 1181**Example** 1182 1183```ts 1184import { BusinessError } from '@kit.BasicServicesKit'; 1185import { avSession } from '@kit.AVSessionKit'; 1186@Entry 1187@Component 1188struct Index { 1189 @State message: string = 'hello world'; 1190 1191 build() { 1192 Column() { 1193 Text(this.message) 1194 .onClick(()=>{ 1195 let currentAVSession: avSession.AVSession | undefined = undefined; 1196 let tag = "createNewSession"; 1197 let context: Context = this.getUIContext().getHostContext() as Context; 1198 1199 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1200 if (err) { 1201 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1202 } else { 1203 currentAVSession = data; 1204 } 1205 }); 1206 if (currentAVSession !== undefined) { 1207 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => { 1208 console.info('setExtras successfully'); 1209 }).catch((err: BusinessError) => { 1210 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1211 }) 1212 } 1213 }) 1214 } 1215 .width('100%') 1216 .height('100%') 1217 } 1218} 1219``` 1220 1221### setExtras<sup>10+</sup> 1222 1223setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void 1224 1225Sets a custom media packet in the form of key-value pairs. This API uses an asynchronous callback to return the result. It is called by the provider. 1226 1227**System capability**: SystemCapability.Multimedia.AVSession.Core 1228 1229**Parameters** 1230 1231| Name | Type | Mandatory| Description | 1232| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1233| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| 1234| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1235 1236> **NOTE** 1237 1238> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 1239 1240**Error codes** 1241 1242For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1243 1244| ID| Error Message| 1245| -------- | ---------------------------------------- | 1246| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1247| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1248| 6600102 | The session does not exist. | 1249 1250**Example** 1251 1252```ts 1253import { BusinessError } from '@kit.BasicServicesKit'; 1254import { avSession } from '@kit.AVSessionKit'; 1255@Entry 1256@Component 1257struct Index { 1258 @State message: string = 'hello world'; 1259 1260 build() { 1261 Column() { 1262 Text(this.message) 1263 .onClick(()=>{ 1264 let currentAVSession: avSession.AVSession | undefined = undefined; 1265 let tag = "createNewSession"; 1266 let context: Context = this.getUIContext().getHostContext() as Context; 1267 1268 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1269 if (err) { 1270 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1271 } else { 1272 currentAVSession = data; 1273 } 1274 }); 1275 if (currentAVSession !== undefined) { 1276 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => { 1277 if (err) { 1278 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1279 } 1280 }) 1281 } 1282 }) 1283 } 1284 .width('100%') 1285 .height('100%') 1286 } 1287} 1288``` 1289 1290### getController<sup>10+</sup> 1291 1292getController(): Promise\<AVSessionController> 1293 1294Obtains the controller corresponding to this session. This API uses a promise to return the result. 1295 1296**Atomic service API**: This API can be used in atomic services since API version 12. 1297 1298**System capability**: SystemCapability.Multimedia.AVSession.Core 1299 1300**Return value** 1301 1302| Type | Description | 1303| ---------------------------------------------------- | ----------------------------- | 1304| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.| 1305 1306**Error codes** 1307 1308For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1309 1310| ID| Error Message| 1311| -------- | ---------------------------------------- | 1312| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1313| 6600102 | The session does not exist. | 1314 1315**Example** 1316 1317```ts 1318import { BusinessError } from '@kit.BasicServicesKit'; 1319import { avSession } from '@kit.AVSessionKit'; 1320 1321@Entry 1322@Component 1323struct Index { 1324 @State message: string = 'hello world'; 1325 build() { 1326 Column() { 1327 Text(this.message) 1328 .onClick(async ()=>{ 1329 let context: Context = this.getUIContext().getHostContext() as Context; 1330 let currentAVSession: avSession.AVSession = await avSession.createAVSession(context, 'SESSION_NAME', 'audio'); 1331 let avsessionController: avSession.AVSessionController; 1332 currentAVSession.getController().then(async (avcontroller: avSession.AVSessionController) => { 1333 avsessionController = avcontroller; 1334 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1335 }).catch((err: BusinessError) => { 1336 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1337 }); 1338 }) 1339 } 1340 .width('100%') 1341 .height('100%') 1342 } 1343} 1344``` 1345 1346### getController<sup>10+</sup> 1347 1348getController(callback: AsyncCallback\<AVSessionController>): void 1349 1350Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result. 1351 1352**System capability**: SystemCapability.Multimedia.AVSession.Core 1353 1354**Parameters** 1355 1356| Name | Type | Mandatory| Description | 1357| -------- | ----------------------------------------------------------- | ---- | -------------------------- | 1358| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes | Callback used to return the session controller.| 1359 1360**Error codes** 1361 1362For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1363 1364| ID| Error Message| 1365| -------- | ---------------------------------------- | 1366| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1367| 6600102 | The session does not exist. | 1368 1369**Example** 1370 1371```ts 1372import { avSession } from '@kit.AVSessionKit'; 1373import { BusinessError } from '@kit.BasicServicesKit'; 1374 1375@Entry 1376@Component 1377struct Index { 1378 @State message: string = 'hello world'; 1379 1380 build() { 1381 Column() { 1382 Text(this.message) 1383 .onClick(async () => { 1384 let context: Context = this.getUIContext().getHostContext() as Context; 1385 let currentAVSession: avSession.AVSession = await avSession.createAVSession(context, 'SESSION_NAME', 'audio'); 1386 let avsessionController: avSession.AVSessionController; 1387 currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => { 1388 if (err) { 1389 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1390 } else { 1391 avsessionController = avcontroller; 1392 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1393 } 1394 }); 1395 }) 1396 } 1397 .width('100%') 1398 .height('100%') 1399 } 1400} 1401``` 1402 1403### getAVCastController<sup>10+</sup> 1404 1405getAVCastController(): Promise\<AVCastController> 1406 1407Obtains the cast controller when a casting connection is set up. This API uses a promise to return the result. If the session is not in the cast state, the controller returns **null**. 1408 1409**Atomic service API**: This API can be used in atomic services since API version 12. 1410 1411**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1412 1413**Return value** 1414 1415| Type | Description | 1416| --------- | ------------------------------------------------------------ | 1417| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller.| 1418 1419**Error codes** 1420 1421For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1422 1423| ID| Error Message| 1424| -------- | --------------------------------------- | 1425| 6600102| The session does not exist. | 1426| 6600109| The remote connection is not established. | 1427 1428**Example** 1429 1430```ts 1431import { BusinessError } from '@kit.BasicServicesKit'; 1432 1433let aVCastController: avSession.AVCastController; 1434currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => { 1435 aVCastController = avcontroller; 1436 console.info('getAVCastController : SUCCESS'); 1437}).catch((err: BusinessError) => { 1438 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1439}); 1440``` 1441 1442### getAVCastController<sup>10+</sup> 1443 1444getAVCastController(callback: AsyncCallback\<AVCastController>): void 1445 1446Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. If the session is not in the cast state, the controller returns **null**. 1447 1448**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1449 1450**Parameters** 1451 1452| Name | Type | Mandatory| Description | 1453| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1454| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller.| 1455 1456**Error codes** 1457 1458For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1459 1460| ID| Error Message | 1461| -------- |---------------------------------------| 1462| 6600102| The session does not exist. | 1463| 6600109| The remote connection is not established. | 1464 1465**Example** 1466 1467```ts 1468import { BusinessError } from '@kit.BasicServicesKit'; 1469 1470let aVCastController: avSession.AVCastController; 1471currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => { 1472 if (err) { 1473 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1474 } else { 1475 aVCastController = avcontroller; 1476 console.info('getAVCastController : SUCCESS'); 1477 } 1478}); 1479``` 1480 1481### getOutputDevice<sup>10+</sup> 1482 1483getOutputDevice(): Promise\<OutputDeviceInfo> 1484 1485Obtains information about the output device for this session. This API uses a promise to return the result. 1486 1487**Atomic service API**: This API can be used in atomic services since API version 12. 1488 1489**System capability**: SystemCapability.Multimedia.AVSession.Core 1490 1491**Return value** 1492 1493| Type | Description | 1494| ---------------------------------------------- | --------------------------------- | 1495| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.| 1496 1497**Error codes** 1498 1499For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1500 1501| ID| Error Message| 1502| -------- | ---------------------------------------- | 1503| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1504| 6600102 | The session does not exist. | 1505 1506**Example** 1507 1508```ts 1509import { BusinessError } from '@kit.BasicServicesKit'; 1510 1511currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => { 1512 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1513}).catch((err: BusinessError) => { 1514 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1515}) 1516``` 1517 1518### getOutputDevice<sup>10+</sup> 1519 1520getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 1521 1522Obtains information about the output device for this session. This API uses an asynchronous callback to return the result. 1523 1524**System capability**: SystemCapability.Multimedia.AVSession.Core 1525 1526**Parameters** 1527 1528| Name | Type | Mandatory| Description | 1529| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 1530| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| 1531 1532**Error codes** 1533 1534For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1535 1536| ID| Error Message| 1537| -------- | ---------------------------------------- | 1538| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1539| 6600102 | The session does not exist. | 1540 1541**Example** 1542 1543```ts 1544import { BusinessError } from '@kit.BasicServicesKit'; 1545 1546currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => { 1547 if (err) { 1548 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1549 } else { 1550 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1551 } 1552}); 1553``` 1554 1555### activate<sup>10+</sup> 1556 1557activate(): Promise\<void> 1558 1559Activates this session. A session can be used only after being activated. This API uses a promise to return the result. 1560 1561**Atomic service API**: This API can be used in atomic services since API version 12. 1562 1563**System capability**: SystemCapability.Multimedia.AVSession.Core 1564 1565**Return value** 1566 1567| Type | Description | 1568| -------------- | ----------------------------- | 1569| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.| 1570 1571**Error codes** 1572 1573For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1574 1575| ID| Error Message| 1576| -------- | ---------------------------------------- | 1577| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1578| 6600102 | The session does not exist. | 1579 1580**Example** 1581 1582```ts 1583import { BusinessError } from '@kit.BasicServicesKit'; 1584 1585currentAVSession.activate().then(() => { 1586 console.info('Activate : SUCCESS '); 1587}).catch((err: BusinessError) => { 1588 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1589}); 1590``` 1591 1592### activate<sup>10+</sup> 1593 1594activate(callback: AsyncCallback\<void>): void 1595 1596Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result. 1597 1598**System capability**: SystemCapability.Multimedia.AVSession.Core 1599 1600**Parameters** 1601 1602| Name | Type | Mandatory| Description | 1603| -------- | -------------------- | ---- | ---------- | 1604| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.| 1605 1606**Error codes** 1607 1608For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1609 1610| ID| Error Message| 1611| -------- | ---------------------------------------- | 1612| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1613| 6600102 | The session does not exist. | 1614 1615**Example** 1616 1617```ts 1618import { BusinessError } from '@kit.BasicServicesKit'; 1619 1620currentAVSession.activate((err: BusinessError) => { 1621 if (err) { 1622 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1623 } else { 1624 console.info('Activate : SUCCESS '); 1625 } 1626}); 1627``` 1628 1629### deactivate<sup>10+</sup> 1630 1631deactivate(): Promise\<void> 1632 1633Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result. 1634 1635**Atomic service API**: This API can be used in atomic services since API version 12. 1636 1637**System capability**: SystemCapability.Multimedia.AVSession.Core 1638 1639**Return value** 1640 1641| Type | Description | 1642| -------------- | ----------------------------- | 1643| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.| 1644 1645**Error codes** 1646 1647For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1648 1649| ID| Error Message| 1650| -------- | ---------------------------------------- | 1651| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1652| 6600102 | The session does not exist. | 1653 1654**Example** 1655 1656```ts 1657import { BusinessError } from '@kit.BasicServicesKit'; 1658 1659currentAVSession.deactivate().then(() => { 1660 console.info('Deactivate : SUCCESS '); 1661}).catch((err: BusinessError) => { 1662 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1663}); 1664``` 1665 1666### deactivate<sup>10+</sup> 1667 1668deactivate(callback: AsyncCallback\<void>): void 1669 1670Deactivates this session. This API uses an asynchronous callback to return the result. 1671 1672Deactivates this session. You can use [activate](#activate10) to activate the session again. 1673 1674**System capability**: SystemCapability.Multimedia.AVSession.Core 1675 1676**Parameters** 1677 1678| Name | Type | Mandatory| Description | 1679| -------- | -------------------- | ---- | ---------- | 1680| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.| 1681 1682**Error codes** 1683 1684For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1685 1686| ID| Error Message| 1687| -------- | ---------------------------------------- | 1688| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1689| 6600102 | The session does not exist. | 1690 1691**Example** 1692 1693```ts 1694import { BusinessError } from '@kit.BasicServicesKit'; 1695 1696currentAVSession.deactivate((err: BusinessError) => { 1697 if (err) { 1698 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1699 } else { 1700 console.info('Deactivate : SUCCESS '); 1701 } 1702}); 1703``` 1704 1705### destroy<sup>10+</sup> 1706 1707destroy(): Promise\<void> 1708 1709Destroys this session. This API uses a promise to return the result. 1710 1711**Atomic service API**: This API can be used in atomic services since API version 12. 1712 1713**System capability**: SystemCapability.Multimedia.AVSession.Core 1714 1715**Return value** 1716 1717| Type | Description | 1718| -------------- | ----------------------------- | 1719| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.| 1720 1721**Error codes** 1722 1723For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1724 1725| ID| Error Message| 1726| -------- | ---------------------------------------- | 1727| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1728| 6600102 | The session does not exist. | 1729 1730**Example** 1731 1732```ts 1733import { BusinessError } from '@kit.BasicServicesKit'; 1734 1735currentAVSession.destroy().then(() => { 1736 console.info('Destroy : SUCCESS '); 1737}).catch((err: BusinessError) => { 1738 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1739}); 1740``` 1741 1742### destroy<sup>10+</sup> 1743 1744destroy(callback: AsyncCallback\<void>): void 1745 1746Destroys this session. This API uses an asynchronous callback to return the result. 1747 1748**System capability**: SystemCapability.Multimedia.AVSession.Core 1749 1750**Parameters** 1751 1752| Name | Type | Mandatory| Description | 1753| -------- | -------------------- | ---- | ---------- | 1754| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| 1755 1756**Error codes** 1757 1758For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1759 1760| ID| Error Message| 1761| -------- | ---------------------------------------- | 1762| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1763| 6600102 | The session does not exist. | 1764 1765**Example** 1766 1767```ts 1768import { BusinessError } from '@kit.BasicServicesKit'; 1769 1770currentAVSession.destroy((err: BusinessError) => { 1771 if (err) { 1772 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1773 } else { 1774 console.info('Destroy : SUCCESS '); 1775 } 1776}); 1777``` 1778 1779### on('play')<sup>10+</sup> 1780 1781on(type: 'play', callback: () => void): void 1782 1783Subscribes to play command events. The subscription means that the application supports the play command. 1784 1785Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1786 1787**Atomic service API**: This API can be used in atomic services since API version 12. 1788 1789**System capability**: SystemCapability.Multimedia.AVSession.Core 1790 1791**Parameters** 1792 1793| Name | Type | Mandatory| Description | 1794| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1795| type | string | Yes | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.| 1796| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1797 1798**Error codes** 1799 1800For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1801 1802| ID| Error Message| 1803| -------- | ---------------------------------------- | 1804| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1805| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1806| 6600102 | The session does not exist. | 1807 1808**Example** 1809 1810```ts 1811currentAVSession.on('play', () => { 1812 console.info('on play entry'); 1813}); 1814``` 1815 1816### on('pause')<sup>10+</sup> 1817 1818on(type: 'pause', callback: () => void): void 1819 1820Subscribes to pause command events. The subscription means that the application supports the pause command. 1821 1822Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1823 1824**Atomic service API**: This API can be used in atomic services since API version 12. 1825 1826**System capability**: SystemCapability.Multimedia.AVSession.Core 1827 1828**Parameters** 1829 1830| Name | Type | Mandatory| Description | 1831| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1832| type | string | Yes | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.| 1833| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1834 1835**Error codes** 1836 1837For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1838 1839| ID| Error Message| 1840| -------- | ---------------------------------------- | 1841| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1842| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1843| 6600102 | The session does not exist. | 1844 1845**Example** 1846 1847```ts 1848currentAVSession.on('pause', () => { 1849 console.info('on pause entry'); 1850}); 1851``` 1852 1853### on('stop')<sup>10+</sup> 1854 1855on(type:'stop', callback: () => void): void 1856 1857Subscribes to stop command events. The subscription means that the application supports the stop command. 1858 1859Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1860 1861**Atomic service API**: This API can be used in atomic services since API version 12. 1862 1863**System capability**: SystemCapability.Multimedia.AVSession.Core 1864 1865**Parameters** 1866 1867| Name | Type | Mandatory| Description | 1868| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1869| type | string | Yes | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.| 1870| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1871 1872**Error codes** 1873 1874For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1875 1876| ID| Error Message| 1877| -------- | ---------------------------------------- | 1878| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1879| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1880| 6600102 | The session does not exist. | 1881 1882**Example** 1883 1884```ts 1885currentAVSession.on('stop', () => { 1886 console.info('on stop entry'); 1887}); 1888``` 1889 1890### on('playNext')<sup>10+</sup> 1891 1892on(type:'playNext', callback: () => void): void 1893 1894Subscribes to playNext command events. The subscription means that the application supports the playNext command. 1895 1896Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1897 1898**Atomic service API**: This API can be used in atomic services since API version 12. 1899 1900**System capability**: SystemCapability.Multimedia.AVSession.Core 1901 1902**Parameters** 1903 1904| Name | Type | Mandatory| Description | 1905| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1906| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.| 1907| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1908 1909**Error codes** 1910 1911For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1912 1913| ID| Error Message| 1914| -------- | ---------------------------------------- | 1915| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1916| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1917| 6600102 | The session does not exist. | 1918 1919**Example** 1920 1921```ts 1922currentAVSession.on('playNext', () => { 1923 console.info('on playNext entry'); 1924}); 1925``` 1926 1927### on('playPrevious')<sup>10+</sup> 1928 1929on(type:'playPrevious', callback: () => void): void 1930 1931Subscribes to playPrevious command events. The subscription means that the application supports the playPrevious command. 1932 1933Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1934 1935**Atomic service API**: This API can be used in atomic services since API version 12. 1936 1937**System capability**: SystemCapability.Multimedia.AVSession.Core 1938 1939**Parameters** 1940 1941| Name | Type | Mandatory| Description | 1942| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1943| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.| 1944| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1945 1946**Error codes** 1947 1948For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1949 1950| ID| Error Message| 1951| -------- | ---------------------------------------- | 1952| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1953| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1954| 6600102 | The session does not exist. | 1955 1956**Example** 1957 1958```ts 1959currentAVSession.on('playPrevious', () => { 1960 console.info('on playPrevious entry'); 1961}); 1962``` 1963 1964### on('fastForward')<sup>10+</sup> 1965 1966on(type: 'fastForward', callback: (time?: number) => void): void 1967 1968Subscribes to fastForward command events. The subscription means that the application supports the fastForward command. 1969 1970Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1971 1972**Atomic service API**: This API can be used in atomic services since API version 12. 1973 1974**System capability**: SystemCapability.Multimedia.AVSession.Core 1975 1976**Parameters** 1977 1978| Name | Type | Mandatory| Description | 1979| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1980| type | string | Yes | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.| 1981| callback | (time?: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds. | 1982 1983**Error codes** 1984 1985For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1986 1987| ID| Error Message| 1988| -------- | ---------------------------------------- | 1989| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1990| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 1991| 6600102 | The session does not exist. | 1992 1993**Example** 1994 1995```ts 1996currentAVSession.on('fastForward', (time?: number) => { 1997 console.info('on fastForward entry'); 1998}); 1999``` 2000 2001### on('rewind')<sup>10+</sup> 2002 2003on(type:'rewind', callback: (time?: number) => void): void 2004 2005Subscribes to rewind command events. 2006 2007**Atomic service API**: This API can be used in atomic services since API version 12. 2008 2009**System capability**: SystemCapability.Multimedia.AVSession.Core 2010 2011**Parameters** 2012 2013| Name | Type | Mandatory| Description | 2014| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2015| type | string | Yes | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.| 2016| callback | (time?: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds. | 2017 2018**Error codes** 2019 2020For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2021 2022| ID| Error Message| 2023| -------- | ---------------------------------------- | 2024| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2025| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2026| 6600102 | The session does not exist. | 2027 2028**Example** 2029 2030```ts 2031currentAVSession.on('rewind', (time?: number) => { 2032 console.info('on rewind entry'); 2033}); 2034``` 2035 2036### on('playFromAssetId')<sup>(deprecated)</sup> 2037 2038on(type:'playFromAssetId', callback: (assetId: number) => void): void 2039 2040Subscribes to playback events with a given media asset ID. 2041 2042> **NOTE** 2043> 2044> This API is supported since API version 11 and deprecated since API version 20. You are advised to use [on('playWithAssetId')](#onplaywithassetid20) instead. 2045 2046**Atomic service API**: This API can be used in atomic services since API version 12. 2047 2048**System capability**: SystemCapability.Multimedia.AVSession.Core 2049 2050**Parameters** 2051 2052| Name | Type | Mandatory| Description | 2053| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2054| type | string | Yes | Event type. The event **'playFromAssetId'** is triggered when the media asset ID is played.| 2055| callback | (assetId: number) => void | Yes | Callback The **assetId** parameter in the callback indicates the media asset ID. | 2056 2057**Error codes** 2058 2059For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2060 2061| ID| Error Message| 2062| -------- | ---------------------------------------- | 2063| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2064| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2065| 6600102 | The session does not exist. | 2066 2067**Example** 2068 2069```ts 2070currentAVSession.on('playFromAssetId', (assetId: number) => { 2071 console.info('on playFromAssetId entry'); 2072}); 2073``` 2074 2075### off('playFromAssetId')<sup>(deprecated)</sup> 2076 2077off(type: 'playFromAssetId', callback?: (assetId: number) => void): void 2078 2079Unsubscribes from playback events with a given media asset ID. 2080 2081> **NOTE** 2082> 2083> This API is supported since API version 11 and deprecated since API version 20. You are advised to use [off('playWithAssetId')](#offplaywithassetid20) instead. 2084 2085**Atomic service API**: This API can be used in atomic services since API version 12. 2086 2087**System capability**: SystemCapability.Multimedia.AVSession.Core 2088 2089**Parameters** 2090 2091| Name | Type | Mandatory| Description | 2092| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2093| type | string | Yes | Event type, which is **'playFromAssetId'** in this case.| 2094| callback | (assetId: number) => 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. The **assetId** parameter in the callback indicates the media asset ID. | 2095 2096**Error codes** 2097 2098For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2099 2100| ID| Error Message| 2101| -------- | ---------------------------------------- | 2102| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2103| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2104| 6600102 | The session does not exist. | 2105 2106**Example** 2107 2108```ts 2109currentAVSession.off('playFromAssetId'); 2110``` 2111 2112### on('playWithAssetId')<sup>20+</sup> 2113 2114on(type:'playWithAssetId', callback: Callback\<string>): void 2115 2116Subscribes to playback events with a given media asset ID. 2117 2118**Atomic service API**: This API can be used in atomic services since API version 20. 2119 2120**System capability**: SystemCapability.Multimedia.AVSession.Core 2121 2122**Parameters** 2123 2124| Name | Type | Mandatory| Description | 2125| -------- | -------------------- | ---- | ------------------------------------------------------------ | 2126| type | string | Yes | Event type. The event **'playWithAssetId'** is triggered when the media asset ID is played.| 2127| callback | Callback\<string> | Yes | Callback The **assetId** parameter in the callback indicates the media asset ID. | 2128 2129**Error codes** 2130 2131For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2132 2133| ID| Error Message| 2134| -------- | ---------------------------------------- | 2135| 6600101 | Session service exception. | 2136| 6600102 | The session does not exist. | 2137 2138**Example** 2139 2140```ts 2141let playWithAssetIdCallback = (assetId: string) => { 2142 console.info(`on playWithAssetId entry, assetId = ${assetId}`); 2143} 2144currentAVSession.on('playWithAssetId', playWithAssetIdCallback); 2145``` 2146 2147 2148### off('playWithAssetId')<sup>20+</sup> 2149 2150off(type: 'playWithAssetId', callback?: Callback\<string>): void 2151 2152Unsubscribes from playback events with a given media asset ID. 2153 2154**Atomic service API**: This API can be used in atomic services since API version 20. 2155 2156**System capability**: SystemCapability.Multimedia.AVSession.Core 2157 2158**Parameters** 2159 2160| Name | Type | Mandatory| Description | 2161| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2162| type | string | Yes | Event type, which is **'playWithAssetId'** in this case.| 2163| callback | Callback\<string> | 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. The **assetId** parameter in the callback indicates the media asset ID. | 2164 2165**Error codes** 2166 2167For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2168 2169| ID| Error Message| 2170| -------- | ---------------------------------------- | 2171| 6600101 | Session service exception. | 2172| 6600102 | The session does not exist. | 2173 2174**Example** 2175 2176```ts 2177currentAVSession.off('playWithAssetId'); 2178``` 2179 2180### on('seek')<sup>10+</sup> 2181 2182on(type: 'seek', callback: (time: number) => void): void 2183 2184Subscribes to seek command events. 2185 2186**Atomic service API**: This API can be used in atomic services since API version 12. 2187 2188**System capability**: SystemCapability.Multimedia.AVSession.Core 2189 2190**Parameters** 2191 2192| Name | Type | Mandatory| Description | 2193| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 2194| type | string | Yes | Event type. The event **'seek'** is triggered when the seek command is sent to the session.| 2195| callback | (time: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds. | 2196 2197**Error codes** 2198 2199For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2200 2201| ID| Error Message| 2202| -------- | ---------------------------------------- | 2203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2204| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2205| 6600102 | The session does not exist. | 2206 2207**Example** 2208 2209```ts 2210currentAVSession.on('seek', (time: number) => { 2211 console.info(`on seek entry time : ${time}`); 2212}); 2213``` 2214 2215### on('setSpeed')<sup>10+</sup> 2216 2217on(type: 'setSpeed', callback: (speed: number) => void): void 2218 2219Subscribes to setSpeed command events. 2220 2221**Atomic service API**: This API can be used in atomic services since API version 12. 2222 2223**System capability**: SystemCapability.Multimedia.AVSession.Core 2224 2225**Parameters** 2226 2227| Name | Type | Mandatory| Description | 2228| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 2229| type | string | Yes | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.| 2230| callback | (speed: number) => void | Yes | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed. | 2231 2232**Error codes** 2233 2234For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2235 2236| ID| Error Message| 2237| -------- | ---------------------------------------- | 2238| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2239| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2240| 6600102 | The session does not exist. | 2241 2242**Example** 2243 2244```ts 2245currentAVSession.on('setSpeed', (speed: number) => { 2246 console.info(`on setSpeed speed : ${speed}`); 2247}); 2248``` 2249 2250### on('setLoopMode')<sup>10+</sup> 2251 2252on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void 2253 2254Subscribes to setLoopMode command events. 2255 2256**Atomic service API**: This API can be used in atomic services since API version 12. 2257 2258**System capability**: SystemCapability.Multimedia.AVSession.Core 2259 2260**Parameters** 2261 2262| Name | Type | Mandatory| Description | 2263| -------- | ------------------------------------- | ---- | ---- | 2264| type | string | Yes | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.| 2265| callback | (mode: [LoopMode](#loopmode10)) => void | Yes | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode. | 2266 2267**Error codes** 2268 2269For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2270 2271| ID| Error Message| 2272| -------- | ---------------------------------------- | 2273| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2274| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2275| 6600102 | The session does not exist. | 2276 2277**Example** 2278 2279```ts 2280currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => { 2281 console.info(`on setLoopMode mode : ${mode}`); 2282}); 2283``` 2284 2285### on('setTargetLoopMode')<sup>18+</sup> 2286 2287on(type: 'setTargetLoopMode', callback: Callback\<LoopMode>): void 2288 2289Subscribes to setTargetLoopMode command events. 2290 2291**Atomic service API**: This API can be used in atomic services since API version 18. 2292 2293**System capability**: SystemCapability.Multimedia.AVSession.Core 2294 2295**Parameters** 2296 2297| Name | Type | Mandatory| Description | 2298| -------- | ------------------------------------- | ---- | ---- | 2299| type | string | Yes | Event type. The event **'setTargetLoopMode'**<br>is triggered when the command for setting the target loop mode is sent to the session.| 2300| callback | Callback<[LoopMode](#loopmode10)> | Yes | Callback used for subscription. The **LoopMode** parameter in the callback indicates the target loop mode. | 2301 2302**Error codes** 2303 2304For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [AVSession Error Codes](errorcode-avsession.md). 2305 2306| ID| Error Message| 2307| -------- | ---------------------------------------- | 2308| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2309| 6600102 | The session does not exist. | 2310 2311**Example** 2312 2313```ts 2314currentAVSession.on('setTargetLoopMode', (mode: avSession.LoopMode) => { 2315 console.info(`on setTargetLoopMode mode : ${mode}`); 2316}); 2317``` 2318 2319### on('toggleFavorite')<sup>10+</sup> 2320 2321on(type: 'toggleFavorite', callback: (assetId: string) => void): void 2322 2323Subscribes to toggleFavorite command events. 2324 2325**Atomic service API**: This API can be used in atomic services since API version 12. 2326 2327**System capability**: SystemCapability.Multimedia.AVSession.Core 2328 2329**Parameters** 2330 2331| Name | Type | Mandatory| Description | 2332| -------- | ------------------------- | ---- | ------------------------------------------------------------ | 2333| type | string | Yes | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.| 2334| callback | (assetId: string) => void | Yes | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID. | 2335 2336**Error codes** 2337 2338For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2339 2340| ID| Error Message| 2341| -------- | ---------------------------------------- | 2342| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2343| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2344| 6600102 | The session does not exist. | 2345 2346**Example** 2347 2348```ts 2349currentAVSession.on('toggleFavorite', (assetId: string) => { 2350 console.info(`on toggleFavorite mode : ${assetId}`); 2351}); 2352``` 2353 2354### on('skipToQueueItem')<sup>10+</sup> 2355 2356on(type: 'skipToQueueItem', callback: (itemId: number) => void): void 2357 2358Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item. 2359 2360**Atomic service API**: This API can be used in atomic services since API version 12. 2361 2362**System capability**: SystemCapability.Multimedia.AVSession.Core 2363 2364**Parameters** 2365 2366| Name | Type | Mandatory| Description | 2367| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | 2368| type | string | Yes | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.| 2369| callback | (itemId: number) => void | Yes | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item. | 2370 2371**Error codes** 2372 2373For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2374 2375| ID| Error Message| 2376| -------- | ---------------------------------------- | 2377| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2378| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2379| 6600102 | The session does not exist. | 2380 2381**Example** 2382 2383```ts 2384currentAVSession.on('skipToQueueItem', (itemId: number) => { 2385 console.info(`on skipToQueueItem id : ${itemId}`); 2386}); 2387``` 2388 2389### on('handleKeyEvent')<sup>10+</sup> 2390 2391on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void 2392 2393Subscribes to key events of external devices such as Bluetooth and wired devices to listen for the play, pause, previous, next, fast-forward, and rewind commands in the key events. 2394 2395**Atomic service API**: This API can be used in atomic services since API version 12. 2396 2397**System capability**: SystemCapability.Multimedia.AVSession.Core 2398 2399**Parameters** 2400 2401| Name | Type | Mandatory| Description | 2402| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2403| type | string | Yes | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.| 2404| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | Yes | Callback used for subscription. The **event** parameter in the callback indicates the key event. | 2405 2406**Error codes** 2407 2408For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2409 2410| ID| Error Message| 2411| -------- | ---------------------------------------- | 2412| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2413| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2414| 6600102 | The session does not exist. | 2415 2416**Example** 2417 2418```ts 2419import { KeyEvent } from '@kit.InputKit'; 2420 2421currentAVSession.on('handleKeyEvent', (event: KeyEvent) => { 2422 console.info(`on handleKeyEvent event : ${event}`); 2423}); 2424 2425``` 2426 2427### on('outputDeviceChange')<sup>10+</sup> 2428 2429on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2430 2431Subscribes to output device change events. After the application integrates the [AVCastPicker component](ohos-multimedia-avcastpicker.md), the application receives the device change callback when the user switches the device through the component. 2432 2433**Atomic service API**: This API can be used in atomic services since API version 12. 2434 2435**System capability**: SystemCapability.Multimedia.AVSession.Core 2436 2437**Parameters** 2438 2439| Name | Type | Mandatory| Description | 2440| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2441| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| 2442| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback function, where the **device** parameter specifies the output device information.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 2443 2444**Error codes** 2445 2446For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2447 2448| ID| Error Message| 2449| -------- | ---------------------------------------- | 2450| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2451| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2452| 6600102 | The session does not exist. | 2453 2454**Example** 2455 2456```ts 2457currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 2458 console.info(`on outputDeviceChange device : ${device}`); 2459}); 2460``` 2461 2462### on('commonCommand')<sup>10+</sup> 2463 2464on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void 2465 2466Subscribes to custom control command change events. 2467 2468**Atomic service API**: This API can be used in atomic services since API version 12. 2469 2470**System capability**: SystemCapability.Multimedia.AVSession.Core 2471 2472**Parameters** 2473 2474| Name | Type | Mandatory| Description | 2475| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2476| type | string | Yes | Event type. The event **'commonCommand'** is triggered when a custom control command changes.| 2477| callback | (command: string, args: {[key: string]: Object}) => void | Yes | Callback used for subscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command. The parameters must be the same as those set in [sendCommonCommand](#sendcommoncommand10). | 2478 2479**Error codes** 2480 2481For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2482 2483| ID| Error Message| 2484| -------- | ------------------------------ | 2485| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2486| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2487| 6600102 | The session does not exist. | 2488 2489**Example** 2490 2491```ts 2492import { BusinessError } from '@kit.BasicServicesKit'; 2493import { avSession } from '@kit.AVSessionKit'; 2494@Entry 2495@Component 2496struct Index { 2497 @State message: string = 'hello world'; 2498 2499 build() { 2500 Column() { 2501 Text(this.message) 2502 .onClick(()=>{ 2503 let currentAVSession: avSession.AVSession | undefined = undefined; 2504 let tag = "createNewSession"; 2505 let context: Context = this.getUIContext().getHostContext() as Context; 2506 2507 avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 2508 if (err) { 2509 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 2510 } else { 2511 currentAVSession = data; 2512 } 2513 }); 2514 if (currentAVSession !== undefined) { 2515 (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => { 2516 console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); 2517 }); 2518 } 2519 }) 2520 } 2521 .width('100%') 2522 .height('100%') 2523 } 2524} 2525``` 2526 2527### off('play')<sup>10+</sup> 2528 2529off(type: 'play', callback?: () => void): void 2530 2531Unsubscribes from play command events. 2532 2533After the callback is canceled, the list of supported commands must be updated. 2534 2535**Atomic service API**: This API can be used in atomic services since API version 12. 2536 2537**System capability**: SystemCapability.Multimedia.AVSession.Core 2538 2539**Parameters** 2540 2541| Name | Type | Mandatory| Description | 2542| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2543| type | string | Yes | Event type, which is **'play'** in this case.| 2544| 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. | 2545 2546**Error codes** 2547 2548For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2549 2550| ID| Error Message| 2551| -------- | ---------------------------------------- | 2552| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2553| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2554| 6600102 | The session does not exist. | 2555 2556**Example** 2557 2558```ts 2559currentAVSession.off('play'); 2560``` 2561 2562### off('pause')<sup>10+</sup> 2563 2564off(type: 'pause', callback?: () => void): void 2565 2566Unsubscribes from pause command events. 2567 2568After the callback is canceled, the list of supported commands must be updated. 2569 2570**Atomic service API**: This API can be used in atomic services since API version 12. 2571 2572**System capability**: SystemCapability.Multimedia.AVSession.Core 2573 2574**Parameters** 2575 2576| Name | Type | Mandatory| Description | 2577| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2578| type | string | Yes | Event type, which is **'pause'** in this case.| 2579| 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.| 2580 2581**Error codes** 2582 2583For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2584 2585| ID| Error Message| 2586| -------- | ---------------------------------------- | 2587| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2588| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2589| 6600102 | The session does not exist. | 2590 2591**Example** 2592 2593```ts 2594currentAVSession.off('pause'); 2595``` 2596 2597### off('stop')<sup>10+</sup> 2598 2599off(type: 'stop', callback?: () => void): void 2600 2601Unsubscribes from stop command events. 2602 2603After the callback is canceled, the list of supported commands must be updated. 2604 2605**Atomic service API**: This API can be used in atomic services since API version 12. 2606 2607**System capability**: SystemCapability.Multimedia.AVSession.Core 2608 2609**Parameters** 2610 2611| Name | Type | Mandatory| Description | 2612| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2613| type | string | Yes | Event type, which is **'stop'** in this case.| 2614| 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. | 2615 2616**Error codes** 2617 2618For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2619 2620| ID| Error Message| 2621| -------- | ---------------------------------------- | 2622| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2623| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2624| 6600102 | The session does not exist. | 2625 2626**Example** 2627 2628```ts 2629currentAVSession.off('stop'); 2630``` 2631 2632### off('playNext')<sup>10+</sup> 2633 2634off(type: 'playNext', callback?: () => void): void 2635 2636Unsubscribes from playNext command events. 2637 2638After the callback is canceled, the list of supported commands must be updated. 2639 2640**Atomic service API**: This API can be used in atomic services since API version 12. 2641 2642**System capability**: SystemCapability.Multimedia.AVSession.Core 2643 2644**Parameters** 2645 2646| Name | Type | Mandatory| Description | 2647| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2648| type | string | Yes | Event type, which is **'playNext'** in this case.| 2649| 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. | 2650 2651**Error codes** 2652 2653For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2654 2655| ID| Error Message| 2656| -------- | ---------------------------------------- | 2657| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2658| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2659| 6600102 | The session does not exist. | 2660 2661**Example** 2662 2663```ts 2664currentAVSession.off('playNext'); 2665``` 2666 2667### off('playPrevious')<sup>10+</sup> 2668 2669off(type: 'playPrevious', callback?: () => void): void 2670 2671Unsubscribes from playPrevious command events. 2672 2673After the callback is canceled, the list of supported commands must be updated. 2674 2675**Atomic service API**: This API can be used in atomic services since API version 12. 2676 2677**System capability**: SystemCapability.Multimedia.AVSession.Core 2678 2679**Parameters** 2680 2681| Name | Type | Mandatory| Description | 2682| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2683| type | string | Yes | Event type, which is **'playPrevious'** in this case.| 2684| 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. | 2685 2686**Error codes** 2687 2688For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2689 2690| ID| Error Message| 2691| -------- | ---------------------------------------- | 2692| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2693| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2694| 6600102 | The session does not exist. | 2695 2696**Example** 2697 2698```ts 2699currentAVSession.off('playPrevious'); 2700``` 2701 2702### off('fastForward')<sup>10+</sup> 2703 2704off(type: 'fastForward', callback?: () => void): void 2705 2706Unsubscribes from fastForward command events. 2707 2708After the callback is canceled, the list of supported commands must be updated. 2709 2710**Atomic service API**: This API can be used in atomic services since API version 12. 2711 2712**System capability**: SystemCapability.Multimedia.AVSession.Core 2713 2714**Parameters** 2715 2716| Name | Type | Mandatory| Description | 2717| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2718| type | string | Yes | Event type, which is **'fastForward'** in this case.| 2719| 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. | 2720 2721**Error codes** 2722 2723For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2724 2725| ID| Error Message| 2726| -------- | ---------------------------------------- | 2727| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2728| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2729| 6600102 | The session does not exist. | 2730 2731**Example** 2732 2733```ts 2734currentAVSession.off('fastForward'); 2735``` 2736 2737### off('rewind')<sup>10+</sup> 2738 2739off(type: 'rewind', callback?: () => void): void 2740 2741Unsubscribes from rewind command events. 2742 2743**Atomic service API**: This API can be used in atomic services since API version 12. 2744 2745**System capability**: SystemCapability.Multimedia.AVSession.Core 2746 2747**Parameters** 2748 2749| Name | Type | Mandatory| Description | 2750| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2751| type | string | Yes | Event type, which is **'rewind'** in this case.| 2752| 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. | 2753 2754**Error codes** 2755 2756For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2757 2758| ID| Error Message| 2759| -------- | ---------------------------------------- | 2760| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2761| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2762| 6600102 | The session does not exist. | 2763 2764**Example** 2765 2766```ts 2767currentAVSession.off('rewind'); 2768``` 2769 2770### off('seek')<sup>10+</sup> 2771 2772off(type: 'seek', callback?: (time: number) => void): void 2773 2774Unsubscribes from seek command events. 2775 2776**Atomic service API**: This API can be used in atomic services since API version 12. 2777 2778**System capability**: SystemCapability.Multimedia.AVSession.Core 2779 2780**Parameters** 2781 2782| Name | Type | Mandatory| Description | 2783| -------- | ---------------------- | ---- | ----------------------------------------- | 2784| type | string | Yes | Event type, which is **'seek'** in this case. | 2785| callback | (time: number) => void | No | Callback used for unsubscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.<br>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. | 2786 2787**Error codes** 2788 2789For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2790 2791| ID| Error Message| 2792| -------- | ---------------------------------------- | 2793| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2794| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2795| 6600102 | The session does not exist. | 2796 2797**Example** 2798 2799```ts 2800currentAVSession.off('seek'); 2801``` 2802 2803### off('setSpeed')<sup>10+</sup> 2804 2805off(type: 'setSpeed', callback?: (speed: number) => void): void 2806 2807Unsubscribes from setSpeed command events. 2808 2809**Atomic service API**: This API can be used in atomic services since API version 12. 2810 2811**System capability**: SystemCapability.Multimedia.AVSession.Core 2812 2813**Parameters** 2814 2815| Name | Type | Mandatory| Description | 2816| -------- | ----------------------- | ---- | -------------------------------------------| 2817| type | string | Yes | Event type, which is **'setSpeed'** in this case. | 2818| callback | (speed: number) => void | No | Callback used for unsubscription. The **speed** parameter in the callback indicates the playback speed.<br>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. | 2819 2820**Error codes** 2821 2822For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2823 2824| ID| Error Message| 2825| -------- | ---------------------------------------- | 2826| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2827| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2828| 6600102 | The session does not exist. | 2829 2830**Example** 2831 2832```ts 2833currentAVSession.off('setSpeed'); 2834``` 2835 2836### off('setLoopMode')<sup>10+</sup> 2837 2838off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void 2839 2840Unsubscribes from setLoopMode command events. 2841 2842**Atomic service API**: This API can be used in atomic services since API version 12. 2843 2844**System capability**: SystemCapability.Multimedia.AVSession.Core 2845 2846**Parameters** 2847 2848| Name | Type | Mandatory| Description | 2849| -------- | ------------------------------------- | ---- | ----- | 2850| type | string | Yes | Event type, which is **'setLoopMode'** in this case.| 2851| callback | (mode: [LoopMode](#loopmode10)) => void | No | Callback used for unsubscription. The **mode** parameter in the callback indicates the loop mode.<br>- 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.| 2852 2853**Error codes** 2854 2855For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2856 2857| ID| Error Message| 2858| -------- | ---------------------------------------- | 2859| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2860| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2861| 6600102 | The session does not exist. | 2862 2863**Example** 2864 2865```ts 2866currentAVSession.off('setLoopMode'); 2867``` 2868 2869### off('setTargetLoopMode')<sup>18+</sup> 2870 2871off(type: 'setTargetLoopMode', callback?: Callback\<LoopMode>): void 2872 2873Unsubscribes from setTargetLoopMode command events. 2874 2875**Atomic service API**: This API can be used in atomic services since API version 18. 2876 2877**System capability**: SystemCapability.Multimedia.AVSession.Core 2878 2879**Parameters** 2880 2881| Name | Type | Mandatory| Description | 2882| -------- | ------------------------------------- | ---- | ----- | 2883| type | string | Yes | Event type, which is **'setTargetLoopMode'** in this case.| 2884| callback | Callback<[LoopMode](#loopmode10)> | No | Callback used for unsubscription. The **LoopMode** parameter in the callback indicates the target loop mode.<br>- 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.| 2885 2886**Error codes** 2887 2888For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [AVSession Error Codes](errorcode-avsession.md). 2889 2890| ID| Error Message| 2891| -------- | ---------------------------------------- | 2892| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2893| 6600102 | The session does not exist. | 2894 2895**Example** 2896 2897```ts 2898currentAVSession.off('setTargetLoopMode'); 2899``` 2900 2901### off('toggleFavorite')<sup>10+</sup> 2902 2903off(type: 'toggleFavorite', callback?: (assetId: string) => void): void 2904 2905Unsubscribes from toggleFavorite command events. 2906 2907**Atomic service API**: This API can be used in atomic services since API version 12. 2908 2909**System capability**: SystemCapability.Multimedia.AVSession.Core 2910 2911**Parameters** 2912 2913| Name | Type | Mandatory| Description | 2914| -------- | ------------------------- | ---- | -------------------------------------------------------- | 2915| type | string | Yes | Event type, which is **'toggleFavorite'** in this case. | 2916| callback | (assetId: string) => void | No | Callback used for unsubscription. The **assetId** parameter in the callback indicates the media asset ID.<br>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. | 2917 2918**Error codes** 2919 2920For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2921 2922| ID| Error Message| 2923| -------- | ---------------------------------------- | 2924| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2925| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2926| 6600102 | The session does not exist. | 2927 2928**Example** 2929 2930```ts 2931currentAVSession.off('toggleFavorite'); 2932``` 2933 2934### off('skipToQueueItem')<sup>10+</sup> 2935 2936off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void 2937 2938Unsubscribes from the event that indicates an item in the playlist is selected. 2939 2940**Atomic service API**: This API can be used in atomic services since API version 12. 2941 2942**System capability**: SystemCapability.Multimedia.AVSession.Core 2943 2944**Parameters** 2945 2946| Name | Type | Mandatory| Description | 2947| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | 2948| type | string | Yes | Event type, which is **'skipToQueueItem'** in this case. | 2949| callback | (itemId: number) => void | No | Callback used for unsubscription. The **itemId** parameter in the callback indicates the ID of the item.<br>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.| 2950 2951**Error codes** 2952 2953For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2954 2955| ID| Error Message| 2956| -------- | ---------------------------------------- | 2957| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2958| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2959| 6600102 | The session does not exist. | 2960 2961**Example** 2962 2963```ts 2964currentAVSession.off('skipToQueueItem'); 2965``` 2966 2967### off('handleKeyEvent')<sup>10+</sup> 2968 2969off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void 2970 2971Unsubscribes from key events. 2972 2973**Atomic service API**: This API can be used in atomic services since API version 12. 2974 2975**System capability**: SystemCapability.Multimedia.AVSession.Core 2976 2977**Parameters** 2978 2979| Name | Type | Mandatory| Description | 2980| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2981| type | string | Yes | Event type, which is **'handleKeyEvent'** in this case. | 2982| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | No | Callback used for unsubscription. The **event** parameter in the callback indicates the key event.<br>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. | 2983 2984**Error codes** 2985 2986For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2987 2988| ID| Error Message| 2989| -------- | ---------------------------------------- | 2990| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2991| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 2992| 6600102 | The session does not exist. | 2993 2994**Example** 2995 2996```ts 2997currentAVSession.off('handleKeyEvent'); 2998``` 2999 3000### off('outputDeviceChange')<sup>10+</sup> 3001 3002off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 3003 3004Unsubscribes from playback device change events. 3005 3006**Atomic service API**: This API can be used in atomic services since API version 12. 3007 3008**System capability**: SystemCapability.Multimedia.AVSession.Core 3009 3010**Parameters** 3011 3012| Name | Type | Mandatory| Description | 3013| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 3014| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | 3015| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback function, where the **device** parameter specifies the output device information.<br>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. | 3016 3017**Error codes** 3018 3019For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3020 3021| ID| Error Message| 3022| -------- | ---------------------------------------- | 3023| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3024| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3025| 6600102 | The session does not exist. | 3026 3027**Example** 3028 3029```ts 3030currentAVSession.off('outputDeviceChange'); 3031``` 3032 3033 3034### off('commonCommand')<sup>10+</sup> 3035 3036off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void 3037 3038Unsubscribes from custom control command change events. 3039 3040**Atomic service API**: This API can be used in atomic services since API version 12. 3041 3042**System capability**: SystemCapability.Multimedia.AVSession.Core 3043 3044**Parameters** 3045 3046| Name | Type | Mandatory| Description | 3047| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 3048| type | string | Yes | Event type, which is **'commonCommand'** in this case. | 3049| callback | (command: string, args: {[key:string]: Object}) => void | No | Callback used for unsubscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 3050 3051**Error codes** 3052 3053For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3054 3055| ID| Error Message| 3056| -------- | ---------------- | 3057| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3058| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3059| 6600102 | The session does not exist. | 3060 3061**Example** 3062 3063```ts 3064currentAVSession.off('commonCommand'); 3065``` 3066 3067### on('answer')<sup>11+</sup> 3068 3069on(type: 'answer', callback: Callback\<void>): void 3070 3071Subscribes to call answer events. 3072 3073**Atomic service API**: This API can be used in atomic services since API version 12. 3074 3075**System capability**: SystemCapability.Multimedia.AVSession.Core 3076 3077**Parameters** 3078 3079| Name | Type | Mandatory| Description | 3080| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3081| type | string | Yes | Event type. The event **'answer'** is triggered when a call is answered.| 3082| callback | Callback\<void> | Yes | Callback used to return the result. | 3083 3084**Error codes** 3085 3086For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3087 3088| ID| Error Message| 3089| -------- | ------------------------------ | 3090| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3091| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3092| 6600102 | The session does not exist. | 3093 3094**Example** 3095 3096```ts 3097currentAVSession.on('answer', () => { 3098 console.info('on call answer'); 3099}); 3100``` 3101 3102### off('answer')<sup>11+</sup> 3103 3104off(type: 'answer', callback?: Callback\<void>): void 3105 3106Unsubscribes from call answer events. 3107 3108**Atomic service API**: This API can be used in atomic services since API version 12. 3109 3110**System capability**: SystemCapability.Multimedia.AVSession.Core 3111 3112**Parameters** 3113 3114| Name | Type | Mandatory| Description | 3115| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3116| type | string | Yes | Event type, which is **'answer'** in this case.| 3117| 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. | 3118 3119**Error codes** 3120 3121For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3122 3123| ID| Error Message| 3124| -------- | ---------------------------------------- | 3125| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3126| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3127| 6600102 | The session does not exist. | 3128 3129**Example** 3130 3131```ts 3132currentAVSession.off('answer'); 3133``` 3134 3135### on('hangUp')<sup>11+</sup> 3136 3137on(type: 'hangUp', callback: Callback\<void>): void 3138 3139Subscribes to call hangup events. 3140 3141**Atomic service API**: This API can be used in atomic services since API version 12. 3142 3143**System capability**: SystemCapability.Multimedia.AVSession.Core 3144 3145**Parameters** 3146 3147| Name | Type | Mandatory| Description | 3148| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3149| type | string | Yes | Event type. The event **'hangUp'** is triggered when a call is hung up.| 3150| callback | Callback\<void> | Yes | Callback used to return the result. | 3151 3152**Error codes** 3153 3154For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3155 3156| ID| Error Message| 3157| -------- | ------------------------------ | 3158| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3159| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3160| 6600102 | The session does not exist. | 3161 3162**Example** 3163 3164```ts 3165currentAVSession.on('hangUp', () => { 3166 console.info('on call hangUp'); 3167}); 3168``` 3169 3170### off('hangUp')<sup>11+</sup> 3171 3172off(type: 'hangUp', callback?: Callback\<void>): void 3173 3174Unsubscribes from call answer events. 3175 3176**Atomic service API**: This API can be used in atomic services since API version 12. 3177 3178**System capability**: SystemCapability.Multimedia.AVSession.Core 3179 3180**Parameters** 3181 3182| Name | Type | Mandatory| Description | 3183| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3184| type | string | Yes | Event type, which is **'hangUp'** in this case.| 3185| 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. | 3186 3187**Error codes** 3188 3189For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3190 3191| ID| Error Message| 3192| -------- | ---------------------------------------- | 3193| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3194| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3195| 6600102 | The session does not exist. | 3196 3197**Example** 3198 3199```ts 3200currentAVSession.off('hangUp'); 3201``` 3202 3203### on('toggleCallMute')<sup>11+</sup> 3204 3205on(type: 'toggleCallMute', callback: Callback\<void>): void 3206 3207Subscribes to call mute events. 3208 3209**Atomic service API**: This API can be used in atomic services since API version 12. 3210 3211**System capability**: SystemCapability.Multimedia.AVSession.Core 3212 3213**Parameters** 3214 3215| Name | Type | Mandatory| Description | 3216| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3217| type | string | Yes | Event type. The event **'toggleCallMute'** is triggered when a call is muted or unmuted.| 3218| callback | Callback\<void> | Yes | Callback used to return the result. | 3219 3220**Error codes** 3221 3222For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3223 3224| ID| Error Message| 3225| -------- | ------------------------------ | 3226| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3227| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3228| 6600102 | The session does not exist. | 3229 3230**Example** 3231 3232```ts 3233currentAVSession.on('toggleCallMute', () => { 3234 console.info('on call toggleCallMute'); 3235}); 3236``` 3237 3238### off('toggleCallMute')<sup>11+</sup> 3239 3240off(type: 'toggleCallMute', callback?: Callback\<void>): void 3241 3242Unsubscribes from call mute events. 3243 3244**Atomic service API**: This API can be used in atomic services since API version 12. 3245 3246**System capability**: SystemCapability.Multimedia.AVSession.Core 3247 3248**Parameters** 3249 3250| Name | Type | Mandatory| Description | 3251| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3252| type | string | Yes | Event type, which is **'toggleCallMute'** in this case.| 3253| 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. | 3254 3255**Error codes** 3256 3257For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3258 3259| ID| Error Message| 3260| -------- | ---------------------------------------- | 3261| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3262| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3263| 6600102 | The session does not exist. | 3264 3265**Example** 3266 3267```ts 3268currentAVSession.off('toggleCallMute'); 3269``` 3270 3271### on('castDisplayChange')<sup>12+</sup> 3272 3273on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void 3274 3275Subscribes to cast display change events in the case of extended screens. 3276 3277**Atomic service API**: This API can be used in atomic services since API version 12. 3278 3279**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3280 3281**Parameters** 3282 3283| Name | Type | Mandatory| Description | 3284| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3285| type | string | Yes | Event type. The event **'castDisplayChange'** is triggered when the cast display in the case of extended screens changes.| 3286| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | Yes | Callback used to return the information about the cast display. | 3287 3288**Error codes** 3289 3290For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3291 3292| ID| Error Message| 3293| -------- | ---------------------------------------- | 3294| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3295| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3296| 6600102 | The session does not exist. | 3297 3298**Example** 3299 3300```ts 3301let castDisplay: avSession.CastDisplayInfo; 3302currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => { 3303 if (display.state === avSession.CastDisplayState.STATE_ON) { 3304 castDisplay = display; 3305 console.info(`Succeeded in castDisplayChange display : ${display.id} ON`); 3306 } else if (display.state === avSession.CastDisplayState.STATE_OFF){ 3307 console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`); 3308 } 3309}); 3310``` 3311### off('castDisplayChange')<sup>12+</sup> 3312 3313 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void 3314 3315Unsubscribes from cast display change events in the case of extended screens. 3316 3317**Atomic service API**: This API can be used in atomic services since API version 12. 3318 3319**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3320 3321**Parameters** 3322 3323| Name | Type | Mandatory| Description | 3324| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3325| type | string | Yes | Event type, which is **'castDisplayChange'** in this case.| 3326| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | 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. | 3327 3328**Error codes** 3329 3330For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3331 3332| ID| Error Message| 3333| -------- | ---------------------------------------- | 3334| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3335| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3336| 6600102 | The session does not exist. | 3337 3338**Example** 3339 3340```ts 3341currentAVSession.off('castDisplayChange'); 3342``` 3343 3344### stopCasting<sup>10+</sup> 3345 3346stopCasting(callback: AsyncCallback\<void>): void 3347 3348Stops castings. This API uses an asynchronous callback to return the result. 3349 3350**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3351 3352**Parameters** 3353 3354| Name | Type | Mandatory| Description | 3355| -------- | ------------------------------------- | ---- | ------------------------------------- | 3356| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3357 3358**Error codes** 3359 3360For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3361 3362| ID| Error Message| 3363| -------- | ---------------------------------------- | 3364| 6600109 | The remote connection is not established. | 3365 3366**Example** 3367 3368```ts 3369import { BusinessError } from '@kit.BasicServicesKit'; 3370 3371currentAVSession.stopCasting((err: BusinessError) => { 3372 if (err) { 3373 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3374 } else { 3375 console.info('stopCasting successfully'); 3376 } 3377}); 3378``` 3379 3380### stopCasting<sup>10+</sup> 3381 3382stopCasting(): Promise\<void> 3383 3384Stops castings. This API uses a promise to return the result. 3385 3386**Atomic service API**: This API can be used in atomic services since API version 12. 3387 3388**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3389 3390**Return value** 3391 3392| Type | Description | 3393| -------------- | ----------------------------- | 3394| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.| 3395 3396**Error codes** 3397 3398For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3399 3400| ID| Error Message| 3401| -------- | ---------------------------------------- | 3402| 6600109 | The remote connection is not established. | 3403 3404**Example** 3405 3406```ts 3407import { BusinessError } from '@kit.BasicServicesKit'; 3408 3409currentAVSession.stopCasting().then(() => { 3410 console.info('stopCasting successfully'); 3411}).catch((err: BusinessError) => { 3412 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3413}); 3414``` 3415 3416### getOutputDeviceSync<sup>10+</sup> 3417 3418getOutputDeviceSync(): OutputDeviceInfo 3419 3420Obtains the output device information. This API returns the result synchronously. 3421 3422**Atomic service API**: This API can be used in atomic services since API version 12. 3423 3424**System capability**: SystemCapability.Multimedia.AVSession.Core 3425 3426**Return value** 3427 3428| Type | Description | 3429| ----------------------------------------------- | --------------------------------- | 3430| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.| 3431 3432**Error codes** 3433 3434For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3435 3436| ID | Error Message| 3437|---------| --------------------------------------- | 3438| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3439| 6600102 | The session does not exist. | 3440 3441**Example** 3442 3443```ts 3444import { BusinessError } from '@kit.BasicServicesKit'; 3445 3446try { 3447 let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync(); 3448} catch (err) { 3449 let error = err as BusinessError; 3450 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 3451} 3452``` 3453### getAllCastDisplays<sup>12+</sup> 3454 3455getAllCastDisplays(): Promise<Array\<CastDisplayInfo>> 3456 3457Obtains all displays that support extended screen projection in the current system. This API uses a promise to return the result. 3458 3459**Atomic service API**: This API can be used in atomic services since API version 12. 3460 3461**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3462 3463**Return value** 3464 3465| Type | Description | 3466| ----------------------------------------------- | --------------------------------- | 3467| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise used to return the information about all the cast displays.| 3468 3469**Error codes** 3470 3471For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3472 3473| ID | Error Message| 3474|---------| --------------------------------------- | 3475| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3476| 6600102 | The session does not exist. | 3477 3478**Example** 3479 3480```ts 3481import { BusinessError } from '@kit.BasicServicesKit'; 3482 3483let castDisplay: avSession.CastDisplayInfo; 3484currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => { 3485 if (data.length >= 1) { 3486 castDisplay = data[0]; 3487 } 3488 }).catch((err: BusinessError) => { 3489 console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`); 3490 }); 3491``` 3492 3493## AVCastControlCommandType<sup>10+</sup> 3494 3495type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 3496 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute' 3497 3498Defines the commands that can be sent by a cast controller. 3499 3500**Atomic service API**: This API can be used in atomic services since API version 12. 3501 3502**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3503 3504| Type | Description | 3505| ---------------- | ------------ | 3506| 'play' | Play the media. No parameter is required.| 3507| 'pause' | Pause the playback. No parameter is required. | 3508| 'stop' | Stop the playback. No parameter is required. | 3509| 'playNext' | Play the next media asset. No parameter is required. | 3510| 'playPrevious' | Play the previous media asset. No parameter is required. | 3511| 'fastForward' | Fast-forward. No parameter is required. | 3512| 'rewind' | Rewind. No parameter is required. | 3513| 'seek' | Seek to a playback position. The corresponding parameter is of the number type.| 3514| 'setVolume' | Set the volume. The corresponding parameter is of the number type. You can use [AVPlaybackState.maxVolume](#avplaybackstate10) to obtain the maximum system volume. | 3515| 'setSpeed' | Set the playback speed. The corresponding parameter is [media.PlaybackSpeed](../apis-media-kit/arkts-apis-media-e.md#playbackspeed8).| 3516| 'setLoopMode' | Set the loop mode. The corresponding parameter is [LoopMode](#loopmode10).| 3517| 'toggleFavorite' | Favorite the media asset. The corresponding parameter is [AVMetadata.assetId](#avmetadata10). | 3518| 'toggleMute' | Set the muted status. No parameter is required.| 3519 3520## AVCastControlCommand<sup>10+</sup> 3521 3522Describes the command that can be sent by a cast controller. 3523 3524**Atomic service API**: This API can be used in atomic services since API version 12. 3525 3526**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3527 3528| Name | Type | Mandatory| Description | 3529| --------- | ------------------------------------------------- | ---- | -------------- | 3530| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | Yes | Command. The parameters carried in each command are different. For details, see [AVCastControlCommandType](#avcastcontrolcommandtype10).| 3531| parameter | [media.PlaybackSpeed](../apis-media-kit/arkts-apis-media-e.md#playbackspeed8) | number | string | [LoopMode](#loopmode10) | No | Parameters carried in the command.| 3532 3533## AVCastController<sup>10+</sup> 3534 3535After a casting connection is set up, you can call [avSession.getAVCastController](#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. 3536 3537### getAVPlaybackState<sup>10+</sup> 3538 3539getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 3540 3541Obtains the remote playback state. This API uses an asynchronous callback to return the result. 3542 3543**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3544 3545**Parameters** 3546 3547| Name | Type | Mandatory| Description | 3548| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3549| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| 3550 3551**Error codes** 3552 3553For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3554 3555| ID| Error Message| 3556| -------- | ---------------------------------------- | 3557| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3558 3559**Example** 3560 3561```ts 3562import { BusinessError } from '@kit.BasicServicesKit'; 3563 3564aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 3565 if (err) { 3566 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3567 } else { 3568 console.info('getAVPlaybackState : SUCCESS'); 3569 } 3570}); 3571``` 3572 3573### getAVPlaybackState<sup>10+</sup> 3574 3575getAVPlaybackState(): Promise\<AVPlaybackState> 3576 3577Obtains the remote playback state. This API uses a promise to return the result. 3578 3579**Atomic service API**: This API can be used in atomic services since API version 12. 3580 3581**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3582 3583**Return value** 3584 3585| Type | Description | 3586| --------- | ------------------------------------------------------------ | 3587| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state.| 3588 3589**Error codes** 3590 3591For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3592 3593| ID| Error Message| 3594| -------- | ---------------------------------------- | 3595| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3596 3597**Example** 3598 3599```ts 3600import { BusinessError } from '@kit.BasicServicesKit'; 3601 3602aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 3603 console.info('getAVPlaybackState : SUCCESS'); 3604}).catch((err: BusinessError) => { 3605 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3606}); 3607``` 3608 3609### getSupportedDecoders<sup>19+</sup> 3610 3611getSupportedDecoders(): Promise\<Array\<DecoderType>> 3612 3613Obtains the decoding modes supported by the current remote device. This API uses a promise to return the result. 3614 3615**Atomic service API**: This API can be used in atomic services since API version 19. 3616 3617**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3618 3619**Return value** 3620 3621| Type | Description | 3622| --------- | ------------------------------------------------------------ | 3623| Promise\<Array\<[DecoderType](#decodertype19)\>\> | Promise used to return an array of decoding modes supported by the remote device.| 3624 3625**Error codes** 3626 3627For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3628 3629| ID| Error Message| 3630| -------- | ---------------------------------------- | 3631| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3632 3633**Example** 3634 3635```ts 3636import { BusinessError } from '@kit.BasicServicesKit'; 3637 3638aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => { 3639 console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`); 3640 if (decoderTypes.length > 0 ) { 3641 console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`); 3642 } 3643}).catch((err: BusinessError) => { 3644 console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`); 3645}); 3646``` 3647 3648### getRecommendedResolutionLevel<sup>19+</sup> 3649 3650getRecommendedResolutionLevel(decoderType: DecoderType): Promise\<ResolutionLevel> 3651 3652Obtains the recommended resolution level based on the passed decoding mode. This API uses a promise to return the result. 3653 3654**Atomic service API**: This API can be used in atomic services since API version 19. 3655 3656**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3657 3658**Parameters** 3659| Name | Type | Mandatory| Description | 3660| -------- | ----------------------------------------- | ---- | -------------------------- | 3661| decoderType | [DecoderType](#decodertype19) | Yes| Decoding format supported by the device.<br>The following decoding formats are supported by the device:<br>**'OH_AVCODEC_MIMETYPE_VIDEO_AVC'**: VIDEO AVC.<br>**'OH_AVCODEC_MIMETYPE_VIDEO_HEVC'**: VIDEO HEVC.<br>**'OH_AVCODEC_MIMETYPE_AUDIO_VIVID'**: AUDIO AV3A.| 3662 3663**Return value** 3664 3665| Type | Description | 3666| --------- | ------------------------------------------------------------ | 3667| Promise\<[ResolutionLevel](#resolutionlevel19)\> | Promise used to return the recommended resolution level of the remote device.| 3668 3669**Error codes** 3670 3671For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3672 3673| ID| Error Message| 3674| -------- | ---------------------------------------- | 3675| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3676 3677**Example** 3678 3679```ts 3680import { BusinessError } from '@kit.BasicServicesKit'; 3681 3682let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC; 3683let resolutionLeve = avSession.ResolutionLevel; 3684aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLeve) => { 3685 console.info('getRecommendedResolutionLevel successfully'); 3686}).catch((err: BusinessError) => { 3687 console.error(`getRecommendedResolutionLevel BusinessError: code: ${err.code}, message: ${err.message}`); 3688}); 3689``` 3690 3691### getSupportedHdrCapabilities<sup>19+</sup> 3692 3693getSupportedHdrCapabilities(): Promise\<Array\<hdrCapability.HDRFormat>> 3694 3695Obtains the HDR capabilities supported by the current remote device. This API uses a promise to return the result. 3696 3697**Atomic service API**: This API can be used in atomic services since API version 19. 3698 3699**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3700 3701**Return value** 3702 3703| Type | Description | 3704| --------- | ------------------------------------------------------------ | 3705| Promise\<Array\<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md#hdrformat)\>\> | Promise used to return an array of HDR capabilities supported by the remote device.| 3706 3707**Error codes** 3708 3709For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3710 3711| ID| Error Message| 3712| -------- | ---------------------------------------- | 3713| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3714 3715**Example** 3716 3717```ts 3718import { BusinessError } from '@kit.BasicServicesKit'; 3719import type hdrCapability from './@ohos.graphics.hdrCapability'; 3720 3721aVCastController.getSupportedHdrCapabilities().then((hdrFormats: hdrCapability.HDRFormat[]) => { 3722 console.info(`getSupportedHdrCapabilities : SUCCESS : hdrFormats.length : ${hdrFormats.length}`); 3723 if (hdrFormats.length > 0 ) { 3724 console.info(`getSupportedHdrCapabilities : SUCCESS : descriptors[0] : ${hdrFormats[0]}`); 3725 } 3726}).catch((err: BusinessError) => { 3727 console.error(`getSupportedHdrCapabilities BusinessError: code: ${err.code}, message: ${err.message}`); 3728}); 3729``` 3730 3731### getSupportedPlaySpeeds<sup>19+</sup> 3732 3733getSupportedPlaySpeeds(): Promise\<Array\<number>> 3734 3735Obtains the playback speeds supported by the current remote device. This API uses a promise to return the result. 3736 3737**Atomic service API**: This API can be used in atomic services since API version 19. 3738 3739**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3740 3741**Return value** 3742 3743| Type | Description | 3744| --------- | ------------------------------------------------------------ | 3745| Promise\<Array\<number\>\> | Promise used to return an array of playback speeds supported by the remote device.| 3746 3747**Error codes** 3748 3749For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3750 3751| ID| Error Message| 3752| -------- | ---------------------------------------- | 3753| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3754 3755**Example** 3756 3757```ts 3758import { BusinessError } from '@kit.BasicServicesKit'; 3759 3760aVCastController.getSupportedPlaySpeeds().then((nums: number[]) => { 3761 console.info(`getSupportedPlaySpeeds : SUCCESS : hdrFormats.length : ${nums.length}`); 3762 if (nums.length > 0 ) { 3763 console.info(`getSupportedPlaySpeeds : SUCCESS : descriptors[0] : ${nums[0]}`); 3764 } 3765}).catch((err: BusinessError) => { 3766 console.error(`getSupportedPlaySpeeds BusinessError: code: ${err.code}, message: ${err.message}`); 3767}); 3768``` 3769 3770### sendControlCommand<sup>10+</sup> 3771 3772sendControlCommand(command: AVCastControlCommand): Promise\<void> 3773 3774Sends a control command to the session through the controller. This API uses a promise to return the result. 3775 3776 3777**Atomic service API**: This API can be used in atomic services since API version 12. 3778 3779**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3780 3781**Parameters** 3782 3783| Name | Type | Mandatory| Description | 3784| ------- | ------------------------------------- | ---- | ------------------------------ | 3785| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| 3786 3787**Return value** 3788 3789| Type | Description | 3790| -------------- | ----------------------------- | 3791| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 3792 3793**Error codes** 3794 3795For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3796 3797| ID| Error Message| 3798| -------- | ---------------------------------------- | 3799| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3800| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3801| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 3802| 6600109 | The remote connection is not established. | 3803 3804**Example** 3805 3806```ts 3807import { BusinessError } from '@kit.BasicServicesKit'; 3808 3809let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3810aVCastController.sendControlCommand(avCommand).then(() => { 3811 console.info('SendControlCommand successfully'); 3812}).catch((err: BusinessError) => { 3813 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3814}); 3815``` 3816 3817### sendControlCommand<sup>10+</sup> 3818 3819sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void 3820 3821Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result. 3822 3823 3824**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3825 3826**Parameters** 3827 3828| Name | Type | Mandatory| Description | 3829| -------- | ------------------------------------- | ---- | ------------------------------ | 3830| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| 3831| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 3832 3833**Error codes** 3834 3835For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3836 3837| ID| Error Message| 3838| -------- | ------------------------------- | 3839| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3840| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3841| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 3842| 6600109 | The remote connection is not established. | 3843 3844**Example** 3845 3846```ts 3847import { BusinessError } from '@kit.BasicServicesKit'; 3848 3849let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3850aVCastController.sendControlCommand(avCommand, (err: BusinessError) => { 3851 if (err) { 3852 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3853 } else { 3854 console.info('SendControlCommand successfully'); 3855 } 3856}); 3857``` 3858 3859### prepare<sup>10+</sup> 3860 3861prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void 3862 3863Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses an asynchronous callback to return the result. 3864 3865**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3866 3867**Parameters** 3868 3869| Name | Type | Mandatory| Description | 3870| ------- | ------------------------------------- | ---- | ------------------------------ | 3871| item | [AVQueueItem](#avqueueitem10) | Yes | Properties of an item in the playlist.| 3872| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3873 3874**Error codes** 3875 3876For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3877 3878| ID| Error Message| 3879| -------- | ---------------------------------------- | 3880| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3881| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3882| 6600109 | The remote connection is not established. | 3883 3884**Example** 3885 3886```ts 3887import { BusinessError } from '@kit.BasicServicesKit'; 3888 3889// Set playback parameters. 3890let playItem: avSession.AVQueueItem = { 3891 itemId: 0, 3892 description: { 3893 assetId: '12345', 3894 mediaType: 'AUDIO', 3895 mediaUri: 'http://resource1_address', 3896 mediaSize: 12345, 3897 startPosition: 0, 3898 duration: 0, 3899 artist: 'mysong', 3900 albumTitle: 'song1_title', 3901 albumCoverUri: "http://resource1_album_address", 3902 lyricUri: "http://resource1_lyric_address", 3903 appName: 'MyMusic' 3904 } 3905}; 3906// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. 3907aVCastController.prepare(playItem, (err: BusinessError) => { 3908 if (err) { 3909 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3910 } else { 3911 console.info('prepare successfully'); 3912 } 3913}); 3914``` 3915 3916 3917### prepare<sup>10+</sup> 3918 3919prepare(item: AVQueueItem): Promise\<void> 3920 3921Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result. 3922 3923 3924**Atomic service API**: This API can be used in atomic services since API version 12. 3925 3926**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3927 3928**Parameters** 3929 3930| Name | Type | Mandatory| Description | 3931| ------- | ------------------------------------- | ---- | ------------------------------ | 3932| item | [AVQueueItem](#avqueueitem10) | Yes | Properties of an item in the playlist.| 3933 3934**Return value** 3935 3936| Type | Description | 3937| -------------- | ----------------------------- | 3938| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 3939 3940**Error codes** 3941 3942For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3943 3944| ID| Error Message| 3945| -------- | ---------------------------------------- | 3946| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3947| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 3948| 6600109 | The remote connection is not established. | 3949 3950 3951**Example** 3952 3953```ts 3954import { BusinessError } from '@kit.BasicServicesKit'; 3955 3956// Set playback parameters. 3957let playItem: avSession.AVQueueItem = { 3958 itemId: 0, 3959 description: { 3960 assetId: '12345', 3961 mediaType: 'AUDIO', 3962 mediaUri: 'http://resource1_address', 3963 mediaSize: 12345, 3964 startPosition: 0, 3965 duration: 0, 3966 artist: 'mysong', 3967 albumTitle: 'song1_title', 3968 albumCoverUri: "http://resource1_album_address", 3969 lyricUri: "http://resource1_lyric_address", 3970 appName: 'MyMusic' 3971 } 3972}; 3973// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. 3974aVCastController.prepare(playItem).then(() => { 3975 console.info('prepare successfully'); 3976}).catch((err: BusinessError) => { 3977 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3978}); 3979``` 3980 3981### start<sup>10+</sup> 3982 3983start(item: AVQueueItem, callback: AsyncCallback\<void>): void 3984 3985Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result. 3986 3987**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3988 3989**Parameters** 3990 3991| Name | Type | Mandatory| Description | 3992| ------- | ------------------------------------- | ---- | ------------------------------ | 3993| item | [AVQueueItem](#avqueueitem10) | Yes | Properties of an item in the playlist.| 3994| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3995 3996**Error codes** 3997 3998For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3999 4000| ID| Error Message| 4001| -------- | ---------------------------------------- | 4002| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4003| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4004| 6600109 | The remote connection is not established. | 4005 4006**Example** 4007 4008```ts 4009import { BusinessError } from '@kit.BasicServicesKit'; 4010 4011// Set playback parameters. 4012let playItem: avSession.AVQueueItem = { 4013 itemId: 0, 4014 description: { 4015 assetId: '12345', 4016 mediaType: 'AUDIO', 4017 mediaUri: 'http://resource1_address', 4018 mediaSize: 12345, 4019 startPosition: 0, 4020 duration: 0, 4021 artist: 'mysong', 4022 albumTitle: 'song1_title', 4023 albumCoverUri: "http://resource1_album_address", 4024 lyricUri: "http://resource1_lyric_address", 4025 appName: 'MyMusic' 4026 } 4027}; 4028 4029// Start playback. 4030aVCastController.start(playItem, (err: BusinessError) => { 4031 if (err) { 4032 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 4033 } else { 4034 console.info('start successfully'); 4035 } 4036}); 4037``` 4038 4039### start<sup>10+</sup> 4040 4041start(item: AVQueueItem): Promise\<void> 4042 4043Prepares for the playback of a media asset. This API uses a promise to return the result. 4044 4045 4046**Atomic service API**: This API can be used in atomic services since API version 12. 4047 4048**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4049 4050**Parameters** 4051 4052| Name | Type | Mandatory| Description | 4053| ------- | ------------------------------------- | ---- | ------------------------------ | 4054| item | [AVQueueItem](#avqueueitem10) | Yes | Properties of an item in the playlist.| 4055 4056**Return value** 4057 4058| Type | Description | 4059| -------------- | ----------------------------- | 4060| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 4061 4062**Error codes** 4063 4064For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4065 4066| ID| Error Message| 4067| -------- | ---------------------------------------- | 4068| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4069| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4070| 6600109 | The remote connection is not established. | 4071 4072 4073**Example** 4074 4075```ts 4076import { BusinessError } from '@kit.BasicServicesKit'; 4077 4078// Set playback parameters. 4079let playItem: avSession.AVQueueItem = { 4080 itemId: 0, 4081 description: { 4082 assetId: '12345', 4083 mediaType: 'AUDIO', 4084 mediaUri: 'http://resource1_address', 4085 mediaSize: 12345, 4086 startPosition: 0, 4087 duration: 0, 4088 artist: 'mysong', 4089 albumTitle: 'song1_title', 4090 albumCoverUri: "http://resource1_album_address", 4091 lyricUri: "http://resource1_lyric_address", 4092 appName: 'MyMusic' 4093 } 4094}; 4095// Start playback. 4096aVCastController.start(playItem).then(() => { 4097 console.info('start successfully'); 4098}).catch((err: BusinessError) => { 4099 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 4100}); 4101``` 4102 4103### getCurrentItem<sup>10+</sup> 4104 4105getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void 4106 4107Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result. 4108 4109**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4110 4111**Parameters** 4112 4113| Name | Type | Mandatory| Description | 4114| -------- | ------------------------------------- | ---- | ------------------------------------- | 4115| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 4116 4117**Error codes** 4118 4119For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4120 4121| ID| Error Message| 4122| -------- | ---------------------------------------- | 4123| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4124 4125**Example** 4126 4127```ts 4128import { BusinessError } from '@kit.BasicServicesKit'; 4129 4130aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => { 4131 if (err) { 4132 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 4133 } else { 4134 console.info('getCurrentItem successfully'); 4135 } 4136}); 4137``` 4138 4139### getCurrentItem<sup>10+</sup> 4140 4141getCurrentItem(): Promise\<AVQueueItem> 4142 4143Obtains the information about the media asset that is being played. This API uses a promise to return the result. 4144 4145**Atomic service API**: This API can be used in atomic services since API version 12. 4146 4147**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4148 4149**Return value** 4150 4151| Type | Description | 4152| -------------- | ----------------------------- | 4153| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.| 4154 4155**Error codes** 4156 4157For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4158 4159| ID| Error Message| 4160| -------- | ---------------------------------------- | 4161| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4162 4163**Example** 4164 4165```ts 4166import { BusinessError } from '@kit.BasicServicesKit'; 4167 4168aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => { 4169 console.info('getCurrentItem successfully'); 4170}).catch((err: BusinessError) => { 4171 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 4172}); 4173``` 4174 4175### getValidCommands<sup>11+</sup> 4176 4177getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void 4178 4179Obtains the supported commands. This API uses an asynchronous callback to return the result. 4180 4181**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4182 4183**Parameters** 4184 4185| Name| Type| Mandatory| Description| 4186| -------- | ------------------------------------- | ---- | ------------------------------------- | 4187| callback | AsyncCallback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Yes| Callback return the supported commands.| 4188 4189**Error codes** 4190 4191For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4192 4193| ID| Error Message| 4194| -------- | ---------------------------------------- | 4195| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4196 4197**Example** 4198 4199```ts 4200import { BusinessError } from '@kit.BasicServicesKit'; 4201 4202aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType[]) => { 4203 if (err) { 4204 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 4205 } else { 4206 console.info('getValidCommands successfully'); 4207 } 4208}); 4209``` 4210 4211### getValidCommands<sup>11+</sup> 4212 4213getValidCommands(): Promise<Array\<AVCastControlCommandType>> 4214 4215Obtains the supported commands. This API uses a promise to return the result. 4216 4217**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4218 4219**Return value** 4220 4221| Type| Description| 4222| -------------- | ----------------------------- | 4223| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise used to return the supported commands.| 4224 4225**Error codes** 4226 4227For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4228 4229| ID| Error Message| 4230| -------- | ---------------------------------------- | 4231| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4232 4233**Example** 4234 4235```ts 4236import { BusinessError } from '@kit.BasicServicesKit'; 4237 4238aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType[]) => { 4239 console.info('getValidCommands successfully'); 4240}).catch((err: BusinessError) => { 4241 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 4242}); 4243``` 4244 4245### processMediaKeyResponse<sup>12+</sup> 4246 4247processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void> 4248 4249Processes the response to a media key request during online DRM resource projection. This API uses a promise to return the result. 4250 4251**Atomic service API**: This API can be used in atomic services since API version 12. 4252 4253**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4254 4255**Parameters** 4256 4257| Name | Type | Mandatory| Description | 4258| -------- | ------------------------------------- | ---- | ------------------------------------- | 4259| assetId | string | Yes | Media asset ID.| 4260| response | Uint8Array | Yes | Response to the media key request.| 4261 4262**Return value** 4263 4264| Type | Description | 4265| -------------- | ----------------------------- | 4266| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned.| 4267 4268**Error codes** 4269 4270For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4271 4272| ID| Error Message| 4273| -------- | ---------------------------------------- | 4274| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 4275| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4276 4277**Example** 4278 4279```ts 4280let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4281 // Obtain the DRM URL based on the asset ID. 4282 let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense'; 4283 // Obtain a media key from the server. Assign a value based on service requirements. 4284 let licenseResponseData: Uint8Array = new Uint8Array(); 4285 console.info(`Succeeded in get license by ${drmUrl}.`); 4286 aVCastController.processMediaKeyResponse(assetId, licenseResponseData); 4287} 4288``` 4289 4290### release<sup>11+</sup> 4291 4292release(callback: AsyncCallback\<void>): void 4293 4294Releases this cast controller. This API uses an asynchronous callback to return the result. 4295 4296**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4297 4298**Parameters** 4299 4300| Name | Type | Mandatory| Description | 4301| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 4302| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object.| 4303 4304**Error codes** 4305 4306For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4307 4308| ID| Error Message| 4309| -------- | -------------------------- | 4310| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4311 4312**Example** 4313 4314```ts 4315import { BusinessError } from '@kit.BasicServicesKit'; 4316 4317aVCastController.release((err: BusinessError) => { 4318 if (err) { 4319 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 4320 } else { 4321 console.info('release successfully'); 4322 } 4323}); 4324``` 4325 4326### release<sup>11+</sup> 4327 4328release(): Promise\<void> 4329 4330Releases this cast controller. This API uses a promise to return the result. 4331 4332**Atomic service API**: This API can be used in atomic services since API version 12. 4333 4334**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4335 4336**Return value** 4337 4338| Type | Description | 4339| -------------- | ----------------------------- | 4340| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned.| 4341 4342**Error codes** 4343 4344For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4345 4346| ID| Error Message| 4347| -------- | ------------------------------ | 4348| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4349 4350**Example** 4351 4352```ts 4353import { BusinessError } from '@kit.BasicServicesKit'; 4354 4355aVCastController.release().then(() => { 4356 console.info('release successfully'); 4357}).catch((err: BusinessError) => { 4358 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 4359}); 4360 4361``` 4362 4363### on('playbackStateChange')<sup>10+</sup> 4364 4365on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void 4366 4367Subscribes to playback state change events. 4368 4369**Atomic service API**: This API can be used in atomic services since API version 12. 4370 4371**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4372 4373**Parameters** 4374 4375| Name | Type | Mandatory| Description | 4376| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4377| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| 4378| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | Yes | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof [AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.| 4379| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. | 4380 4381**Error codes** 4382 4383For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4384 4385| ID| Error Message| 4386| -------- | ------------------------------ | 4387| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4388| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4389 4390**Example** 4391 4392```ts 4393aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 4394 console.info(`on playbackStateChange state : ${playbackState.state}`); 4395}); 4396 4397let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode']; 4398aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => { 4399 console.info(`on playbackStateChange state : ${playbackState.state}`); 4400}); 4401``` 4402 4403### off('playbackStateChange')<sup>10+</sup> 4404 4405off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void 4406 4407Unsubscribes from playback state change events. This API is called by the controller. 4408 4409**Atomic service API**: This API can be used in atomic services since API version 12. 4410 4411**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4412 4413**Parameters** 4414 4415| Name | Type | Mandatory| Description | 4416| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4417| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | 4418| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | No | Callback function, where the **state** parameter indicates the new playback state.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 4419 4420**Error codes** 4421 4422For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4423 4424| ID| Error Message| 4425| -------- | ---------------- | 4426| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4427| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4428 4429**Example** 4430 4431```ts 4432aVCastController.off('playbackStateChange'); 4433``` 4434 4435### on('mediaItemChange')<sup>10+</sup> 4436 4437on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void 4438 4439Subscribes to media asset change events. 4440 4441**Atomic service API**: This API can be used in atomic services since API version 12. 4442 4443**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4444 4445**Parameters** 4446 4447| Name | Type | Mandatory| Description | 4448| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4449| type | string | Yes | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.| 4450| callback | Callback<[AVQueueItem](#avqueueitem10)> | Yes | Callback used for subscription. **AVQueueItem** is the media asset that is being played. | 4451 4452**Error codes** 4453 4454For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4455 4456| ID| Error Message| 4457| -------- | ------------------------------ | 4458| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4459| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4460 4461**Example** 4462 4463```ts 4464aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => { 4465 console.info(`on mediaItemChange state : ${item.itemId}`); 4466}); 4467``` 4468 4469### off('mediaItemChange')<sup>10+</sup> 4470 4471off(type: 'mediaItemChange'): void 4472 4473Unsubscribes from media asset change events. 4474 4475**Atomic service API**: This API can be used in atomic services since API version 12. 4476 4477**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4478 4479**Parameters** 4480 4481| Name | Type | Mandatory| Description | 4482| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4483| type | string | Yes | Event type, which is **'mediaItemChange'** in this case. | 4484 4485**Error codes** 4486 4487For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4488 4489| ID| Error Message| 4490| -------- | ---------------- | 4491| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4492| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4493 4494**Example** 4495 4496```ts 4497aVCastController.off('mediaItemChange'); 4498``` 4499 4500### on('playNext')<sup>10+</sup> 4501 4502on(type: 'playNext', callback: Callback\<void>): void 4503 4504Subscribes to playNext command events. 4505 4506**Atomic service API**: This API can be used in atomic services since API version 12. 4507 4508**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4509 4510**Parameters** 4511 4512| Name | Type | Mandatory| Description | 4513| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4514| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.| 4515| callback | Callback\<void\> | Yes | Callback used to return the result. | 4516 4517**Error codes** 4518 4519For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4520 4521| ID| Error Message| 4522| -------- | ------------------------------ | 4523| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4524| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4525 4526**Example** 4527 4528```ts 4529aVCastController.on('playNext', () => { 4530 console.info('on playNext'); 4531}); 4532``` 4533 4534### off('playNext')<sup>10+</sup> 4535 4536off(type: 'playNext'): void 4537 4538Unsubscribes from playNext command events. 4539 4540**Atomic service API**: This API can be used in atomic services since API version 12. 4541 4542**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4543 4544**Parameters** 4545 4546| Name | Type | Mandatory| Description | 4547| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4548| type | string | Yes | Event type, which is **'playNext'** in this case. | 4549 4550**Error codes** 4551 4552For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4553 4554| ID| Error Message| 4555| -------- | ---------------- | 4556| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4557| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4558 4559**Example** 4560 4561```ts 4562aVCastController.off('playNext'); 4563``` 4564 4565### on('playPrevious')<sup>10+</sup> 4566 4567on(type: 'playPrevious', callback: Callback\<void>): void 4568 4569Subscribes to playPrevious command events. 4570 4571**Atomic service API**: This API can be used in atomic services since API version 12. 4572 4573**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4574 4575**Parameters** 4576 4577| Name | Type | Mandatory| Description | 4578| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4579| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.| 4580| callback | Callback\<void\> | Yes | Callback used to return the result. | 4581 4582**Error codes** 4583 4584For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4585 4586| ID| Error Message| 4587| -------- | ------------------------------ | 4588| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4589| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4590 4591**Example** 4592 4593```ts 4594aVCastController.on('playPrevious', () => { 4595 console.info('on playPrevious'); 4596}); 4597``` 4598 4599### off('playPrevious')<sup>10+</sup> 4600 4601off(type: 'playPrevious'): void 4602 4603Unsubscribes from playPrevious command events. 4604 4605**Atomic service API**: This API can be used in atomic services since API version 12. 4606 4607**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4608 4609**Parameters** 4610 4611| Name | Type | Mandatory| Description | 4612| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4613| type | string | Yes | Event type, which is **'playPrevious'** in this case. | 4614 4615**Error codes** 4616 4617For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4618 4619| ID| Error Message| 4620| -------- | ---------------- | 4621| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4622| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4623 4624**Example** 4625 4626```ts 4627aVCastController.off('playPrevious'); 4628``` 4629 4630### on('requestPlay')<sup>11+</sup> 4631 4632on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void 4633 4634Subscribes to playback request events. 4635 4636**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4637 4638**Parameters** 4639 4640| Name | Type | Mandatory| Description | 4641| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4642| type | string | Yes | Event type. The event **'requestPlay'** is triggered when a playback request is received.| 4643| callback | Callback\<[AVQueueItem](#avqueueitem10)> | Yes | Callback function, where the **AVQueueItem** parameter specifies the media asset that is being played. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4644 4645**Error codes** 4646 4647For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4648 4649| ID| Error Message| 4650| -------- | ------------------------------ | 4651| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4652| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4653 4654**Example** 4655 4656```ts 4657aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => { 4658 console.info(`on requestPlay state : ${item.itemId}`); 4659}); 4660``` 4661 4662### off('requestPlay')<sup>11+</sup> 4663 4664off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void 4665 4666Unsubscribes from playback request events. 4667 4668**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4669 4670**Parameters** 4671 4672| Name | Type | Mandatory| Description | 4673| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4674| type | string | Yes | Event type, which is **'requestPlay'** in this case. | 4675| callback | Callback\<[AVQueueItem](#avqueueitem10)> | No | Callback function, where the **AVQueueItem** parameter specifies the media asset that is being played. 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.| 4676 4677**Error codes** 4678 4679For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4680 4681| ID| Error Message| 4682| -------- | ---------------- | 4683| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4684| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4685 4686**Example** 4687 4688```ts 4689aVCastController.off('requestPlay'); 4690``` 4691 4692### on('endOfStream')<sup>11+</sup> 4693 4694on(type: 'endOfStream', callback: Callback\<void>): void 4695 4696Subscribes to playback end events. 4697 4698**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4699 4700**Parameters** 4701 4702| Name | Type | Mandatory| Description | 4703| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ | 4704| type | string | Yes | Event type. The event **'endOfStream'** is triggered when the playback operation is complete.| 4705| callback | Callback\<void\> | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4706 4707**Error codes** 4708 4709For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4710 4711| ID| Error Message| 4712| -------- | ------------------------------ | 4713| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4714| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4715 4716**Example** 4717 4718```ts 4719aVCastController.on('endOfStream', () => { 4720 console.info('on endOfStream'); 4721}); 4722``` 4723 4724### off('endOfStream')<sup>11+</sup> 4725 4726off(type: 'endOfStream', callback?: Callback\<void>): void 4727 4728Unsubscribes from the playback end events. 4729 4730**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4731 4732**Parameters** 4733 4734| Name | Type | Mandatory| Description | 4735| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4736| type | string | Yes | Event type, which is **'endOfStream'** in this case. | 4737| callback | Callback\<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. | 4738 4739**Error codes** 4740 4741For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4742 4743| ID| Error Message| 4744| -------- | ---------------- | 4745| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4746| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4747 4748**Example** 4749 4750```ts 4751aVCastController.off('endOfStream'); 4752``` 4753 4754### on('seekDone')<sup>10+</sup> 4755 4756on(type: 'seekDone', callback: Callback\<number>): void 4757 4758Subscribes to seek done events. 4759 4760**Atomic service API**: This API can be used in atomic services since API version 12. 4761 4762**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4763 4764**Parameters** 4765 4766| Name | Type | Mandatory| Description | 4767| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4768| type | string | Yes | Event type. The event **'seekDone'** is triggered when the seek operation is complete.| 4769| callback | Callback\<number\> | Yes | Callback used to return the position after the seek operation. | 4770 4771**Error codes** 4772 4773For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4774 4775| ID| Error Message| 4776| -------- | ------------------------------ | 4777| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4778| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4779 4780**Example** 4781 4782```ts 4783aVCastController.on('seekDone', (pos: number) => { 4784 console.info(`on seekDone pos: ${pos} `); 4785}); 4786``` 4787 4788### off('seekDone')<sup>10+</sup> 4789 4790off(type: 'seekDone'): void 4791 4792Unsubscribes from the seek done events. 4793 4794**Atomic service API**: This API can be used in atomic services since API version 12. 4795 4796**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4797 4798**Parameters** 4799 4800| Name | Type | Mandatory| Description | 4801| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4802| type | string | Yes | Event type, which is **'seekDone'** in this case. | 4803 4804**Error codes** 4805 4806For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4807 4808| ID| Error Message| 4809| -------- | ---------------- | 4810| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4811| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4812 4813**Example** 4814 4815```ts 4816aVCastController.off('seekDone'); 4817``` 4818 4819### on('validCommandChange')<sup>11+</sup> 4820 4821on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>) 4822 4823Subscribes to valid command change events. 4824 4825**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4826 4827**Parameters** 4828 4829| Name | Type | Mandatory| Description | 4830| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4831| type | string | Yes | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.| 4832| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | 4833 4834**Error codes** 4835 4836For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4837 4838| ID| Error Message| 4839| -------- | ------------------------------ | 4840| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4841| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4842| 6600103 | The session controller does not exist. | 4843 4844**Example** 4845 4846```ts 4847aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => { 4848 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 4849 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 4850}); 4851``` 4852 4853### off('validCommandChange')<sup>11+</sup> 4854 4855off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>) 4856 4857Unsubscribes from valid command change events. This API is called by the controller. 4858 4859**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4860 4861**Parameters** 4862 4863| Name | Type | Mandatory| Description | 4864| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 4865| type | string | Yes | Event type, which is **'validCommandChange'** in this case. | 4866| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | No | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 4867 4868**Error codes** 4869 4870For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4871 4872| ID| Error Message | 4873| -------- | ---------------- | 4874| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4875| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4876| 6600103 | The session controller does not exist. | 4877 4878**Example** 4879 4880```ts 4881aVCastController.off('validCommandChange'); 4882``` 4883 4884### on('error')<sup>10+</sup> 4885 4886on(type: 'error', callback: ErrorCallback): void 4887 4888Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control. 4889 4890**Atomic service API**: This API can be used in atomic services since API version 12. 4891 4892**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4893 4894**Parameters** 4895 4896| Name | Type | Mandatory| Description | 4897| -------- | -------- | ---- | ------------------------------------------------------------ | 4898| type | string | Yes | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.| 4899| callback | ErrorCallback | Yes | Callback used to return the error code ID and error message.| 4900 4901**Error codes** 4902 4903For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 4904 4905| ID| Error Message | 4906| -------- | --------------------- | 4907| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4908| 5400101 | No memory. | 4909| 5400102 | Operation not allowed. | 4910| 5400103 | I/O error. | 4911| 5400104 | Time out. | 4912| 5400105 | Service died. | 4913| 5400106 | Unsupport format. | 4914| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4915 4916**Example** 4917 4918```ts 4919import { BusinessError } from '@kit.BasicServicesKit'; 4920 4921aVCastController.on('error', (error: BusinessError) => { 4922 console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`) 4923}) 4924``` 4925 4926### off('error')<sup>10+</sup> 4927 4928off(type: 'error'): void 4929 4930Unsubscribes from remote AVPlayer errors. 4931 4932**Atomic service API**: This API can be used in atomic services since API version 12. 4933 4934**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4935 4936**Parameters** 4937 4938| Name| Type | Mandatory| Description | 4939| ------ | ------ | ---- | ----------------------------------------- | 4940| type | string | Yes | Event type, which is **'error'** in this case.| 4941 4942**Error codes** 4943 4944For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 4945 4946| ID| Error Message | 4947| -------- | --------------------- | 4948| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4949| 5400101 | No memory. | 4950| 5400102 | Operation not allowed. | 4951| 5400103 | I/O error. | 4952| 5400104 | Time out. | 4953| 5400105 | Service died. | 4954| 5400106 | Unsupport format. | 4955| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4956 4957**Example** 4958 4959```ts 4960aVCastController.off('error') 4961``` 4962 4963### on('keyRequest')<sup>12+</sup> 4964 4965on(type: 'keyRequest', callback: KeyRequestCallback): void 4966 4967Subscribes to media key requests during the cast of online DRM resources. 4968 4969**Atomic service API**: This API can be used in atomic services since API version 12. 4970 4971**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4972 4973**Parameters** 4974 4975| Name| Type | Mandatory| Description | 4976| ------ | ------ | ---- | ----------------------------------------- | 4977| type | string | Yes | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources.| 4978| callback | [KeyRequestCallback](#keyrequestcallback12) | Yes | Callback used to request the media resources and media key.| 4979 4980 4981**Error codes** 4982 4983For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4984 4985| ID| Error Message | 4986| -------- | ---------------- | 4987| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4988| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 4989 4990**Example** 4991 4992```ts 4993let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4994 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 4995} 4996aVCastController.on('keyRequest', keyRequestCallback); 4997``` 4998### off('keyRequest')<sup>12+</sup> 4999 5000off(type: 'keyRequest', callback?: KeyRequestCallback): void 5001 5002Unsubscribes from media key requests during the cast of online DRM resources. 5003 5004**Atomic service API**: This API can be used in atomic services since API version 12. 5005 5006**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5007 5008**Parameters** 5009 5010| Name| Type | Mandatory| Description | 5011| ------ | ------ | ---- | ----------------------------------------- | 5012| type | string | Yes | Event type, which is **'keyRequest'** in this case.| 5013| callback | [KeyRequestCallback](#keyrequestcallback12) | 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. | 5014 5015**Error codes** 5016 5017For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5018 5019| ID| Error Message | 5020| -------- | ---------------- | 5021| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 5022| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5023 5024**Example** 5025 5026```ts 5027aVCastController.off('keyRequest'); 5028``` 5029 5030### on('castControlGenericError')<sup>13+</sup> 5031 5032on(type: 'castControlGenericError', callback: ErrorCallback): void 5033 5034Subscribes to generic error events during cast control. 5035 5036**Atomic service API**: This API can be used in atomic services since API version 13. 5037 5038**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5039 5040**Parameters** 5041 5042| Name | Type | Mandatory| Description | 5043| -------- | -------- | ---- | ------------------------------------------------------------ | 5044| type | string | Yes | Event type, which is **'castControlGenericError'** in this case.| 5045| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5046 5047**Error codes** 5048 5049| ID| Error Message | 5050| -------- | --------------------- | 5051| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5052| 6611000 | The error code for cast control is unspecified. | 5053| 6611001 | An unspecified error occurs in the remote player. | 5054| 6611002 | The playback position falls behind the live window. | 5055| 6611003 | The process of cast control times out. | 5056| 6611004 | The runtime check failed. | 5057| 6611100 | Cross-device data transmission is locked. | 5058| 6611101 | The specified seek mode is not supported. | 5059| 6611102 | The position to seek to is out of the range of the media asset or the specified seek mode is not supported. | 5060| 6611103 | The specified playback mode is not supported. | 5061| 6611104 | The specified playback speed is not supported. | 5062| 6611105 | The action failed because either the media source device or the media sink device has been revoked. | 5063| 6611106 | The parameter is invalid, for example, the url is illegal to play. | 5064| 6611107 | Allocation of memory failed. | 5065| 6611108 | Operation is not allowed. | 5066 5067**Example** 5068 5069```ts 5070aVCastController.on('castControlGenericError', (error: BusinessError) => { 5071 console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`) 5072}) 5073``` 5074 5075### off('castControlGenericError')<sup>13+</sup> 5076 5077off(type: 'castControlGenericError', callback?: ErrorCallback): void 5078 5079Unsubscribes from generic error events during cast control. 5080 5081**Atomic service API**: This API can be used in atomic services since API version 13. 5082 5083**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5084 5085**Parameters** 5086 5087| Name | Type | Mandatory| Description | 5088| -------- | -------- | ---- | ------------------------------------------------------------ | 5089| type | string | Yes | Event type, which is **'castControlGenericError'** in this case.| 5090| callback | ErrorCallback | 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.| 5091 5092**Error codes** 5093 5094| ID| Error Message | 5095| -------- | --------------------- | 5096| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5097 5098**Example** 5099 5100```ts 5101aVCastController.off('castControlGenericError'); 5102``` 5103 5104### on('castControlIoError')<sup>13+</sup> 5105 5106on(type: 'castControlIoError', callback: ErrorCallback): void 5107 5108Subscribes to input/output error events during cast control. 5109 5110**Atomic service API**: This API can be used in atomic services since API version 13. 5111 5112**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5113 5114**Parameters** 5115 5116| Name | Type | Mandatory| Description | 5117| -------- | -------- | ---- | ------------------------------------------------------------ | 5118| type | string | Yes | Event type, which is **'castControlIoError'** in this case.| 5119| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5120 5121**Error codes** 5122 5123| ID| Error Message | 5124| -------- | --------------------- | 5125| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5126| 6612000 | An unspecified input/output error occurs. | 5127| 6612001 | Network connection failure. | 5128| 6612002 | Network timeout. | 5129| 6612003 | Invalid "Content-Type" HTTP header. | 5130| 6612004 | The HTTP server returns an unexpected HTTP response status code. | 5131| 6612005 | The file does not exist. | 5132| 6612006 | No permission is granted to perform the IO operation. | 5133| 6612007 | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. | 5134| 6612008 | Reading data out of the data bound. | 5135| 6612100 | The media does not contain any contents that can be played. | 5136| 6612101 | The media cannot be read, for example, because of dust or scratches. | 5137| 6612102 | This resource is already in use. | 5138| 6612103 | The content using the validity interval has expired. | 5139| 6612104 | Using the requested content to play is not allowed. | 5140| 6612105 | The use of the allowed content cannot be verified. | 5141| 6612106 | The number of times this content has been used as requested has reached the maximum allowed number of uses. | 5142| 6612107 | An error occurs when sending packet from source device to sink device. | 5143 5144**Example** 5145 5146```ts 5147aVCastController.on('castControlIoError', (error: BusinessError) => { 5148 console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`) 5149}) 5150``` 5151 5152### off('castControlIoError')<sup>13+</sup> 5153 5154off(type: 'castControlIoError', callback?: ErrorCallback): void 5155 5156Unsubscribes from input/output error events during cast control. 5157 5158**Atomic service API**: This API can be used in atomic services since API version 13. 5159 5160**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5161 5162**Parameters** 5163 5164| Name | Type | Mandatory| Description | 5165| -------- | -------- | ---- | ------------------------------------------------------------ | 5166| type | string | Yes | Event type, which is **'castControlIoError'** in this case.| 5167| callback | ErrorCallback | 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.| 5168 5169**Error codes** 5170 5171| ID| Error Message | 5172| -------- | --------------------- | 5173| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5174 5175**Example** 5176 5177```ts 5178aVCastController.off('castControlIoError'); 5179``` 5180 5181### on('castControlParsingError')<sup>13+</sup> 5182 5183on(type: 'castControlParsingError', callback: ErrorCallback): void 5184 5185Subscribes to parsing error events during cast control. 5186 5187**Atomic service API**: This API can be used in atomic services since API version 13. 5188 5189**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5190 5191**Parameters** 5192 5193| Name | Type | Mandatory| Description | 5194| -------- | -------- | ---- | ------------------------------------------------------------ | 5195| type | string | Yes | Event type, which is **'castControlParsingError'** in this case.| 5196| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5197 5198**Error codes** 5199 5200| ID | Error Message | 5201| -------- | --------------------- | 5202| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5203| 6613000 | Unspecified error related to content parsing. | 5204| 6613001 | Parsing error associated with media container format bit streams. | 5205| 6613002 | Parsing error associated with the media manifest. | 5206| 6613003 | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature. | 5207| 6613004 | Unsupported feature in the media manifest. | 5208 5209**Example** 5210 5211```ts 5212aVCastController.on('castControlParsingError', (error: BusinessError) => { 5213 console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`) 5214}) 5215``` 5216 5217### off('castControlParsingError')<sup>13+</sup> 5218 5219off(type: 'castControlParsingError', callback?: ErrorCallback): void 5220 5221Unsubscribes from parsing error events during cast control. 5222 5223**Atomic service API**: This API can be used in atomic services since API version 13. 5224 5225**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5226 5227**Parameters** 5228 5229| Name | Type | Mandatory| Description | 5230| -------- | -------- | ---- | ------------------------------------------------------------ | 5231| type | string | Yes | Event type, which is **'castControlParsingError'** in this case.| 5232| callback | ErrorCallback | 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.| 5233 5234**Error codes** 5235 5236| ID| Error Message | 5237| -------- | --------------------- | 5238| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5239 5240**Example** 5241 5242```ts 5243aVCastController.off('castControlParsingError'); 5244``` 5245 5246### on('castControlDecodingError')<sup>13+</sup> 5247 5248on(type: 'castControlDecodingError', callback: ErrorCallback): void 5249 5250Subscribes to decoding error events during cast control. 5251 5252**Atomic service API**: This API can be used in atomic services since API version 13. 5253 5254**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5255 5256**Parameters** 5257 5258| Name | Type | Mandatory| Description | 5259| -------- | -------- | ---- | ------------------------------------------------------------ | 5260| type | string | Yes | Event type, which is **'castControlDecodingError'** in this case.| 5261| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5262 5263**Error codes** 5264 5265| ID| Error Message | 5266| -------- | --------------------- | 5267| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5268| 6614000 | Unspecified decoding error. | 5269| 6614001 | Decoder initialization failed. | 5270| 6614002 | Decoder query failed. | 5271| 6614003 | Decoding the media samples failed. | 5272| 6614004 | The format of the content to decode exceeds the capabilities of the device. | 5273| 6614005 | The format of the content to decode is not supported. | 5274 5275**Example** 5276 5277```ts 5278aVCastController.on('castControlDecodingError', (error: BusinessError) => { 5279 console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`) 5280}) 5281``` 5282### off('castControlDecodingError')<sup>13+</sup> 5283 5284off(type: 'castControlDecodingError', callback?: ErrorCallback): void 5285 5286Unsubscribes from decoding error events during cast control. 5287 5288**Atomic service API**: This API can be used in atomic services since API version 13. 5289 5290**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5291 5292**Parameters** 5293 5294| Name | Type | Mandatory| Description | 5295| -------- | -------- | ---- | ------------------------------------------------------------ | 5296| type | string | Yes | Event type, which is **'castControlDecodingError'** in this case.| 5297| callback | ErrorCallback | 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.| 5298 5299**Error codes** 5300 5301| ID| Error Message | 5302| -------- | --------------------- | 5303| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5304 5305**Example** 5306 5307```ts 5308aVCastController.off('castControlDecodingError'); 5309``` 5310 5311### on('castControlAudioRendererError')<sup>13+</sup> 5312 5313on(type: 'castControlAudioRendererError', callback: ErrorCallback): void 5314 5315Subscribes to audio renderer error events during cast control. 5316 5317**Atomic service API**: This API can be used in atomic services since API version 13. 5318 5319**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5320 5321**Parameters** 5322 5323| Name | Type | Mandatory| Description | 5324| -------- | -------- | ---- | ------------------------------------------------------------ | 5325| type | string | Yes | Event type, which is **'castControlAudioRendererError'** in this case.| 5326| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5327 5328**Error codes** 5329 5330For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 5331 5332| ID| Error Message | 5333| -------- | --------------------- | 5334| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5335| 6615000 | Unspecified errors related to the audio renderer. | 5336| 6615001 | Initializing the audio renderer failed. | 5337| 6615002 | The audio renderer fails to write data. | 5338 5339**Example** 5340 5341```ts 5342aVCastController.on('castControlAudioRendererError', (error: BusinessError) => { 5343 console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`) 5344}) 5345``` 5346### off('castControlAudioRendererError')<sup>13+</sup> 5347 5348off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void 5349 5350Unsubscribes from audio renderer error events during cast control. 5351 5352**Atomic service API**: This API can be used in atomic services since API version 13. 5353 5354**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5355 5356**Parameters** 5357 5358| Name | Type | Mandatory| Description | 5359| -------- | -------- | ---- | ------------------------------------------------------------ | 5360| type | string | Yes | Event type, which is **'castControlAudioRendererError'** in this case.| 5361| callback | ErrorCallback | 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.| 5362 5363**Error codes** 5364 5365| ID| Error Message | 5366| -------- | --------------------- | 5367| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 5368 5369**Example** 5370 5371```ts 5372aVCastController.off('castControlAudioRendererError'); 5373``` 5374 5375### on('castControlDrmError')<sup>13+</sup> 5376 5377on(type: 'castControlDrmError', callback: ErrorCallback): void 5378 5379Subscribes to DRM error events during cast control. 5380 5381**Atomic service API**: This API can be used in atomic services since API version 13. 5382 5383**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5384 5385**Parameters** 5386 5387| Name | Type | Mandatory| Description | 5388| -------- | -------- | ---- | ------------------------------------------------------------ | 5389| type | string | Yes | Event type, which is **'castControlDrmError'** in this case.| 5390| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 5391 5392**Error codes** 5393 5394| ID| Error Message | 5395| -------- | --------------------- | 5396| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5397| 6616000 | Unspecified error related to DRM. | 5398| 6616001 | The chosen DRM protection scheme is not supported by the device. | 5399| 6616002 | Device provisioning failed. | 5400| 6616003 | The DRM-protected content to play is incompatible. | 5401| 6616004 | Failed to obtain a license. | 5402| 6616005 | The operation is disallowed by the license policy. | 5403| 6616006 | An error occurs in the DRM system. | 5404| 6616007 | The device has revoked DRM privileges. | 5405| 6616008 | The DRM license being loaded into the open DRM session has expired. | 5406| 6616100 | An error occurs when the DRM processes the key response. | 5407 5408**Example** 5409 5410```ts 5411aVCastController.on('castControlDrmError', (error: BusinessError) => { 5412 console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`) 5413}) 5414``` 5415 5416### off('castControlDrmError')<sup>13+</sup> 5417 5418off(type: 'castControlDrmError', callback?: ErrorCallback): void 5419 5420Unsubscribes from DRM error events during cast control. 5421 5422**Atomic service API**: This API can be used in atomic services since API version 13. 5423 5424**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5425 5426**Parameters** 5427 5428| Name | Type | Mandatory| Description | 5429| -------- | -------- | ---- | ------------------------------------------------------------ | 5430| type | string | Yes | Event type, which is **'castControlDrmError'** in this case.| 5431| callback | ErrorCallback | 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.| 5432 5433**Error codes** 5434 5435| ID| Error Message | 5436| -------- | --------------------- | 5437| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 5438 5439**Example** 5440 5441```ts 5442aVCastController.off('castControlDrmError'); 5443``` 5444 5445## ExtraInfo<sup>18+</sup> 5446type ExtraInfo = { [key: string]: Object; } 5447 5448Defines the custom media packet set by the provider. 5449 5450**System capability**: SystemCapability.Multimedia.AVSession.Core 5451 5452| Type | Description | 5453| ----------------------------------- | ----------------------------- | 5454| [key: string]: Object | **key** specifies the remote distributed event type. Currently, the following event types are supported:<br>**'AUDIO_GET_VOLUME'**: obtains the volume of the remote device.<br>**'AUDIO_GET_AVAILABLE_DEVICES'**: obtains all remote devices that can be connected.<br>**'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'**: obtains the actual remote audio device.<br>The provider returns the corresponding media packet object based on the event type.| 5455 5456## KeyRequestCallback<sup>12+</sup> 5457type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void 5458 5459Defines the callback invoked for the media key request event. 5460 5461**Atomic service API**: This API can be used in atomic services since API version 12. 5462 5463**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5464 5465**Parameters** 5466 5467| Name| Type | Mandatory| Description | 5468| ------ | ------ | ---- | ----------------------------------------- | 5469| assetId | string | Yes | Media asset ID.| 5470| requestData | Uint8Array | Yes | Data carried in the media key request. | 5471 5472**Example** 5473<!--code_no_check--> 5474```ts 5475let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 5476 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 5477} 5478``` 5479 5480## CastDisplayState<sup>12+</sup> 5481 5482Enumerates the states of the cast display. 5483 5484**Atomic service API**: This API can be used in atomic services since API version 12. 5485 5486**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5487 5488| Name | Value | Description | 5489| --------------------------- | ---- | ----------- | 5490| STATE_OFF | 1 | The device is disconnected, and the extended screen does not display any content. | 5491| STATE_ON | 2 | The device is connected, and the extended screen is available.| 5492 5493 5494## CastDisplayInfo<sup>12+</sup> 5495 5496Describes the information about the cast display in the case of extended screens. 5497 5498**Atomic service API**: This API can be used in atomic services since API version 12. 5499 5500**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5501 5502| Name | Type | Read-Only| Optional| Description | 5503| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5504| id | number | No | No | ID of the cast display. The value must be an integer. | 5505| name | string | No | No | Name of the cast display. | 5506| state | [CastDisplayState](#castdisplaystate12) | No | No |State of the cast display. | 5507| width | number | No | No | Screen width of the cast display, in px. The value must be an integer. | 5508| height | number | No | No | Screen height of the cast display, in px. The value must be an integer. | 5509 5510## ConnectionState<sup>10+</sup> 5511 5512Enumerates the connection states. 5513 5514**Atomic service API**: This API can be used in atomic services since API version 12. 5515 5516**System capability**: SystemCapability.Multimedia.AVSession.Core 5517 5518| Name | Value | Description | 5519| --------------------------- | ---- | ----------- | 5520| STATE_CONNECTING | 0 | The device is connecting. | 5521| STATE_CONNECTED | 1 | The device is connected.| 5522| STATE_DISCONNECTED | 6 | The device is disconnected.| 5523 5524## AVMetadata<sup>10+</sup> 5525 5526Describes the media metadata. 5527 5528**System capability**: SystemCapability.Multimedia.AVSession.Core 5529 5530| Name | Type | Read-Only| Optional| Description | 5531| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5532| assetId | string | No | No | Media asset ID. It is the unique ID of a song and defined by the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5533| title | string | No | Yes | Title.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5534| artist | string | No | Yes | Artist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5535| author | string | No | Yes | Author.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5536| avQueueName<sup>12+</sup> | string | No | Yes | Playlist name. | 5537| avQueueId<sup>11+</sup> | string | No | Yes | Unique ID of the playlist. | 5538| avQueueImage<sup>11+</sup> | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | string | No | Yes | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path). Applications call **setAVMetadata** to set the image data.<br>- If the data type is set to **PixelMap**, the data obtained by calling **getAVMetadata** is the pixel data of an image.<br>- If the data type is set to **url**, the data obtained is an image path. | 5539| album | string | No | Yes | Album name.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5540| writer | string | No | Yes | Writer.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5541| composer | string | No | Yes | composer. | 5542| duration | number | No | Yes | Media duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5543| mediaImage | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | string | No | Yes | Pixel map or image path (local path or network path) of the image. Applications call **setAVMetadata** to set the image data.<br>- If the data type is set to **PixelMap**, the data obtained by calling **getAVMetadata** is the pixel data of an image.<br>- If the data type is set to **url**, the data obtained is an image path.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5544| bundleIcon<sup>18+</sup> | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | Yes | Yes | Pixel data of the image that is used as the application icon. It is read-only and cannot be set on the application side.| 5545| publishDate | Date | No | Yes | Release date. | 5546| subtitle | string | No | Yes | Subtitle.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5547| description | string | No | Yes | Media description.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5548| lyric | string | No | Yes | Lyrics. The application needs to combine the lyrics into a string.<br>The string length must be less than 40960 bytes.<br>**NOTE**: The system supports lyrics in the simple LRC format. If the lyrics are not standard (for example, having duplicate timestamps), the lyrics fail to be parsed and cannot be displayed properly in the system.| 5549| singleLyricText<sup>17+</sup> | string | No | Yes | Lyrics of a single media asset. The application must combine the lyrics into a string (excluding the timestamp).<br>The string length must be less than 40960 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 17.| 5550| previousAssetId | string | No | Yes | ID of the previous media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5551| nextAssetId | string | No | Yes | ID of the next media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5552| filter<sup>11+</sup> | number | No | Yes | Protocol supported by the media session. The default value is **TYPE_CAST_PLUS_STREAM**. For details, see [ProtocolType](#protocoltype11).<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5553| drmSchemes<sup>12+</sup> | Array\<string> | No | Yes | DRM scheme supported by the media session. The value is the UUID of the DRM scheme.| 5554| skipIntervals<sup>11+</sup> | [SkipIntervals](#skipintervals11) | No | Yes | Intervals supported for fast-forwarding and rewinding. The default value is **SECONDS_15**, that is, 15 seconds. | 5555|displayTags<sup>11+</sup> | number | No | Yes | Display tags of the media asset. For details, see [DisplayTag](#displaytag11). | 5556 5557## AVMediaDescription<sup>10+</sup> 5558 5559Describes the properties related to the media metadata in the playlist. 5560 5561**System capability**: SystemCapability.Multimedia.AVSession.Core 5562 5563| Name | Type | Read-Only | Optional | Description | 5564| ------------ | ----------------------- | ---- | ---- | ----------------------- | 5565| assetId | string | No | No | Media ID in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5566| title | string | No | Yes | Name of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5567| subtitle | string | No | Yes | Subname of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5568| description | string | No | Yes | Description of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5569| mediaImage | image.PixelMap \| string | No | Yes | Pixel map of the image of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5570| extras | {[key: string]: Object} | No | Yes | Additional fields of the media asset in the playlist. | 5571| mediaUri | string | No | Yes | URI of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5572| mediaType | string | No | Yes | Type of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5573| mediaSize | number | No | Yes | Size of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5574| albumTitle | string | No | Yes | Album name of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5575| albumCoverUri | string | No | Yes | URI of the album title of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5576| lyricContent | string | No | Yes | Lyric content of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5577| lyricUri | string | No | Yes | Lyric URI of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5578| artist | string | No | Yes | Author of the lyric of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5579| fdSrc | media.AVFileDescriptor | No | Yes | Handle to the local media file in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5580| dataSrc<sup>12+</sup> | media.AVDataSrcDescriptor | No | Yes | Descriptor of the data source in the playlist. | 5581| pcmSrc<sup>20+</sup> | boolean | No | Yes | Whether the playlist uses a PCM data source. **true** if the PCM data source used, **false** otherwise.<br>Due to device limitations, this parameter is temporarily unavailable and will be supported in future versions. | 5582| drmScheme<sup>12+</sup> | string | No | Yes | DRM scheme supported by the playlist. The value is the UUID of the DRM scheme. | 5583| duration | number | No | Yes | Playback duration of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5584| startPosition | number | No | Yes | Start position for playing the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5585| creditsPosition | number | No | Yes | Position for playing the closing credits of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5586| appName | string | No | Yes | Name of the application provided by the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5587|displayTags<sup>11+</sup> | number | No | Yes | Display tags of the media asset. For details, see [DisplayTag](#displaytag11).<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5588 5589## AVQueueItem<sup>10+</sup> 5590 5591Describes the properties of an item in the playlist. 5592 5593**Atomic service API**: This API can be used in atomic services since API version 12. 5594 5595**System capability**: SystemCapability.Multimedia.AVSession.Core 5596 5597| Name | Type | Mandatory| Description | 5598| ------------ | ------------------------------------------ | ---- | --------------------------- | 5599| itemId | number | Yes | ID of an item in the playlist. | 5600| description | [AVMediaDescription](#avmediadescription10) | No | Media metadata of the item in the playlist. | 5601 5602## AVPlaybackState<sup>10+</sup> 5603 5604Describes the information related to the media playback state. 5605 5606**System capability**: SystemCapability.Multimedia.AVSession.Core 5607 5608| Name | Type | Mandatory| Description | 5609| ------------ | ------------------------------------- | ---- | ------- | 5610| state | [PlaybackState](#playbackstate10) | No | Playback state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5611| speed | number | No | Playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5612| position | [PlaybackPosition](#playbackposition10) | No | Playback position.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5613| bufferedTime | number | No | Buffered time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5614| loopMode | [LoopMode](#loopmode10) | No | Loop mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5615| isFavorite | boolean | No | Whether the media asset is favorited. The value **true** means that the media asset is favorited.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5616| activeItemId<sup>10+</sup> | number | No | ID of the item that is being played.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5617| volume<sup>10+</sup> | number | No | Media volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5618| maxVolume<sup>11+</sup> | number | No | Maximum volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5619| muted<sup>11+</sup> | boolean | No | Mute status. The value **true** means the muted state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5620| duration<sup>11+</sup> | number | No | Duration of the media asset.| 5621| videoWidth<sup>11+</sup> | number | No | Video width of the media asset, in px.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5622| videoHeight<sup>11+</sup> | number | No | Video height of the media asset, in px.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5623| extras<sup>10+</sup> | {[key: string]: Object} | No | Custom media data.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5624 5625## PlaybackPosition<sup>10+</sup> 5626 5627Describes the information related to the playback position. 5628 5629**Atomic service API**: This API can be used in atomic services since API version 12. 5630 5631**System capability**: SystemCapability.Multimedia.AVSession.Core 5632 5633| Name | Type | Mandatory| Description | 5634| ----------- | ------ | ---- | ------------------ | 5635| elapsedTime | number | Yes | Elapsed time, in ms.| 5636| updateTime | number | Yes | Updated time, in ms.| 5637 5638## CallMetadata<sup>11+</sup> 5639 5640Describes the properties related to call metadata. 5641 5642**Atomic service API**: This API can be used in atomic services since API version 12. 5643 5644**System capability**: SystemCapability.Multimedia.AVSession.Core 5645 5646| Name | Type | Mandatory| Description | 5647| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5648| name | string | No | Name (alias) of the caller. | 5649| phoneNumber | string | No | Phone number of the caller. | 5650| avatar | [image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md) | No | Profile picture of the caller. | 5651 5652## AVCallState<sup>11+</sup> 5653 5654Describes the properties related to the call state. 5655 5656**Atomic service API**: This API can be used in atomic services since API version 12. 5657 5658**System capability**: SystemCapability.Multimedia.AVSession.Core 5659 5660| Name | Type | Mandatory| Description | 5661| --------------- |------------------------- | ---- |---------------------------------------------------------------------| 5662| state | [CallState](#callstate11) | Yes | Call state. | 5663| muted | boolean | Yes | Whether the microphone is muted.<br>**true**: The microphone is muted.<br>**false**: The microphone is not muted.| 5664 5665## CallState<sup>11+</sup> 5666 5667Enumerates the call states. 5668 5669**Atomic service API**: This API can be used in atomic services since API version 12. 5670 5671**System capability**: SystemCapability.Multimedia.AVSession.Core 5672 5673| Name | Value | Description | 5674| -------------------------- | ---- | -------- | 5675| CALL_STATE_IDLE | 0 | The phone is idle. | 5676| CALL_STATE_INCOMING | 1 | The phone is ringing. | 5677| CALL_STATE_ACTIVE | 2 | The call is connected. | 5678| CALL_STATE_DIALING | 3 | The caller is dialing. | 5679| CALL_STATE_WAITING | 4 | The call is waiting for connection. | 5680| CALL_STATE_HOLDING | 5 | The call is placed on hold. | 5681| CALL_STATE_DISCONNECTING | 6 | The call is disconnecting. | 5682 5683## DisplayTag<sup>11+</sup> 5684 5685Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source. 5686 5687**System capability**: SystemCapability.Multimedia.AVSession.Core 5688 5689| Name | Value | Description | 5690| -------------------------- | ---- | ------------ | 5691| TAG_AUDIO_VIVID | 1 | AUDIO VIVID | 5692 5693## DecoderType<sup>19+</sup> 5694 5695Enumerates the decoding formats supported by the device. 5696 5697**Atomic service API**: This API can be used in atomic services since API version 19. 5698 5699**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5700 5701| Name | Value | Description | 5702| -------------------------- | ---- | ------------ | 5703| OH_AVCODEC_MIMETYPE_VIDEO_AVC | "video/avc" | VIDEO AVC. | 5704| OH_AVCODEC_MIMETYPE_VIDEO_HEVC | "video/hevc" | VIDEO HEVC. | 5705| OH_AVCODEC_MIMETYPE_AUDIO_VIVID | "audio/av3a" | AUDIO AV3A. | 5706 5707 5708## ResolutionLevel<sup>19+</sup> 5709 5710Enumerates the resolution levels supported by the device. 5711 5712**Atomic service API**: This API can be used in atomic services since API version 19. 5713 5714**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5715 5716| Name | Value | Description | 5717| -------------------------- | ---- | ------------ | 5718| RESOLUTION_480P | 0 | 480p (640 x 480 dpi). | 5719| RESOLUTION_720P | 1 | 720p (1280 x 720 dpi). | 5720| RESOLUTION_1080P | 2 | 1080p (1920 x 1080 dpi). | 5721| RESOLUTION_2K | 3 | 2K (2560 x 1440 dpi). | 5722| RESOLUTION_4K | 4 | 4K (4096 x 3840 dpi). | 5723 5724## AVCastCategory<sup>10+</sup> 5725 5726Enumerates the cast categories. 5727 5728**Atomic service API**: This API can be used in atomic services since API version 12. 5729 5730**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5731 5732| Name | Value | Description | 5733| --------------------------- | ---- | ----------- | 5734| CATEGORY_LOCAL | 0 | Local playback. The sound is played from the local device or a connected Bluetooth headset by default. | 5735| CATEGORY_REMOTE | 1 | Remote playback. The sound or images are played from a remote device. | 5736 5737## DeviceType<sup>10+</sup> 5738 5739Enumerates the output device types. 5740 5741**Atomic service API**: This API can be used in atomic services since API version 12. 5742 5743| Name | Value | Description | 5744| --------------------------- | ---- | ----------- | 5745| DEVICE_TYPE_LOCAL | 0 | Local device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core| 5746| DEVICE_TYPE_BLUETOOTH | 10 | Bluetooth device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core| 5747| DEVICE_TYPE_TV | 2 | TV.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 5748| DEVICE_TYPE_SMART_SPEAKER | 3 | Speaker.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 5749 5750## DeviceInfo<sup>10+</sup> 5751 5752Describes the information related to the output device. 5753 5754| Name | Type | Mandatory| Description | 5755| ---------- | -------------- | ---- | ---------------------- | 5756| castCategory | AVCastCategory | Yes | Cast category.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5757| deviceId | string | Yes | ID of the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5758| deviceName | string | Yes | Name of the output device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5759| deviceType | DeviceType | Yes | Type of the output device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5760| supportedProtocols<sup>11+</sup> | number | No | Protocol supported by the output device. The default value is **TYPE_LOCAL**. For details, see [ProtocolType](#protocoltype11).<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5761| supportedDrmCapabilities<sup>12+</sup> | Array\<string> | No | DRM capability supported by the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5762| manufacturer<sup>13+</sup> | string | No | Manufacturer of the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 5763| modelName<sup>13+</sup> | string | No | Model name of the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast<br>**Atomic service API**: This API can be used in atomic services since API version 13.| 5764| audioCapabilities<sup>20+</sup> | [AudioCapabilities](#audiocapabilities20) | No | Audio capabilities supported by the output device.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 5765 5766## OutputDeviceInfo<sup>10+</sup> 5767 5768Describes the information related to the output device. 5769 5770**Atomic service API**: This API can be used in atomic services since API version 12. 5771 5772**System capability**: SystemCapability.Multimedia.AVSession.Core 5773 5774| Name | Type | Mandatory| Description | 5775| ---------- | -------------- | ---- | ---------------------- | 5776| devices | Array\<DeviceInfo\> | Yes | Output devices. | 5777 5778## LoopMode<sup>10+</sup> 5779 5780Enumerates the loop modes of media playback. 5781 5782**Atomic service API**: This API can be used in atomic services since API version 12. 5783 5784**System capability**: SystemCapability.Multimedia.AVSession.Core 5785 5786| Name | Value | Description | 5787| ------------------ | ---- | -------- | 5788| LOOP_MODE_SEQUENCE | 0 | Sequential playback.| 5789| LOOP_MODE_SINGLE | 1 | Single loop.| 5790| LOOP_MODE_LIST | 2 | Playlist loop.| 5791| LOOP_MODE_SHUFFLE | 3 | Shuffle.| 5792| LOOP_MODE_CUSTOM<sup>11+</sup> | 4 | Custom playback. | 5793 5794## PlaybackState<sup>10+</sup> 5795 5796Enumerates the media playback states. 5797 5798**Atomic service API**: This API can be used in atomic services since API version 12. 5799 5800**System capability**: SystemCapability.Multimedia.AVSession.Core 5801 5802| Name | Value | Description | 5803| --------------------------- | ---- | ----------- | 5804| PLAYBACK_STATE_INITIAL | 0 | Initial. | 5805| PLAYBACK_STATE_PREPARE | 1 | Preparing. | 5806| PLAYBACK_STATE_PLAY | 2 | Playing. | 5807| PLAYBACK_STATE_PAUSE | 3 | Paused. | 5808| PLAYBACK_STATE_FAST_FORWARD | 4 | Fast-forwarding. | 5809| PLAYBACK_STATE_REWIND | 5 | Rewinding. | 5810| PLAYBACK_STATE_STOP | 6 | Stopped. | 5811| PLAYBACK_STATE_COMPLETED | 7 | Playback complete. | 5812| PLAYBACK_STATE_RELEASED | 8 | Released. | 5813| PLAYBACK_STATE_ERROR | 9 | Error. | 5814| PLAYBACK_STATE_IDLE<sup>11+</sup> | 10 | Idle. | 5815| PLAYBACK_STATE_BUFFERING<sup>11+</sup> | 11 | Buffering. | 5816 5817## AVSessionController<sup>10+</sup> 5818 5819Through the AV session controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information. 5820 5821### Properties 5822 5823**Atomic service API**: This API can be used in atomic services since API version 12. 5824 5825**System capability**: SystemCapability.Multimedia.AVSession.Core 5826 5827| Name | Type | Read-Only| Optional| Description | 5828| :-------- | :----- | :--- | :--- | :-------------------------------------- | 5829| sessionId | string | Yes | No | Unique session ID of the AVSessionController object.| 5830 5831 5832**Example** 5833 5834```ts 5835import { BusinessError } from '@kit.BasicServicesKit'; 5836import { avSession } from '@kit.AVSessionKit'; 5837 5838let tag: string = "createNewSession"; 5839let sessionId: string = ""; 5840let AVSessionController: avSession.AVSessionController; 5841avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 5842 currentAVSession = data; 5843 sessionId = currentAVSession.sessionId; 5844 AVSessionController = await currentAVSession.getController(); 5845 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 5846}).catch((err: BusinessError) => { 5847 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 5848}); 5849``` 5850 5851### getAVPlaybackState<sup>10+</sup> 5852 5853getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 5854 5855Obtains the remote playback state. This API uses an asynchronous callback to return the result. 5856 5857**System capability**: SystemCapability.Multimedia.AVSession.Core 5858 5859**Parameters** 5860 5861| Name | Type | Mandatory| Description | 5862| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 5863| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| 5864 5865**Error codes** 5866 5867For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5868 5869| ID| Error Message| 5870| -------- | ---------------------------------------- | 5871| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5872| 6600102 | The session does not exist. | 5873| 6600103 | The session controller does not exist. | 5874 5875**Example** 5876 5877```ts 5878import { BusinessError } from '@kit.BasicServicesKit'; 5879 5880avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 5881 if (err) { 5882 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5883 } else { 5884 console.info('getAVPlaybackState : SUCCESS'); 5885 } 5886}); 5887``` 5888 5889### getAVPlaybackState<sup>10+</sup> 5890 5891getAVPlaybackState(): Promise\<AVPlaybackState> 5892 5893Obtains the remote playback state. This API uses a promise to return the result. 5894 5895**Atomic service API**: This API can be used in atomic services since API version 12. 5896 5897**System capability**: SystemCapability.Multimedia.AVSession.Core 5898 5899**Return value** 5900 5901| Type | Description | 5902| --------- | ------------------------------------------------------------ | 5903| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state. | 5904 5905**Error codes** 5906 5907For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5908 5909| ID| Error Message| 5910| -------- | ---------------------------------------- | 5911| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5912| 6600102 | The session does not exist. | 5913| 6600103 | The session controller does not exist. | 5914 5915**Example** 5916 5917```ts 5918import { BusinessError } from '@kit.BasicServicesKit'; 5919 5920avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 5921 console.info('getAVPlaybackState : SUCCESS'); 5922}).catch((err: BusinessError) => { 5923 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5924}); 5925``` 5926 5927### getAVMetadata<sup>10+</sup> 5928 5929getAVMetadata(): Promise\<AVMetadata> 5930 5931Obtains the session metadata. This API uses a promise to return the result. 5932 5933**Atomic service API**: This API can be used in atomic services since API version 12. 5934 5935**System capability**: SystemCapability.Multimedia.AVSession.Core 5936 5937**Return value** 5938 5939| Type | Description | 5940| ----------------------------------- | ----------------------------- | 5941| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.| 5942 5943**Error codes** 5944 5945For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5946 5947| ID| Error Message| 5948| -------- | ---------------------------------------- | 5949| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5950| 6600102 | The session does not exist. | 5951| 6600103 | The session controller does not exist. | 5952 5953**Example** 5954 5955```ts 5956import { BusinessError } from '@kit.BasicServicesKit'; 5957 5958avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => { 5959 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5960}).catch((err: BusinessError) => { 5961 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5962}); 5963``` 5964 5965### getAVMetadata<sup>10+</sup> 5966 5967getAVMetadata(callback: AsyncCallback\<AVMetadata>): void 5968 5969Obtains the session metadata. This API uses an asynchronous callback to return the result. 5970 5971**System capability**: SystemCapability.Multimedia.AVSession.Core 5972 5973**Parameters** 5974 5975| Name | Type | Mandatory| Description | 5976| -------- | ----------------------------------------- | ---- | -------------------------- | 5977| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes | Callback used to return the metadata obtained.| 5978 5979**Error codes** 5980 5981For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5982 5983| ID| Error Message| 5984| -------- | ---------------------------------------- | 5985| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 5986| 6600102 | The session does not exist. | 5987| 6600103 | The session controller does not exist. | 5988 5989**Example** 5990 5991```ts 5992import { BusinessError } from '@kit.BasicServicesKit'; 5993 5994avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => { 5995 if (err) { 5996 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5997 } else { 5998 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5999 } 6000}); 6001``` 6002 6003### getAVQueueTitle<sup>10+</sup> 6004 6005getAVQueueTitle(): Promise\<string> 6006 6007Obtains the name of the playlist. This API uses a promise to return the result. 6008 6009**Atomic service API**: This API can be used in atomic services since API version 12. 6010 6011**System capability**: SystemCapability.Multimedia.AVSession.Core 6012 6013**Return value** 6014 6015| Type | Description | 6016| ---------------- | ----------------------------- | 6017| Promise<string\> | Promise used to return the playlist name.| 6018 6019**Error codes** 6020 6021For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6022 6023| ID| Error Message| 6024| -------- | ---------------------------------------- | 6025| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6026| 6600102 | The session does not exist. | 6027| 6600103 | The session controller does not exist. | 6028 6029**Example** 6030 6031```ts 6032import { BusinessError } from '@kit.BasicServicesKit'; 6033 6034avsessionController.getAVQueueTitle().then((title: string) => { 6035 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 6036}).catch((err: BusinessError) => { 6037 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 6038}); 6039``` 6040 6041### getAVQueueTitle<sup>10+</sup> 6042 6043getAVQueueTitle(callback: AsyncCallback\<string>): void 6044 6045Obtains the name of the playlist. This API uses an asynchronous callback to return the result. 6046 6047**System capability**: SystemCapability.Multimedia.AVSession.Core 6048 6049**Parameters** 6050 6051| Name | Type | Mandatory| Description | 6052| -------- | ---------------------- | ---- | ------------------------- | 6053| callback | AsyncCallback<string\> | Yes | Callback used to return the playlist name.| 6054 6055**Error codes** 6056 6057For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6058 6059| ID| Error Message| 6060| -------- | ---------------------------------------- | 6061| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6062| 6600102 | The session does not exist. | 6063| 6600103 | The session controller does not exist. | 6064 6065**Example** 6066 6067```ts 6068import { BusinessError } from '@kit.BasicServicesKit'; 6069 6070avsessionController.getAVQueueTitle((err: BusinessError, title: string) => { 6071 if (err) { 6072 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 6073 } else { 6074 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 6075 } 6076}); 6077``` 6078 6079### getAVQueueItems<sup>10+</sup> 6080 6081getAVQueueItems(): Promise\<Array\<AVQueueItem>> 6082 6083Obtains the information related to the items in the queue. This API uses a promise to return the result. 6084 6085**Atomic service API**: This API can be used in atomic services since API version 12. 6086 6087**System capability**: SystemCapability.Multimedia.AVSession.Core 6088 6089**Return value** 6090 6091| Type | Description | 6092| --------------------------------------------- | ----------------------------- | 6093| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue.| 6094 6095**Error codes** 6096 6097For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6098 6099| ID| Error Message| 6100| -------- | ---------------------------------------- | 6101| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6102| 6600102 | The session does not exist. | 6103| 6600103 | The session controller does not exist. | 6104 6105**Example** 6106 6107```ts 6108import { BusinessError } from '@kit.BasicServicesKit'; 6109 6110avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => { 6111 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 6112}).catch((err: BusinessError) => { 6113 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 6114}); 6115``` 6116 6117### getAVQueueItems<sup>10+</sup> 6118 6119getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void 6120 6121Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result. 6122 6123**System capability**: SystemCapability.Multimedia.AVSession.Core 6124 6125**Parameters** 6126 6127| Name | Type | Mandatory| Description | 6128| -------- | --------------------------------------------------- | ---- | ------------------------- | 6129| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes | Callback used to return the items in the playlist.| 6130 6131**Error codes** 6132 6133For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6134 6135| ID| Error Message| 6136| -------- | ---------------------------------------- | 6137| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6138| 6600102 | The session does not exist. | 6139| 6600103 | The session controller does not exist. | 6140 6141**Example** 6142 6143```ts 6144import { BusinessError } from '@kit.BasicServicesKit'; 6145 6146avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => { 6147 if (err) { 6148 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 6149 } else { 6150 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 6151 } 6152}); 6153``` 6154 6155### skipToQueueItem<sup>10+</sup> 6156 6157skipToQueueItem(itemId: number): Promise\<void> 6158 6159Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses a promise to return the result. 6160 6161**Atomic service API**: This API can be used in atomic services since API version 12. 6162 6163**System capability**: SystemCapability.Multimedia.AVSession.Core 6164 6165**Parameters** 6166 6167| Name | Type | Mandatory| Description | 6168| ------ | ------- | ---- | ------------------------------------------- | 6169| itemId | number | Yes | ID of an item in the playlist.| 6170 6171**Return value** 6172 6173| Type | Description | 6174| -------------- | --------------------------------------------------------------- | 6175| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.| 6176 6177**Error codes** 6178 6179For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6180 6181| ID| Error Message| 6182| -------- | ---------------------------------------- | 6183| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6184| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6185| 6600102 | The session does not exist. | 6186| 6600103 | The session controller does not exist. | 6187 6188**Example** 6189 6190```ts 6191import { BusinessError } from '@kit.BasicServicesKit'; 6192 6193let queueItemId = 0; 6194avsessionController.skipToQueueItem(queueItemId).then(() => { 6195 console.info('SkipToQueueItem successfully'); 6196}).catch((err: BusinessError) => { 6197 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 6198}); 6199``` 6200 6201### skipToQueueItem<sup>10+</sup> 6202 6203skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void 6204 6205Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses an asynchronous callback to return the result. 6206 6207**System capability**: SystemCapability.Multimedia.AVSession.Core 6208 6209**Parameters** 6210 6211| Name | Type | Mandatory| Description | 6212| -------- | --------------------- | ---- | ----------------------------------------------------------- | 6213| itemId | number | Yes | ID of an item in the playlist. | 6214| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 6215 6216**Error codes** 6217 6218For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6219 6220| ID| Error Message| 6221| -------- | ---------------------------------------- | 6222| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6223| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6224| 6600102 | The session does not exist. | 6225| 6600103 | The session controller does not exist. | 6226 6227**Example** 6228 6229```ts 6230import { BusinessError } from '@kit.BasicServicesKit'; 6231 6232let queueItemId = 0; 6233avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => { 6234 if (err) { 6235 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 6236 } else { 6237 console.info('SkipToQueueItem successfully'); 6238 } 6239}); 6240``` 6241 6242### getOutputDevice<sup>10+</sup> 6243 6244getOutputDevice(): Promise\<OutputDeviceInfo> 6245 6246Obtains the output device information. This API uses a promise to return the result. 6247 6248**Atomic service API**: This API can be used in atomic services since API version 12. 6249 6250**System capability**: SystemCapability.Multimedia.AVSession.Core 6251 6252**Return value** 6253 6254| Type | Description | 6255| ----------------------------------------------- | --------------------------------- | 6256| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.| 6257 6258**Error codes** 6259 6260For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6261 6262| ID| Error Message| 6263| -------- | ---------------------------------------- | 6264| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6265| 600103 | The session controller does not exist. | 6266 6267**Example** 6268 6269```ts 6270import { BusinessError } from '@kit.BasicServicesKit'; 6271 6272avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => { 6273 console.info('GetOutputDevice : SUCCESS'); 6274}).catch((err: BusinessError) => { 6275 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 6276}); 6277``` 6278 6279### getOutputDevice<sup>10+</sup> 6280 6281getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 6282 6283Obtains the output device information. This API uses an asynchronous callback to return the result. 6284 6285**System capability**: SystemCapability.Multimedia.AVSession.Core 6286 6287**Parameters** 6288 6289| Name | Type | Mandatory| Description | 6290| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 6291| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| 6292 6293**Error codes** 6294 6295For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6296 6297| ID| Error Message| 6298| -------- | ---------------------------------------- | 6299| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6300| 600103 | The session controller does not exist. | 6301 6302**Example** 6303 6304```ts 6305import { BusinessError } from '@kit.BasicServicesKit'; 6306 6307avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => { 6308 if (err) { 6309 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 6310 } else { 6311 console.info('GetOutputDevice : SUCCESS'); 6312 } 6313}); 6314``` 6315 6316### sendAVKeyEvent<sup>10+</sup> 6317 6318sendAVKeyEvent(event: KeyEvent): Promise\<void> 6319 6320Sends a key event to the session corresponding to this controller. This API uses a promise to return the result. 6321 6322**Atomic service API**: This API can be used in atomic services since API version 12. 6323 6324**System capability**: SystemCapability.Multimedia.AVSession.Core 6325 6326**Parameters** 6327 6328| Name| Type | Mandatory| Description | 6329| ------ | ------------------------------------------------------------ | ---- | ---------- | 6330| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes | Key event.| 6331 6332**Error codes** 6333 6334For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6335 6336| ID| Error Message| 6337| -------- | ---------------------------------------- | 6338| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6339| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6340| 600102 | The session does not exist. | 6341| 600103 | The session controller does not exist. | 6342| 600105 | Invalid session command. | 6343| 600106 | The session is not activated. | 6344 6345**Return value** 6346 6347| Type | Description | 6348| -------------- | ----------------------------- | 6349| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.| 6350 6351**Example** 6352 6353```ts 6354import { Key, KeyEvent } from '@kit.InputKit'; 6355import { BusinessError } from '@kit.BasicServicesKit'; 6356 6357let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 6358let event: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}; 6359 6360 6361avsessionController.sendAVKeyEvent(event).then(() => { 6362 console.info('SendAVKeyEvent Successfully'); 6363}).catch((err: BusinessError) => { 6364 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 6365}); 6366``` 6367 6368### sendAVKeyEvent<sup>10+</sup> 6369 6370sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 6371 6372Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result. 6373 6374**System capability**: SystemCapability.Multimedia.AVSession.Core 6375 6376**Parameters** 6377 6378| Name | Type | Mandatory| Description | 6379| -------- | ------------------------------------------------------------ | ---- | ---------- | 6380| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes | Key event.| 6381| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.| 6382 6383**Error codes** 6384 6385For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6386 6387| ID| Error Message| 6388| -------- | ---------------------------------------- | 6389| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6390| 600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6391| 600102 | The session does not exist. | 6392| 600103 | The session controller does not exist. | 6393| 600105 | Invalid session command. | 6394| 600106 | The session is not activated. | 6395 6396**Example** 6397 6398```ts 6399import { Key, KeyEvent } from '@kit.InputKit'; 6400import { BusinessError } from '@kit.BasicServicesKit'; 6401 6402let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 6403let event: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}; 6404avsessionController.sendAVKeyEvent(event, (err: BusinessError) => { 6405 if (err) { 6406 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 6407 } else { 6408 console.info('SendAVKeyEvent Successfully'); 6409 } 6410}); 6411``` 6412 6413### getLaunchAbility<sup>10+</sup> 6414 6415getLaunchAbility(): Promise\<WantAgent> 6416 6417Obtains the WantAgent object saved by the application in the session. This API uses a promise to return the result. 6418 6419**Atomic service API**: This API can be used in atomic services since API version 12. 6420 6421**System capability**: SystemCapability.Multimedia.AVSession.Core 6422 6423**Return value** 6424 6425| Type | Description | 6426| ------------------------------------------------------- | ------------------------------------------------------------ | 6427| Promise<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | Promise used to return the object saved by calling [setLaunchAbility](#setlaunchability10). The object includes the application property, such as the bundle name, ability name, and device ID.| 6428 6429**Error codes** 6430 6431For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6432 6433| ID| Error Message| 6434| -------- | ---------------------------------------- | 6435| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6436| 6600102 | The session does not exist. | 6437| 6600103 | The session controller does not exist. | 6438 6439**Example** 6440 6441```ts 6442import { BusinessError } from '@kit.BasicServicesKit'; 6443 6444avsessionController.getLaunchAbility().then((agent: object) => { 6445 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 6446}).catch((err: BusinessError) => { 6447 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 6448}); 6449``` 6450 6451### getLaunchAbility<sup>10+</sup> 6452 6453getLaunchAbility(callback: AsyncCallback\<WantAgent>): void 6454 6455Obtains the WantAgent object saved by the application in the session. This API uses an asynchronous callback to return the result. 6456 6457**System capability**: SystemCapability.Multimedia.AVSession.Core 6458 6459**Parameters** 6460 6461| Name | Type | Mandatory| Description | 6462| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6463| callback | AsyncCallback<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | Yes | Callback used to return the object saved by calling [setLaunchAbility](#setlaunchability10). The object includes the application property, such as the bundle name, ability name, and device ID.| 6464 6465**Error codes** 6466 6467For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6468 6469| ID| Error Message| 6470| -------- | ---------------------------------------- | 6471| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6472| 6600102 | The session does not exist. | 6473| 6600103 | The session controller does not exist. | 6474 6475**Example** 6476 6477```ts 6478import { BusinessError } from '@kit.BasicServicesKit'; 6479 6480avsessionController.getLaunchAbility((err: BusinessError, agent: object) => { 6481 if (err) { 6482 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 6483 } else { 6484 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 6485 } 6486}); 6487``` 6488 6489### getRealPlaybackPositionSync<sup>10+</sup> 6490 6491getRealPlaybackPositionSync(): number 6492 6493Obtains the playback position. 6494 6495**Atomic service API**: This API can be used in atomic services since API version 12. 6496 6497**System capability**: SystemCapability.Multimedia.AVSession.Core 6498 6499**Return value** 6500 6501| Type | Description | 6502| ------ | ------------------ | 6503| number | Playback position, in milliseconds.| 6504 6505**Error codes** 6506 6507For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6508 6509| ID| Error Message| 6510| -------- | ---------------------------------------- | 6511| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6512| 6600103 | The session controller does not exist. | 6513 6514**Example** 6515 6516```ts 6517let time: number = avsessionController.getRealPlaybackPositionSync(); 6518``` 6519 6520### isActive<sup>10+</sup> 6521 6522isActive(): Promise\<boolean> 6523 6524Checks whether the session is activated. This API uses a promise to return the result. 6525 6526**Atomic service API**: This API can be used in atomic services since API version 12. 6527 6528**System capability**: SystemCapability.Multimedia.AVSession.Core 6529 6530**Return value** 6531 6532| Type | Description | 6533| ----------------- | ------------------------------------------------------------ | 6534| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.| 6535 6536**Error codes** 6537 6538For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6539 6540| ID| Error Message| 6541| -------- | ---------------------------------------- | 6542| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6543| 6600102 | The session does not exist. | 6544| 6600103 | The session controller does not exist. | 6545 6546**Example** 6547 6548```ts 6549import { BusinessError } from '@kit.BasicServicesKit'; 6550 6551avsessionController.isActive().then((isActive: boolean) => { 6552 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6553}).catch((err: BusinessError) => { 6554 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6555}); 6556``` 6557 6558### isActive<sup>10+</sup> 6559 6560isActive(callback: AsyncCallback\<boolean>): void 6561 6562Checks whether the session is activated. This API uses an asynchronous callback to return the result. 6563 6564**System capability**: SystemCapability.Multimedia.AVSession.Core 6565 6566**Parameters** 6567 6568| Name | Type | Mandatory| Description | 6569| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 6570| callback | AsyncCallback<boolean\> | Yes | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.| 6571 6572**Error codes** 6573 6574For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6575 6576| ID| Error Message| 6577| -------- | ---------------------------------------- | 6578| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6579| 6600102 | The session does not exist. | 6580| 6600103 | The session controller does not exist. | 6581 6582**Example** 6583 6584```ts 6585import { BusinessError } from '@kit.BasicServicesKit'; 6586 6587avsessionController.isActive((err: BusinessError, isActive: boolean) => { 6588 if (err) { 6589 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6590 } else { 6591 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6592 } 6593}); 6594``` 6595 6596### destroy<sup>10+</sup> 6597 6598destroy(): Promise\<void> 6599 6600Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result. 6601 6602**Atomic service API**: This API can be used in atomic services since API version 12. 6603 6604**System capability**: SystemCapability.Multimedia.AVSession.Core 6605 6606**Return value** 6607 6608| Type | Description | 6609| -------------- | ----------------------------- | 6610| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.| 6611 6612**Error codes** 6613 6614For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6615 6616| ID| Error Message| 6617| -------- | ---------------------------------------- | 6618| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6619| 6600103 | The session controller does not exist. | 6620 6621**Example** 6622 6623```ts 6624import { BusinessError } from '@kit.BasicServicesKit'; 6625 6626avsessionController.destroy().then(() => { 6627 console.info('Destroy : SUCCESS '); 6628}).catch((err: BusinessError) => { 6629 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6630}); 6631``` 6632 6633### destroy<sup>10+</sup> 6634 6635destroy(callback: AsyncCallback\<void>): void 6636 6637Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result. 6638 6639**System capability**: SystemCapability.Multimedia.AVSession.Core 6640 6641**Parameters** 6642 6643| Name | Type | Mandatory| Description | 6644| -------- | -------------------- | ---- | ---------- | 6645| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| 6646 6647**Error codes** 6648 6649For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6650 6651| ID| Error Message| 6652| -------- | ---------------------------------------- | 6653| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6654| 6600103 | The session controller does not exist. | 6655 6656**Example** 6657 6658```ts 6659import { BusinessError } from '@kit.BasicServicesKit'; 6660 6661avsessionController.destroy((err: BusinessError) => { 6662 if (err) { 6663 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6664 } else { 6665 console.info('Destroy : SUCCESS '); 6666 } 6667}); 6668``` 6669 6670### getValidCommands<sup>10+</sup> 6671 6672getValidCommands(): Promise\<Array\<AVControlCommandType>> 6673 6674Obtains valid commands supported by the session. This API uses a promise to return the result. 6675 6676**Atomic service API**: This API can be used in atomic services since API version 12. 6677 6678**System capability**: SystemCapability.Multimedia.AVSession.Core 6679 6680**Return value** 6681 6682| Type | Description | 6683| ------------------------------------------------------------ | --------------------------------- | 6684| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands.| 6685 6686**Error codes** 6687 6688For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6689 6690| ID| Error Message| 6691| -------- | ---------------------------------------- | 6692| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6693| 6600102 | The session does not exist. | 6694| 6600103 | The session controller does not exist. | 6695 6696**Example** 6697 6698```ts 6699import { BusinessError } from '@kit.BasicServicesKit'; 6700 6701avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => { 6702 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6703}).catch((err: BusinessError) => { 6704 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6705}); 6706``` 6707 6708### getValidCommands<sup>10+</sup> 6709 6710getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void 6711 6712Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result. 6713 6714**System capability**: SystemCapability.Multimedia.AVSession.Core 6715 6716**Parameters** 6717 6718| Name | Type | Mandatory| Description | 6719| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 6720| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes | Callback used to return a set of valid commands.| 6721 6722**Error codes** 6723 6724For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6725 6726| ID| Error Message| 6727| -------- | ---------------------------------------- | 6728| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6729| 6600102 | The session does not exist. | 6730| 6600103 | The session controller does not exist. | 6731 6732**Example** 6733 6734```ts 6735import { BusinessError } from '@kit.BasicServicesKit'; 6736 6737avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => { 6738 if (err) { 6739 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6740 } else { 6741 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6742 } 6743}); 6744``` 6745 6746### sendControlCommand<sup>10+</sup> 6747 6748sendControlCommand(command: AVControlCommand): Promise\<void> 6749 6750Sends a control command to the session through the controller. This API uses a promise to return the result. 6751 6752> **NOTE** 6753> 6754> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like. 6755 6756**Atomic service API**: This API can be used in atomic services since API version 12. 6757 6758**System capability**: SystemCapability.Multimedia.AVSession.Core 6759 6760**Parameters** 6761 6762| Name | Type | Mandatory| Description | 6763| ------- | ------------------------------------- | ---- | ------------------------------ | 6764| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| 6765 6766**Return value** 6767 6768| Type | Description | 6769| -------------- | ----------------------------- | 6770| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 6771 6772**Error codes** 6773 6774For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6775 6776| ID| Error Message| 6777| -------- | ---------------------------------------- | 6778| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6779| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6780| 6600102 | The session does not exist. | 6781| 6600103 | The session controller does not exist. | 6782| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6783| 6600106 | The session is not activated. | 6784| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6785 6786**Example** 6787 6788```ts 6789import { BusinessError } from '@kit.BasicServicesKit'; 6790 6791let avCommand: avSession.AVControlCommand = {command:'play'}; 6792avsessionController.sendControlCommand(avCommand).then(() => { 6793 console.info('SendControlCommand successfully'); 6794}).catch((err: BusinessError) => { 6795 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6796}); 6797``` 6798 6799### sendControlCommand<sup>10+</sup> 6800 6801sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 6802 6803Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result. 6804 6805> **NOTE** 6806> 6807> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like. 6808 6809**System capability**: SystemCapability.Multimedia.AVSession.Core 6810 6811**Parameters** 6812 6813| Name | Type | Mandatory| Description | 6814| -------- | ------------------------------------- | ---- | ------------------------------ | 6815| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| 6816| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 6817 6818**Error codes** 6819 6820For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6821 6822| ID| Error Message| 6823| -------- | ------------------------------- | 6824| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6825| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6826| 6600102 | The session does not exist. | 6827| 6600103 | The session controller does not exist. | 6828| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6829| 6600106 | The session is not activated. | 6830| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6831 6832**Example** 6833 6834```ts 6835import { BusinessError } from '@kit.BasicServicesKit'; 6836 6837let avCommand: avSession.AVControlCommand = {command:'play'}; 6838avsessionController.sendControlCommand(avCommand, (err: BusinessError) => { 6839 if (err) { 6840 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6841 } else { 6842 console.info('SendControlCommand successfully'); 6843 } 6844}); 6845``` 6846 6847### sendCommonCommand<sup>10+</sup> 6848 6849sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void> 6850 6851Sends a custom control command to the session through the controller. This API uses a promise to return the result. 6852 6853**Atomic service API**: This API can be used in atomic services since API version 12. 6854 6855**System capability**: SystemCapability.Multimedia.AVSession.Core 6856 6857**Parameters** 6858 6859| Name | Type | Mandatory| Description | 6860| ------- | ------------------------------------- | ---- | ------------------------------ | 6861| command | string | Yes | Name of the custom control command.| 6862| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command.| 6863 6864> **NOTE** 6865> 6866> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 6867 6868**Return value** 6869 6870| Type | Description | 6871| -------------- | ----------------------------- | 6872| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 6873 6874**Error codes** 6875 6876For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6877 6878| ID| Error Message| 6879| -------- | ---------------------------------------- | 6880| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6881| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6882| 6600102 | The session does not exist. | 6883| 6600103 | The session controller does not exist. | 6884| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6885| 6600106 | The session is not activated. | 6886| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6887 6888**Example** 6889 6890```ts 6891import { BusinessError } from '@kit.BasicServicesKit'; 6892import { avSession } from '@kit.AVSessionKit'; 6893 6894let tag: string = "createNewSession"; 6895let sessionId: string = ""; 6896let controller:avSession.AVSessionController | undefined = undefined; 6897avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 6898 currentAVSession = data; 6899 sessionId = currentAVSession.sessionId; 6900 controller = await currentAVSession.getController(); 6901 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 6902}).catch((err: BusinessError) => { 6903 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 6904}); 6905let commandName = "my_command"; 6906if (controller !== undefined) { 6907 (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => { 6908 console.info('SendCommonCommand successfully'); 6909 }).catch((err: BusinessError) => { 6910 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6911 }) 6912} 6913``` 6914 6915### sendCommonCommand<sup>10+</sup> 6916 6917sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 6918 6919Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result. 6920 6921**System capability**: SystemCapability.Multimedia.AVSession.Core 6922 6923**Parameters** 6924 6925| Name | Type | Mandatory| Description | 6926| ------- | ------------------------------------- | ---- | ------------------------------ | 6927| command | string | Yes | Name of the custom control command.| 6928| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command.| 6929| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 6930 6931> **NOTE** 6932> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md). 6933 6934**Error codes** 6935 6936For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6937 6938| ID| Error Message| 6939| -------- | ------------------------------- | 6940| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.| 6941| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6942| 6600102 | The session does not exist. | 6943| 6600103 | The session controller does not exist. | 6944| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 6945| 6600106 | The session is not activated. | 6946| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 6947 6948**Example** 6949 6950```ts 6951import { BusinessError } from '@kit.BasicServicesKit'; 6952import { avSession } from '@kit.AVSessionKit'; 6953 6954let tag: string = "createNewSession"; 6955let sessionId: string = ""; 6956let controller:avSession.AVSessionController | undefined = undefined; 6957avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 6958 currentAVSession = data; 6959 sessionId = currentAVSession.sessionId; 6960 controller = await currentAVSession.getController(); 6961 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 6962}).catch((err: BusinessError) => { 6963 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 6964}); 6965let commandName = "my_command"; 6966if (controller !== undefined) { 6967 (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => { 6968 if (err) { 6969 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6970 } 6971 }) 6972} 6973``` 6974 6975### getExtras<sup>10+</sup> 6976 6977getExtras(): Promise\<{[key: string]: Object}> 6978 6979Obtains the custom media packet set by the provider. This API uses a promise to return the result. 6980 6981**Atomic service API**: This API can be used in atomic services since API version 12. 6982 6983**System capability**: SystemCapability.Multimedia.AVSession.Core 6984 6985**Return value** 6986 6987| Type | Description | 6988| ----------------------------------- | ----------------------------- | 6989| Promise<{[key: string]: Object}\> | Promise used to return the custom media packet. The content of the packet is the same as that set in **setExtras**.| 6990 6991**Error codes** 6992 6993For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6994 6995| ID| Error Message| 6996| -------- | ---------------------------------------- | 6997| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6998| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 6999| 6600102 | The session does not exist. | 7000| 6600103 | The session controller does not exist. | 7001| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 7002| 6600107 | Too many commands or events.Controls the frequency of sending self-query and control commands. | 7003 7004**Example** 7005 7006```ts 7007import { BusinessError } from '@kit.BasicServicesKit'; 7008import { avSession } from '@kit.AVSessionKit'; 7009 7010let tag: string = "createNewSession"; 7011let sessionId: string = ""; 7012let controller:avSession.AVSessionController | undefined = undefined; 7013avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7014 currentAVSession = data; 7015 sessionId = currentAVSession.sessionId; 7016 controller = await currentAVSession.getController(); 7017 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7018}).catch((err: BusinessError) => { 7019 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7020}); 7021if (controller !== undefined) { 7022 (controller as avSession.AVSessionController).getExtras().then((extras) => { 7023 console.info(`getExtras : SUCCESS : ${extras}`); 7024 }).catch((err: BusinessError) => { 7025 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 7026 }); 7027} 7028 7029``` 7030 7031### getExtras<sup>10+</sup> 7032 7033getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void 7034 7035Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result. 7036 7037**System capability**: SystemCapability.Multimedia.AVSession.Core 7038 7039**Parameters** 7040 7041| Name | Type | Mandatory| Description | 7042| -------- | ----------------------------------------- | ---- | -------------------------- | 7043| callback | AsyncCallback<{[key: string]: Object}\> | Yes | Callback used to return the custom media packet. The content of the packet is the same as that set in **setExtras**.| 7044 7045**Error codes** 7046 7047For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7048 7049| ID| Error Message| 7050| -------- | ---------------------------------------- | 7051| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 7052| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7053| 6600102 | The session does not exist. | 7054| 6600103 | The session controller does not exist. | 7055| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 7056| 6600107 |Too many commands or events.Controls the frequency of sending self-query and control commands. | 7057 7058**Example** 7059 7060```ts 7061import { BusinessError } from '@kit.BasicServicesKit'; 7062import { avSession } from '@kit.AVSessionKit'; 7063 7064let tag: string = "createNewSession"; 7065let sessionId: string = ""; 7066let controller:avSession.AVSessionController | undefined = undefined; 7067avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7068 currentAVSession = data; 7069 sessionId = currentAVSession.sessionId; 7070 controller = await currentAVSession.getController(); 7071 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7072}).catch((err: BusinessError) => { 7073 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7074}); 7075if (controller !== undefined) { 7076 (controller as avSession.AVSessionController).getExtras((err, extras) => { 7077 if (err) { 7078 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 7079 } else { 7080 console.info(`getExtras : SUCCESS : ${extras}`); 7081 } 7082 }); 7083} 7084``` 7085 7086### getExtrasWithEvent<sup>18+</sup> 7087 7088getExtrasWithEvent(extraEvent: string): Promise\<ExtraInfo> 7089 7090Obtains the custom media packet set by the remote distributed media provider based on the remote distributed event type. This API uses a promise to return the result. 7091 7092**System capability**: SystemCapability.Multimedia.AVSession.Core 7093 7094**Parameters** 7095 7096| Name | Type | Mandatory| Description | 7097| -------- | ----------------------------------------- | ---- | -------------------------- | 7098| extraEvent | string | Yes| Remote distributed event type.<br>Currently, the following event types are supported:<br>**'AUDIO_GET_VOLUME'**: obtains the volume of the remote device.<br>**'AUDIO_GET_AVAILABLE_DEVICES'**: obtains all remote devices that can be connected.<br>**'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'**: obtains the actual remote audio device.| 7099 7100**Return value** 7101 7102| Type | Description | 7103| ----------------------------------- | ----------------------------- | 7104| Promise<[ExtraInfo](#extrainfo18)\> | Promise used to return the custom media packet set by the remote distributed media provider.<br>The **ExtraInfo** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).| 7105 7106**Error codes** 7107 7108For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7109 7110| ID| Error Message| 7111| -------- | ---------------------------------------- | 7112| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7113| 6600102 | The session does not exist. | 7114| 6600103 | The session controller does not exist. | 7115| 6600105 | Invalid session command.Stop sending the command or event,sending commands supported by the controlled end. | 7116 7117**Example** 7118 7119```ts 7120import { BusinessError } from '@kit.BasicServicesKit'; 7121 7122let controller: avSession.AVSessionController | ESObject; 7123const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME'; 7124const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES'; 7125const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'; 7126if (controller !== undefined) { 7127 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then(() => { 7128 console.info(`${[COMMON_COMMAND_STRING_1]}`); 7129 }).catch((err: BusinessError) => { 7130 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7131 }) 7132 7133 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then(() => { 7134 console.info(`${[COMMON_COMMAND_STRING_2]}`); 7135 }).catch((err: BusinessError) => { 7136 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7137 }) 7138 7139 controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then(() => { 7140 console.info(`${[COMMON_COMMAND_STRING_3]}`); 7141 }).catch((err: BusinessError) => { 7142 console.error(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`); 7143 }) 7144} 7145``` 7146 7147### on('metadataChange')<sup>10+</sup> 7148 7149on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void) 7150 7151Subscribes to metadata change events. 7152 7153**Atomic service API**: This API can be used in atomic services since API version 12. 7154 7155**System capability**: SystemCapability.Multimedia.AVSession.Core 7156 7157**Parameters** 7158 7159| Name | Type | Mandatory| Description | 7160| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7161| type | string | Yes | Event type. The event **'metadataChange'** is triggered when the session metadata changes.| 7162| filter | Array\<keyof [AVMetadata](#avmetadata10)\> | 'all' | Yes | The value **'all'** indicates that any metadata field change will trigger the event, and **Array<keyof [AVMetadata](#avmetadata10)\>** indicates that only changes to the listed metadata field will trigger the event.| 7163| callback | (data: [AVMetadata](#avmetadata10)) => void | Yes | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata. | 7164 7165**Error codes** 7166 7167For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7168 7169| ID| Error Message| 7170| -------- | ------------------------------ | 7171| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7172| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7173| 6600103 | The session controller does not exist. | 7174 7175**Example** 7176 7177```ts 7178avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => { 7179 console.info(`on metadataChange assetId : ${metadata.assetId}`); 7180}); 7181 7182avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => { 7183 console.info(`on metadataChange assetId : ${metadata.assetId}`); 7184}); 7185 7186``` 7187 7188### off('metadataChange')<sup>10+</sup> 7189 7190off(type: 'metadataChange', callback?: (data: AVMetadata) => void) 7191 7192Unsubscribes from metadata change events. This API is called by the controller. 7193 7194**Atomic service API**: This API can be used in atomic services since API version 12. 7195 7196**System capability**: SystemCapability.Multimedia.AVSession.Core 7197 7198**Parameters** 7199 7200| Name | Type | Mandatory| Description | 7201| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 7202| type | string | Yes | Event type, which is **'metadataChange'** in this case. | 7203| callback | (data: [AVMetadata](#avmetadata10)) => void | No | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7204 7205**Error codes** 7206 7207For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7208 7209| ID| Error Message| 7210| -------- | ---------------- | 7211| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7212| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7213| 6600103 | The session controller does not exist. | 7214 7215**Example** 7216 7217```ts 7218avsessionController.off('metadataChange'); 7219``` 7220 7221### on('playbackStateChange')<sup>10+</sup> 7222 7223on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void) 7224 7225Subscribes to playback state change events. 7226 7227**Atomic service API**: This API can be used in atomic services since API version 12. 7228 7229**System capability**: SystemCapability.Multimedia.AVSession.Core 7230 7231**Parameters** 7232 7233| Name | Type | Mandatory| Description | 7234| --------| -----------|-----|------------| 7235| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| 7236| filter | Array\<keyof [AVPlaybackState](#avplaybackstate10)\> | 'all' | Yes | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof [AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.| 7237| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.| 7238 7239**Error codes** 7240 7241For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7242 7243| ID| Error Message| 7244| -------- | ------------------------------ | 7245| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7246| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7247| 6600103 | The session controller does not exist. | 7248 7249**Example** 7250 7251```ts 7252avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 7253 console.info(`on playbackStateChange state : ${playbackState.state}`); 7254}); 7255 7256avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => { 7257 console.info(`on playbackStateChange state : ${playbackState.state}`); 7258}); 7259``` 7260 7261### off('playbackStateChange')<sup>10+</sup> 7262 7263off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) 7264 7265Unsubscribes from playback state change events. This API is called by the controller. 7266 7267**Atomic service API**: This API can be used in atomic services since API version 12. 7268 7269**System capability**: SystemCapability.Multimedia.AVSession.Core 7270 7271**Parameters** 7272 7273| Name | Type | Mandatory| Description | 7274| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7275| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | 7276| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | No | Callback function, where the **state** parameter indicates the new playback state.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7277 7278**Error codes** 7279 7280For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7281 7282| ID| Error Message| 7283| -------- | ---------------- | 7284| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7285| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7286| 6600103 | The session controller does not exist. | 7287 7288**Example** 7289 7290```ts 7291avsessionController.off('playbackStateChange'); 7292``` 7293 7294### on('callMetadataChange')<sup>11+</sup> 7295 7296on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void 7297 7298Subscribes to call metadata change events. 7299 7300**Atomic service API**: This API can be used in atomic services since API version 12. 7301 7302**System capability**: SystemCapability.Multimedia.AVSession.Core 7303 7304**Parameters** 7305 7306| Name | Type | Mandatory| Description | 7307| --------| -----------|-----|------------| 7308| type | string | Yes | Event type. The event **'callMetadataChange'** is triggered when the call metadata changes.| 7309| filter | Array\<keyof [CallMetadata](#callmetadata11)\> | 'all' | Yes | The value **'all'** indicates that any call metadata field change will trigger the event, and **Array<keyof [CallMetadata](#callmetadata11)\>** indicates that only changes to the listed metadata field will trigger the event.| 7310| callback | Callback<[CallMetadata](#callmetadata11)\> | Yes | Callback used for subscription. The **callmetadata** parameter in the callback indicates the changed call metadata.| 7311 7312**Error codes** 7313 7314For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7315 7316| ID| Error Message| 7317| -------- | ------------------------------ | 7318| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7319| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7320| 6600103 | The session controller does not exist. | 7321 7322**Example** 7323 7324```ts 7325avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => { 7326 console.info(`on callMetadataChange state : ${callmetadata.name}`); 7327}); 7328 7329avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => { 7330 console.info(`on callMetadataChange state : ${callmetadata.name}`); 7331}); 7332``` 7333 7334### off('callMetadataChange')<sup>11+</sup> 7335 7336off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void 7337 7338Unsubscribes from call metadata change events. 7339 7340**Atomic service API**: This API can be used in atomic services since API version 12. 7341 7342**System capability**: SystemCapability.Multimedia.AVSession.Core 7343 7344**Parameters** 7345 7346| Name | Type | Mandatory| Description | 7347| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7348| type | string | Yes | Event type, which is **'callMetadataChange'** in this case. | 7349| callback | Callback<[CallMetadata](#callmetadata11)\> | No | Callback used for unsubscription. The **calldata** parameter in the callback indicates the changed call metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7350 7351**Error codes** 7352 7353For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7354 7355| ID| Error Message| 7356| -------- | ---------------- | 7357| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7358| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7359| 6600103 | The session controller does not exist. | 7360 7361**Example** 7362 7363```ts 7364avsessionController.off('callMetadataChange'); 7365``` 7366 7367### on('callStateChange')<sup>11+</sup> 7368 7369on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void 7370 7371Subscribes to call state change events. 7372 7373**Atomic service API**: This API can be used in atomic services since API version 12. 7374 7375**System capability**: SystemCapability.Multimedia.AVSession.Core 7376 7377**Parameters** 7378 7379| Name | Type | Mandatory| Description | 7380| --------| -----------|-----|------------| 7381| type | string | Yes | Event type. The event **'callStateChange'** is triggered when the call state changes.| 7382| filter | Array<keyof [AVCallState](#avcallstate11)\> | 'all' | Yes | The value **'all'** indicates that any call state field change will trigger the event, and **Array<keyof [AVCallState](#avcallstate11)\>** indicates that only changes to the listed call state field will trigger the event.| 7383| callback | Callback<[AVCallState](#avcallstate11)\> | Yes | Callback function, where the **callstate** parameter indicates the new call state.| 7384 7385**Error codes** 7386 7387For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7388 7389| ID| Error Message| 7390| -------- | ------------------------------ | 7391| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7392| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7393| 6600103 | The session controller does not exist. | 7394 7395**Example** 7396 7397```ts 7398avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => { 7399 console.info(`on callStateChange state : ${callstate.state}`); 7400}); 7401 7402avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => { 7403 console.info(`on callStateChange state : ${callstate.state}`); 7404}); 7405``` 7406 7407### off('callStateChange')<sup>11+</sup> 7408 7409off(type: 'callStateChange', callback?: Callback\<AVCallState>): void 7410 7411Unsubscribes from call state change events. 7412 7413**Atomic service API**: This API can be used in atomic services since API version 12. 7414 7415**System capability**: SystemCapability.Multimedia.AVSession.Core 7416 7417**Parameters** 7418 7419| Name | Type | Mandatory| Description | 7420| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7421| type | string | Yes | Event type, which is **'callStateChange'** in this case. | 7422| callback | Callback<[AVCallState](#avcallstate11)\> | No | Callback function, where the **callstate** parameter indicates the new call metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7423 7424**Error codes** 7425 7426For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7427 7428| ID| Error Message| 7429| -------- | ---------------- | 7430| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7431| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7432| 6600103 | The session controller does not exist. | 7433 7434**Example** 7435 7436```ts 7437avsessionController.off('callMetadataChange'); 7438``` 7439 7440### on('sessionDestroy')<sup>10+</sup> 7441 7442on(type: 'sessionDestroy', callback: () => void) 7443 7444Subscribes to session destruction events. 7445 7446**Atomic service API**: This API can be used in atomic services since API version 12. 7447 7448**System capability**: SystemCapability.Multimedia.AVSession.Core 7449 7450**Parameters** 7451 7452| Name | Type | Mandatory| Description | 7453| -------- | ---------- | ---- | ------------------------------------------------------------ | 7454| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| 7455| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 7456 7457**Error codes** 7458 7459For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7460 7461| ID| Error Message| 7462| -------- | ------------------------------ | 7463| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7464| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7465| 6600103 | The session controller does not exist. | 7466 7467**Example** 7468 7469```ts 7470avsessionController.on('sessionDestroy', () => { 7471 console.info('on sessionDestroy : SUCCESS '); 7472}); 7473``` 7474 7475### off('sessionDestroy')<sup>10+</sup> 7476 7477off(type: 'sessionDestroy', callback?: () => void) 7478 7479Unsubscribes from session destruction events. This API is called by the controller. 7480 7481**Atomic service API**: This API can be used in atomic services since API version 12. 7482 7483**System capability**: SystemCapability.Multimedia.AVSession.Core 7484 7485**Parameters** 7486 7487| Name | Type | Mandatory| Description | 7488| -------- | ---------- | ---- | ----------------------------------------------------- | 7489| type | string | Yes | Event type, which is **'sessionDestroy'** in this case. | 7490| 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. | 7491 7492**Error codes** 7493 7494For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7495 7496| ID| Error Message| 7497| -------- | ---------------- | 7498| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7499| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7500| 6600103 | The session controller does not exist. | 7501 7502**Example** 7503 7504```ts 7505avsessionController.off('sessionDestroy'); 7506``` 7507 7508### on('activeStateChange')<sup>10+</sup> 7509 7510on(type: 'activeStateChange', callback: (isActive: boolean) => void) 7511 7512Subscribes to session activation state change events. 7513 7514**Atomic service API**: This API can be used in atomic services since API version 12. 7515 7516**System capability**: SystemCapability.Multimedia.AVSession.Core 7517 7518**Parameters** 7519 7520| Name | Type | Mandatory| Description | 7521| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 7522| type | string | Yes | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes.| 7523| callback | (isActive: boolean) => void | Yes | Callback used for subscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the service is activated, and **false** means the opposite. | 7524 7525**Error codes** 7526 7527For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7528 7529| ID| Error Message| 7530| -------- | ----------------------------- | 7531| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7532| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7533| 6600103 |The session controller does not exist. | 7534 7535**Example** 7536 7537```ts 7538avsessionController.on('activeStateChange', (isActive: boolean) => { 7539 console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); 7540}); 7541``` 7542 7543### off('activeStateChange')<sup>10+</sup> 7544 7545off(type: 'activeStateChange', callback?: (isActive: boolean) => void) 7546 7547Unsubscribes from session activation state change events. This API is called by the controller. 7548 7549**Atomic service API**: This API can be used in atomic services since API version 12. 7550 7551**System capability**: SystemCapability.Multimedia.AVSession.Core 7552 7553**Parameters** 7554 7555| Name | Type | Mandatory| Description | 7556| -------- | --------------------------- | ---- | ----------------------------------------------------- | 7557| type | string | Yes | Event type, which is **'activeStateChange'** in this case. | 7558| callback | (isActive: boolean) => void | No | Callback used for unsubscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the session is activated, and **false** means the opposite.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7559 7560**Error codes** 7561 7562For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7563 7564| ID| Error Message| 7565| -------- | ---------------- | 7566| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7567| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7568| 6600103 | The session controller does not exist. | 7569 7570**Example** 7571 7572```ts 7573avsessionController.off('activeStateChange'); 7574``` 7575 7576### on('validCommandChange')<sup>10+</sup> 7577 7578on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void) 7579 7580Subscribes to valid command change events. 7581 7582**Atomic service API**: This API can be used in atomic services since API version 12. 7583 7584**System capability**: SystemCapability.Multimedia.AVSession.Core 7585 7586**Parameters** 7587 7588| Name | Type | Mandatory| Description | 7589| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7590| type | string | Yes | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.| 7591| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | 7592 7593**Error codes** 7594 7595For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7596 7597| ID| Error Message| 7598| -------- | ------------------------------ | 7599| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7600| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7601| 6600103 | The session controller does not exist. | 7602 7603**Example** 7604 7605```ts 7606avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => { 7607 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 7608 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 7609}); 7610``` 7611 7612### off('validCommandChange')<sup>10+</sup> 7613 7614off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void) 7615 7616Unsubscribes from valid command change events. This API is called by the controller. 7617 7618**Atomic service API**: This API can be used in atomic services since API version 12. 7619 7620**System capability**: SystemCapability.Multimedia.AVSession.Core 7621 7622**Parameters** 7623 7624| Name | Type | Mandatory| Description | 7625| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 7626| type | string | Yes | Event type, which is **'validCommandChange'** in this case. | 7627| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | No | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7628 7629**Error codes** 7630 7631For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7632 7633| ID| Error Message | 7634| -------- | ---------------- | 7635| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7636| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7637| 6600103 | The session controller does not exist. | 7638 7639**Example** 7640 7641```ts 7642avsessionController.off('validCommandChange'); 7643``` 7644 7645### on('outputDeviceChange')<sup>10+</sup> 7646 7647on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7648 7649Subscribes to output device change events. 7650 7651**Atomic service API**: This API can be used in atomic services since API version 12. 7652 7653**System capability**: SystemCapability.Multimedia.AVSession.Core 7654 7655**Parameters** 7656 7657| Name | Type | Mandatory| Description | 7658| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 7659| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| 7660| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information. | 7661 7662**Error codes** 7663 7664For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7665 7666| ID| Error Message| 7667| -------- | ----------------------- | 7668| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7669| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7670| 6600103 | The session controller does not exist. | 7671 7672**Example** 7673 7674```ts 7675avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 7676 console.info(`on outputDeviceChange state: ${state}, device : ${device}`); 7677}); 7678``` 7679 7680### off('outputDeviceChange')<sup>10+</sup> 7681 7682off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7683 7684Unsubscribes from output device change events. This API is called by the controller. 7685 7686**Atomic service API**: This API can be used in atomic services since API version 12. 7687 7688**System capability**: SystemCapability.Multimedia.AVSession.Core 7689 7690**Parameters** 7691 7692| Name | Type | Mandatory| Description | 7693| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 7694| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | 7695| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No | Callback function, where the **device** parameter specifies the output device information.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7696 7697**Error codes** 7698 7699For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7700 7701| ID | Error Message | 7702| -------- | ---------------- | 7703| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7704| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7705| 6600103 | The session controller does not exist. | 7706 7707**Example** 7708 7709```ts 7710avsessionController.off('outputDeviceChange'); 7711``` 7712 7713### on('sessionEvent')<sup>10+</sup> 7714 7715on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key: string]: Object}) => void): void 7716 7717Subscribes to session event change events. This API is called by the controller. 7718 7719**Atomic service API**: This API can be used in atomic services since API version 12. 7720 7721**System capability**: SystemCapability.Multimedia.AVSession.Core 7722 7723**Parameters** 7724 7725| Name | Type | Mandatory| Description | 7726| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7727| type | string | Yes | Event type. The event **'sessionEvent'** is triggered when the session event changes.| 7728| callback | (sessionEvent: string, args: {[key: string]: Object}) => void | Yes | Callback used for subscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event. | 7729 7730**Error codes** 7731 7732For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7733 7734| ID| Error Message| 7735| -------- | ------------------------------ | 7736| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7737| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7738| 6600103 | The session controller does not exist. | 7739 7740**Example** 7741 7742```ts 7743import { BusinessError } from '@kit.BasicServicesKit'; 7744import { avSession } from '@kit.AVSessionKit'; 7745 7746let tag: string = "createNewSession"; 7747let sessionId: string = ""; 7748let controller:avSession.AVSessionController | undefined = undefined; 7749avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7750 currentAVSession = data; 7751 sessionId = currentAVSession.sessionId; 7752 controller = await currentAVSession.getController(); 7753 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7754}).catch((err: BusinessError) => { 7755 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7756}); 7757if (controller !== undefined) { 7758 (controller as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => { 7759 console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); 7760 }); 7761} 7762``` 7763 7764### off('sessionEvent')<sup>10+</sup> 7765 7766off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key: string]: Object}) => void): void 7767 7768Unsubscribes from session event change events. This API is called by the controller. 7769 7770**Atomic service API**: This API can be used in atomic services since API version 12. 7771 7772**System capability**: SystemCapability.Multimedia.AVSession.Core 7773 7774**Parameters** 7775 7776| Name | Type | Mandatory| Description | 7777| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7778| type | string | Yes | Event type, which is **'sessionEvent'** in this case. | 7779| callback | (sessionEvent: string, args: {[key: string]: Object}) => void | No | Callback used for unsubscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. | 7780 7781**Error codes** 7782 7783For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7784 7785| ID| Error Message| 7786| -------- | ---------------- | 7787| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7788| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7789| 6600103 | The session controller does not exist. | 7790 7791**Example** 7792 7793```ts 7794avsessionController.off('sessionEvent'); 7795``` 7796 7797### on('queueItemsChange')<sup>10+</sup> 7798 7799on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7800 7801Subscribes to playlist item change events. This API is called by the controller. 7802 7803**Atomic service API**: This API can be used in atomic services since API version 12. 7804 7805**System capability**: SystemCapability.Multimedia.AVSession.Core 7806 7807**Parameters** 7808 7809| Name | Type | Mandatory| Description | 7810| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | 7811| type | string | Yes | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.| 7812| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | Yes | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist. | 7813 7814**Error codes** 7815 7816For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7817 7818| ID| Error Message| 7819| -------- | ------------------------------ | 7820| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7821| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7822| 6600103 | The session controller does not exist. | 7823 7824**Example** 7825 7826```ts 7827avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => { 7828 console.info(`OnQueueItemsChange, items length is ${items.length}`); 7829}); 7830``` 7831 7832### off('queueItemsChange')<sup>10+</sup> 7833 7834off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7835 7836Unsubscribes from playback item change events. This API is called by the controller. 7837 7838**Atomic service API**: This API can be used in atomic services since API version 12. 7839 7840**System capability**: SystemCapability.Multimedia.AVSession.Core 7841 7842**Parameters** 7843 7844| Name | Type | Mandatory| Description | 7845| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | 7846| type | string | Yes | Event type, which is **'queueItemsChange'** in this case. | 7847| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed items in the playlist.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| 7848 7849**Error codes** 7850 7851For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7852 7853| ID| Error Message| 7854| -------- | ---------------- | 7855| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7856| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7857| 6600103 | The session controller does not exist. | 7858 7859**Example** 7860 7861```ts 7862avsessionController.off('queueItemsChange'); 7863``` 7864 7865### on('queueTitleChange')<sup>10+</sup> 7866 7867on(type: 'queueTitleChange', callback: (title: string) => void): void 7868 7869Subscribes to playlist name change events. This API is called by the controller. 7870 7871**Atomic service API**: This API can be used in atomic services since API version 12. 7872 7873**System capability**: SystemCapability.Multimedia.AVSession.Core 7874 7875**Parameters** 7876 7877| Name | Type | Mandatory| Description | 7878| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | 7879| type | string | Yes | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.| 7880| callback | (title: string) => void | Yes | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name. | 7881 7882**Error codes** 7883 7884For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7885 7886| ID| Error Message| 7887| -------- | ------------------------------ | 7888| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7889| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7890| 6600103 | The session controller does not exist. | 7891 7892**Example** 7893 7894```ts 7895avsessionController.on('queueTitleChange', (title: string) => { 7896 console.info(`queueTitleChange, title is ${title}`); 7897}); 7898``` 7899 7900### off('queueTitleChange')<sup>10+</sup> 7901 7902off(type: 'queueTitleChange', callback?: (title: string) => void): void 7903 7904Unsubscribes from playlist name change events. This API is called by the controller. 7905 7906**Atomic service API**: This API can be used in atomic services since API version 12. 7907 7908**System capability**: SystemCapability.Multimedia.AVSession.Core 7909 7910**Parameters** 7911 7912| Name | Type | Mandatory| Description | 7913| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7914| type | string | Yes | Event type, which is **'queueTitleChange'** in this case. | 7915| callback | (title: string) => void | No | Callback used for unsubscription. The **items** parameter in the callback indicates the changed playlist name.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| 7916 7917**Error codes** 7918 7919For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7920 7921| ID| Error Message| 7922| -------- | ---------------- | 7923| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7924| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7925| 6600103 | The session controller does not exist. | 7926 7927**Example** 7928 7929```ts 7930avsessionController.off('queueTitleChange'); 7931``` 7932 7933### on('extrasChange')<sup>10+</sup> 7934 7935on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void 7936 7937Subscribes to custom media packet change events. This API is called by the controller. 7938 7939**Atomic service API**: This API can be used in atomic services since API version 12. 7940 7941**System capability**: SystemCapability.Multimedia.AVSession.Core 7942 7943**Parameters** 7944 7945| Name | Type | Mandatory| Description | 7946| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7947| type | string | Yes | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.| 7948| callback | (extras: {[key:string]: Object}) => void | Yes | Callback used for subscription. The **extras** parameter in the callback indicates the custom media packet set by the provider. This packet is the same as that set in **dispatchSessionEvent**. | 7949 7950**Error codes** 7951 7952For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7953 7954| ID| Error Message| 7955| -------- | ------------------------------ | 7956| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7957| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 7958| 6600103 | The session controller does not exist. | 7959 7960**Example** 7961 7962```ts 7963import { BusinessError } from '@kit.BasicServicesKit'; 7964import { avSession } from '@kit.AVSessionKit'; 7965 7966let tag: string = "createNewSession"; 7967let sessionId: string = ""; 7968let controller:avSession.AVSessionController | undefined = undefined; 7969avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> { 7970 currentAVSession = data; 7971 sessionId = currentAVSession.sessionId; 7972 controller = await currentAVSession.getController(); 7973 console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}'); 7974}).catch((err: BusinessError) => { 7975 console.error('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}') 7976}); 7977if (controller !== undefined) { 7978 (controller as avSession.AVSessionController).on('extrasChange', (extras) => { 7979 console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); 7980 }); 7981} 7982``` 7983 7984### off('extrasChange')<sup>10+</sup> 7985 7986off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void 7987 7988Unsubscribes from custom media packet change events. This API is called by the controller. 7989 7990**Atomic service API**: This API can be used in atomic services since API version 12. 7991 7992**System capability**: SystemCapability.Multimedia.AVSession.Core 7993 7994**Parameters** 7995 7996| Name | Type | Mandatory| Description | 7997| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7998| type | string | Yes | Event type, which is **'extrasChange'** in this case. | 7999| callback | (extras: {[key:string]: Object}) => void | No | Callback used for unsubscription.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.| 8000 8001**Error codes** 8002 8003For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8004 8005| ID| Error Message| 8006| -------- | ---------------- | 8007| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8008| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8009| 6600103 | The session controller does not exist. | 8010 8011**Example** 8012 8013```ts 8014avsessionController.off('extrasChange'); 8015``` 8016 8017### getAVPlaybackStateSync<sup>10+</sup> 8018 8019getAVPlaybackStateSync(): AVPlaybackState; 8020 8021Obtains the playback state of this session. This API returns the result synchronously. 8022 8023**Atomic service API**: This API can be used in atomic services since API version 12. 8024 8025**System capability**: SystemCapability.Multimedia.AVSession.Core 8026 8027**Return value** 8028 8029| Type | Description | 8030| --------- | ------------------------------------------------------------ | 8031| [AVPlaybackState](#avplaybackstate10) | Playback state of the session.| 8032 8033**Error codes** 8034 8035For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8036 8037| ID| Error Message| 8038| -------- | ---------------------------------------- | 8039| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8040| 6600102 | The session does not exist. | 8041| 6600103 | The session controller does not exist. | 8042 8043**Example** 8044 8045```ts 8046import { BusinessError } from '@kit.BasicServicesKit'; 8047 8048try { 8049 let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync(); 8050} catch (err) { 8051 let error = err as BusinessError; 8052 console.error(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`); 8053} 8054``` 8055 8056### getAVMetadataSync<sup>10+</sup> 8057 8058getAVMetadataSync(): AVMetadata 8059 8060Obtains the session metadata. This API returns the result synchronously. 8061 8062**Atomic service API**: This API can be used in atomic services since API version 12. 8063 8064**System capability**: SystemCapability.Multimedia.AVSession.Core 8065 8066**Return value** 8067 8068| Type | Description | 8069| ----------------------------------- | ----------------------------- | 8070| [AVMetadata](#avmetadata10) | Session metadata.| 8071 8072**Error codes** 8073 8074For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8075 8076| ID| Error Message| 8077| -------- | ---------------------------------------- | 8078| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8079| 6600102 | The session does not exist. | 8080| 6600103 | The session controller does not exist. | 8081 8082**Example** 8083```ts 8084import { BusinessError } from '@kit.BasicServicesKit'; 8085 8086try { 8087 let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync(); 8088} catch (err) { 8089 let error = err as BusinessError; 8090 console.error(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`); 8091} 8092``` 8093 8094### getAVCallState<sup>11+</sup> 8095 8096getAVCallState(): Promise\<AVCallState> 8097 8098Obtains the call state. This API uses a promise to return the result. 8099 8100**System capability**: SystemCapability.Multimedia.AVSession.Core 8101 8102**Return value** 8103 8104| Type | Description | 8105| ----------------------------------- | ----------------------------- | 8106| Promise<[AVCallState](#avcallstate11)\> | Promise used to return the call state obtained.| 8107 8108**Error codes** 8109 8110For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8111 8112| ID| Error Message| 8113| -------- | ---------------------------------------- | 8114| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8115| 6600102 | The session does not exist. | 8116| 6600103 | The session controller does not exist. | 8117 8118**Example** 8119 8120```ts 8121import { BusinessError } from '@kit.BasicServicesKit'; 8122 8123avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => { 8124 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 8125}).catch((err: BusinessError) => { 8126 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 8127}); 8128``` 8129 8130### getAVCallState<sup>11+</sup> 8131 8132getAVCallState(callback: AsyncCallback\<AVCallState>): void 8133 8134Obtains the call state. This API uses an asynchronous callback to return the result. 8135 8136**System capability**: SystemCapability.Multimedia.AVSession.Core 8137 8138**Parameters** 8139 8140| Name | Type | Mandatory| Description | 8141| -------- | ----------------------------------------- | ---- | -------------------------- | 8142| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | Yes | Callback used to return the call state obtained.| 8143 8144**Error codes** 8145 8146For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8147 8148| ID| Error Message| 8149| -------- | ---------------------------------------- | 8150| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8151| 6600102 | The session does not exist. | 8152| 6600103 | The session controller does not exist. | 8153 8154**Example** 8155 8156```ts 8157import { BusinessError } from '@kit.BasicServicesKit'; 8158 8159avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => { 8160 if (err) { 8161 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 8162 } else { 8163 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 8164 } 8165}); 8166``` 8167 8168### getCallMetadata<sup>11+</sup> 8169 8170getCallMetadata(): Promise\<CallMetadata> 8171 8172Obtains the call metadata. This API uses a promise to return the result. 8173 8174**System capability**: SystemCapability.Multimedia.AVSession.Core 8175 8176**Return value** 8177 8178| Type | Description | 8179| ----------------------------------- | ----------------------------- | 8180| Promise<[CallMetadata](#callmetadata11)\> | Promise used to return the metadata obtained.| 8181 8182**Error codes** 8183 8184For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8185 8186| ID| Error Message| 8187| -------- | ---------------------------------------- | 8188| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8189| 6600102 | The session does not exist. | 8190| 6600103 | The session controller does not exist. | 8191 8192**Example** 8193 8194```ts 8195import { BusinessError } from '@kit.BasicServicesKit'; 8196 8197avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => { 8198 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 8199}).catch((err: BusinessError) => { 8200 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 8201}); 8202``` 8203 8204### getCallMetadata<sup>11+</sup> 8205 8206getCallMetadata(callback: AsyncCallback\<CallMetadata>): void 8207 8208Obtains the call metadata. This API uses an asynchronous callback to return the result. 8209 8210**System capability**: SystemCapability.Multimedia.AVSession.Core 8211 8212**Parameters** 8213 8214| Name | Type | Mandatory| Description | 8215| -------- | ----------------------------------------- | ---- | -------------------------- | 8216| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | Yes | Callback used to return the metadata obtained.| 8217 8218**Error codes** 8219 8220For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8221 8222| ID| Error Message| 8223| -------- | ---------------------------------------- | 8224| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8225| 6600102 | The session does not exist. | 8226| 6600103 | The session controller does not exist. | 8227 8228**Example** 8229 8230```ts 8231import { BusinessError } from '@kit.BasicServicesKit'; 8232 8233avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => { 8234 if (err) { 8235 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 8236 } else { 8237 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 8238 } 8239}); 8240``` 8241 8242### getAVQueueTitleSync<sup>10+</sup> 8243 8244getAVQueueTitleSync(): string 8245 8246Obtains the name of the playlist of this session. This API returns the result synchronously. 8247 8248**Atomic service API**: This API can be used in atomic services since API version 12. 8249 8250**System capability**: SystemCapability.Multimedia.AVSession.Core 8251 8252**Return value** 8253 8254| Type | Description | 8255| ---------------- | ----------------------------- | 8256| string | Playlist name.| 8257 8258**Error codes** 8259 8260For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8261 8262| ID| Error Message| 8263| -------- | ---------------------------------------- | 8264| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8265| 6600102 | The session does not exist. | 8266| 6600103 | The session controller does not exist. | 8267 8268**Example** 8269 8270```ts 8271import { BusinessError } from '@kit.BasicServicesKit'; 8272 8273try { 8274 let currentQueueTitle: string = avsessionController.getAVQueueTitleSync(); 8275} catch (err) { 8276 let error = err as BusinessError; 8277 console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`); 8278} 8279``` 8280 8281### getAVQueueItemsSync<sup>10+</sup> 8282 8283getAVQueueItemsSync(): Array\<AVQueueItem\> 8284 8285Obtains the information related to the items in the playlist of this session. This API returns the result synchronously. 8286 8287**Atomic service API**: This API can be used in atomic services since API version 12. 8288 8289**System capability**: SystemCapability.Multimedia.AVSession.Core 8290 8291**Return value** 8292 8293| Type | Description | 8294| --------------------------------------------- | ----------------------------- | 8295| Array<[AVQueueItem](#avqueueitem10)\> | Items in the queue.| 8296 8297**Error codes** 8298 8299For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8300 8301| ID| Error Message| 8302| -------- | ---------------------------------------- | 8303| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8304| 6600102 | The session does not exist. | 8305| 6600103 | The session controller does not exist. | 8306 8307**Example** 8308 8309```ts 8310import { BusinessError } from '@kit.BasicServicesKit'; 8311 8312try { 8313 let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync(); 8314} catch (err) { 8315 let error = err as BusinessError; 8316 console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`); 8317} 8318``` 8319 8320### getOutputDeviceSync<sup>10+</sup> 8321 8322getOutputDeviceSync(): OutputDeviceInfo 8323 8324Obtains the output device information. This API returns the result synchronously. 8325 8326**Atomic service API**: This API can be used in atomic services since API version 12. 8327 8328**System capability**: SystemCapability.Multimedia.AVSession.Core 8329 8330**Return value** 8331 8332| Type | Description | 8333| ----------------------------------------------- | --------------------------------- | 8334| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.| 8335 8336**Error codes** 8337 8338For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8339 8340| ID| Error Message| 8341| -------- | ---------------------------------------- | 8342| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8343| 6600103 | The session controller does not exist. | 8344 8345**Example** 8346 8347```ts 8348import { BusinessError } from '@kit.BasicServicesKit'; 8349 8350try { 8351 let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync(); 8352} catch (err) { 8353 let error = err as BusinessError; 8354 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 8355} 8356``` 8357 8358### isActiveSync<sup>10+</sup> 8359 8360isActiveSync(): boolean 8361 8362Checks whether the session is activated. This API returns the result synchronously. 8363 8364**Atomic service API**: This API can be used in atomic services since API version 12. 8365 8366**System capability**: SystemCapability.Multimedia.AVSession.Core 8367 8368**Return value** 8369 8370| Type | Description | 8371| ----------------- | ------------------------------------------------------------ | 8372| boolean | Returns **true** is returned if the session is activated; returns **false** otherwise.| 8373 8374**Error codes** 8375 8376For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8377 8378| ID| Error Message| 8379| -------- | ---------------------------------------- | 8380| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8381| 6600102 | The session does not exist. | 8382| 6600103 | The session controller does not exist. | 8383 8384**Example** 8385 8386```ts 8387import { BusinessError } from '@kit.BasicServicesKit'; 8388 8389try { 8390 let isActive: boolean = avsessionController.isActiveSync(); 8391} catch (err) { 8392 let error = err as BusinessError; 8393 console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`); 8394} 8395``` 8396 8397### getValidCommandsSync<sup>10+</sup> 8398 8399getValidCommandsSync(): Array\<AVControlCommandType\> 8400 8401Obtains valid commands supported by the session. This API returns the result synchronously. 8402 8403**Atomic service API**: This API can be used in atomic services since API version 12. 8404 8405**System capability**: SystemCapability.Multimedia.AVSession.Core 8406 8407**Return value** 8408 8409| Type | Description | 8410| ------------------------------------------------------------ | --------------------------------- | 8411| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | A set of valid commands.| 8412 8413**Error codes** 8414 8415For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8416 8417| ID| Error Message| 8418| -------- | ---------------------------------------- | 8419| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8420| 6600102 | The session does not exist. | 8421| 6600103 | The session controller does not exist. | 8422 8423**Example** 8424 8425```ts 8426import { BusinessError } from '@kit.BasicServicesKit'; 8427 8428try { 8429 let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync(); 8430} catch (err) { 8431 let error = err as BusinessError; 8432 console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`); 8433} 8434``` 8435 8436## AVControlCommandType<sup>10+</sup> 8437 8438type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 8439 'seek' | 'setSpeed' | 'setLoopMode' | 'setTargetLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'playWithAssetId' | 'answer' | 'hangUp' | 'toggleCallMute' 8440 8441Defines the commands that can be sent to a session. 8442 8443You can use the union of the strings listed in the following table. 8444 8445**Atomic service API**: This API can be used in atomic services since API version 12. 8446 8447**System capability**: SystemCapability.Multimedia.AVSession.Core 8448 8449| Type | Description | 8450| ---------------- | ------------ | 8451| 'play' | Play the media. No parameter is required.| 8452| 'pause' | Pause the playback. No parameter is required.| 8453| 'stop' | Stop the playback. No parameter is required.| 8454| 'playNext' | Play the next media asset. No parameter is required.| 8455| 'playPrevious' | Play the previous media asset. No parameter is required.| 8456| 'fastForward' | Fast-forward. No parameter is required.| 8457| 'rewind' | Rewind. No parameter is required.| 8458| 'seek' | Seek to a playback position. The corresponding parameter is of the number type.| 8459| 'setSpeed' | Set the playback speed. The corresponding parameter is of the number type.| 8460| 'setLoopMode' | Set the loop mode. The corresponding parameter is [LoopMode](#loopmode10).| 8461| 'setTargetLoopMode' <sup>18+</sup> | Set the target loop mode. The recommended parameter is [LoopMode](#loopmode10).| 8462| 'toggleFavorite' | Favorite the media asset. The corresponding parameter is [AVMetadata.assetId](#avmetadata10). | 8463| 'playFromAssetId'| Play the media asset with the specified asset ID.| 8464| 'playWithAssetId' <sup>20+</sup> | Play the media asset with the specified asset ID. The corresponding parameter is [AVMetadata.assetId](#avmetadata10).<br>The string length must be less than 40960 bytes.<br>| 8465|'answer' | Answer a call. No parameter is required. | 8466| 'hangUp' | The call is disconnecting. No parameter is required. | 8467|'toggleCallMute' | Set the mute status for a call. No parameter is required.| 8468 8469## AVControlCommand<sup>10+</sup> 8470 8471Describes the command that can be sent to the session. 8472 8473**Atomic service API**: This API can be used in atomic services since API version 12. 8474 8475**System capability**: SystemCapability.Multimedia.AVSession.Core 8476 8477| Name | Type | Mandatory| Description | 8478| --------- | ------------------------------------------------- | ---- | -------------- | 8479| command | [AVControlCommandType](#avcontrolcommandtype10) | Yes | Command. The parameters carried in each command are different. For details, see [AVControlCommandType](#avcontrolcommandtype10). | 8480| parameter | [LoopMode](#loopmode10) | string | number | No | Parameters carried in the command.| 8481 8482 8483## AVCastPickerOptions<sup>14+</sup> 8484 8485Describes the properties related to the semi-modal window that is started for casting purposes. 8486 8487**Atomic service API**: This API can be used in atomic services since API version 14. 8488 8489**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8490 8491| Name | Type | Mandatory| Description | 8492| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 8493| sessionType | [AVSessionType](#avsessiontype10) | No | Session type. The default value is **'audio'**.<br>Currently, only the **'audio'** and **'video'** session types are supported. If **'voice_call'** and **'video_call'** are passed, they are treated as the default value **'audio'**. | 8494 8495## AVCastPickerHelper<sup>14+</sup> 8496 8497Implements a semi-modal object used for casting. It displays a semi-modal window for users to select a target cast device. Before using the APIs of this class, you need to create an AVCastPickerHelper instance. 8498 8499**Atomic service API**: This API can be used in atomic services since API version 14. 8500 8501**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8502 8503### constructor<sup>14+</sup> 8504 8505constructor(context: Context) 8506 8507Creates an AVCastPickerHelper instance. For details about how to obtain the context, see [getContext](../apis-arkui/arkts-apis-uicontext-uicontext.md#gethostcontext12). 8508 8509**Atomic service API**: This API can be used in atomic services since API version 14. 8510 8511**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8512 8513**Parameters** 8514 8515| Name | Type | Mandatory| Description | 8516| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8517| context | Context | Yes | Application context. (Only [UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) is supported.)| 8518 8519**Error codes** 8520 8521For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8522 8523| ID| Error Message| 8524| -------- | ---------------------------------------- | 8525| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8526| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8527 8528**Example** 8529 8530```ts 8531import { common } from '@kit.AbilityKit'; 8532import { avSession } from '@kit.AVSessionKit'; 8533@Entry 8534@Component 8535struct Index { 8536 @State message: string = 'hello world'; 8537 8538 build() { 8539 Row() { 8540 Column() { 8541 Text(this.message) 8542 .fontSize(40) 8543 .fontWeight(FontWeight.Bold) 8544 .onClick(()=>{ 8545 let context = this.getUIContext().getHostContext() as Context; 8546 let avCastPicker = new avSession.AVCastPickerHelper(context); 8547 }) 8548 } 8549 .width('100%') 8550 } 8551 .height('100%') 8552 } 8553} 8554``` 8555 8556### select<sup>14+</sup> 8557 8558select(options?: AVCastPickerOptions): Promise\<void> 8559 8560Starts the AVCastPicker dialog box, where users can select the target cast device. This API uses a promise to return the result. You can pass in **AVCastPickerOptions** to specify the properties for selection. 8561 8562**Atomic service API**: This API can be used in atomic services since API version 14. 8563 8564**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8565 8566**Parameters** 8567 8568| Name | Type | Mandatory| Description | 8569| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8570| options | [AVCastPickerOptions](#avcastpickeroptions14) | No | AVCastPicker selection options. If this parameter is not specified, the default value of **AVCastPickerOptions** is used.| 8571 8572**Return value** 8573 8574| Type | Description | 8575| -------------- | ----------------------------- | 8576| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 8577 8578**Error codes** 8579 8580For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8581 8582| ID| Error Message| 8583| -------- | ---------------------------------------- | 8584| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8585 8586**Example** 8587 8588```ts 8589import { common } from '@kit.AbilityKit'; 8590import { BusinessError } from '@kit.BasicServicesKit'; 8591 8592async function avCastPicker(context: common.Context) { 8593 let avCastPickerOptions : avSession.AVCastPickerOptions = { 8594 sessionType : 'video', 8595 } 8596 let avCastPicker = new avSession.AVCastPickerHelper(context); 8597 avCastPicker.select(avCastPickerOptions).then(() => { 8598 console.info('select successfully'); 8599 }).catch((err: BusinessError) => { 8600 console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`); 8601 }); 8602} 8603``` 8604### on('pickerStateChange')<sup>14+</sup> 8605 8606on(type: 'pickerStateChange', callback: Callback<AVCastPickerState\>) : void 8607 8608Subscribes to semi-modal window change events. 8609 8610**Atomic service API**: This API can be used in atomic services since API version 14. 8611 8612**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8613 8614**Parameters** 8615 8616| Name | Type | Mandatory| Description | 8617| --------| -----------|-----|------------| 8618| type | string | Yes | Event type. The event **'pickerStateChange'** is triggered when the semi-modal window changes.| 8619| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | Yes | Callback function, where the **state** parameter indicates the new state of the semi-modal window.| 8620 8621**Error codes** 8622 8623For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8624 8625| ID| Error Message| 8626| -------- | ---------------------------------------- | 8627| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8628| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8629 8630**Example** 8631 8632```ts 8633import { common } from '@kit.AbilityKit'; 8634import { AVCastPickerState } from '@kit.AVSessionKit'; 8635 8636async function onPickerStateChange(context: common.Context) { 8637 let avCastPicker = new avSession.AVCastPickerHelper(context); 8638 avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => { 8639 console.info(`picker state change : ${state}`); 8640 }); 8641} 8642``` 8643 8644### off('pickerStateChange')<sup>14+</sup> 8645 8646off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState\>) : void 8647 8648Unsubscribes from semi-modal window change events. After the unsubscription, the event callback is not triggered. 8649 8650**Atomic service API**: This API can be used in atomic services since API version 14. 8651 8652**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8653 8654**Parameters** 8655 8656| Name | Type | Mandatory| Description | 8657| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 8658| type | string | Yes | Event type, which is **'pickerStateChange'** in this case. | 8659| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | No | Callback function, where the **state** parameter indicates the new state of the semi-modal window.<br>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. | 8660 8661**Error codes** 8662 8663For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8664 8665| ID| Error Message| 8666| -------- | ---------------------------------------- | 8667| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8668| 6600101 | Session service exception.You are advised to:1.Scheduled retry.2.Destroy the current session or session controller and re-create it. | 8669 8670**Example** 8671 8672```ts 8673import { common } from '@kit.AbilityKit'; 8674 8675async function onPickerStateChange(context: common.Context) { 8676 let avCastPicker = new avSession.AVCastPickerHelper(context); 8677 avCastPicker.off('pickerStateChange'); 8678} 8679``` 8680 8681## AVSessionErrorCode<sup>10+</sup> 8682 8683Enumerates the error codes used in the media session. 8684 8685| Name | Value | Description | 8686| -------------------------------------- | ------- | ------------------------------- | 8687| ERR_CODE_SERVICE_EXCEPTION | 6600101 | The session server is abnormal.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8688| ERR_CODE_SESSION_NOT_EXIST | 6600102 | The session does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8689| ERR_CODE_CONTROLLER_NOT_EXIST | 6600103 | The session controller does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8690| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | Connection to the remote session fails.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8691| ERR_CODE_COMMAND_INVALID | 6600105 | The session command is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8692| ERR_CODE_SESSION_INACTIVE | 6600106 | The session is not activated.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8693| ERR_CODE_MESSAGE_OVERLOAD | 6600107 | Too many commands or messages.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8694| ERR_CODE_DEVICE_CONNECTION_FAILED | 6600108 | Connection to the device fails.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8695| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | The remote session does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core| 8696| ERR_CODE_CAST_CONTROL_UNSPECIFIED<sup>13+</sup> | 6611000 | An undefined error occurs during cast control.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8697| ERR_CODE_CAST_CONTROL_REMOTE_ERROR<sup>13+</sup> | 6611001 | An unknown error occurs in the remote player.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8698| ERR_CODE_CAST_CONTROL_BEHIND_LIVE_WINDOW<sup>13+</sup> | 6611002 | The playback is delayed.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8699| ERR_CODE_CAST_CONTROL_TIMEOUT<sup>13+</sup> | 6611003 | The cast control process times out.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8700| ERR_CODE_CAST_CONTROL_RUNTIME_CHECK_FAILED<sup>13+</sup> | 6611004 | The runtime check fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8701| ERR_CODE_CAST_CONTROL_PLAYER_NOT_WORKING<sup>13+</sup> | 6611100 | Cross-device data transfer is locked.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8702| ERR_CODE_CAST_CONTROL_SEEK_MODE_UNSUPPORTED<sup>13+</sup> | 6611101 | The specified seek mode is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8703| ERR_CODE_CAST_CONTROL_ILLEGAL_SEEK_TARGET<sup>13+</sup> | 6611102 | The seek position is out of the media range, or the current seek mode is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8704| ERR_CODE_CAST_CONTROL_PLAY_MODE_UNSUPPORTED<sup>13+</sup> | 6611103 | The specified playback mode is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8705| ERR_CODE_CAST_CONTROL_PLAY_SPEED_UNSUPPORTED<sup>13+</sup> | 6611104 | The specified playback speed is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8706| ERR_CODE_CAST_CONTROL_DEVICE_MISSING<sup>13+</sup> | 6611105 | Operation failed because the media source device or media receiver device has been destroyed.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8707| ERR_CODE_CAST_CONTROL_INVALID_PARAM<sup>13+</sup> | 6611106 | The parameter is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8708| ERR_CODE_CAST_CONTROL_NO_MEMORY<sup>13+</sup> | 6611107 | Failed to allocate memory.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8709| ERR_CODE_CAST_CONTROL_OPERATION_NOT_ALLOWED<sup>13+</sup> | 6611108 | The operation is not allowed.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8710| ERR_CODE_CAST_CONTROL_IO_UNSPECIFIED<sup>13+</sup> | 6612000 | An unspecified input/output error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8711| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_FAILED<sup>13+</sup> | 6612001 | Network connection fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8712| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_TIMEOUT<sup>13+</sup> | 6612002 | Network connection times out.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8713| ERR_CODE_CAST_CONTROL_IO_INVALID_HTTP_CONTENT_TYPE <sup>13+</sup> | 6612003 | The value of **Content-Type** is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8714| ERR_CODE_CAST_CONTROL_IO_BAD_HTTP_STATUS<sup>13+</sup> | 6612004 | The HTTP server returns an unexpected HTTP response status code.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8715| ERR_CODE_CAST_CONTROL_IO_FILE_NOT_FOUND<sup>13+</sup> | 6612005 | The file does not exist.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8716| ERR_CODE_CAST_CONTROL_IO_NO_PERMISSION<sup>13+</sup> | 6612006 | The input/output operation is not allowed.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8717| ERR_CODE_CAST_CONTROL_IO_CLEARTEXT_NOT_PERMITTED<sup>13+</sup> | 6612007 | The network security configuration of the application does not allow access to plaintext HTTP traffic.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8718| ERR_CODE_CAST_CONTROL_IO_READ_POSITION_OUT_OF_RANGE<sup>13+</sup> | 6612008 | Data is read from data binding.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8719| ERR_CODE_CAST_CONTROL_IO_NO_CONTENTS<sup>13+</sup> | 6612100 | No content can be played in the media.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8720| ERR_CODE_CAST_CONTROL_IO_READ_ERROR<sup>13+</sup> | 6612101 | The media cannot be read.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8721| ERR_CODE_CAST_CONTROL_IO_CONTENT_BUSY<sup>13+</sup> | 6612102 | The resource is in use.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8722| ERR_CODE_CAST_CONTROL_IO_CONTENT_EXPIRED<sup>13+</sup> | 6612103 | The input/output request content has expired.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8723| ERR_CODE_CAST_CONTROL_IO_USE_FORBIDDEN<sup>13+</sup> | 6612104 | The requested content cannot be played.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8724| ERR_CODE_CAST_CONTROL_IO_NOT_VERIFIED<sup>13+</sup> | 6612105 | The allowed content cannot be verified.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8725| ERR_CODE_CAST_CONTROL_IO_EXHAUSTED_ALLOWED_USES<sup>13+</sup> | 6612106 | The number of times that the content can be used has reached the maximum.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8726| ERR_CODE_CAST_CONTROL_IO_NETWORK_PACKET_SENDING_FAILED<sup>13+</sup> | 6612107 | An error occurs when the source device sends data packets to the destination device.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8727| ERR_CODE_CAST_CONTROL_PARSING_UNSPECIFIED<sup>13+</sup> | 6613000 | An unspecified content parsing error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8728| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_MALFORMED<sup>13+</sup> | 6613001 | The format of the media container bit stream is incorrectly parsed.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8729| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_MALFORMED<sup>13+</sup> | 6613002 | An error occurred when parsing the media list.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8730| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_UNSUPPORTED<sup>13+</sup> | 6613003 | The media container format or feature of the file is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8731| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_UNSUPPORTED<sup>13+</sup> | 6613004 | The feature is not supported in the media list.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8732| ERR_CODE_CAST_CONTROL_DECODING_UNSPECIFIED<sup>13+</sup> | 6614000 | An unspecified decoding error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8733| ERR_CODE_CAST_CONTROL_DECODING_INIT_FAILED<sup>13+</sup> | 6614001 | Initializing the decoder fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8734| ERR_CODE_CAST_CONTROL_DECODING_QUERY_FAILED<sup>13+</sup> | 6614002 | Querying the decoder fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8735| ERR_CODE_CAST_CONTROL_DECODING_FAILED<sup>13+</sup> | 6614003 | Decoding the media sample fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8736| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_EXCEEDS_CAPABILITIES<sup>13+</sup> | 6614004 | The device cannot decode the current format.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8737| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_UNSUPPORTED<sup>13+</sup> | 6614005 | The decoding format is not supported.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8738| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_UNSPECIFIED<sup>13+</sup> | 6615000 | An unspecified audio renderer error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8739| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_INIT_FAILED <sup>13+</sup> | 6615001 | Initializing the audio renderer fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8740| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_WRITE_FAILED<sup>13+</sup> | 6615002 | Writing data to the audio renderer fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8741| ERR_CODE_CAST_CONTROL_DRM_UNSPECIFIED<sup>13+</sup> | 6616000 | An unspecified DRM-related error occurs.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8742| ERR_CODE_CAST_CONTROL_DRM_SCHEME_UNSUPPORTED<sup>13+</sup> | 6616001 | The device does not support the selected DRM scheme.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8743| ERR_CODE_CAST_CONTROL_DRM_PROVISIONING_FAILED<sup>13+</sup> | 6616002 | Device configurations fail.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8744| ERR_CODE_CAST_CONTROL_DRM_CONTENT_ERROR<sup>13+</sup> | 6616003 | The DRM-protected content cannot be played.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8745| ERR_CODE_CAST_CONTROL_DRM_LICENSE_ACQUISITION_FAILED<sup>13+</sup> | 6616004 | Obtaining a license fails.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8746| ERR_CODE_CAST_CONTROL_DRM_DISALLOWED_OPERATION<sup>13+</sup> | 6616005 | The license policy does not allow this operation.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8747| ERR_CODE_CAST_CONTROL_DRM_SYSTEM_ERROR<sup>13+</sup> | 6616006 | An error occurs in the DRM system.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8748| ERR_CODE_CAST_CONTROL_DRM_DEVICE_REVOKED<sup>13+</sup> | 6616007 | The DRM permission has been revoked from the device.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8749| ERR_CODE_CAST_CONTROL_DRM_LICENSE_EXPIRED<sup>13+</sup> | 6616008 | The DRM license that is being loaded has expired.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8750| ERR_CODE_CAST_CONTROL_DRM_PROVIDE_KEY_RESPONSE_ERROR<sup>13+</sup> | 6616100 | An error occurs when the DRM processes the key response.<br>**Atomic service API**: This API can be used in atomic services since API version 13.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast| 8751 8752## SkipIntervals<sup>11+</sup> 8753 8754Enumerates the fast-forward or rewind intervals supported by the media session. 8755 8756**System capability**: SystemCapability.Multimedia.AVSession.Core 8757 8758| Name | Value| Description | 8759| ---------------------- | -- | ----------------------- | 8760| SECONDS_10 | 10 | The time is 10 seconds. | 8761| SECONDS_15 | 15 | The time is 15 seconds. | 8762| SECONDS_30 | 30 | The time is 30 seconds. | 8763 8764## AudioCapabilities<sup>20+</sup> 8765 8766Describes the audio capabilities supported by the casting device. 8767 8768**Atomic service API**: This API can be used in atomic services since API version 20. 8769 8770**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8771 8772| Name | Type | Read-Only| Optional| Description | 8773| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 8774| streamInfos | Array\<[audio.AudioStreamInfo](../apis-audio-kit/arkts-apis-audio-i.md#audiostreaminfo8)> | Yes | No | Audio capability parameters. | 8775