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. | 53 54**Example** 55 56```ts 57import { BusinessError } from '@kit.BasicServicesKit'; 58 59let currentAVSession: avSession.AVSession; 60let tag = "createNewSession"; 61let context: Context = getContext(this); 62let sessionId: string; // Used as an input parameter of subsequent functions. 63 64avSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => { 65 currentAVSession = data; 66 sessionId = currentAVSession.sessionId; 67 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 68}).catch((err: BusinessError) => { 69 console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 70}); 71``` 72 73## avSession.createAVSession<sup>10+</sup> 74 75createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void 76 77Creates 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. 78 79**System capability**: SystemCapability.Multimedia.AVSession.Core 80 81**Parameters** 82 83| Name | Type | Mandatory| Description | 84| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | 85| 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. | 86| tag | string | Yes | Custom session name. | 87| type | [AVSessionType](#avsessiontype10) | Yes | Session type. | 88| 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.| 89 90**Error codes** 91 92For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 93 94| ID| Error Message| 95| -------- | ---------------------------------------- | 96| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 97| 6600101 | Session service exception. | 98 99**Example** 100 101```ts 102import { BusinessError } from '@kit.BasicServicesKit'; 103 104let currentAVSession: avSession.AVSession; 105let tag = "createNewSession"; 106let context: Context = getContext(this); 107let sessionId: string; // Used as an input parameter of subsequent functions. 108 109avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 110 if (err) { 111 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 112 } else { 113 currentAVSession = data; 114 sessionId = currentAVSession.sessionId; 115 console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`); 116 } 117}); 118``` 119 120## ProtocolType<sup>11+</sup> 121 122Enumerates the protocol types supported by the remote device. 123 124**Atomic service API**: This API can be used in atomic services since API version 12. 125 126**System capability**: SystemCapability.Multimedia.AVSession.AVCast 127 128| Name | Value | Description | 129| --------------------------- | ---- | ----------- | 130| 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.| 131| TYPE_CAST_PLUS_STREAM<sup>11+</sup> | 2 | Cast+ stream mode, indicating that the media asset is being displayed on another device.| 132| TYPE_DLNA<sup>12+</sup> | 4 | DLNA protocol, indicating that the media asset is being displayed on another device.| 133 134## AVSessionType<sup>10+<sup> 135 136type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call' 137 138Enumerates the session types supported by the session. 139 140You can use the strings listed in the following table. 141 142**Atomic service API**: This API can be used in atomic services since API version 12. 143 144**System capability**: SystemCapability.Multimedia.AVSession.Core 145 146| Type | Description| 147| ----- | ---- | 148| 'audio' | Audio session.| 149| 'video' | Video session.| 150| 'voice_call'<sup>11+<sup> | Voice call.| 151| 'video_call'<sup>12+<sup> | Video call.| 152 153## AVSession<sup>10+</sup> 154 155An **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. 156 157### Attributes 158 159**Atomic service API**: This API can be used in atomic services since API version 12. 160 161**System capability**: SystemCapability.Multimedia.AVSession.Core 162 163| Name | Type | Readable| Writable| Description | 164| :-------- | :----- | :--- | :--- | :---------------------------- | 165| sessionId | string | Yes | No | Unique session ID of the **AVSession** object.| 166| sessionType| [AVSessionType](#avsessiontype10) | Yes | No | AVSession type.| 167 168**Example** 169 170```ts 171let sessionId: string = currentAVSession.sessionId; 172let sessionType: avSession.AVSessionType = currentAVSession.sessionType; 173``` 174 175### setAVMetadata<sup>10+</sup> 176 177setAVMetadata(data: AVMetadata): Promise\<void> 178 179Sets session metadata. This API uses a promise to return the result. 180 181**Atomic service API**: This API can be used in atomic services since API version 12. 182 183**System capability**: SystemCapability.Multimedia.AVSession.Core 184 185**Parameters** 186 187| Name| Type | Mandatory| Description | 188| ------ | ------------------------- | ---- | ------------ | 189| data | [AVMetadata](#avmetadata10) | Yes | Session metadata.| 190 191**Return value** 192 193| Type | Description | 194| -------------- | ----------------------------- | 195| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 196 197**Error codes** 198 199For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 200 201| ID| Error Message| 202| -------- | ---------------------------------------- | 203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 204| 6600101 | Session service exception. | 205| 6600102 | The session does not exist. | 206 207**Example** 208 209```ts 210import { BusinessError } from '@kit.BasicServicesKit'; 211 212let metadata: avSession.AVMetadata = { 213 assetId: "121278", 214 title: "lose yourself", 215 artist: "Eminem", 216 author: "ST", 217 album: "Slim shady", 218 writer: "ST", 219 composer: "ST", 220 duration: 2222, 221 mediaImage: "https://www.example.com/example.jpg", 222 subtitle: "8 Mile", 223 description: "Rap", 224 // The LRC contains two types of elements: time tag + lyrics, and ID tag. 225 // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n 226 lyric: "Lyrics in LRC format", 227 previousAssetId: "121277", 228 nextAssetId: "121279" 229}; 230currentAVSession.setAVMetadata(metadata).then(() => { 231 console.info('SetAVMetadata successfully'); 232}).catch((err: BusinessError) => { 233 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 234}); 235``` 236 237### setAVMetadata<sup>10+</sup> 238 239setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void 240 241Sets session metadata. This API uses an asynchronous callback to return the result. 242 243**System capability**: SystemCapability.Multimedia.AVSession.Core 244 245**Parameters** 246 247| Name | Type | Mandatory| Description | 248| -------- | ------------------------- | ---- | ------------------------------------- | 249| data | [AVMetadata](#avmetadata10) | Yes | Session metadata. | 250| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 251 252**Error codes** 253 254For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 255 256| ID| Error Message| 257| -------- | ---------------------------------------- | 258| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 259| 6600101 | Session service exception. | 260| 6600102 | The session does not exist. | 261 262**Example** 263 264```ts 265import { BusinessError } from '@kit.BasicServicesKit'; 266 267let metadata: avSession.AVMetadata = { 268 assetId: "121278", 269 title: "lose yourself", 270 artist: "Eminem", 271 author: "ST", 272 album: "Slim shady", 273 writer: "ST", 274 composer: "ST", 275 duration: 2222, 276 mediaImage: "https://www.example.com/example.jpg", 277 subtitle: "8 Mile", 278 description: "Rap", 279 // The LRC contains two types of elements: time tag + lyrics, and ID tag. 280 // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n 281 lyric: "Lyrics in LRC format", 282 previousAssetId: "121277", 283 nextAssetId: "121279" 284}; 285currentAVSession.setAVMetadata(metadata, (err: BusinessError) => { 286 if (err) { 287 console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 288 } else { 289 console.info('SetAVMetadata successfully'); 290 } 291}); 292``` 293 294### setCallMetadata<sup>11+</sup> 295 296setCallMetadata(data: CallMetadata): Promise\<void> 297 298Sets call metadata. This API uses a promise to return the result. 299 300**System capability**: SystemCapability.Multimedia.AVSession.Core 301 302**Parameters** 303 304| Name| Type | Mandatory| Description | 305| ------ | ------------------------- | ---- | ------------ | 306| data | [CallMetadata](#callmetadata11) | Yes | Call metadata.| 307 308**Return value** 309 310| Type | Description | 311| -------------- | ----------------------------- | 312| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 313 314**Error codes** 315 316For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 317 318| ID| Error Message| 319| -------- | ---------------------------------------- | 320| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 321| 6600101 | Session service exception. | 322| 6600102 | The session does not exist. | 323 324**Example** 325 326```ts 327import { image } from '@kit.ImageKit'; 328import { resourceManager } from '@kit.LocalizationKit'; 329import { BusinessError } from '@kit.BasicServicesKit'; 330 331let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 332 let imageSource = await image.createImageSource(value.buffer); 333 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 334 let calldata: avSession.CallMetadata = { 335 name: "xiaoming", 336 phoneNumber: "111xxxxxxxx", 337 avatar: imagePixel 338 }; 339currentAVSession.setCallMetadata(calldata).then(() => { 340 console.info('setCallMetadata successfully'); 341}).catch((err: BusinessError) => { 342 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 343}); 344``` 345 346### setCallMetadata<sup>11+</sup> 347 348setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void 349 350Sets call metadata. This API uses an asynchronous callback to return the result. 351 352**System capability**: SystemCapability.Multimedia.AVSession.Core 353 354**Parameters** 355 356| Name | Type | Mandatory| Description | 357| -------- | ------------------------- | ---- | ------------------------------------- | 358| data | [CallMetadata](#callmetadata11) | Yes | Call metadata. | 359| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 360 361**Error codes** 362 363For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 364 365| ID| Error Message| 366| -------- | ---------------------------------------- | 367| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 368| 6600101 | Session service exception. | 369| 6600102 | The session does not exist. | 370 371**Example** 372 373```ts 374import { image } from '@kit.ImageKit'; 375import { resourceManager } from '@kit.LocalizationKit'; 376import { BusinessError } from '@kit.BasicServicesKit'; 377 378async function setCallMetadata() { 379 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 380 let imageSource = await image.createImageSource(value.buffer); 381 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 382 let calldata: avSession.CallMetadata = { 383 name: "xiaoming", 384 phoneNumber: "111xxxxxxxx", 385 avatar: imagePixel 386 }; 387 currentAVSession.setCallMetadata(calldata, (err: BusinessError) => { 388 if (err) { 389 console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 390 } else { 391 console.info('setCallMetadata successfully'); 392 } 393 }); 394} 395``` 396 397### setAVCallState<sup>11+</sup> 398 399setAVCallState(state: AVCallState): Promise\<void> 400 401Sets the call state. This API uses a promise to return the result. 402 403**System capability**: SystemCapability.Multimedia.AVSession.Core 404 405**Parameters** 406 407| Name| Type | Mandatory| Description | 408| ------ | ------------------------- | ---- | ------------ | 409| state | [AVCallState](#avcallstate11) | Yes | Call state.| 410 411**Return value** 412 413| Type | Description | 414| -------------- | ----------------------------- | 415| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 416 417**Error codes** 418 419For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 420 421| ID| Error Message| 422| -------- | ---------------------------------------- | 423| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 424| 6600101 | Session service exception. | 425| 6600102 | The session does not exist. | 426 427**Example** 428 429```ts 430import { BusinessError } from '@kit.BasicServicesKit'; 431 432let calldata: avSession.AVCallState = { 433 state: avSession.CallState.CALL_STATE_ACTIVE, 434 muted: false 435}; 436currentAVSession.setAVCallState(calldata).then(() => { 437 console.info('setAVCallState successfully'); 438}).catch((err: BusinessError) => { 439 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 440}); 441``` 442 443### setAVCallState<sup>11+</sup> 444 445setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void 446 447Sets the call state. This API uses an asynchronous callback to return the result. 448 449**System capability**: SystemCapability.Multimedia.AVSession.Core 450 451**Parameters** 452 453| Name | Type | Mandatory| Description | 454| -------- | ------------------------- | ---- | ------------------------------------- | 455| state | [AVCallState](#avcallstate11) | Yes | Call state. | 456| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 457 458**Error codes** 459 460For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 461 462| ID| Error Message| 463| -------- | ---------------------------------------- | 464| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 465| 6600101 | Session service exception. | 466| 6600102 | The session does not exist. | 467 468**Example** 469 470```ts 471import { BusinessError } from '@kit.BasicServicesKit'; 472 473let avcalldata: avSession.AVCallState = { 474 state: avSession.CallState.CALL_STATE_ACTIVE, 475 muted: false 476}; 477currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => { 478 if (err) { 479 console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 480 } else { 481 console.info('setAVCallState successfully'); 482 } 483}); 484``` 485 486### setAVPlaybackState<sup>10+</sup> 487 488setAVPlaybackState(state: AVPlaybackState): Promise\<void> 489 490Sets information related to the session playback state. This API uses a promise to return the result. 491 492**Atomic service API**: This API can be used in atomic services since API version 12. 493 494**System capability**: SystemCapability.Multimedia.AVSession.Core 495 496**Parameters** 497 498| Name| Type | Mandatory| Description | 499| ------ | ----------------------------------- | ---- | ---------------------------------------------- | 500| state | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| 501 502**Return value** 503 504| Type | Description | 505| -------------- | ----------------------------- | 506| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 507 508**Error codes** 509 510For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 511 512| ID| Error Message| 513| -------- | ---------------------------------------- | 514| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 515| 6600101 | Session service exception. | 516| 6600102 | The session does not exist. | 517 518**Example** 519 520```ts 521import { BusinessError } from '@kit.BasicServicesKit'; 522 523let playbackState: avSession.AVPlaybackState = { 524 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 525 speed: 1.0, 526 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 527 bufferedTime:1000, 528 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 529 isFavorite:true 530}; 531currentAVSession.setAVPlaybackState(playbackState).then(() => { 532 console.info('SetAVPlaybackState successfully'); 533}).catch((err: BusinessError) => { 534 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 535}); 536``` 537 538### setAVPlaybackState<sup>10+</sup> 539 540setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void 541 542Sets information related to the session playback state. This API uses an asynchronous callback to return the result. 543 544**System capability**: SystemCapability.Multimedia.AVSession.Core 545 546**Parameters** 547 548| Name | Type | Mandatory| Description | 549| -------- | ----------------------------------- | ---- | ---------------------------------------------- | 550| state | [AVPlaybackState](#avplaybackstate10) | Yes | Information related to the session playback state.| 551| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object. | 552 553**Error codes** 554 555For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 556 557| ID| Error Message| 558| -------- | ---------------------------------------- | 559| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 560| 6600101 | Session service exception. | 561| 6600102 | The session does not exist. | 562 563**Example** 564 565```ts 566import { BusinessError } from '@kit.BasicServicesKit'; 567 568let PlaybackState: avSession.AVPlaybackState = { 569 state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, 570 speed: 1.0, 571 position:{elapsedTime:10, updateTime:(new Date()).getTime()}, 572 bufferedTime:1000, 573 loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, 574 isFavorite:true 575}; 576currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => { 577 if (err) { 578 console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 579 } else { 580 console.info('SetAVPlaybackState successfully'); 581 } 582}); 583``` 584 585### setLaunchAbility<sup>10+</sup> 586 587setLaunchAbility(ability: WantAgent): Promise\<void> 588 589Sets a launcher ability. This API uses a promise to return the result. 590 591**Atomic service API**: This API can be used in atomic services since API version 12. 592 593**System capability**: SystemCapability.Multimedia.AVSession.Core 594 595**Parameters** 596 597| Name | Type | Mandatory| Description | 598| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 599| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID.| 600 601**Return value** 602 603| Type | Description | 604| -------------- | ----------------------------- | 605| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 606 607**Error codes** 608 609For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 610 611| ID| Error Message| 612| -------- | ---------------------------------------- | 613| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 614| 6600101 | Session service exception. | 615| 6600102 | The session does not exist. | 616 617**Example** 618 619```ts 620import { wantAgent } from '@kit.AbilityKit'; 621import { BusinessError } from '@kit.BasicServicesKit'; 622 623// WantAgentInfo object. 624let wantAgentInfo: wantAgent.WantAgentInfo = { 625 wants: [ 626 { 627 deviceId: "deviceId", 628 bundleName: "com.example.myapplication", 629 abilityName: "EntryAbility", 630 action: "action1", 631 entities: ["entity1"], 632 type: "MIMETYPE", 633 uri: "key = {true,true,false}", 634 parameters: 635 { 636 mykey0: 2222, 637 mykey1: [1, 2, 3], 638 mykey2: "[1, 2, 3]", 639 mykey3: "ssssssssssssssssssssssssss", 640 mykey4: [false, true, false], 641 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 642 mykey6: true 643 } 644 } 645 ], 646 operationType: wantAgent.OperationType.START_ABILITIES, 647 requestCode: 0, 648 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 649} 650 651wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 652 currentAVSession.setLaunchAbility(agent).then(() => { 653 console.info('SetLaunchAbility successfully'); 654 }).catch((err: BusinessError) => { 655 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 656 }); 657}); 658``` 659 660### setLaunchAbility<sup>10+</sup> 661 662setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void 663 664Sets a launcher ability. This API uses an asynchronous callback to return the result. 665 666**System capability**: SystemCapability.Multimedia.AVSession.Core 667 668**Parameters** 669 670| Name | Type | Mandatory| Description | 671| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | 672| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes | Application attributes, such as the bundle name, ability name, and deviceID. | 673| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 674 675**Error codes** 676 677For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 678 679| ID| Error Message| 680| -------- | ---------------------------------------- | 681| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 682| 6600101 | Session service exception. | 683| 6600102 | The session does not exist. | 684 685**Example** 686 687```ts 688import { wantAgent } from '@kit.AbilityKit'; 689import { BusinessError } from '@kit.BasicServicesKit'; 690 691// WantAgentInfo object. 692let wantAgentInfo: wantAgent.WantAgentInfo = { 693 wants: [ 694 { 695 deviceId: "deviceId", 696 bundleName: "com.example.myapplication", 697 abilityName: "EntryAbility", 698 action: "action1", 699 entities: ["entity1"], 700 type: "MIMETYPE", 701 uri: "key = {true,true,false}", 702 parameters: 703 { 704 mykey0: 2222, 705 mykey1: [1, 2, 3], 706 mykey2: "[1, 2, 3]", 707 mykey3: "ssssssssssssssssssssssssss", 708 mykey4: [false, true, false], 709 mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"], 710 mykey6: true 711 } 712 } 713 ], 714 operationType: wantAgent.OperationType.START_ABILITIES, 715 requestCode: 0, 716 wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG] 717} 718 719wantAgent.getWantAgent(wantAgentInfo).then((agent) => { 720 currentAVSession.setLaunchAbility(agent, (err: BusinessError) => { 721 if (err) { 722 console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 723 } else { 724 console.info('SetLaunchAbility successfully'); 725 } 726 }); 727}); 728``` 729 730### dispatchSessionEvent<sup>10+</sup> 731 732dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void> 733 734Dispatches 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. 735 736**Atomic service API**: This API can be used in atomic services since API version 12. 737 738**System capability**: SystemCapability.Multimedia.AVSession.Core 739 740**Parameters** 741 742| Name | Type | Mandatory| Description | 743| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 744| event | string | Yes | Name of the session event.| 745| args | {[key: string]: Object} | Yes | Content of the session event.| 746 747> **NOTE** 748> 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). 749 750**Return value** 751 752| Type | Description | 753| -------------- | ----------------------------- | 754| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 755 756**Error codes** 757 758For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 759 760| ID| Error Message| 761| -------- | ---------------------------------------- | 762| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 763| 6600101 | Session service exception. | 764| 6600102 | The session does not exist. | 765 766**Example** 767 768```ts 769import { BusinessError } from '@kit.BasicServicesKit'; 770 771let currentAVSession: avSession.AVSession | undefined = undefined; 772let tag = "createNewSession"; 773let context: Context = getContext(this); 774 775avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 776 if (err) { 777 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 778 } else { 779 currentAVSession = data; 780 } 781}); 782let eventName = "dynamic_lyric"; 783if (currentAVSession !== undefined) { 784 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => { 785 console.info('dispatchSessionEvent successfully'); 786 }).catch((err: BusinessError) => { 787 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 788 }) 789} 790``` 791 792### dispatchSessionEvent<sup>10+</sup> 793 794dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 795 796Dispatches 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. 797 798**System capability**: SystemCapability.Multimedia.AVSession.Core 799 800**Parameters** 801 802| Name | Type | Mandatory| Description | 803| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 804| event | string | Yes | Name of the session event.| 805| args | {[key: string]: Object} | Yes | Content of the session event.| 806| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 807 808> **NOTE** 809 810> 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). 811 812**Error codes** 813 814For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 815 816| ID| Error Message| 817| -------- | ---------------------------------------- | 818| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 819| 6600101 | Session service exception. | 820| 6600102 | The session does not exist. | 821 822**Example** 823 824```ts 825import { BusinessError } from '@kit.BasicServicesKit'; 826 827let currentAVSession: avSession.AVSession | undefined = undefined; 828let tag = "createNewSession"; 829let context: Context = getContext(this); 830 831avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 832 if (err) { 833 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 834 } else { 835 currentAVSession = data; 836 } 837}); 838let eventName: string = "dynamic_lyric"; 839if (currentAVSession !== undefined) { 840 (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => { 841 if (err) { 842 console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); 843 } 844 }) 845} 846``` 847 848### setAVQueueItems<sup>10+</sup> 849 850setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void> 851 852Sets a playlist. This API uses a promise to return the result. 853 854**Atomic service API**: This API can be used in atomic services since API version 12. 855 856**System capability**: SystemCapability.Multimedia.AVSession.Core 857 858**Parameters** 859 860| Name | Type | Mandatory| Description | 861| ------ | ------------------------------------ | ---- | ---------------------------------- | 862| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set.| 863 864**Return value** 865 866| Type | Description | 867| -------------- | ----------------------------- | 868| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 869 870**Error codes** 871 872For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 873 874| ID| Error Message| 875| -------- | ---------------------------------------- | 876| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 877| 6600101 | Session service exception. | 878| 6600102 | The session does not exist. | 879 880**Example** 881 882```ts 883import { image } from '@kit.ImageKit'; 884import { resourceManager } from '@kit.LocalizationKit'; 885import { BusinessError } from '@kit.BasicServicesKit'; 886 887async function setAVQueueItems() { 888 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 889 let imageSource = await image.createImageSource(value.buffer); 890 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 891 let queueItemDescription_1: avSession.AVMediaDescription = { 892 assetId: '001', 893 title: 'music_name', 894 subtitle: 'music_sub_name', 895 description: 'music_description', 896 mediaImage : imagePixel, 897 extras: {extras:'any'} 898 }; 899 let queueItem_1: avSession.AVQueueItem = { 900 itemId: 1, 901 description: queueItemDescription_1 902 }; 903 let queueItemDescription_2: avSession.AVMediaDescription = { 904 assetId: '002', 905 title: 'music_name', 906 subtitle: 'music_sub_name', 907 description: 'music_description', 908 mediaImage: imagePixel, 909 extras: {extras:'any'} 910 }; 911 let queueItem_2: avSession.AVQueueItem = { 912 itemId: 2, 913 description: queueItemDescription_2 914 }; 915 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 916 currentAVSession.setAVQueueItems(queueItemsArray).then(() => { 917 console.info('SetAVQueueItems successfully'); 918 }).catch((err: BusinessError) => { 919 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 920 }); 921} 922``` 923 924### setAVQueueItems<sup>10+</sup> 925 926setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void 927 928Sets a playlist. This API uses an asynchronous callback to return the result. 929 930**System capability**: SystemCapability.Multimedia.AVSession.Core 931 932**Parameters** 933 934| Name | Type | Mandatory| Description | 935| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | 936| items | Array<[AVQueueItem](#avqueueitem10)\> | Yes | Playlist to set. | 937| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 938 939**Error codes** 940 941For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 942 943| ID| Error Message| 944| -------- | ---------------------------------------- | 945| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 946| 6600101 | Session service exception. | 947| 6600102 | The session does not exist. | 948 949**Example** 950 951```ts 952import { image } from '@kit.ImageKit'; 953import { resourceManager } from '@kit.LocalizationKit'; 954import { BusinessError } from '@kit.BasicServicesKit'; 955 956async function setAVQueueItems() { 957 let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI'); 958 let imageSource = await image.createImageSource(value.buffer); 959 let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); 960 let queueItemDescription_1: avSession.AVMediaDescription = { 961 assetId: '001', 962 title: 'music_name', 963 subtitle: 'music_sub_name', 964 description: 'music_description', 965 mediaImage : imagePixel, 966 extras: {extras:'any'} 967 }; 968 let queueItem_1: avSession.AVQueueItem = { 969 itemId: 1, 970 description: queueItemDescription_1 971 }; 972 let queueItemDescription_2: avSession.AVMediaDescription = { 973 assetId: '002', 974 title: 'music_name', 975 subtitle: 'music_sub_name', 976 description: 'music_description', 977 mediaImage: imagePixel, 978 extras: {extras:'any'} 979 }; 980 let queueItem_2: avSession.AVQueueItem = { 981 itemId: 2, 982 description: queueItemDescription_2 983 }; 984 let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2]; 985 currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => { 986 if (err) { 987 console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 988 } else { 989 console.info('SetAVQueueItems successfully'); 990 } 991 }); 992} 993``` 994 995### setAVQueueTitle<sup>10+</sup> 996 997setAVQueueTitle(title: string): Promise\<void> 998 999Sets a name for the playlist. This API uses a promise to return the result. 1000 1001**Atomic service API**: This API can be used in atomic services since API version 12. 1002 1003**System capability**: SystemCapability.Multimedia.AVSession.Core 1004 1005**Parameters** 1006 1007| Name | Type | Mandatory| Description | 1008| ------ | ------ | ---- | -------------- | 1009| title | string | Yes | Name of the playlist.| 1010 1011**Return value** 1012 1013| Type | Description | 1014| -------------- | ----------------------------- | 1015| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 1016 1017**Error codes** 1018 1019For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1020 1021| ID| Error Message| 1022| -------- | ---------------------------------------- | 1023| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1024| 6600101 | Session service exception. | 1025| 6600102 | The session does not exist. | 1026 1027**Example** 1028 1029```ts 1030import { BusinessError } from '@kit.BasicServicesKit'; 1031 1032let queueTitle = 'QUEUE_TITLE'; 1033currentAVSession.setAVQueueTitle(queueTitle).then(() => { 1034 console.info('SetAVQueueTitle successfully'); 1035}).catch((err: BusinessError) => { 1036 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1037}); 1038``` 1039 1040### setAVQueueTitle<sup>10+</sup> 1041 1042setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void 1043 1044Sets a name for the playlist. This API uses an asynchronous callback to return the result. 1045 1046**System capability**: SystemCapability.Multimedia.AVSession.Core 1047 1048**Parameters** 1049 1050| Name | Type | Mandatory| Description | 1051| -------- | --------------------- | ---- | ----------------------------------------------------------- | 1052| title | string | Yes | Name of the playlist. | 1053| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1054 1055**Error codes** 1056 1057For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1058 1059| ID| Error Message| 1060| -------- | ---------------------------------------- | 1061| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1062| 6600101 | Session service exception. | 1063| 6600102 | The session does not exist. | 1064 1065**Example** 1066 1067```ts 1068import { BusinessError } from '@kit.BasicServicesKit'; 1069 1070let queueTitle = 'QUEUE_TITLE'; 1071currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => { 1072 if (err) { 1073 console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 1074 } else { 1075 console.info('SetAVQueueTitle successfully'); 1076 } 1077}); 1078``` 1079 1080### setExtras<sup>10+</sup> 1081 1082setExtras(extras: {[key: string]: Object}): Promise\<void> 1083 1084Sets 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. 1085 1086**Atomic service API**: This API can be used in atomic services since API version 12. 1087 1088**System capability**: SystemCapability.Multimedia.AVSession.Core 1089 1090**Parameters** 1091 1092| Name | Type | Mandatory| Description | 1093| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1094| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| 1095 1096> **NOTE** 1097 1098> 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). 1099 1100**Return value** 1101 1102| Type | Description | 1103| -------------- | ----------------------------- | 1104| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.| 1105 1106**Error codes** 1107 1108For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1109 1110| ID| Error Message| 1111| -------- | ---------------------------------------- | 1112| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1113| 6600101 | Session service exception. | 1114| 6600102 | The session does not exist. | 1115 1116**Example** 1117 1118```ts 1119import { BusinessError } from '@kit.BasicServicesKit'; 1120 1121let currentAVSession: avSession.AVSession | undefined = undefined; 1122let tag = "createNewSession"; 1123let context: Context = getContext(this); 1124 1125avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1126 if (err) { 1127 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1128 } else { 1129 currentAVSession = data; 1130 } 1131}); 1132if (currentAVSession !== undefined) { 1133 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => { 1134 console.info('setExtras successfully'); 1135 }).catch((err: BusinessError) => { 1136 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1137 }) 1138} 1139``` 1140 1141### setExtras<sup>10+</sup> 1142 1143setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void 1144 1145Sets 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. 1146 1147**System capability**: SystemCapability.Multimedia.AVSession.Core 1148 1149**Parameters** 1150 1151| Name | Type | Mandatory| Description | 1152| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | 1153| extras | {[key: string]: Object} | Yes | Key-value pairs of the custom media packet.| 1154| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 1155 1156> **NOTE** 1157 1158> 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). 1159 1160**Error codes** 1161 1162For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1163 1164| ID| Error Message| 1165| -------- | ---------------------------------------- | 1166| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 1167| 6600101 | Session service exception. | 1168| 6600102 | The session does not exist. | 1169 1170**Example** 1171 1172```ts 1173import { BusinessError } from '@kit.BasicServicesKit'; 1174 1175let currentAVSession: avSession.AVSession | undefined = undefined; 1176let tag = "createNewSession"; 1177let context: Context = getContext(this); 1178 1179avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 1180 if (err) { 1181 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 1182 } else { 1183 currentAVSession = data; 1184 } 1185}); 1186if (currentAVSession !== undefined) { 1187 (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => { 1188 if (err) { 1189 console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); 1190 } 1191 }) 1192} 1193``` 1194 1195### getController<sup>10+</sup> 1196 1197getController(): Promise\<AVSessionController> 1198 1199Obtains the controller corresponding to this session. This API uses a promise to return the result. 1200 1201**Atomic service API**: This API can be used in atomic services since API version 12. 1202 1203**System capability**: SystemCapability.Multimedia.AVSession.Core 1204 1205**Return value** 1206 1207| Type | Description | 1208| ---------------------------------------------------- | ----------------------------- | 1209| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.| 1210 1211**Error codes** 1212 1213For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1214 1215| ID| Error Message| 1216| -------- | ---------------------------------------- | 1217| 6600101 | Session service exception. | 1218| 6600102 | The session does not exist. | 1219 1220**Example** 1221 1222```ts 1223import { BusinessError } from '@kit.BasicServicesKit'; 1224 1225let avsessionController: avSession.AVSessionController; 1226currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => { 1227 avsessionController = avcontroller; 1228 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1229}).catch((err: BusinessError) => { 1230 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1231}); 1232``` 1233 1234### getController<sup>10+</sup> 1235 1236getController(callback: AsyncCallback\<AVSessionController>): void 1237 1238Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result. 1239 1240**System capability**: SystemCapability.Multimedia.AVSession.Core 1241 1242**Parameters** 1243 1244| Name | Type | Mandatory| Description | 1245| -------- | ----------------------------------------------------------- | ---- | -------------------------- | 1246| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes | Callback used to return the session controller.| 1247 1248**Error codes** 1249 1250For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1251 1252| ID| Error Message| 1253| -------- | ---------------------------------------- | 1254| 6600101 | Session service exception. | 1255| 6600102 | The session does not exist. | 1256 1257**Example** 1258 1259```ts 1260import { BusinessError } from '@kit.BasicServicesKit'; 1261 1262let avsessionController: avSession.AVSessionController; 1263currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => { 1264 if (err) { 1265 console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); 1266 } else { 1267 avsessionController = avcontroller; 1268 console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); 1269 } 1270}); 1271``` 1272 1273### getAVCastController<sup>10+</sup> 1274 1275getAVCastController(): Promise\<AVCastController> 1276 1277Obtains 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**. 1278 1279**Atomic service API**: This API can be used in atomic services since API version 12. 1280 1281**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1282 1283**Return value** 1284 1285| Type | Description | 1286| --------- | ------------------------------------------------------------ | 1287| Promise<[AVCastController](#avcastcontroller10)\> | Promise used to return the cast controller.| 1288 1289**Error codes** 1290 1291For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1292 1293| ID| Error Message| 1294| -------- | --------------------------------------- | 1295| 6600102| The session does not exist. | 1296| 6600109| The remote connection is not established. | 1297 1298**Example** 1299 1300```ts 1301import { BusinessError } from '@kit.BasicServicesKit'; 1302 1303let aVCastController: avSession.AVCastController; 1304currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => { 1305 aVCastController = avcontroller; 1306 console.info('getAVCastController : SUCCESS'); 1307}).catch((err: BusinessError) => { 1308 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1309}); 1310``` 1311 1312### getAVCastController<sup>10+</sup> 1313 1314getAVCastController(callback: AsyncCallback\<AVCastController>): void 1315 1316Obtains 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**. 1317 1318**System capability**: SystemCapability.Multimedia.AVSession.AVCast 1319 1320**Parameters** 1321 1322| Name | Type | Mandatory| Description | 1323| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 1324| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes | Callback used to return the cast controller.| 1325 1326**Error codes** 1327 1328For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1329 1330| ID| Error Message | 1331| -------- |---------------------------------------| 1332| 6600102| The session does not exist. | 1333| 6600109| The remote connection is not established. | 1334 1335**Example** 1336 1337```ts 1338import { BusinessError } from '@kit.BasicServicesKit'; 1339 1340let aVCastController: avSession.AVCastController; 1341currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => { 1342 if (err) { 1343 console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); 1344 } else { 1345 aVCastController = avcontroller; 1346 console.info('getAVCastController : SUCCESS'); 1347 } 1348}); 1349``` 1350 1351### getOutputDevice<sup>10+</sup> 1352 1353getOutputDevice(): Promise\<OutputDeviceInfo> 1354 1355Obtains information about the output device for this session. This API uses a promise to return the result. 1356 1357**Atomic service API**: This API can be used in atomic services since API version 12. 1358 1359**System capability**: SystemCapability.Multimedia.AVSession.Core 1360 1361**Return value** 1362 1363| Type | Description | 1364| ---------------------------------------------- | --------------------------------- | 1365| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.| 1366 1367**Error codes** 1368 1369For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1370 1371| ID| Error Message| 1372| -------- | ---------------------------------------- | 1373| 6600101 | Session service exception. | 1374| 6600102 | The session does not exist. | 1375 1376**Example** 1377 1378```ts 1379import { BusinessError } from '@kit.BasicServicesKit'; 1380 1381currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => { 1382 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1383}).catch((err: BusinessError) => { 1384 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1385}) 1386``` 1387 1388### getOutputDevice<sup>10+</sup> 1389 1390getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 1391 1392Obtains information about the output device for this session. This API uses an asynchronous callback to return the result. 1393 1394**System capability**: SystemCapability.Multimedia.AVSession.Core 1395 1396**Parameters** 1397 1398| Name | Type | Mandatory| Description | 1399| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 1400| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| 1401 1402**Error codes** 1403 1404For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1405 1406| ID| Error Message| 1407| -------- | ---------------------------------------- | 1408| 6600101 | Session service exception. | 1409| 6600102 | The session does not exist. | 1410 1411**Example** 1412 1413```ts 1414import { BusinessError } from '@kit.BasicServicesKit'; 1415 1416currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => { 1417 if (err) { 1418 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 1419 } else { 1420 console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`); 1421 } 1422}); 1423``` 1424 1425### activate<sup>10+</sup> 1426 1427activate(): Promise\<void> 1428 1429Activates this session. A session can be used only after being activated. This API uses a promise to return the result. 1430 1431**Atomic service API**: This API can be used in atomic services since API version 12. 1432 1433**System capability**: SystemCapability.Multimedia.AVSession.Core 1434 1435**Return value** 1436 1437| Type | Description | 1438| -------------- | ----------------------------- | 1439| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.| 1440 1441**Error codes** 1442 1443For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1444 1445| ID| Error Message| 1446| -------- | ---------------------------------------- | 1447| 6600101 | Session service exception. | 1448| 6600102 | The session does not exist. | 1449 1450**Example** 1451 1452```ts 1453import { BusinessError } from '@kit.BasicServicesKit'; 1454 1455currentAVSession.activate().then(() => { 1456 console.info('Activate : SUCCESS '); 1457}).catch((err: BusinessError) => { 1458 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1459}); 1460``` 1461 1462### activate<sup>10+</sup> 1463 1464activate(callback: AsyncCallback\<void>): void 1465 1466Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result. 1467 1468**System capability**: SystemCapability.Multimedia.AVSession.Core 1469 1470**Parameters** 1471 1472| Name | Type | Mandatory| Description | 1473| -------- | -------------------- | ---- | ---------- | 1474| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.| 1475 1476**Error codes** 1477 1478For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1479 1480| ID| Error Message| 1481| -------- | ---------------------------------------- | 1482| 6600101 | Session service exception. | 1483| 6600102 | The session does not exist. | 1484 1485**Example** 1486 1487```ts 1488import { BusinessError } from '@kit.BasicServicesKit'; 1489 1490currentAVSession.activate((err: BusinessError) => { 1491 if (err) { 1492 console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); 1493 } else { 1494 console.info('Activate : SUCCESS '); 1495 } 1496}); 1497``` 1498 1499### deactivate<sup>10+</sup> 1500 1501deactivate(): Promise\<void> 1502 1503Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result. 1504 1505**Atomic service API**: This API can be used in atomic services since API version 12. 1506 1507**System capability**: SystemCapability.Multimedia.AVSession.Core 1508 1509**Return value** 1510 1511| Type | Description | 1512| -------------- | ----------------------------- | 1513| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.| 1514 1515**Error codes** 1516 1517For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1518 1519| ID| Error Message| 1520| -------- | ---------------------------------------- | 1521| 6600101 | Session service exception. | 1522| 6600102 | The session does not exist. | 1523 1524**Example** 1525 1526```ts 1527import { BusinessError } from '@kit.BasicServicesKit'; 1528 1529currentAVSession.deactivate().then(() => { 1530 console.info('Deactivate : SUCCESS '); 1531}).catch((err: BusinessError) => { 1532 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1533}); 1534``` 1535 1536### deactivate<sup>10+</sup> 1537 1538deactivate(callback: AsyncCallback\<void>): void 1539 1540Deactivates this session. This API uses an asynchronous callback to return the result. 1541 1542Deactivates this session. You can use [activate](#activate10) to activate the session again. 1543 1544**System capability**: SystemCapability.Multimedia.AVSession.Core 1545 1546**Parameters** 1547 1548| Name | Type | Mandatory| Description | 1549| -------- | -------------------- | ---- | ---------- | 1550| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.| 1551 1552**Error codes** 1553 1554For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1555 1556| ID| Error Message| 1557| -------- | ---------------------------------------- | 1558| 6600101 | Session service exception. | 1559| 6600102 | The session does not exist. | 1560 1561**Example** 1562 1563```ts 1564import { BusinessError } from '@kit.BasicServicesKit'; 1565 1566currentAVSession.deactivate((err: BusinessError) => { 1567 if (err) { 1568 console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); 1569 } else { 1570 console.info('Deactivate : SUCCESS '); 1571 } 1572}); 1573``` 1574 1575### destroy<sup>10+</sup> 1576 1577destroy(): Promise\<void> 1578 1579Destroys this session. This API uses a promise to return the result. 1580 1581**Atomic service API**: This API can be used in atomic services since API version 12. 1582 1583**System capability**: SystemCapability.Multimedia.AVSession.Core 1584 1585**Return value** 1586 1587| Type | Description | 1588| -------------- | ----------------------------- | 1589| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.| 1590 1591**Error codes** 1592 1593For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1594 1595| ID| Error Message| 1596| -------- | ---------------------------------------- | 1597| 6600101 | Session service exception. | 1598| 6600102 | The session does not exist. | 1599 1600**Example** 1601 1602```ts 1603import { BusinessError } from '@kit.BasicServicesKit'; 1604 1605currentAVSession.destroy().then(() => { 1606 console.info('Destroy : SUCCESS '); 1607}).catch((err: BusinessError) => { 1608 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1609}); 1610``` 1611 1612### destroy<sup>10+</sup> 1613 1614destroy(callback: AsyncCallback\<void>): void 1615 1616Destroys this session. This API uses an asynchronous callback to return the result. 1617 1618**System capability**: SystemCapability.Multimedia.AVSession.Core 1619 1620**Parameters** 1621 1622| Name | Type | Mandatory| Description | 1623| -------- | -------------------- | ---- | ---------- | 1624| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| 1625 1626**Error codes** 1627 1628For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1629 1630| ID| Error Message| 1631| -------- | ---------------------------------------- | 1632| 6600101 | Session service exception. | 1633| 6600102 | The session does not exist. | 1634 1635**Example** 1636 1637```ts 1638import { BusinessError } from '@kit.BasicServicesKit'; 1639 1640currentAVSession.destroy((err: BusinessError) => { 1641 if (err) { 1642 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 1643 } else { 1644 console.info('Destroy : SUCCESS '); 1645 } 1646}); 1647``` 1648 1649### on('play')<sup>10+</sup> 1650 1651on(type: 'play', callback: () => void): void 1652 1653Subscribes to play command events. The subscription means that the application supports the play command. 1654 1655Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1656 1657**Atomic service API**: This API can be used in atomic services since API version 12. 1658 1659**System capability**: SystemCapability.Multimedia.AVSession.Core 1660 1661**Parameters** 1662 1663| Name | Type | Mandatory| Description | 1664| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1665| type | string | Yes | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.| 1666| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1667 1668**Error codes** 1669 1670For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1671 1672| ID| Error Message| 1673| -------- | ---------------------------------------- | 1674| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1675| 6600101 | Session service exception. | 1676| 6600102 | The session does not exist. | 1677 1678**Example** 1679 1680```ts 1681currentAVSession.on('play', () => { 1682 console.info('on play entry'); 1683}); 1684``` 1685 1686### on('pause')<sup>10+</sup> 1687 1688on(type: 'pause', callback: () => void): void 1689 1690Subscribes to pause command events. The subscription means that the application supports the pause command. 1691 1692Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1693 1694**Atomic service API**: This API can be used in atomic services since API version 12. 1695 1696**System capability**: SystemCapability.Multimedia.AVSession.Core 1697 1698**Parameters** 1699 1700| Name | Type | Mandatory| Description | 1701| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1702| type | string | Yes | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.| 1703| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1704 1705**Error codes** 1706 1707For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1708 1709| ID| Error Message| 1710| -------- | ---------------------------------------- | 1711| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1712| 6600101 | Session service exception. | 1713| 6600102 | The session does not exist. | 1714 1715**Example** 1716 1717```ts 1718currentAVSession.on('pause', () => { 1719 console.info('on pause entry'); 1720}); 1721``` 1722 1723### on('stop')<sup>10+</sup> 1724 1725on(type:'stop', callback: () => void): void 1726 1727Subscribes to stop command events. The subscription means that the application supports the stop command. 1728 1729Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1730 1731**Atomic service API**: This API can be used in atomic services since API version 12. 1732 1733**System capability**: SystemCapability.Multimedia.AVSession.Core 1734 1735**Parameters** 1736 1737| Name | Type | Mandatory| Description | 1738| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1739| type | string | Yes | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.| 1740| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1741 1742**Error codes** 1743 1744For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1745 1746| ID| Error Message| 1747| -------- | ---------------------------------------- | 1748| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1749| 6600101 | Session service exception. | 1750| 6600102 | The session does not exist. | 1751 1752**Example** 1753 1754```ts 1755currentAVSession.on('stop', () => { 1756 console.info('on stop entry'); 1757}); 1758``` 1759 1760### on('playNext')<sup>10+</sup> 1761 1762on(type:'playNext', callback: () => void): void 1763 1764Subscribes to playNext command events. The subscription means that the application supports the playNext command. 1765 1766Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1767 1768**Atomic service API**: This API can be used in atomic services since API version 12. 1769 1770**System capability**: SystemCapability.Multimedia.AVSession.Core 1771 1772**Parameters** 1773 1774| Name | Type | Mandatory| Description | 1775| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1776| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.| 1777| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1778 1779**Error codes** 1780 1781For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1782 1783| ID| Error Message| 1784| -------- | ---------------------------------------- | 1785| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1786| 6600101 | Session service exception. | 1787| 6600102 | The session does not exist. | 1788 1789**Example** 1790 1791```ts 1792currentAVSession.on('playNext', () => { 1793 console.info('on playNext entry'); 1794}); 1795``` 1796 1797### on('playPrevious')<sup>10+</sup> 1798 1799on(type:'playPrevious', callback: () => void): void 1800 1801Subscribes to playPrevious command events. The subscription means that the application supports the playPrevious command. 1802 1803Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1804 1805**Atomic service API**: This API can be used in atomic services since API version 12. 1806 1807**System capability**: SystemCapability.Multimedia.AVSession.Core 1808 1809**Parameters** 1810 1811| Name | Type | Mandatory| Description | 1812| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1813| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.| 1814| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 1815 1816**Error codes** 1817 1818For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1819 1820| ID| Error Message| 1821| -------- | ---------------------------------------- | 1822| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1823| 6600101 | Session service exception. | 1824| 6600102 | The session does not exist. | 1825 1826**Example** 1827 1828```ts 1829currentAVSession.on('playPrevious', () => { 1830 console.info('on playPrevious entry'); 1831}); 1832``` 1833 1834### on('fastForward')<sup>10+</sup> 1835 1836on(type: 'fastForward', callback: (time?: number) => void): void 1837 1838Subscribes to fastForward command events. The subscription means that the application supports the fastForward command. 1839 1840Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced. 1841 1842**Atomic service API**: This API can be used in atomic services since API version 12. 1843 1844**System capability**: SystemCapability.Multimedia.AVSession.Core 1845 1846**Parameters** 1847 1848| Name | Type | Mandatory| Description | 1849| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1850| type | string | Yes | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.| 1851| callback | (time?: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds. | 1852 1853**Error codes** 1854 1855For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1856 1857| ID| Error Message| 1858| -------- | ---------------------------------------- | 1859| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1860| 6600101 | Session service exception. | 1861| 6600102 | The session does not exist. | 1862 1863**Example** 1864 1865```ts 1866currentAVSession.on('fastForward', (time?: number) => { 1867 console.info('on fastForward entry'); 1868}); 1869``` 1870 1871### on('rewind')<sup>10+</sup> 1872 1873on(type:'rewind', callback: (time?: number) => void): void 1874 1875Subscribes to rewind command events. 1876 1877**Atomic service API**: This API can be used in atomic services since API version 12. 1878 1879**System capability**: SystemCapability.Multimedia.AVSession.Core 1880 1881**Parameters** 1882 1883| Name | Type | Mandatory| Description | 1884| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1885| type | string | Yes | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.| 1886| callback | (time?: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds. | 1887 1888**Error codes** 1889 1890For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1891 1892| ID| Error Message| 1893| -------- | ---------------------------------------- | 1894| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1895| 6600101 | Session service exception. | 1896| 6600102 | The session does not exist. | 1897 1898**Example** 1899 1900```ts 1901currentAVSession.on('rewind', (time?: number) => { 1902 console.info('on rewind entry'); 1903}); 1904``` 1905 1906### on('playFromAssetId')<sup>11+</sup> 1907 1908on(type:'playFromAssetId', callback: (assetId: number) => void): void 1909 1910Subscribes to playback events of a given media ID. 1911 1912**Atomic service API**: This API can be used in atomic services since API version 12. 1913 1914**System capability**: SystemCapability.Multimedia.AVSession.Core 1915 1916**Parameters** 1917 1918| Name | Type | Mandatory| Description | 1919| -------- | -------------------- | ---- | ------------------------------------------------------------ | 1920| type | string | Yes | Event type. The event **'playFromAssetId'** is triggered when the media ID is played.| 1921| callback | callback: (assetId: number) => void | Yes | Callback The **assetId** parameter in the callback indicates the media asset ID. | 1922 1923**Error codes** 1924 1925For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1926 1927| ID| Error Message| 1928| -------- | ---------------------------------------- | 1929| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1930| 6600101 | Session service exception. | 1931| 6600102 | The session does not exist. | 1932 1933**Example** 1934 1935```ts 1936currentAVSession.on('playFromAssetId', (assetId: number) => { 1937 console.info('on playFromAssetId entry'); 1938}); 1939``` 1940 1941### off('playFromAssetId')<sup>11+</sup> 1942 1943off(type: 'playFromAssetId', callback?: (assetId: number) => void): void 1944 1945Unsubscribes from playback events of a given media ID. 1946 1947**Atomic service API**: This API can be used in atomic services since API version 12. 1948 1949**System capability**: SystemCapability.Multimedia.AVSession.Core 1950 1951**Parameters** 1952 1953| Name | Type | Mandatory| Description | 1954| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 1955| type | string | Yes | Event type, which is **'playFromAssetId'** in this case.| 1956| callback | 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. | 1957 1958**Error codes** 1959 1960For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1961 1962| ID| Error Message| 1963| -------- | ---------------------------------------- | 1964| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1965| 6600101 | Session service exception. | 1966| 6600102 | The session does not exist. | 1967 1968**Example** 1969 1970```ts 1971currentAVSession.off('playFromAssetId'); 1972``` 1973 1974### on('seek')<sup>10+</sup> 1975 1976on(type: 'seek', callback: (time: number) => void): void 1977 1978Subscribes to seek command events. 1979 1980**Atomic service API**: This API can be used in atomic services since API version 12. 1981 1982**System capability**: SystemCapability.Multimedia.AVSession.Core 1983 1984**Parameters** 1985 1986| Name | Type | Mandatory| Description | 1987| -------- | ---------------------- | ---- | ------------------------------------------------------------ | 1988| type | string | Yes | Event type. The event **'seek'** is triggered when the seek command is sent to the session.| 1989| callback | (time: number) => void | Yes | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds. | 1990 1991**Error codes** 1992 1993For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 1994 1995| ID| Error Message| 1996| -------- | ---------------------------------------- | 1997| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 1998| 6600101 | Session service exception. | 1999| 6600102 | The session does not exist. | 2000 2001**Example** 2002 2003```ts 2004currentAVSession.on('seek', (time: number) => { 2005 console.info(`on seek entry time : ${time}`); 2006}); 2007``` 2008 2009### on('setSpeed')<sup>10+</sup> 2010 2011on(type: 'setSpeed', callback: (speed: number) => void): void 2012 2013Subscribes to setSpeed command events. 2014 2015**Atomic service API**: This API can be used in atomic services since API version 12. 2016 2017**System capability**: SystemCapability.Multimedia.AVSession.Core 2018 2019**Parameters** 2020 2021| Name | Type | Mandatory| Description | 2022| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 2023| type | string | Yes | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.| 2024| callback | (speed: number) => void | Yes | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed. | 2025 2026**Error codes** 2027 2028For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2029 2030| ID| Error Message| 2031| -------- | ---------------------------------------- | 2032| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2033| 6600101 | Session service exception. | 2034| 6600102 | The session does not exist. | 2035 2036**Example** 2037 2038```ts 2039currentAVSession.on('setSpeed', (speed: number) => { 2040 console.info(`on setSpeed speed : ${speed}`); 2041}); 2042``` 2043 2044### on('setLoopMode')<sup>10+</sup> 2045 2046on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void 2047 2048Subscribes to setLoopMode command events. 2049 2050**Atomic service API**: This API can be used in atomic services since API version 12. 2051 2052**System capability**: SystemCapability.Multimedia.AVSession.Core 2053 2054**Parameters** 2055 2056| Name | Type | Mandatory| Description | 2057| -------- | ------------------------------------- | ---- | ---- | 2058| type | string | Yes | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.| 2059| callback | (mode: [LoopMode](#loopmode10)) => void | Yes | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode. | 2060 2061**Error codes** 2062 2063For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2064 2065| ID| Error Message| 2066| -------- | ---------------------------------------- | 2067| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2068| 6600101 | Session service exception. | 2069| 6600102 | The session does not exist. | 2070 2071**Example** 2072 2073```ts 2074currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => { 2075 console.info(`on setLoopMode mode : ${mode}`); 2076}); 2077``` 2078 2079### on('toggleFavorite')<sup>10+</sup> 2080 2081on(type: 'toggleFavorite', callback: (assetId: string) => void): void 2082 2083Subscribes to toggleFavorite command events. 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. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.| 2094| callback | (assetId: string) => void | Yes | Callback used for subscription. 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. | 2104| 6600102 | The session does not exist. | 2105 2106**Example** 2107 2108```ts 2109currentAVSession.on('toggleFavorite', (assetId: string) => { 2110 console.info(`on toggleFavorite mode : ${assetId}`); 2111}); 2112``` 2113 2114### on('skipToQueueItem')<sup>10+</sup> 2115 2116on(type: 'skipToQueueItem', callback: (itemId: number) => void): void 2117 2118Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item. 2119 2120**Atomic service API**: This API can be used in atomic services since API version 12. 2121 2122**System capability**: SystemCapability.Multimedia.AVSession.Core 2123 2124**Parameters** 2125 2126| Name | Type | Mandatory| Description | 2127| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- | 2128| type | string | Yes | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.| 2129| callback | (itemId: number) => void | Yes | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item. | 2130 2131**Error codes** 2132 2133For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2134 2135| ID| Error Message| 2136| -------- | ---------------------------------------- | 2137| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2138| 6600101 | Session service exception. | 2139| 6600102 | The session does not exist. | 2140 2141**Example** 2142 2143```ts 2144currentAVSession.on('skipToQueueItem', (itemId: number) => { 2145 console.info(`on skipToQueueItem id : ${itemId}`); 2146}); 2147``` 2148 2149### on('handleKeyEvent')<sup>10+</sup> 2150 2151on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void 2152 2153Subscribes 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. 2154 2155**Atomic service API**: This API can be used in atomic services since API version 12. 2156 2157**System capability**: SystemCapability.Multimedia.AVSession.Core 2158 2159**Parameters** 2160 2161| Name | Type | Mandatory| Description | 2162| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2163| type | string | Yes | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.| 2164| 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. | 2165 2166**Error codes** 2167 2168For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2169 2170| ID| Error Message| 2171| -------- | ---------------------------------------- | 2172| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2173| 6600101 | Session service exception. | 2174| 6600102 | The session does not exist. | 2175 2176**Example** 2177 2178```ts 2179import { KeyEvent } from '@kit.InputKit'; 2180 2181currentAVSession.on('handleKeyEvent', (event: KeyEvent) => { 2182 console.info(`on handleKeyEvent event : ${event}`); 2183}); 2184 2185``` 2186 2187### on('outputDeviceChange')<sup>10+</sup> 2188 2189on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2190 2191Subscribes 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. 2192 2193**Atomic service API**: This API can be used in atomic services since API version 12. 2194 2195**System capability**: SystemCapability.Multimedia.AVSession.Core 2196 2197**Parameters** 2198 2199| Name | Type | Mandatory| Description | 2200| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 2201| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| 2202| 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. | 2203 2204**Error codes** 2205 2206For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2207 2208| ID| Error Message| 2209| -------- | ---------------------------------------- | 2210| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2211| 6600101 | Session service exception. | 2212| 6600102 | The session does not exist. | 2213 2214**Example** 2215 2216```ts 2217currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 2218 console.info(`on outputDeviceChange device : ${device}`); 2219}); 2220``` 2221 2222### on('commonCommand')<sup>10+</sup> 2223 2224on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void 2225 2226Subscribes to custom control command change events. 2227 2228**Atomic service API**: This API can be used in atomic services since API version 12. 2229 2230**System capability**: SystemCapability.Multimedia.AVSession.Core 2231 2232**Parameters** 2233 2234| Name | Type | Mandatory| Description | 2235| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2236| type | string | Yes | Event type. The event **'commonCommand'** is triggered when a custom control command changes.| 2237| 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). | 2238 2239**Error codes** 2240 2241For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2242 2243| ID| Error Message| 2244| -------- | ------------------------------ | 2245| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2246| 6600101 | Session service exception. | 2247| 6600102 | The session does not exist. | 2248 2249**Example** 2250 2251```ts 2252import { BusinessError } from '@kit.BasicServicesKit'; 2253 2254let currentAVSession: avSession.AVSession | undefined = undefined; 2255let tag = "createNewSession"; 2256let context: Context = getContext(this); 2257 2258avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 2259 if (err) { 2260 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 2261 } else { 2262 currentAVSession = data; 2263 } 2264}); 2265if (currentAVSession !== undefined) { 2266 (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => { 2267 console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); 2268 }); 2269} 2270``` 2271 2272### off('play')<sup>10+</sup> 2273 2274off(type: 'play', callback?: () => void): void 2275 2276Unsubscribes from play command events. 2277 2278After the callback is canceled, the list of supported commands must be updated. 2279 2280**Atomic service API**: This API can be used in atomic services since API version 12. 2281 2282**System capability**: SystemCapability.Multimedia.AVSession.Core 2283 2284**Parameters** 2285 2286| Name | Type | Mandatory| Description | 2287| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2288| type | string | Yes | Event type, which is **'play'** in this case.| 2289| 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. | 2290 2291**Error codes** 2292 2293For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2294 2295| ID| Error Message| 2296| -------- | ---------------------------------------- | 2297| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2298| 6600101 | Session service exception. | 2299| 6600102 | The session does not exist. | 2300 2301**Example** 2302 2303```ts 2304currentAVSession.off('play'); 2305``` 2306 2307### off('pause')<sup>10+</sup> 2308 2309off(type: 'pause', callback?: () => void): void 2310 2311Unsubscribes from pause command events. 2312 2313After the callback is canceled, the list of supported commands must be updated. 2314 2315**Atomic service API**: This API can be used in atomic services since API version 12. 2316 2317**System capability**: SystemCapability.Multimedia.AVSession.Core 2318 2319**Parameters** 2320 2321| Name | Type | Mandatory| Description | 2322| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2323| type | string | Yes | Event type, which is **'pause'** in this case.| 2324| 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.| 2325 2326**Error codes** 2327 2328For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2329 2330| ID| Error Message| 2331| -------- | ---------------------------------------- | 2332| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2333| 6600101 | Session service exception. | 2334| 6600102 | The session does not exist. | 2335 2336**Example** 2337 2338```ts 2339currentAVSession.off('pause'); 2340``` 2341 2342### off('stop')<sup>10+</sup> 2343 2344off(type: 'stop', callback?: () => void): void 2345 2346Unsubscribes from stop command events. 2347 2348After the callback is canceled, the list of supported commands must be updated. 2349 2350**Atomic service API**: This API can be used in atomic services since API version 12. 2351 2352**System capability**: SystemCapability.Multimedia.AVSession.Core 2353 2354**Parameters** 2355 2356| Name | Type | Mandatory| Description | 2357| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2358| type | string | Yes | Event type, which is **'stop'** in this case.| 2359| 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. | 2360 2361**Error codes** 2362 2363For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2364 2365| ID| Error Message| 2366| -------- | ---------------------------------------- | 2367| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2368| 6600101 | Session service exception. | 2369| 6600102 | The session does not exist. | 2370 2371**Example** 2372 2373```ts 2374currentAVSession.off('stop'); 2375``` 2376 2377### off('playNext')<sup>10+</sup> 2378 2379off(type: 'playNext', callback?: () => void): void 2380 2381Unsubscribes from playNext command events. 2382 2383After the callback is canceled, the list of supported commands must be updated. 2384 2385**Atomic service API**: This API can be used in atomic services since API version 12. 2386 2387**System capability**: SystemCapability.Multimedia.AVSession.Core 2388 2389**Parameters** 2390 2391| Name | Type | Mandatory| Description | 2392| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2393| type | string | Yes | Event type, which is **'playNext'** in this case.| 2394| 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. | 2395 2396**Error codes** 2397 2398For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2399 2400| ID| Error Message| 2401| -------- | ---------------------------------------- | 2402| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2403| 6600101 | Session service exception. | 2404| 6600102 | The session does not exist. | 2405 2406**Example** 2407 2408```ts 2409currentAVSession.off('playNext'); 2410``` 2411 2412### off('playPrevious')<sup>10+</sup> 2413 2414off(type: 'playPrevious', callback?: () => void): void 2415 2416Unsubscribes from playPrevious command events. 2417 2418After the callback is canceled, the list of supported commands must be updated. 2419 2420**Atomic service API**: This API can be used in atomic services since API version 12. 2421 2422**System capability**: SystemCapability.Multimedia.AVSession.Core 2423 2424**Parameters** 2425 2426| Name | Type | Mandatory| Description | 2427| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2428| type | string | Yes | Event type, which is **'playPrevious'** in this case.| 2429| 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. | 2430 2431**Error codes** 2432 2433For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2434 2435| ID| Error Message| 2436| -------- | ---------------------------------------- | 2437| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2438| 6600101 | Session service exception. | 2439| 6600102 | The session does not exist. | 2440 2441**Example** 2442 2443```ts 2444currentAVSession.off('playPrevious'); 2445``` 2446 2447### off('fastForward')<sup>10+</sup> 2448 2449off(type: 'fastForward', callback?: () => void): void 2450 2451Unsubscribes from fastForward command events. 2452 2453After the callback is canceled, the list of supported commands must be updated. 2454 2455**Atomic service API**: This API can be used in atomic services since API version 12. 2456 2457**System capability**: SystemCapability.Multimedia.AVSession.Core 2458 2459**Parameters** 2460 2461| Name | Type | Mandatory| Description | 2462| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2463| type | string | Yes | Event type, which is **'fastForward'** in this case.| 2464| 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. | 2465 2466**Error codes** 2467 2468For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2469 2470| ID| Error Message| 2471| -------- | ---------------------------------------- | 2472| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2473| 6600101 | Session service exception. | 2474| 6600102 | The session does not exist. | 2475 2476**Example** 2477 2478```ts 2479currentAVSession.off('fastForward'); 2480``` 2481 2482### off('rewind')<sup>10+</sup> 2483 2484off(type: 'rewind', callback?: () => void): void 2485 2486Unsubscribes from rewind command events. 2487 2488**Atomic service API**: This API can be used in atomic services since API version 12. 2489 2490**System capability**: SystemCapability.Multimedia.AVSession.Core 2491 2492**Parameters** 2493 2494| Name | Type | Mandatory| Description | 2495| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2496| type | string | Yes | Event type, which is **'rewind'** in this case.| 2497| 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. | 2498 2499**Error codes** 2500 2501For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2502 2503| ID| Error Message| 2504| -------- | ---------------------------------------- | 2505| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2506| 6600101 | Session service exception. | 2507| 6600102 | The session does not exist. | 2508 2509**Example** 2510 2511```ts 2512currentAVSession.off('rewind'); 2513``` 2514 2515### off('seek')<sup>10+</sup> 2516 2517off(type: 'seek', callback?: (time: number) => void): void 2518 2519Unsubscribes from seek command events. 2520 2521**Atomic service API**: This API can be used in atomic services since API version 12. 2522 2523**System capability**: SystemCapability.Multimedia.AVSession.Core 2524 2525**Parameters** 2526 2527| Name | Type | Mandatory| Description | 2528| -------- | ---------------------- | ---- | ----------------------------------------- | 2529| type | string | Yes | Event type, which is **'seek'** in this case. | 2530| 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. | 2531 2532**Error codes** 2533 2534For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2535 2536| ID| Error Message| 2537| -------- | ---------------------------------------- | 2538| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2539| 6600101 | Session service exception. | 2540| 6600102 | The session does not exist. | 2541 2542**Example** 2543 2544```ts 2545currentAVSession.off('seek'); 2546``` 2547 2548### off('setSpeed')<sup>10+</sup> 2549 2550off(type: 'setSpeed', callback?: (speed: number) => void): void 2551 2552Unsubscribes from setSpeed command events. 2553 2554**Atomic service API**: This API can be used in atomic services since API version 12. 2555 2556**System capability**: SystemCapability.Multimedia.AVSession.Core 2557 2558**Parameters** 2559 2560| Name | Type | Mandatory| Description | 2561| -------- | ----------------------- | ---- | -------------------------------------------| 2562| type | string | Yes | Event type, which is **'setSpeed'** in this case. | 2563| 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. | 2564 2565**Error codes** 2566 2567For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2568 2569| ID| Error Message| 2570| -------- | ---------------------------------------- | 2571| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2572| 6600101 | Session service exception. | 2573| 6600102 | The session does not exist. | 2574 2575**Example** 2576 2577```ts 2578currentAVSession.off('setSpeed'); 2579``` 2580 2581### off('setLoopMode')<sup>10+</sup> 2582 2583off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void 2584 2585Unsubscribes from setSpeed command events. 2586 2587**Atomic service API**: This API can be used in atomic services since API version 12. 2588 2589**System capability**: SystemCapability.Multimedia.AVSession.Core 2590 2591**Parameters** 2592 2593| Name | Type | Mandatory| Description | 2594| -------- | ------------------------------------- | ---- | ----- | 2595| type | string | Yes | Event type, which is **'setLoopMode'** in this case.| 2596| 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.| 2597 2598**Error codes** 2599 2600For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2601 2602| ID| Error Message| 2603| -------- | ---------------------------------------- | 2604| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2605| 6600101 | Session service exception. | 2606| 6600102 | The session does not exist. | 2607 2608**Example** 2609 2610```ts 2611currentAVSession.off('setLoopMode'); 2612``` 2613 2614### off('toggleFavorite')<sup>10+</sup> 2615 2616off(type: 'toggleFavorite', callback?: (assetId: string) => void): void 2617 2618Unsubscribes from toggleFavorite command events. 2619 2620**Atomic service API**: This API can be used in atomic services since API version 12. 2621 2622**System capability**: SystemCapability.Multimedia.AVSession.Core 2623 2624**Parameters** 2625 2626| Name | Type | Mandatory| Description | 2627| -------- | ------------------------- | ---- | -------------------------------------------------------- | 2628| type | string | Yes | Event type, which is **'toggleFavorite'** in this case. | 2629| 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. | 2630 2631**Error codes** 2632 2633For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2634 2635| ID| Error Message| 2636| -------- | ---------------------------------------- | 2637| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2638| 6600101 | Session service exception. | 2639| 6600102 | The session does not exist. | 2640 2641**Example** 2642 2643```ts 2644currentAVSession.off('toggleFavorite'); 2645``` 2646 2647### off('skipToQueueItem')<sup>10+</sup> 2648 2649off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void 2650 2651Unsubscribes from the event that indicates an item in the playlist is selected. 2652 2653**Atomic service API**: This API can be used in atomic services since API version 12. 2654 2655**System capability**: SystemCapability.Multimedia.AVSession.Core 2656 2657**Parameters** 2658 2659| Name | Type | Mandatory| Description | 2660| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | 2661| type | string | Yes | Event type, which is **'skipToQueueItem'** in this case. | 2662| 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.| 2663 2664**Error codes** 2665 2666For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2667 2668| ID| Error Message| 2669| -------- | ---------------------------------------- | 2670| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2671| 6600101 | Session service exception. | 2672| 6600102 | The session does not exist. | 2673 2674**Example** 2675 2676```ts 2677currentAVSession.off('skipToQueueItem'); 2678``` 2679 2680### off('handleKeyEvent')<sup>10+</sup> 2681 2682off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void 2683 2684Unsubscribes from key events. 2685 2686**Atomic service API**: This API can be used in atomic services since API version 12. 2687 2688**System capability**: SystemCapability.Multimedia.AVSession.Core 2689 2690**Parameters** 2691 2692| Name | Type | Mandatory| Description | 2693| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2694| type | string | Yes | Event type, which is **'handleKeyEvent'** in this case. | 2695| 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. | 2696 2697**Error codes** 2698 2699For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2700 2701| ID| Error Message| 2702| -------- | ---------------------------------------- | 2703| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2704| 6600101 | Session service exception. | 2705| 6600102 | The session does not exist. | 2706 2707**Example** 2708 2709```ts 2710currentAVSession.off('handleKeyEvent'); 2711``` 2712 2713### off('outputDeviceChange')<sup>10+</sup> 2714 2715off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 2716 2717Unsubscribes from playback device change events. 2718 2719**Atomic service API**: This API can be used in atomic services since API version 12. 2720 2721**System capability**: SystemCapability.Multimedia.AVSession.Core 2722 2723**Parameters** 2724 2725| Name | Type | Mandatory| Description | 2726| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 2727| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | 2728| 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. | 2729 2730**Error codes** 2731 2732For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2733 2734| ID| Error Message| 2735| -------- | ---------------------------------------- | 2736| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2737| 6600101 | Session service exception. | 2738| 6600102 | The session does not exist. | 2739 2740**Example** 2741 2742```ts 2743currentAVSession.off('outputDeviceChange'); 2744``` 2745 2746 2747### off('commonCommand')<sup>10+</sup> 2748 2749off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void 2750 2751Unsubscribes from custom control command change events. 2752 2753**Atomic service API**: This API can be used in atomic services since API version 12. 2754 2755**System capability**: SystemCapability.Multimedia.AVSession.Core 2756 2757**Parameters** 2758 2759| Name | Type | Mandatory| Description | 2760| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 2761| type | string | Yes | Event type, which is **'commonCommand'** in this case. | 2762| 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. | 2763 2764**Error codes** 2765 2766For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2767 2768| ID| Error Message| 2769| -------- | ---------------- | 2770| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2771| 6600101 | Session service exception. | 2772| 6600102 | The session does not exist. | 2773 2774**Example** 2775 2776```ts 2777currentAVSession.off('commonCommand'); 2778``` 2779 2780### on('answer')<sup>11+</sup> 2781 2782on(type: 'answer', callback: Callback\<void>): void; 2783 2784Subscribes to call answer events. 2785 2786**Atomic service API**: This API can be used in atomic services since API version 12. 2787 2788**System capability**: SystemCapability.Multimedia.AVSession.Core 2789 2790**Parameters** 2791 2792| Name | Type | Mandatory| Description | 2793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2794| type | string | Yes | Event type. The event **'answer'** is triggered when a call is answered.| 2795| callback | Callback\<void> | Yes | Callback used to return the result. | 2796 2797**Error codes** 2798 2799For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2800 2801| ID| Error Message| 2802| -------- | ------------------------------ | 2803| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2804| 6600101 | Session service exception. | 2805| 6600102 | The session does not exist. | 2806 2807**Example** 2808 2809```ts 2810currentAVSession.on('answer', () => { 2811 console.info('on call answer'); 2812}); 2813``` 2814 2815### off('answer')<sup>11+</sup> 2816 2817off(type: 'answer', callback?: Callback\<void>): void; 2818 2819Unsubscribes from call answer events. 2820 2821**Atomic service API**: This API can be used in atomic services since API version 12. 2822 2823**System capability**: SystemCapability.Multimedia.AVSession.Core 2824 2825**Parameters** 2826 2827| Name | Type | Mandatory| Description | 2828| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2829| type | string | Yes | Event type, which is **'answer'** in this case.| 2830| 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. | 2831 2832**Error codes** 2833 2834For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2835 2836| ID| Error Message| 2837| -------- | ---------------------------------------- | 2838| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2839| 6600101 | Session service exception. | 2840| 6600102 | The session does not exist. | 2841 2842**Example** 2843 2844```ts 2845currentAVSession.off('answer'); 2846``` 2847 2848### on('hangUp')<sup>11+</sup> 2849 2850on(type: 'hangUp', callback: Callback\<void>): void; 2851 2852Subscribes to call hangup events. 2853 2854**Atomic service API**: This API can be used in atomic services since API version 12. 2855 2856**System capability**: SystemCapability.Multimedia.AVSession.Core 2857 2858**Parameters** 2859 2860| Name | Type | Mandatory| Description | 2861| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2862| type | string | Yes | Event type. The event **'hangUp'** is triggered when a call is hung up.| 2863| callback | Callback\<void> | Yes | Callback used to return the result. | 2864 2865**Error codes** 2866 2867For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2868 2869| ID| Error Message| 2870| -------- | ------------------------------ | 2871| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2872| 6600101 | Session service exception. | 2873| 6600102 | The session does not exist. | 2874 2875**Example** 2876 2877```ts 2878currentAVSession.on('hangUp', () => { 2879 console.info('on call hangUp'); 2880}); 2881``` 2882 2883### off('hangUp')<sup>11+</sup> 2884 2885off(type: 'hangUp', callback?: Callback\<void>): void; 2886 2887Unsubscribes from call answer events. 2888 2889**Atomic service API**: This API can be used in atomic services since API version 12. 2890 2891**System capability**: SystemCapability.Multimedia.AVSession.Core 2892 2893**Parameters** 2894 2895| Name | Type | Mandatory| Description | 2896| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2897| type | string | Yes | Event type, which is **'hangUp'** in this case.| 2898| 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. | 2899 2900**Error codes** 2901 2902For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2903 2904| ID| Error Message| 2905| -------- | ---------------------------------------- | 2906| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2907| 6600101 | Session service exception. | 2908| 6600102 | The session does not exist. | 2909 2910**Example** 2911 2912```ts 2913currentAVSession.off('hangUp'); 2914``` 2915 2916### on('toggleCallMute')<sup>11+</sup> 2917 2918on(type: 'toggleCallMute', callback: Callback\<void>): void; 2919 2920Subscribes to call mute events. 2921 2922**Atomic service API**: This API can be used in atomic services since API version 12. 2923 2924**System capability**: SystemCapability.Multimedia.AVSession.Core 2925 2926**Parameters** 2927 2928| Name | Type | Mandatory| Description | 2929| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 2930| type | string | Yes | Event type. The event **'toggleCallMute'** is triggered when a call is muted or unmuted.| 2931| callback | Callback\<void> | Yes | Callback used to return the result. | 2932 2933**Error codes** 2934 2935For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2936 2937| ID| Error Message| 2938| -------- | ------------------------------ | 2939| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2940| 6600101 | Session service exception. | 2941| 6600102 | The session does not exist. | 2942 2943**Example** 2944 2945```ts 2946currentAVSession.on('toggleCallMute', () => { 2947 console.info('on call toggleCallMute'); 2948}); 2949``` 2950 2951### off('toggleCallMute')<sup>11+</sup> 2952 2953off(type: 'toggleCallMute', callback?: Callback\<void>): void; 2954 2955Unsubscribes from call mute events. 2956 2957**Atomic service API**: This API can be used in atomic services since API version 12. 2958 2959**System capability**: SystemCapability.Multimedia.AVSession.Core 2960 2961**Parameters** 2962 2963| Name | Type | Mandatory| Description | 2964| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2965| type | string | Yes | Event type, which is **'toggleCallMute'** in this case.| 2966| 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. | 2967 2968**Error codes** 2969 2970For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 2971 2972| ID| Error Message| 2973| -------- | ---------------------------------------- | 2974| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 2975| 6600101 | Session service exception. | 2976| 6600102 | The session does not exist. | 2977 2978**Example** 2979 2980```ts 2981currentAVSession.off('toggleCallMute'); 2982``` 2983 2984### on('castDisplayChange')<sup>12+</sup> 2985 2986on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void 2987 2988Subscribes to cast display change events in the case of extended screens. 2989 2990**Atomic service API**: This API can be used in atomic services since API version 12. 2991 2992**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 2993 2994**Parameters** 2995 2996| Name | Type | Mandatory| Description | 2997| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 2998| type | string | Yes | Event type. The event **'castDisplayChange'** is triggered when the cast display in the case of extended screens changes.| 2999| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)> | Yes | Callback used to return the information about the cast display. | 3000 3001**Error codes** 3002 3003For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3004 3005| ID| Error Message| 3006| -------- | ---------------------------------------- | 3007| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3008| 6600101 | Session service exception. | 3009| 6600102 | The session does not exist. | 3010 3011**Example** 3012 3013```ts 3014let castDisplay: avSession.CastDisplayInfo; 3015currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => { 3016 if (display.state === avSession.CastDisplayState.STATE_ON) { 3017 castDisplay = display; 3018 console.info(`Succeeded in castDisplayChange display : ${display.id} ON`); 3019 } else if (display.state === avSession.CastDisplayState.STATE_OFF){ 3020 console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`); 3021 } 3022}); 3023``` 3024### off('castDisplayChange')<sup>12+</sup> 3025 3026 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void 3027 3028Unsubscribes from cast display change events in the case of extended screens. 3029 3030**Atomic service API**: This API can be used in atomic services since API version 12. 3031 3032**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3033 3034**Parameters** 3035 3036| Name | Type | Mandatory| Description | 3037| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- | 3038| type | string | Yes | Event type, which is **'castDisplayChange'** in this case.| 3039| 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. | 3040 3041**Error codes** 3042 3043For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3044 3045| ID| Error Message| 3046| -------- | ---------------------------------------- | 3047| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3048| 6600101 | Session service exception. | 3049| 6600102 | The session does not exist. | 3050 3051**Example** 3052 3053```ts 3054currentAVSession.off('castDisplayChange'); 3055``` 3056 3057### stopCasting<sup>10+</sup> 3058 3059stopCasting(callback: AsyncCallback\<void>): void 3060 3061Stops castings. This API uses an asynchronous callback to return the result. 3062 3063**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3064 3065**Parameters** 3066 3067| Name | Type | Mandatory| Description | 3068| -------- | ------------------------------------- | ---- | ------------------------------------- | 3069| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3070 3071**Error codes** 3072 3073For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3074 3075| ID| Error Message| 3076| -------- | ---------------------------------------- | 3077| 6600109 | The remote connection is not established. | 3078 3079**Example** 3080 3081```ts 3082import { BusinessError } from '@kit.BasicServicesKit'; 3083 3084currentAVSession.stopCasting((err: BusinessError) => { 3085 if (err) { 3086 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3087 } else { 3088 console.info('stopCasting successfully'); 3089 } 3090}); 3091``` 3092 3093### stopCasting<sup>10+</sup> 3094 3095stopCasting(): Promise\<void> 3096 3097Stops castings. This API uses a promise to return the result. 3098 3099**Atomic service API**: This API can be used in atomic services since API version 12. 3100 3101**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3102 3103**Return value** 3104 3105| Type | Description | 3106| -------------- | ----------------------------- | 3107| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.| 3108 3109**Error codes** 3110 3111For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3112 3113| ID| Error Message| 3114| -------- | ---------------------------------------- | 3115| 6600109 | The remote connection is not established. | 3116 3117**Example** 3118 3119```ts 3120import { BusinessError } from '@kit.BasicServicesKit'; 3121 3122currentAVSession.stopCasting().then(() => { 3123 console.info('stopCasting successfully'); 3124}).catch((err: BusinessError) => { 3125 console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); 3126}); 3127``` 3128 3129### getOutputDeviceSync<sup>10+</sup> 3130 3131getOutputDeviceSync(): OutputDeviceInfo 3132 3133Obtains the output device information. This API returns the result synchronously. 3134 3135**Atomic service API**: This API can be used in atomic services since API version 12. 3136 3137**System capability**: SystemCapability.Multimedia.AVSession.Core 3138 3139**Return value** 3140 3141| Type | Description | 3142| ----------------------------------------------- | --------------------------------- | 3143| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.| 3144 3145**Error codes** 3146 3147For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3148 3149| ID | Error Message| 3150|---------| --------------------------------------- | 3151| 6600101 | Session service exception. | 3152| 6600102 | The session does not exist. | 3153 3154**Example** 3155 3156```ts 3157import { BusinessError } from '@kit.BasicServicesKit'; 3158 3159try { 3160 let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync(); 3161} catch (err) { 3162 let error = err as BusinessError; 3163 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 3164} 3165``` 3166### getAllCastDisplays<sup>12+</sup> 3167 3168getAllCastDisplays(): Promise<Array\<CastDisplayInfo>> 3169 3170Obtains all displays that support extended screen projection in the current system. This API uses a promise to return the result. 3171 3172**Atomic service API**: This API can be used in atomic services since API version 12. 3173 3174**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 3175 3176**Return value** 3177 3178| Type | Description | 3179| ----------------------------------------------- | --------------------------------- | 3180| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise used to return the information about all the cast displays.| 3181 3182**Error codes** 3183 3184For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3185 3186| ID | Error Message| 3187|---------| --------------------------------------- | 3188| 6600101 | Session service exception. | 3189| 6600102 | The session does not exist. | 3190 3191**Example** 3192 3193```ts 3194import { BusinessError } from '@kit.BasicServicesKit'; 3195 3196let castDisplay: avSession.CastDisplayInfo; 3197currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => { 3198 if (data.length >= 1) { 3199 castDisplay = data[0]; 3200 } 3201 }).catch((err: BusinessError) => { 3202 console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`); 3203 }); 3204``` 3205 3206## AVCastControlCommandType<sup>10+</sup> 3207 3208type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 3209 'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute' 3210 3211Enumerates the commands that can be sent by a cast controller. 3212 3213**Atomic service API**: This API can be used in atomic services since API version 12. 3214 3215**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3216 3217| Type | Description | 3218| ---------------- | ------------ | 3219| 'play' | Play the media. | 3220| 'pause' | Pause the playback. | 3221| 'stop' | Stop the playback. | 3222| 'playNext' | Play the next media asset. | 3223| 'playPrevious' | Play the previous media asset. | 3224| 'fastForward' | Fast-forward. | 3225| 'rewind' | Rewind. | 3226| 'seek' | Seek to a playback position.| 3227| 'setVolume' | Set the volume. | 3228| 'setSpeed' | Set the playback speed.| 3229| 'setLoopMode' | Set the loop mode.| 3230| 'toggleFavorite' | Favorite the media asset. | 3231| 'toggleMute' | Set the muted status.| 3232 3233## AVCastControlCommand<sup>10+</sup> 3234 3235Defines the command that can be sent by a cast controller. 3236 3237**Atomic service API**: This API can be used in atomic services since API version 12. 3238 3239**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3240 3241| Name | Type | Mandatory| Description | 3242| --------- | ------------------------------------------------- | ---- | -------------- | 3243| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | Yes | Command. | 3244| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) | number | string | [LoopMode](#loopmode10) | No | Parameters carried in the command.| 3245 3246## AVCastController<sup>10+</sup> 3247 3248After 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. 3249 3250### getAVPlaybackState<sup>10+</sup> 3251 3252getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 3253 3254Obtains the remote playback state. This API uses an asynchronous callback to return the result. 3255 3256**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3257 3258**Parameters** 3259 3260| Name | Type | Mandatory| Description | 3261| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 3262| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| 3263 3264**Error codes** 3265 3266For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3267 3268| ID| Error Message| 3269| -------- | ---------------------------------------- | 3270| 6600101 | Session service exception | 3271 3272**Example** 3273 3274```ts 3275import { BusinessError } from '@kit.BasicServicesKit'; 3276 3277aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 3278 if (err) { 3279 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3280 } else { 3281 console.info('getAVPlaybackState : SUCCESS'); 3282 } 3283}); 3284``` 3285 3286### getAVPlaybackState<sup>10+</sup> 3287 3288getAVPlaybackState(): Promise\<AVPlaybackState> 3289 3290Obtains the remote playback state. This API uses a promise to return the result. 3291 3292**Atomic service API**: This API can be used in atomic services since API version 12. 3293 3294**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3295 3296**Return value** 3297 3298| Type | Description | 3299| --------- | ------------------------------------------------------------ | 3300| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state.| 3301 3302**Error codes** 3303 3304For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3305 3306| ID| Error Message| 3307| -------- | ---------------------------------------- | 3308| 6600101 | Session service exception | 3309 3310**Example** 3311 3312```ts 3313import { BusinessError } from '@kit.BasicServicesKit'; 3314 3315aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 3316 console.info('getAVPlaybackState : SUCCESS'); 3317}).catch((err: BusinessError) => { 3318 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 3319}); 3320``` 3321 3322### sendControlCommand<sup>10+</sup> 3323 3324sendControlCommand(command: AVCastControlCommand): Promise\<void> 3325 3326Sends a control command to the session through the controller. This API uses a promise to return the result. 3327 3328 3329**Atomic service API**: This API can be used in atomic services since API version 12. 3330 3331**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3332 3333**Parameters** 3334 3335| Name | Type | Mandatory| Description | 3336| ------- | ------------------------------------- | ---- | ------------------------------ | 3337| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| 3338 3339**Return value** 3340 3341| Type | Description | 3342| -------------- | ----------------------------- | 3343| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 3344 3345**Error codes** 3346 3347For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3348 3349| ID| Error Message| 3350| -------- | ---------------------------------------- | 3351| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3352| 6600101 | Session service exception. | 3353| 6600105 | Invalid session command. | 3354| 6600109 | The remote connection is not established. | 3355 3356**Example** 3357 3358```ts 3359import { BusinessError } from '@kit.BasicServicesKit'; 3360 3361let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3362aVCastController.sendControlCommand(avCommand).then(() => { 3363 console.info('SendControlCommand successfully'); 3364}).catch((err: BusinessError) => { 3365 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3366}); 3367``` 3368 3369### sendControlCommand<sup>10+</sup> 3370 3371sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void 3372 3373Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result. 3374 3375 3376**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3377 3378**Parameters** 3379 3380| Name | Type | Mandatory| Description | 3381| -------- | ------------------------------------- | ---- | ------------------------------ | 3382| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes | Command to send.| 3383| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 3384 3385**Error codes** 3386 3387For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3388 3389| ID| Error Message| 3390| -------- | ------------------------------- | 3391| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3392| 6600101 | Session service exception. | 3393| 6600105 | Invalid session command. | 3394| 6600109 | The remote connection is not established. | 3395 3396**Example** 3397 3398```ts 3399import { BusinessError } from '@kit.BasicServicesKit'; 3400 3401let avCommand: avSession.AVCastControlCommand = {command:'play'}; 3402aVCastController.sendControlCommand(avCommand, (err: BusinessError) => { 3403 if (err) { 3404 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 3405 } else { 3406 console.info('SendControlCommand successfully'); 3407 } 3408}); 3409``` 3410 3411### prepare<sup>10+</sup> 3412 3413prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void 3414 3415Prepares 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. 3416 3417**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3418 3419**Parameters** 3420 3421| Name | Type | Mandatory| Description | 3422| ------- | ------------------------------------- | ---- | ------------------------------ | 3423| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| 3424| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3425 3426**Error codes** 3427 3428For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3429 3430| ID| Error Message| 3431| -------- | ---------------------------------------- | 3432| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3433| 6600101 | Session service exception. | 3434| 6600109 | The remote connection is not established. | 3435 3436**Example** 3437 3438```ts 3439import { BusinessError } from '@kit.BasicServicesKit'; 3440 3441// Set playback parameters. 3442let playItem: avSession.AVQueueItem = { 3443 itemId: 0, 3444 description: { 3445 assetId: '12345', 3446 mediaType: 'AUDIO', 3447 mediaUri: 'http://resource1_address', 3448 mediaSize: 12345, 3449 startPosition: 0, 3450 duration: 0, 3451 artist: 'mysong', 3452 albumTitle: 'song1_title', 3453 albumCoverUri: "http://resource1_album_address", 3454 lyricUri: "http://resource1_lyric_address", 3455 appName: 'MyMusic' 3456 } 3457}; 3458// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. 3459aVCastController.prepare(playItem, (err: BusinessError) => { 3460 if (err) { 3461 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3462 } else { 3463 console.info('prepare successfully'); 3464 } 3465}); 3466``` 3467 3468 3469### prepare<sup>10+</sup> 3470 3471prepare(item: AVQueueItem): Promise\<void> 3472 3473Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result. 3474 3475 3476**Atomic service API**: This API can be used in atomic services since API version 12. 3477 3478**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3479 3480**Parameters** 3481 3482| Name | Type | Mandatory| Description | 3483| ------- | ------------------------------------- | ---- | ------------------------------ | 3484| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| 3485 3486**Return value** 3487 3488| Type | Description | 3489| -------------- | ----------------------------- | 3490| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 3491 3492**Error codes** 3493 3494For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3495 3496| ID| Error Message| 3497| -------- | ---------------------------------------- | 3498| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3499| 6600101 | Session service exception. | 3500| 6600109 | The remote connection is not established. | 3501 3502 3503**Example** 3504 3505```ts 3506import { BusinessError } from '@kit.BasicServicesKit'; 3507 3508// Set playback parameters. 3509let playItem: avSession.AVQueueItem = { 3510 itemId: 0, 3511 description: { 3512 assetId: '12345', 3513 mediaType: 'AUDIO', 3514 mediaUri: 'http://resource1_address', 3515 mediaSize: 12345, 3516 startPosition: 0, 3517 duration: 0, 3518 artist: 'mysong', 3519 albumTitle: 'song1_title', 3520 albumCoverUri: "http://resource1_album_address", 3521 lyricUri: "http://resource1_lyric_address", 3522 appName: 'MyMusic' 3523 } 3524}; 3525// Prepare for playback. This operation triggers loading and buffering, but not the actual playback. 3526aVCastController.prepare(playItem).then(() => { 3527 console.info('prepare successfully'); 3528}).catch((err: BusinessError) => { 3529 console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`); 3530}); 3531``` 3532 3533### start<sup>10+</sup> 3534 3535start(item: AVQueueItem, callback: AsyncCallback\<void>): void 3536 3537Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result. 3538 3539**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3540 3541**Parameters** 3542 3543| Name | Type | Mandatory| Description | 3544| ------- | ------------------------------------- | ---- | ------------------------------ | 3545| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| 3546| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.| 3547 3548**Error codes** 3549 3550For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3551 3552| ID| Error Message| 3553| -------- | ---------------------------------------- | 3554| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3555| 6600101 | Session service exception. | 3556| 6600109 | The remote connection is not established. | 3557 3558**Example** 3559 3560```ts 3561import { BusinessError } from '@kit.BasicServicesKit'; 3562 3563// Set playback parameters. 3564let playItem: avSession.AVQueueItem = { 3565 itemId: 0, 3566 description: { 3567 assetId: '12345', 3568 mediaType: 'AUDIO', 3569 mediaUri: 'http://resource1_address', 3570 mediaSize: 12345, 3571 startPosition: 0, 3572 duration: 0, 3573 artist: 'mysong', 3574 albumTitle: 'song1_title', 3575 albumCoverUri: "http://resource1_album_address", 3576 lyricUri: "http://resource1_lyric_address", 3577 appName: 'MyMusic' 3578 } 3579}; 3580 3581// Start playback. 3582aVCastController.start(playItem, (err: BusinessError) => { 3583 if (err) { 3584 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 3585 } else { 3586 console.info('start successfully'); 3587 } 3588}); 3589``` 3590 3591### start<sup>10+</sup> 3592 3593start(item: AVQueueItem): Promise\<void> 3594 3595Prepares for the playback of a media asset. This API uses a promise to return the result. 3596 3597 3598**Atomic service API**: This API can be used in atomic services since API version 12. 3599 3600**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3601 3602**Parameters** 3603 3604| Name | Type | Mandatory| Description | 3605| ------- | ------------------------------------- | ---- | ------------------------------ | 3606| item | [AVQueueItem](#avqueueitem10) | Yes | Attributes of an item in the playlist.| 3607 3608**Return value** 3609 3610| Type | Description | 3611| -------------- | ----------------------------- | 3612| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 3613 3614**Error codes** 3615 3616For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3617 3618| ID| Error Message| 3619| -------- | ---------------------------------------- | 3620| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3621| 6600101 | Session service exception. | 3622| 6600109 | The remote connection is not established. | 3623 3624 3625**Example** 3626 3627```ts 3628import { BusinessError } from '@kit.BasicServicesKit'; 3629 3630// Set playback parameters. 3631let playItem: avSession.AVQueueItem = { 3632 itemId: 0, 3633 description: { 3634 assetId: '12345', 3635 mediaType: 'AUDIO', 3636 mediaUri: 'http://resource1_address', 3637 mediaSize: 12345, 3638 startPosition: 0, 3639 duration: 0, 3640 artist: 'mysong', 3641 albumTitle: 'song1_title', 3642 albumCoverUri: "http://resource1_album_address", 3643 lyricUri: "http://resource1_lyric_address", 3644 appName: 'MyMusic' 3645 } 3646}; 3647// Start playback. 3648aVCastController.start(playItem).then(() => { 3649 console.info('start successfully'); 3650}).catch((err: BusinessError) => { 3651 console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`); 3652}); 3653``` 3654 3655### getCurrentItem<sup>10+</sup> 3656 3657getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void 3658 3659Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result. 3660 3661**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3662 3663**Parameters** 3664 3665| Name | Type | Mandatory| Description | 3666| -------- | ------------------------------------- | ---- | ------------------------------------- | 3667| 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.| 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. | 3676 3677**Example** 3678 3679```ts 3680import { BusinessError } from '@kit.BasicServicesKit'; 3681 3682aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => { 3683 if (err) { 3684 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 3685 } else { 3686 console.info('getCurrentItem successfully'); 3687 } 3688}); 3689``` 3690 3691### getCurrentItem<sup>10+</sup> 3692 3693getCurrentItem(): Promise\<AVQueueItem> 3694 3695Obtains the information about the media asset that is being played. 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 12. 3698 3699**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3700 3701**Return value** 3702 3703| Type | Description | 3704| -------------- | ----------------------------- | 3705| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.| 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. | 3714 3715**Example** 3716 3717```ts 3718import { BusinessError } from '@kit.BasicServicesKit'; 3719 3720aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => { 3721 console.info('getCurrentItem successfully'); 3722}).catch((err: BusinessError) => { 3723 console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); 3724}); 3725``` 3726 3727### getValidCommands<sup>11+</sup> 3728 3729getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void 3730 3731Obtains the supported commands. This API uses an asynchronous callback to return the result. 3732 3733**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3734 3735**Parameters** 3736 3737| Name| Type| Mandatory| Description| 3738| -------- | ------------------------------------- | ---- | ------------------------------------- | 3739| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | Yes| Callback return the supported commands.| 3740 3741**Error codes** 3742 3743For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3744 3745| ID| Error Message| 3746| -------- | ---------------------------------------- | 3747| 6600101 | Session service exception. | 3748 3749**Example** 3750 3751```ts 3752import { BusinessError } from '@kit.BasicServicesKit'; 3753 3754aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => { 3755 if (err) { 3756 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 3757 } else { 3758 console.info('getValidCommands successfully'); 3759 } 3760}); 3761``` 3762 3763### getValidCommands<sup>11+</sup> 3764 3765getValidCommands(): Promise<Array\<AVCastControlCommandType>> 3766 3767Obtains the supported commands. This API uses a promise to return the result. 3768 3769**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3770 3771**Return value** 3772 3773| Type| Description| 3774| -------------- | ----------------------------- | 3775| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise used to return the supported commands.| 3776 3777**Error codes** 3778 3779For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3780 3781| ID| Error Message| 3782| -------- | ---------------------------------------- | 3783| 6600101 | Session service exception. | 3784 3785**Example** 3786 3787```ts 3788import { BusinessError } from '@kit.BasicServicesKit'; 3789 3790aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => { 3791 console.info('getValidCommands successfully'); 3792}).catch((err: BusinessError) => { 3793 console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 3794}); 3795``` 3796 3797### processMediaKeyResponse<sup>12+</sup> 3798 3799processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void> 3800 3801Processes the response to a media key request during online DRM resource projection. This API uses a promise to return the result. 3802 3803**Atomic service API**: This API can be used in atomic services since API version 12. 3804 3805**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3806 3807**Parameters** 3808 3809| Name | Type | Mandatory| Description | 3810| -------- | ------------------------------------- | ---- | ------------------------------------- | 3811| assetId | string | Yes | Media asset ID.| 3812| response | Uint8Array | Yes | Response to the media key request.| 3813 3814**Return value** 3815 3816| Type | Description | 3817| -------------- | ----------------------------- | 3818| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned.| 3819 3820**Error codes** 3821 3822For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3823 3824| ID| Error Message| 3825| -------- | ---------------------------------------- | 3826| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 3827| 6600101 | Session service exception. | 3828 3829**Example** 3830 3831```ts 3832let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 3833 // Obtain the DRM URL based on the asset ID. 3834 let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense'; 3835 // Obtain a media key from the server. Assign a value based on service requirements. 3836 let licenseResponseData: Uint8Array = new Uint8Array(); 3837 console.info(`Succeeded in get license by ${drmUrl}.`); 3838 aVCastController.processMediaKeyResponse(assetId, licenseResponseData); 3839} 3840``` 3841 3842### release<sup>11+</sup> 3843 3844release(callback: AsyncCallback\<void>): void 3845 3846Releases this cast controller. This API uses an asynchronous callback to return the result. 3847 3848**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3849 3850**Parameters** 3851 3852| Name | Type | Mandatory| Description | 3853| -------- | -------------------------- | ---- | ------------------------------------------------------------ | 3854| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object.| 3855 3856**Error codes** 3857 3858For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3859 3860| ID| Error Message| 3861| -------- | -------------------------- | 3862| 6600101 | Session service exception. | 3863 3864**Example** 3865 3866```ts 3867import { BusinessError } from '@kit.BasicServicesKit'; 3868 3869aVCastController.release((err: BusinessError) => { 3870 if (err) { 3871 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 3872 } else { 3873 console.info('release successfully'); 3874 } 3875}); 3876``` 3877 3878### release<sup>11+</sup> 3879 3880release(): Promise\<void> 3881 3882Releases this cast controller. This API uses a promise to return the result. 3883 3884**Atomic service API**: This API can be used in atomic services since API version 12. 3885 3886**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3887 3888**Return value** 3889 3890| Type | Description | 3891| -------------- | ----------------------------- | 3892| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned.| 3893 3894**Error codes** 3895 3896For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3897 3898| ID| Error Message| 3899| -------- | ------------------------------ | 3900| 6600101 | Session service exception. | 3901 3902**Example** 3903 3904```ts 3905import { BusinessError } from '@kit.BasicServicesKit'; 3906 3907aVCastController.release().then(() => { 3908 console.info('release successfully'); 3909}).catch((err: BusinessError) => { 3910 console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`); 3911}); 3912 3913``` 3914 3915### on('playbackStateChange')<sup>10+</sup> 3916 3917on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void 3918 3919Subscribes to playback state change events. 3920 3921**Atomic service API**: This API can be used in atomic services since API version 12. 3922 3923**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3924 3925**Parameters** 3926 3927| Name | Type | Mandatory| Description | 3928| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 3929| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| 3930| 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.| 3931| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state. | 3932 3933**Error codes** 3934 3935For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3936 3937| ID| Error Message| 3938| -------- | ------------------------------ | 3939| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3940| 6600101 | Session service exception. | 3941 3942**Example** 3943 3944```ts 3945aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 3946 console.info(`on playbackStateChange state : ${playbackState.state}`); 3947}); 3948 3949let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode']; 3950aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => { 3951 console.info(`on playbackStateChange state : ${playbackState.state}`); 3952}); 3953``` 3954 3955### off('playbackStateChange')<sup>10+</sup> 3956 3957off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void 3958 3959Unsubscribes from playback state change events. This API is called by the controller. 3960 3961**Atomic service API**: This API can be used in atomic services since API version 12. 3962 3963**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3964 3965**Parameters** 3966 3967| Name | Type | Mandatory| Description | 3968| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 3969| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | 3970| 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. | 3971 3972**Error codes** 3973 3974For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 3975 3976| ID| Error Message| 3977| -------- | ---------------- | 3978| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 3979| 6600101 | Session service exception. | 3980 3981**Example** 3982 3983```ts 3984aVCastController.off('playbackStateChange'); 3985``` 3986 3987### on('mediaItemChange')<sup>10+</sup> 3988 3989on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void 3990 3991Subscribes to media asset change events. 3992 3993**Atomic service API**: This API can be used in atomic services since API version 12. 3994 3995**System capability**: SystemCapability.Multimedia.AVSession.AVCast 3996 3997**Parameters** 3998 3999| Name | Type | Mandatory| Description | 4000| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4001| type | string | Yes | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.| 4002| callback | (callback: [AVQueueItem](#avqueueitem10)) => void | Yes | Callback used for subscription. **AVQueueItem** is the media asset that is being played. | 4003 4004**Error codes** 4005 4006For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4007 4008| ID| Error Message| 4009| -------- | ------------------------------ | 4010| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4011| 6600101 | Session service exception. | 4012 4013**Example** 4014 4015```ts 4016aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => { 4017 console.info(`on mediaItemChange state : ${item.itemId}`); 4018}); 4019``` 4020 4021### off('mediaItemChange')<sup>10+</sup> 4022 4023off(type: 'mediaItemChange'): void 4024 4025Unsubscribes from media asset change events. 4026 4027**Atomic service API**: This API can be used in atomic services since API version 12. 4028 4029**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4030 4031**Parameters** 4032 4033| Name | Type | Mandatory| Description | 4034| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4035| type | string | Yes | Event type, which is **'mediaItemChange'** in this case. | 4036 4037**Error codes** 4038 4039For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4040 4041| ID| Error Message| 4042| -------- | ---------------- | 4043| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4044| 6600101 | Session service exception. | 4045 4046**Example** 4047 4048```ts 4049aVCastController.off('mediaItemChange'); 4050``` 4051 4052### on('playNext')<sup>10+</sup> 4053 4054on(type: 'playNext', callback: Callback\<void>): void 4055 4056Subscribes to playNext command events. 4057 4058**Atomic service API**: This API can be used in atomic services since API version 12. 4059 4060**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4061 4062**Parameters** 4063 4064| Name | Type | Mandatory| Description | 4065| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4066| type | string | Yes | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.| 4067| callback | Callback\<void\> | Yes | Callback used to return the result. | 4068 4069**Error codes** 4070 4071For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4072 4073| ID| Error Message| 4074| -------- | ------------------------------ | 4075| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4076| 6600101 | Session service exception. | 4077 4078**Example** 4079 4080```ts 4081aVCastController.on('playNext', () => { 4082 console.info('on playNext'); 4083}); 4084``` 4085 4086### off('playNext')<sup>10+</sup> 4087 4088off(type: 'playNext'): void 4089 4090Unsubscribes from playNext command events. 4091 4092**Atomic service API**: This API can be used in atomic services since API version 12. 4093 4094**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4095 4096**Parameters** 4097 4098| Name | Type | Mandatory| Description | 4099| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4100| type | string | Yes | Event type, which is **'playNext'** in this case. | 4101 4102**Error codes** 4103 4104For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4105 4106| ID| Error Message| 4107| -------- | ---------------- | 4108| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4109| 6600101 | Session service exception. | 4110 4111**Example** 4112 4113```ts 4114aVCastController.off('playNext'); 4115``` 4116 4117### on('playPrevious')<sup>10+</sup> 4118 4119on(type: 'playPrevious', callback: Callback\<void>): void 4120 4121Subscribes to playPrevious command events. 4122 4123**Atomic service API**: This API can be used in atomic services since API version 12. 4124 4125**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4126 4127**Parameters** 4128 4129| Name | Type | Mandatory| Description | 4130| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4131| type | string | Yes | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.| 4132| callback | Callback\<void\> | Yes | Callback used to return the result. | 4133 4134**Error codes** 4135 4136For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4137 4138| ID| Error Message| 4139| -------- | ------------------------------ | 4140| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4141| 6600101 | Session service exception. | 4142 4143**Example** 4144 4145```ts 4146aVCastController.on('playPrevious', () => { 4147 console.info('on playPrevious'); 4148}); 4149``` 4150 4151### off('playPrevious')<sup>10+</sup> 4152 4153off(type: 'playPrevious'): void 4154 4155Unsubscribes from playPrevious command events. 4156 4157**Atomic service API**: This API can be used in atomic services since API version 12. 4158 4159**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4160 4161**Parameters** 4162 4163| Name | Type | Mandatory| Description | 4164| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4165| type | string | Yes | Event type, which is **'playPrevious'** in this case. | 4166 4167**Error codes** 4168 4169For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4170 4171| ID| Error Message| 4172| -------- | ---------------- | 4173| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4174| 6600101 | Session service exception. | 4175 4176**Example** 4177 4178```ts 4179aVCastController.off('playPrevious'); 4180``` 4181 4182### on('requestPlay')<sup>11+</sup> 4183 4184on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void 4185 4186Subscribes to playback request events. 4187 4188**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4189 4190**Parameters** 4191 4192| Name | Type | Mandatory| Description | 4193| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4194| type | string | Yes | Event type. The event **'requestPlay'** is triggered when a playback request is received.| 4195| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 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. | 4196 4197**Error codes** 4198 4199For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4200 4201| ID| Error Message| 4202| -------- | ------------------------------ | 4203| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4204| 6600101 | Session service exception. | 4205 4206**Example** 4207 4208```ts 4209aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => { 4210 console.info(`on requestPlay state : ${item.itemId}`); 4211}); 4212``` 4213 4214### off('requestPlay')<sup>11+</sup> 4215 4216off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void 4217 4218Unsubscribes from playback request events. 4219 4220**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4221 4222**Parameters** 4223 4224| Name | Type | Mandatory| Description | 4225| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4226| type | string | Yes | Event type, which is **'requestPlay'** in this case. | 4227| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 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.| 4228 4229**Error codes** 4230 4231For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4232 4233| ID| Error Message| 4234| -------- | ---------------- | 4235| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4236| 6600101 | Session service exception. | 4237 4238**Example** 4239 4240```ts 4241aVCastController.off('requestPlay'); 4242``` 4243 4244### on('endOfStream')<sup>11+</sup> 4245 4246on(type: 'endOfStream', callback: Callback\<void>): void 4247 4248Subscribes to playback end events. 4249 4250**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4251 4252**Parameters** 4253 4254| Name | Type | Mandatory| Description | 4255| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ | 4256| type | string | Yes | Event type. The event **'endOfStream'** is triggered when the playback operation is complete.| 4257| callback | Callback\<void\> | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 4258 4259**Error codes** 4260 4261For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4262 4263| ID| Error Message| 4264| -------- | ------------------------------ | 4265| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4266| 6600101 | Session service exception. | 4267 4268**Example** 4269 4270```ts 4271aVCastController.on('endOfStream', () => { 4272 console.info('on endOfStream'); 4273}); 4274``` 4275 4276### off('endOfStream')<sup>11+</sup> 4277 4278off(type: 'endOfStream', callback?: Callback\<void>): void 4279 4280Unsubscribes from the playback end events. 4281 4282**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4283 4284**Parameters** 4285 4286| Name | Type | Mandatory| Description | 4287| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- | 4288| type | string | Yes | Event type, which is **'endOfStream'** in this case. | 4289| 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. | 4290 4291**Error codes** 4292 4293For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4294 4295| ID| Error Message| 4296| -------- | ---------------- | 4297| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4298| 6600101 | Session service exception. | 4299 4300**Example** 4301 4302```ts 4303aVCastController.off('endOfStream'); 4304``` 4305 4306### on('seekDone')<sup>10+</sup> 4307 4308on(type: 'seekDone', callback: Callback\<number>): void 4309 4310Subscribes to seek done events. 4311 4312**Atomic service API**: This API can be used in atomic services since API version 12. 4313 4314**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4315 4316**Parameters** 4317 4318| Name | Type | Mandatory| Description | 4319| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4320| type | string | Yes | Event type. The event **'seekDone'** is triggered when the seek operation is complete.| 4321| callback | Callback\<number\> | Yes | Callback used to return the position after the seek operation. | 4322 4323**Error codes** 4324 4325For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4326 4327| ID| Error Message| 4328| -------- | ------------------------------ | 4329| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4330| 6600101 | Session service exception. | 4331 4332**Example** 4333 4334```ts 4335aVCastController.on('seekDone', (pos: number) => { 4336 console.info(`on seekDone pos: ${pos} `); 4337}); 4338``` 4339 4340### off('seekDone')<sup>10+</sup> 4341 4342off(type: 'seekDone'): void 4343 4344Unsubscribes from the seek done events. 4345 4346**Atomic service API**: This API can be used in atomic services since API version 12. 4347 4348**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4349 4350**Parameters** 4351 4352| Name | Type | Mandatory| Description | 4353| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 4354| type | string | Yes | Event type, which is **'seekDone'** in this case. | 4355 4356**Error codes** 4357 4358For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4359 4360| ID| Error Message| 4361| -------- | ---------------- | 4362| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4363| 6600101 | Session service exception. | 4364 4365**Example** 4366 4367```ts 4368aVCastController.off('seekDone'); 4369``` 4370 4371### on('validCommandChange')<sup>11+</sup> 4372 4373on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>) 4374 4375Subscribes to valid command change events. 4376 4377**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4378 4379**Parameters** 4380 4381| Name | Type | Mandatory| Description | 4382| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 4383| type | string | Yes | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.| 4384| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | 4385 4386**Error codes** 4387 4388For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4389 4390| ID| Error Message| 4391| -------- | ------------------------------ | 4392| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4393| 6600101 | Session service exception. | 4394| 6600103 | The session controller does not exist. | 4395 4396**Example** 4397 4398```ts 4399aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => { 4400 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 4401 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 4402}); 4403``` 4404 4405### off('validCommandChange')<sup>11+</sup> 4406 4407off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>) 4408 4409Unsubscribes from valid command change events. This API is called by the controller. 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 **'validCommandChange'** in this case. | 4418| 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. | 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. | 4428| 6600103 | The session controller does not exist. | 4429 4430**Example** 4431 4432```ts 4433aVCastController.off('validCommandChange'); 4434``` 4435 4436### on('error')<sup>10+</sup> 4437 4438on(type: 'error', callback: ErrorCallback): void 4439 4440Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control. 4441 4442**Atomic service API**: This API can be used in atomic services since API version 12. 4443 4444**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4445 4446**Parameters** 4447 4448| Name | Type | Mandatory| Description | 4449| -------- | -------- | ---- | ------------------------------------------------------------ | 4450| type | string | Yes | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.| 4451| callback | ErrorCallback | Yes | Callback used to return the error code ID and error message.| 4452 4453**Error codes** 4454 4455For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 4456 4457| ID| Error Message | 4458| -------- | --------------------- | 4459| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4460| 5400101 | No memory. | 4461| 5400102 | Operation not allowed. | 4462| 5400103 | I/O error. | 4463| 5400104 | Time out. | 4464| 5400105 | Service died. | 4465| 5400106 | Unsupport format. | 4466| 6600101 | Session service exception. | 4467 4468**Example** 4469 4470```ts 4471import { BusinessError } from '@kit.BasicServicesKit'; 4472 4473aVCastController.on('error', (error: BusinessError) => { 4474 console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`) 4475}) 4476``` 4477 4478### off('error')<sup>10+</sup> 4479 4480off(type: 'error'): void 4481 4482Unsubscribes from remote AVPlayer errors. 4483 4484**Atomic service API**: This API can be used in atomic services since API version 12. 4485 4486**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4487 4488**Parameters** 4489 4490| Name| Type | Mandatory| Description | 4491| ------ | ------ | ---- | ----------------------------------------- | 4492| type | string | Yes | Event type, which is **'error'** in this case.| 4493 4494**Error codes** 4495 4496For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 4497 4498| ID| Error Message | 4499| -------- | --------------------- | 4500| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4501| 5400101 | No memory. | 4502| 5400102 | Operation not allowed. | 4503| 5400103 | I/O error. | 4504| 5400104 | Time out. | 4505| 5400105 | Service died. | 4506| 5400106 | Unsupport format. | 4507| 6600101 | Session service exception. | 4508 4509**Example** 4510 4511```ts 4512aVCastController.off('error') 4513``` 4514 4515### on('keyRequest')<sup>12+</sup> 4516 4517on(type: 'keyRequest', callback: KeyRequestCallback): void 4518 4519Subscribes to media key requests during the cast of online DRM resources. 4520 4521**Atomic service API**: This API can be used in atomic services since API version 12. 4522 4523**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4524 4525**Parameters** 4526 4527| Name| Type | Mandatory| Description | 4528| ------ | ------ | ---- | ----------------------------------------- | 4529| type | string | Yes | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources.| 4530| callback | [KeyRequestCallback](#keyrequestcallback12) | Yes | Callback used to request the media resources and media key.| 4531 4532 4533**Error codes** 4534 4535For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4536 4537| ID| Error Message | 4538| -------- | ---------------- | 4539| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4540| 6600101 | Session service exception. | 4541 4542**Example** 4543 4544```ts 4545let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 4546 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 4547} 4548aVCastController.on('keyRequest', keyRequestCallback); 4549``` 4550### off('keyRequest')<sup>12+</sup> 4551 4552off(type: 'keyRequest', callback?: KeyRequestCallback): void 4553 4554Unsubscribes from media key requests during the cast of online DRM resources. 4555 4556**Atomic service API**: This API can be used in atomic services since API version 12. 4557 4558**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4559 4560**Parameters** 4561 4562| Name| Type | Mandatory| Description | 4563| ------ | ------ | ---- | ----------------------------------------- | 4564| type | string | Yes | Event type, which is **'keyRequest'** in this case.| 4565| 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. | 4566 4567**Error codes** 4568 4569For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 4570 4571| ID| Error Message | 4572| -------- | ---------------- | 4573| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 4574| 6600101 | Session service exception. | 4575 4576**Example** 4577 4578```ts 4579aVCastController.off('keyRequest'); 4580``` 4581 4582### on('castControlGenericError')<sup>13+</sup> 4583 4584on(type: 'castControlGenericError', callback: ErrorCallback): void 4585 4586Subscribes to generic error events during cast control. 4587 4588**Atomic service API**: This API can be used in atomic services since API version 13. 4589 4590**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4591 4592**Parameters** 4593 4594| Name | Type | Mandatory| Description | 4595| -------- | -------- | ---- | ------------------------------------------------------------ | 4596| type | string | Yes | Event type, which is **'castControlGenericError'** in this case.| 4597| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4598 4599**Error codes** 4600 4601| ID| Error Message | 4602| -------- | --------------------- | 4603| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4604| 6611000 | The error code for cast control is unspecified. | 4605| 6611001 | An unspecified error occurs in the remote player. | 4606| 6611002 | The playback position falls behind the live window. | 4607| 6611003 | The process of cast control times out. | 4608| 6611004 | The runtime check failed. | 4609| 6611100 | Cross-device data transmission is locked. | 4610| 6611101 | The specified seek mode is not supported. | 4611| 6611102 | The position to seek to is out of the range of the media asset or the specified seek mode is not supported. | 4612| 6611103 | The specified playback mode is not supported. | 4613| 6611104 | The specified playback speed is not supported. | 4614| 6611105 | The action failed because either the media source device or the media sink device has been revoked. | 4615| 6611106 | The parameter is invalid, for example, the url is illegal to play. | 4616| 6611107 | Allocation of memory failed. | 4617| 6611108 | Operation is not allowed. | 4618 4619**Example** 4620 4621```ts 4622aVCastController.on('castControlGenericError', (error: BusinessError) => { 4623 console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`) 4624}) 4625``` 4626 4627### off('castControlGenericError')<sup>13+</sup> 4628 4629off(type: 'castControlGenericError', callback?: ErrorCallback): void 4630 4631Unsubscribes from generic error events during cast control. 4632 4633**Atomic service API**: This API can be used in atomic services since API version 13. 4634 4635**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4636 4637**Parameters** 4638 4639| Name | Type | Mandatory| Description | 4640| -------- | -------- | ---- | ------------------------------------------------------------ | 4641| type | string | Yes | Event type, which is **'castControlGenericError'** in this case.| 4642| 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.| 4643 4644**Error codes** 4645 4646| ID| Error Message | 4647| -------- | --------------------- | 4648| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4649 4650**Example** 4651 4652```ts 4653aVCastController.off('castControlGenericError'); 4654``` 4655 4656### on('castControlIoError')<sup>13+</sup> 4657 4658on(type: 'castControlIoError', callback: ErrorCallback): void 4659 4660Subscribes to input/output error events during cast control. 4661 4662**Atomic service API**: This API can be used in atomic services since API version 13. 4663 4664**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4665 4666**Parameters** 4667 4668| Name | Type | Mandatory| Description | 4669| -------- | -------- | ---- | ------------------------------------------------------------ | 4670| type | string | Yes | Event type, which is **'castControlIoError'** in this case.| 4671| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4672 4673**Error codes** 4674 4675| ID| Error Message | 4676| -------- | --------------------- | 4677| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4678| 6612000 | An unspecified input/output error occurs. | 4679| 6612001 | Network connection failure. | 4680| 6612002 | Network timeout. | 4681| 6612003 | Invalid "Content-Type" HTTP header. | 4682| 6612004 | The HTTP server returns an unexpected HTTP response status code. | 4683| 6612005 | The file does not exist. | 4684| 6612006 | No permission is granted to perform the IO operation. | 4685| 6612007 | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. | 4686| 6612008 | Reading data out of the data bound. | 4687| 6612100 | The media does not contain any contents that can be played. | 4688| 6612101 | The media cannot be read, for example, because of dust or scratches. | 4689| 6612102 | This resource is already in use. | 4690| 6612103 | The content using the validity interval has expired. | 4691| 6612104 | Using the requested content to play is not allowed. | 4692| 6612105 | The use of the allowed content cannot be verified. | 4693| 6612106 | The number of times this content has been used as requested has reached the maximum allowed number of uses. | 4694| 6612107 | An error occurs when sending packet from source device to sink device. | 4695 4696**Example** 4697 4698```ts 4699aVCastController.on('castControlIoError', (error: BusinessError) => { 4700 console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`) 4701}) 4702``` 4703 4704### off('castControlIoError')<sup>13+</sup> 4705 4706off(type: 'castControlIoError', callback?: ErrorCallback): void 4707 4708Unsubscribes from input/output error events during cast control. 4709 4710**Atomic service API**: This API can be used in atomic services since API version 13. 4711 4712**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4713 4714**Parameters** 4715 4716| Name | Type | Mandatory| Description | 4717| -------- | -------- | ---- | ------------------------------------------------------------ | 4718| type | string | Yes | Event type, which is **'castControlIoError'** in this case.| 4719| 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.| 4720 4721**Error codes** 4722 4723| ID| Error Message | 4724| -------- | --------------------- | 4725| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4726 4727**Example** 4728 4729```ts 4730aVCastController.off('castControlIoError'); 4731``` 4732 4733### on('castControlParsingError')<sup>13+</sup> 4734 4735on(type: 'castControlParsingError', callback: ErrorCallback): void 4736 4737Subscribes to parsing error events during cast control. 4738 4739**Atomic service API**: This API can be used in atomic services since API version 13. 4740 4741**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4742 4743**Parameters** 4744 4745| Name | Type | Mandatory| Description | 4746| -------- | -------- | ---- | ------------------------------------------------------------ | 4747| type | string | Yes | Event type, which is **'castControlParsingError'** in this case.| 4748| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4749 4750**Error codes** 4751 4752| ID | Error Message | 4753| -------- | --------------------- | 4754| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4755| 6613000 | Unspecified error related to content parsing. | 4756| 6613001 | Parsing error associated with media container format bit streams. | 4757| 6613002 | Parsing error associated with the media manifest. | 4758| 6613003 | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature. | 4759| 6613004 | Unsupported feature in the media manifest. | 4760 4761**Example** 4762 4763```ts 4764aVCastController.on('castControlParsingError', (error: BusinessError) => { 4765 console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`) 4766}) 4767``` 4768 4769### off('castControlParsingError')<sup>13+</sup> 4770 4771off(type: 'castControlParsingError', callback?: ErrorCallback): void 4772 4773Unsubscribes from parsing error events during cast control. 4774 4775**Atomic service API**: This API can be used in atomic services since API version 13. 4776 4777**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4778 4779**Parameters** 4780 4781| Name | Type | Mandatory| Description | 4782| -------- | -------- | ---- | ------------------------------------------------------------ | 4783| type | string | Yes | Event type, which is **'castControlParsingError'** in this case.| 4784| 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.| 4785 4786**Error codes** 4787 4788| ID| Error Message | 4789| -------- | --------------------- | 4790| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4791 4792**Example** 4793 4794```ts 4795aVCastController.off('castControlParsingError'); 4796``` 4797 4798### on('castControlDecodingError')<sup>13+</sup> 4799 4800on(type: 'castControlDecodingError', callback: ErrorCallback): void 4801 4802Subscribes to decoding error events during cast control. 4803 4804**Atomic service API**: This API can be used in atomic services since API version 13. 4805 4806**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4807 4808**Parameters** 4809 4810| Name | Type | Mandatory| Description | 4811| -------- | -------- | ---- | ------------------------------------------------------------ | 4812| type | string | Yes | Event type, which is **'castControlDecodingError'** in this case.| 4813| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4814 4815**Error codes** 4816 4817| ID| Error Message | 4818| -------- | --------------------- | 4819| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4820| 6614000 | Unspecified decoding error. | 4821| 6614001 | Decoder initialization failed. | 4822| 6614002 | Decoder query failed. | 4823| 6614003 | Decoding the media samples failed. | 4824| 6614004 | The format of the content to decode exceeds the capabilities of the device. | 4825| 6614005 | The format of the content to decode is not supported. | 4826 4827**Example** 4828 4829```ts 4830aVCastController.on('castControlDecodingError', (error: BusinessError) => { 4831 console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`) 4832}) 4833``` 4834### off('castControlDecodingError')<sup>13+</sup> 4835 4836off(type: 'castControlDecodingError', callback?: ErrorCallback): void 4837 4838Unsubscribes from decoding error events during cast control. 4839 4840**Atomic service API**: This API can be used in atomic services since API version 13. 4841 4842**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4843 4844**Parameters** 4845 4846| Name | Type | Mandatory| Description | 4847| -------- | -------- | ---- | ------------------------------------------------------------ | 4848| type | string | Yes | Event type, which is **'castControlDecodingError'** in this case.| 4849| 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.| 4850 4851**Error codes** 4852 4853| ID| Error Message | 4854| -------- | --------------------- | 4855| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4856 4857**Example** 4858 4859```ts 4860aVCastController.off('castControlDecodingError'); 4861``` 4862 4863### on('castControlAudioRendererError')<sup>13+</sup> 4864 4865on(type: 'castControlAudioRendererError', callback: ErrorCallback): void 4866 4867Subscribes to audio renderer error events during cast control. 4868 4869**Atomic service API**: This API can be used in atomic services since API version 13. 4870 4871**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4872 4873**Parameters** 4874 4875| Name | Type | Mandatory| Description | 4876| -------- | -------- | ---- | ------------------------------------------------------------ | 4877| type | string | Yes | Event type, which is **'castControlAudioRendererError'** in this case.| 4878| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4879 4880**Error codes** 4881 4882For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md). 4883 4884| ID| Error Message | 4885| -------- | --------------------- | 4886| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4887| 6615000 | Unspecified errors related to the audio renderer. | 4888| 6615001 | Initializing the audio renderer failed. | 4889| 6615002 | The audio renderer fails to write data. | 4890 4891**Example** 4892 4893```ts 4894aVCastController.on('castControlAudioRendererError', (error: BusinessError) => { 4895 console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`) 4896}) 4897``` 4898### off('castControlAudioRendererError')<sup>13+</sup> 4899 4900off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void 4901 4902Unsubscribes from audio renderer error events during cast control. 4903 4904**Atomic service API**: This API can be used in atomic services since API version 13. 4905 4906**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4907 4908**Parameters** 4909 4910| Name | Type | Mandatory| Description | 4911| -------- | -------- | ---- | ------------------------------------------------------------ | 4912| type | string | Yes | Event type, which is **'castControlAudioRendererError'** in this case.| 4913| 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.| 4914 4915**Error codes** 4916 4917| ID| Error Message | 4918| -------- | --------------------- | 4919| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 4920 4921**Example** 4922 4923```ts 4924aVCastController.off('castControlAudioRendererError'); 4925``` 4926 4927### on('castControlDrmError')<sup>13+</sup> 4928 4929on(type: 'castControlDrmError', callback: ErrorCallback): void 4930 4931Subscribes to DRM error events during cast control. 4932 4933**Atomic service API**: This API can be used in atomic services since API version 13. 4934 4935**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4936 4937**Parameters** 4938 4939| Name | Type | Mandatory| Description | 4940| -------- | -------- | ---- | ------------------------------------------------------------ | 4941| type | string | Yes | Event type, which is **'castControlDrmError'** in this case.| 4942| callback | ErrorCallback | Yes | Callback invoked when the event is triggered.| 4943 4944**Error codes** 4945 4946| ID| Error Message | 4947| -------- | --------------------- | 4948| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4949| 6616000 | Unspecified error related to DRM. | 4950| 6616001 | The chosen DRM protection scheme is not supported by the device. | 4951| 6616002 | Device provisioning failed. | 4952| 6616003 | The DRM-protected content to play is incompatible. | 4953| 6616004 | Failed to obtain a license. | 4954| 6616005 | The operation is disallowed by the license policy. | 4955| 6616006 | An error occurs in the DRM system. | 4956| 6616007 | The device has revoked DRM privileges. | 4957| 6616008 | The DRM license being loaded into the open DRM session has expired. | 4958| 6616100 | An error occurs when the DRM processes the key response. | 4959 4960**Example** 4961 4962```ts 4963aVCastController.on('castControlDrmError', (error: BusinessError) => { 4964 console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`) 4965}) 4966``` 4967 4968### off('castControlDrmError')<sup>13+</sup> 4969 4970off(type: 'castControlDrmError', callback?: ErrorCallback): void 4971 4972Unsubscribes from DRM error events during cast control. 4973 4974**Atomic service API**: This API can be used in atomic services since API version 13. 4975 4976**System capability**: SystemCapability.Multimedia.AVSession.AVCast 4977 4978**Parameters** 4979 4980| Name | Type | Mandatory| Description | 4981| -------- | -------- | ---- | ------------------------------------------------------------ | 4982| type | string | Yes | Event type, which is **'castControlDrmError'** in this case.| 4983| 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.| 4984 4985**Error codes** 4986 4987| ID| Error Message | 4988| -------- | --------------------- | 4989| 401 | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. | 4990 4991**Example** 4992 4993```ts 4994aVCastController.off('castControlDrmError'); 4995``` 4996 4997## KeyRequestCallback<sup>12+</sup> 4998type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void 4999 5000Describes the callback invoked for the media key request event. 5001 5002**Atomic service API**: This API can be used in atomic services since API version 12. 5003 5004**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5005 5006**Parameters** 5007 5008| Name| Type | Mandatory| Description | 5009| ------ | ------ | ---- | ----------------------------------------- | 5010| assetId | string | Yes | Media asset ID.| 5011| requestData | Uint8Array | Yes | Data carried in the media key request. | 5012 5013**Example** 5014<!--code_no_check--> 5015```ts 5016let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => { 5017 console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`); 5018} 5019``` 5020 5021## CastDisplayState<sup>12+</sup> 5022 5023Enumerates the states of the cast display. 5024 5025**Atomic service API**: This API can be used in atomic services since API version 12. 5026 5027**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5028 5029| Name | Value | Description | 5030| --------------------------- | ---- | ----------- | 5031| STATE_OFF | 1 | The device is disconnected, and the extended screen does not display any content. | 5032| STATE_ON | 2 | The device is connected, and the extended screen is available.| 5033 5034 5035## CastDisplayInfo<sup>12+</sup> 5036 5037Describes the information about the cast display in the case of extended screens. 5038 5039**Atomic service API**: This API can be used in atomic services since API version 12. 5040 5041**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast 5042 5043| Name | Type | Read Only| Optional| Description | 5044| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------| 5045| id | number | No | No | ID of the cast display. The value must be an integer. | 5046| name | string | No | No | Name of the cast display. | 5047| state | [CastDisplayState](#castdisplaystate12) | No | No |State of the cast display. | 5048| width | number | No | No | Screen width of the cast display, in px. The value must be an integer. | 5049| height | number | No | No | Screen height of the cast display, in px. The value must be an integer. | 5050 5051## ConnectionState<sup>10+</sup> 5052 5053Enumerates the connection states. 5054 5055**Atomic service API**: This API can be used in atomic services since API version 12. 5056 5057**System capability**: SystemCapability.Multimedia.AVSession.Core 5058 5059| Name | Value | Description | 5060| --------------------------- | ---- | ----------- | 5061| STATE_CONNECTING | 0 | The device is connecting. | 5062| STATE_CONNECTED | 1 | The device is connected.| 5063| STATE_DISCONNECTED | 6 | The device is disconnected.| 5064 5065## AVMetadata<sup>10+</sup> 5066 5067Describes the media metadata. 5068 5069**System capability**: SystemCapability.Multimedia.AVSession.Core 5070 5071| Name | Type | Mandatory| Description | 5072| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5073| assetId | string | Yes | 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. | 5074| title | string | No | Title.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5075| artist | string | No | Artist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5076| author | string | No | Author.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5077| avQueueName<sup>12+</sup> | string | No | Playlist name. | 5078| avQueueId<sup>11+</sup> | string | No | Unique ID of the playlist. | 5079| avQueueImage<sup>11+</sup> | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | string | No | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path).<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL. | 5080| album | string | No | Album name.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5081| writer | string | No | Writer.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5082| composer | string | No | composer. | 5083| duration | number | No | Media duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5084| mediaImage | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | string | No | Pixel map or image path (local path or network path) of the image.<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5085| publishDate | Date | No | Release date. | 5086| subtitle | string | No | Subtitle.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5087| description | string | No | Media description.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5088| lyric | string | No | Lyrics. The application needs to combine the lyrics into a string with less than or equal to 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.| 5089| previousAssetId | string | No | ID of the previous media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5090| nextAssetId | string | No | ID of the next media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5091| filter<sup>11+</sup> | number | No | 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. | 5092| drmSchemes<sup>12+</sup> | Array\<string> | No | DRM scheme supported by the media session. The value is the UUID of the DRM scheme.| 5093| skipIntervals<sup>11+</sup> | [SkipIntervals](#skipintervals11) | No | Fast-forward or rewind interval supported by the media session. The default value is **SECONDS_15**, that is, 15 seconds. | 5094|displayTags<sup>11+</sup> | number | No | Display tags of the media asset. For details, see [DisplayTag](#displaytag11). | 5095 5096## AVMediaDescription<sup>10+</sup> 5097 5098Describes the attributes related to the media metadata in the playlist. 5099 5100**System capability**: SystemCapability.Multimedia.AVSession.Core 5101 5102| Name | Type | Mandatory | Description | 5103| ------------ | ----------------------- | ---- | ----------------------- | 5104| assetId | string | Yes | Media ID in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5105| title | string | No | Name of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5106| subtitle | string | No | Subname of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5107| description | string | No | Description of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5108| mediaImage | image.PixelMap \| string | No | 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.| 5109| extras | {[key: string]: Object} | No | Additional fields of the media asset in the playlist. | 5110| mediaUri | string | No | URI of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5111| mediaType | string | No | Type of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5112| mediaSize | number | No | Size of the media asset in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5113| albumTitle | string | No | 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. | 5114| albumCoverUri | string | No | 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. | 5115| lyricContent | string | No | 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. | 5116| lyricUri | string | No | 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. | 5117| artist | string | No | 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. | 5118| fdSrc | media.AVFileDescriptor | No | 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. | 5119| dataSrc<sup>12+</sup> | media.AVDataSrcDescriptor | No | Descriptor of the data source in the playlist. | 5120| drmScheme<sup>12+</sup> | string | No | DRM scheme supported by the playlist. The value is the UUID of the DRM scheme. | 5121| duration | number | No | 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. | 5122| startPosition | number | No | 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. | 5123| creditsPosition | number | No | 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. | 5124| appName | string | No | Name of the application provided by the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5125|displayTags<sup>11+</sup> | number | No | 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. | 5126 5127## AVQueueItem<sup>10+</sup> 5128 5129Describes the attributes of an item in the playlist. 5130 5131**Atomic service API**: This API can be used in atomic services since API version 12. 5132 5133**System capability**: SystemCapability.Multimedia.AVSession.Core 5134 5135| Name | Type | Mandatory| Description | 5136| ------------ | ------------------------------------------ | ---- | --------------------------- | 5137| itemId | number | Yes | ID of an item in the playlist. | 5138| description | [AVMediaDescription](#avmediadescription10) | No | Media metadata of the item in the playlist. | 5139 5140## AVPlaybackState<sup>10+</sup> 5141 5142Describes the information related to the media playback state. 5143 5144**System capability**: SystemCapability.Multimedia.AVSession.Core 5145 5146| Name | Type | Mandatory| Description | 5147| ------------ | ------------------------------------- | ---- | ------- | 5148| state | [PlaybackState](#playbackstate10) | No | Playback state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5149| speed | number | No | Playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5150| position | [PlaybackPosition](#playbackposition10) | No | Playback position.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5151| bufferedTime | number | No | Buffered time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5152| loopMode | [LoopMode](#loopmode10) | No | Loop mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5153| isFavorite | boolean | No | Whether the media asset is favorited.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5154| 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.| 5155| volume<sup>10+</sup> | number | No | Media volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5156| maxVolume<sup>11+</sup> | number | No | Maximum volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5157| 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.| 5158| duration<sup>11+</sup> | number | No | Duration of the media asset.| 5159| 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.| 5160| 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.| 5161| 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.| 5162 5163## PlaybackPosition<sup>10+</sup> 5164 5165Describes the information related to the playback position. 5166 5167**Atomic service API**: This API can be used in atomic services since API version 12. 5168 5169**System capability**: SystemCapability.Multimedia.AVSession.Core 5170 5171| Name | Type | Mandatory| Description | 5172| ----------- | ------ | ---- | ------------------ | 5173| elapsedTime | number | Yes | Elapsed time, in ms.| 5174| updateTime | number | Yes | Updated time, in ms.| 5175 5176## CallMetadata<sup>11+</sup> 5177 5178Defines the attributes related to call metadata. 5179 5180**Atomic service API**: This API can be used in atomic services since API version 12. 5181 5182**System capability**: SystemCapability.Multimedia.AVSession.Core 5183 5184| Name | Type | Mandatory| Description | 5185| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 5186| name | string | No | Name (alias) of the caller. | 5187| phoneNumber | string | No | Phone number of the caller. | 5188| avatar | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | No | Profile picture of the caller. | 5189 5190## AVCallState<sup>11+</sup> 5191 5192Defines the attributes related to the call state. 5193 5194**Atomic service API**: This API can be used in atomic services since API version 12. 5195 5196**System capability**: SystemCapability.Multimedia.AVSession.Core 5197 5198| Name | Type | Mandatory| Description | 5199| --------------- |------------------------- | ---- |---------------------------------------------------------------------| 5200| state | [CallState](#callstate11) | Yes | Call state. | 5201| muted | boolean | Yes | Whether the microphone is muted.<br>**true**: The microphone is muted.<br>**false**: The microphone is not muted.| 5202 5203## CallState<sup>11+</sup> 5204 5205Enumerates the call states. 5206 5207**Atomic service API**: This API can be used in atomic services since API version 12. 5208 5209**System capability**: SystemCapability.Multimedia.AVSession.Core 5210 5211| Name | Value | Description | 5212| -------------------------- | ---- | -------- | 5213| CALL_STATE_IDLE | 0 | The phone is idle. | 5214| CALL_STATE_INCOMING | 1 | The phone is ringing. | 5215| CALL_STATE_ACTIVE | 2 | The call is connected. | 5216| CALL_STATE_DIALING | 3 | The caller is dialing. | 5217| CALL_STATE_WAITING | 4 | The call is waiting for connection. | 5218| CALL_STATE_HOLDING | 5 | The call is placed on hold. | 5219| CALL_STATE_DISCONNECTING | 6 | The call is disconnecting. | 5220 5221## DisplayTag<sup>11+</sup> 5222 5223Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source. 5224 5225**System capability**: SystemCapability.Multimedia.AVSession.Core 5226 5227| Name | Value | Description | 5228| -------------------------- | ---- | ------------ | 5229| TAG_AUDIO_VIVID | 1 | AUDIO VIVID | 5230 5231## AVCastCategory<sup>10+</sup> 5232 5233Enumerates the cast categories. 5234 5235**Atomic service API**: This API can be used in atomic services since API version 12. 5236 5237**System capability**: SystemCapability.Multimedia.AVSession.AVCast 5238 5239| Name | Value | Description | 5240| --------------------------- | ---- | ----------- | 5241| CATEGORY_LOCAL | 0 | Local playback. The sound is played from the local device or a connected Bluetooth headset by default. | 5242| CATEGORY_REMOTE | 1 | Remote playback. The sound or images are played from a remote device. | 5243 5244## DeviceType<sup>10+</sup> 5245 5246Enumerates the output device types. 5247 5248**Atomic service API**: This API can be used in atomic services since API version 12. 5249 5250| Name | Value | Description | 5251| --------------------------- | ---- | ----------- | 5252| DEVICE_TYPE_LOCAL | 0 | Local device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core| 5253| DEVICE_TYPE_BLUETOOTH | 10 | Bluetooth device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core| 5254| DEVICE_TYPE_TV | 2 | TV.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 5255| DEVICE_TYPE_SMART_SPEAKER | 3 | Speaker.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast| 5256 5257## DeviceInfo<sup>10+</sup> 5258 5259Describes the information related to the output device. 5260 5261| Name | Type | Mandatory| Description | 5262| ---------- | -------------- | ---- | ---------------------- | 5263| 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.| 5264| 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.| 5265| 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.| 5266| 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.| 5267| 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.| 5268| 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.| 5269| 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.| 5270| 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.| 5271 5272## OutputDeviceInfo<sup>10+</sup> 5273 5274Describes the information related to the output device. 5275 5276**Atomic service API**: This API can be used in atomic services since API version 12. 5277 5278**System capability**: SystemCapability.Multimedia.AVSession.Core 5279 5280| Name | Type | Mandatory| Description | 5281| ---------- | -------------- | ---- | ---------------------- | 5282| devices | Array\<DeviceInfo\> | Yes | Output devices. | 5283 5284## LoopMode<sup>10+</sup> 5285 5286Enumerates the loop modes of media playback. 5287 5288**Atomic service API**: This API can be used in atomic services since API version 12. 5289 5290**System capability**: SystemCapability.Multimedia.AVSession.Core 5291 5292| Name | Value | Description | 5293| ------------------ | ---- | -------- | 5294| LOOP_MODE_SEQUENCE | 0 | Sequential playback.| 5295| LOOP_MODE_SINGLE | 1 | Single loop.| 5296| LOOP_MODE_LIST | 2 | Playlist loop.| 5297| LOOP_MODE_SHUFFLE | 3 | Shuffle.| 5298| LOOP_MODE_CUSTOM<sup>11+</sup> | 4 | Custom playback. | 5299 5300## PlaybackState<sup>10+</sup> 5301 5302Enumerates the media playback states. 5303 5304**Atomic service API**: This API can be used in atomic services since API version 12. 5305 5306**System capability**: SystemCapability.Multimedia.AVSession.Core 5307 5308| Name | Value | Description | 5309| --------------------------- | ---- | ----------- | 5310| PLAYBACK_STATE_INITIAL | 0 | Initial. | 5311| PLAYBACK_STATE_PREPARE | 1 | Preparing. | 5312| PLAYBACK_STATE_PLAY | 2 | Playing. | 5313| PLAYBACK_STATE_PAUSE | 3 | Paused. | 5314| PLAYBACK_STATE_FAST_FORWARD | 4 | Fast-forwarding. | 5315| PLAYBACK_STATE_REWIND | 5 | Rewinded. | 5316| PLAYBACK_STATE_STOP | 6 | Stopped. | 5317| PLAYBACK_STATE_COMPLETED | 7 | Playback complete. | 5318| PLAYBACK_STATE_RELEASED | 8 | Released. | 5319| PLAYBACK_STATE_ERROR | 9 | Error. | 5320| PLAYBACK_STATE_IDLE<sup>11+</sup> | 10 | Idle. | 5321| PLAYBACK_STATE_BUFFERING<sup>11+</sup> | 11 | Buffering. | 5322 5323## AVSessionController<sup>10+</sup> 5324 5325Through 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. 5326 5327### Attributes 5328 5329**Atomic service API**: This API can be used in atomic services since API version 12. 5330 5331**System capability**: SystemCapability.Multimedia.AVSession.Core 5332 5333| Name | Type | Readable| Writable| Description | 5334| :-------- | :----- | :--- | :--- | :-------------------------------------- | 5335| sessionId | string | Yes | No | Unique session ID of the **AVSessionController** object.| 5336 5337 5338**Example** 5339 5340```ts 5341import { BusinessError } from '@kit.BasicServicesKit'; 5342 5343let AVSessionController: avSession.AVSessionController; 5344avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => { 5345 AVSessionController = controller; 5346}).catch((err: BusinessError) => { 5347 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 5348}); 5349``` 5350 5351### getAVPlaybackState<sup>10+</sup> 5352 5353getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void 5354 5355Obtains the remote playback state. This API uses an asynchronous callback to return the result. 5356 5357**System capability**: SystemCapability.Multimedia.AVSession.Core 5358 5359**Parameters** 5360 5361| Name | Type | Mandatory| Description | 5362| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 5363| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes | Callback used to return the remote playback state.| 5364 5365**Error codes** 5366 5367For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5368 5369| ID| Error Message| 5370| -------- | ---------------------------------------- | 5371| 6600101 | Session service exception. | 5372| 6600102 | The session does not exist. | 5373| 6600103 | The session controller does not exist. | 5374 5375**Example** 5376 5377```ts 5378import { BusinessError } from '@kit.BasicServicesKit'; 5379 5380avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => { 5381 if (err) { 5382 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5383 } else { 5384 console.info('getAVPlaybackState : SUCCESS'); 5385 } 5386}); 5387``` 5388 5389### getAVPlaybackState<sup>10+</sup> 5390 5391getAVPlaybackState(): Promise\<AVPlaybackState> 5392 5393Obtains the remote playback state. This API uses a promise to return the result. 5394 5395**Atomic service API**: This API can be used in atomic services since API version 12. 5396 5397**System capability**: SystemCapability.Multimedia.AVSession.Core 5398 5399**Return value** 5400 5401| Type | Description | 5402| --------- | ------------------------------------------------------------ | 5403| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise used to return the remote playback state. | 5404 5405**Error codes** 5406 5407For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5408 5409| ID| Error Message| 5410| -------- | ---------------------------------------- | 5411| 6600101 | Session service exception. | 5412| 6600102 | The session does not exist. | 5413| 6600103 | The session controller does not exist. | 5414 5415**Example** 5416 5417```ts 5418import { BusinessError } from '@kit.BasicServicesKit'; 5419 5420avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => { 5421 console.info('getAVPlaybackState : SUCCESS'); 5422}).catch((err: BusinessError) => { 5423 console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); 5424}); 5425``` 5426 5427### getAVMetadata<sup>10+</sup> 5428 5429getAVMetadata(): Promise\<AVMetadata> 5430 5431Obtains the session metadata. This API uses a promise to return the result. 5432 5433**Atomic service API**: This API can be used in atomic services since API version 12. 5434 5435**System capability**: SystemCapability.Multimedia.AVSession.Core 5436 5437**Return value** 5438 5439| Type | Description | 5440| ----------------------------------- | ----------------------------- | 5441| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.| 5442 5443**Error codes** 5444 5445For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5446 5447| ID| Error Message| 5448| -------- | ---------------------------------------- | 5449| 6600101 | Session service exception. | 5450| 6600102 | The session does not exist. | 5451| 6600103 | The session controller does not exist. | 5452 5453**Example** 5454 5455```ts 5456import { BusinessError } from '@kit.BasicServicesKit'; 5457 5458avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => { 5459 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5460}).catch((err: BusinessError) => { 5461 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5462}); 5463``` 5464 5465### getAVMetadata<sup>10+</sup> 5466 5467getAVMetadata(callback: AsyncCallback\<AVMetadata>): void 5468 5469Obtains the session metadata. This API uses an asynchronous callback to return the result. 5470 5471**System capability**: SystemCapability.Multimedia.AVSession.Core 5472 5473**Parameters** 5474 5475| Name | Type | Mandatory| Description | 5476| -------- | ----------------------------------------- | ---- | -------------------------- | 5477| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes | Callback used to return the metadata obtained.| 5478 5479**Error codes** 5480 5481For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5482 5483| ID| Error Message| 5484| -------- | ---------------------------------------- | 5485| 6600101 | Session service exception. | 5486| 6600102 | The session does not exist. | 5487| 6600103 | The session controller does not exist. | 5488 5489**Example** 5490 5491```ts 5492import { BusinessError } from '@kit.BasicServicesKit'; 5493 5494avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => { 5495 if (err) { 5496 console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 5497 } else { 5498 console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); 5499 } 5500}); 5501``` 5502 5503### getAVQueueTitle<sup>10+</sup> 5504 5505getAVQueueTitle(): Promise\<string> 5506 5507Obtains the name of the playlist. This API uses a promise to return the result. 5508 5509**Atomic service API**: This API can be used in atomic services since API version 12. 5510 5511**System capability**: SystemCapability.Multimedia.AVSession.Core 5512 5513**Return value** 5514 5515| Type | Description | 5516| ---------------- | ----------------------------- | 5517| Promise<string\> | Promise used to return the playlist name.| 5518 5519**Error codes** 5520 5521For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5522 5523| ID| Error Message| 5524| -------- | ---------------------------------------- | 5525| 6600101 | Session service exception. | 5526| 6600102 | The session does not exist. | 5527| 6600103 | The session controller does not exist. | 5528 5529**Example** 5530 5531```ts 5532import { BusinessError } from '@kit.BasicServicesKit'; 5533 5534avsessionController.getAVQueueTitle().then((title: string) => { 5535 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 5536}).catch((err: BusinessError) => { 5537 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 5538}); 5539``` 5540 5541### getAVQueueTitle<sup>10+</sup> 5542 5543getAVQueueTitle(callback: AsyncCallback\<string>): void 5544 5545Obtains the name of the playlist. This API uses an asynchronous callback to return the result. 5546 5547**System capability**: SystemCapability.Multimedia.AVSession.Core 5548 5549**Parameters** 5550 5551| Name | Type | Mandatory| Description | 5552| -------- | ---------------------- | ---- | ------------------------- | 5553| callback | AsyncCallback<string\> | Yes | Callback used to return the playlist name.| 5554 5555**Error codes** 5556 5557For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5558 5559| ID| Error Message| 5560| -------- | ---------------------------------------- | 5561| 6600101 | Session service exception. | 5562| 6600102 | The session does not exist. | 5563| 6600103 | The session controller does not exist. | 5564 5565**Example** 5566 5567```ts 5568import { BusinessError } from '@kit.BasicServicesKit'; 5569 5570avsessionController.getAVQueueTitle((err: BusinessError, title: string) => { 5571 if (err) { 5572 console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); 5573 } else { 5574 console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); 5575 } 5576}); 5577``` 5578 5579### getAVQueueItems<sup>10+</sup> 5580 5581getAVQueueItems(): Promise\<Array\<AVQueueItem>> 5582 5583Obtains the information related to the items in the queue. This API uses a promise to return the result. 5584 5585**Atomic service API**: This API can be used in atomic services since API version 12. 5586 5587**System capability**: SystemCapability.Multimedia.AVSession.Core 5588 5589**Return value** 5590 5591| Type | Description | 5592| --------------------------------------------- | ----------------------------- | 5593| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue.| 5594 5595**Error codes** 5596 5597For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5598 5599| ID| Error Message| 5600| -------- | ---------------------------------------- | 5601| 6600101 | Session service exception. | 5602| 6600102 | The session does not exist. | 5603| 6600103 | The session controller does not exist. | 5604 5605**Example** 5606 5607```ts 5608import { BusinessError } from '@kit.BasicServicesKit'; 5609 5610avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => { 5611 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 5612}).catch((err: BusinessError) => { 5613 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 5614}); 5615``` 5616 5617### getAVQueueItems<sup>10+</sup> 5618 5619getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void 5620 5621Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result. 5622 5623**System capability**: SystemCapability.Multimedia.AVSession.Core 5624 5625**Parameters** 5626 5627| Name | Type | Mandatory| Description | 5628| -------- | --------------------------------------------------- | ---- | ------------------------- | 5629| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes | Callback used to return the items in the playlist.| 5630 5631**Error codes** 5632 5633For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5634 5635| ID| Error Message| 5636| -------- | ---------------------------------------- | 5637| 6600101 | Session service exception. | 5638| 6600102 | The session does not exist. | 5639| 6600103 | The session controller does not exist. | 5640 5641**Example** 5642 5643```ts 5644import { BusinessError } from '@kit.BasicServicesKit'; 5645 5646avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => { 5647 if (err) { 5648 console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); 5649 } else { 5650 console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); 5651 } 5652}); 5653``` 5654 5655### skipToQueueItem<sup>10+</sup> 5656 5657skipToQueueItem(itemId: number): Promise\<void> 5658 5659Sends 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. 5660 5661**Atomic service API**: This API can be used in atomic services since API version 12. 5662 5663**System capability**: SystemCapability.Multimedia.AVSession.Core 5664 5665**Parameters** 5666 5667| Name | Type | Mandatory| Description | 5668| ------ | ------- | ---- | ------------------------------------------- | 5669| itemId | number | Yes | ID of an item in the playlist.| 5670 5671**Return value** 5672 5673| Type | Description | 5674| -------------- | --------------------------------------------------------------- | 5675| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.| 5676 5677**Error codes** 5678 5679For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5680 5681| ID| Error Message| 5682| -------- | ---------------------------------------- | 5683| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5684| 6600101 | Session service exception. | 5685| 6600102 | The session does not exist. | 5686| 6600103 | The session controller does not exist. | 5687 5688**Example** 5689 5690```ts 5691import { BusinessError } from '@kit.BasicServicesKit'; 5692 5693let queueItemId = 0; 5694avsessionController.skipToQueueItem(queueItemId).then(() => { 5695 console.info('SkipToQueueItem successfully'); 5696}).catch((err: BusinessError) => { 5697 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 5698}); 5699``` 5700 5701### skipToQueueItem<sup>10+</sup> 5702 5703skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void 5704 5705Sends 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. 5706 5707**System capability**: SystemCapability.Multimedia.AVSession.Core 5708 5709**Parameters** 5710 5711| Name | Type | Mandatory| Description | 5712| -------- | --------------------- | ---- | ----------------------------------------------------------- | 5713| itemId | number | Yes | ID of an item in the playlist. | 5714| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.| 5715 5716**Error codes** 5717 5718For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5719 5720| ID| Error Message| 5721| -------- | ---------------------------------------- | 5722| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5723| 6600101 | Session service exception. | 5724| 6600102 | The session does not exist. | 5725| 6600103 | The session controller does not exist. | 5726 5727**Example** 5728 5729```ts 5730import { BusinessError } from '@kit.BasicServicesKit'; 5731 5732let queueItemId = 0; 5733avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => { 5734 if (err) { 5735 console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); 5736 } else { 5737 console.info('SkipToQueueItem successfully'); 5738 } 5739}); 5740``` 5741 5742### getOutputDevice<sup>10+</sup> 5743 5744getOutputDevice(): Promise\<OutputDeviceInfo> 5745 5746Obtains the output device information. This API uses a promise to return the result. 5747 5748**Atomic service API**: This API can be used in atomic services since API version 12. 5749 5750**System capability**: SystemCapability.Multimedia.AVSession.Core 5751 5752**Return value** 5753 5754| Type | Description | 5755| ----------------------------------------------- | --------------------------------- | 5756| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.| 5757 5758**Error codes** 5759 5760For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5761 5762| ID| Error Message| 5763| -------- | ---------------------------------------- | 5764| 600101 | Session service exception. | 5765| 600103 | The session controller does not exist. | 5766 5767**Example** 5768 5769```ts 5770import { BusinessError } from '@kit.BasicServicesKit'; 5771 5772avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => { 5773 console.info('GetOutputDevice : SUCCESS'); 5774}).catch((err: BusinessError) => { 5775 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 5776}); 5777``` 5778 5779### getOutputDevice<sup>10+</sup> 5780 5781getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void 5782 5783Obtains the output device information. This API uses an asynchronous callback to return the result. 5784 5785**System capability**: SystemCapability.Multimedia.AVSession.Core 5786 5787**Parameters** 5788 5789| Name | Type | Mandatory| Description | 5790| -------- | ----------------------------------------------------- | ---- | ------------------------------ | 5791| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes | Callback used to return the information obtained.| 5792 5793**Error codes** 5794 5795For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5796 5797| ID| Error Message| 5798| -------- | ---------------------------------------- | 5799| 600101 | Session service exception. | 5800| 600103 | The session controller does not exist. | 5801 5802**Example** 5803 5804```ts 5805import { BusinessError } from '@kit.BasicServicesKit'; 5806 5807avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => { 5808 if (err) { 5809 console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); 5810 } else { 5811 console.info('GetOutputDevice : SUCCESS'); 5812 } 5813}); 5814``` 5815 5816### sendAVKeyEvent<sup>10+</sup> 5817 5818sendAVKeyEvent(event: KeyEvent): Promise\<void> 5819 5820Sends a key event to the session corresponding to this controller. This API uses a promise to return the result. 5821 5822**Atomic service API**: This API can be used in atomic services since API version 12. 5823 5824**System capability**: SystemCapability.Multimedia.AVSession.Core 5825 5826**Parameters** 5827 5828| Name| Type | Mandatory| Description | 5829| ------ | ------------------------------------------------------------ | ---- | ---------- | 5830| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes | Key event.| 5831 5832**Error codes** 5833 5834For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5835 5836| ID| Error Message| 5837| -------- | ---------------------------------------- | 5838| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5839| 600101 | Session service exception. | 5840| 600102 | The session does not exist. | 5841| 600103 | The session controller does not exist. | 5842| 600105 | Invalid session command. | 5843| 600106 | The session is not activated. | 5844 5845**Return value** 5846 5847| Type | Description | 5848| -------------- | ----------------------------- | 5849| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.| 5850 5851**Example** 5852 5853```ts 5854import { Key, KeyEvent } from '@kit.InputKit'; 5855import { BusinessError } from '@kit.BasicServicesKit'; 5856 5857let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 5858let 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}; 5859 5860 5861avsessionController.sendAVKeyEvent(event).then(() => { 5862 console.info('SendAVKeyEvent Successfully'); 5863}).catch((err: BusinessError) => { 5864 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 5865}); 5866``` 5867 5868### sendAVKeyEvent<sup>10+</sup> 5869 5870sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void 5871 5872Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result. 5873 5874**System capability**: SystemCapability.Multimedia.AVSession.Core 5875 5876**Parameters** 5877 5878| Name | Type | Mandatory| Description | 5879| -------- | ------------------------------------------------------------ | ---- | ---------- | 5880| event | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes | Key event.| 5881| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.| 5882 5883**Error codes** 5884 5885For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5886 5887| ID| Error Message| 5888| -------- | ---------------------------------------- | 5889| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 5890| 600101 | Session service exception. | 5891| 600102 | The session does not exist. | 5892| 600103 | The session controller does not exist. | 5893| 600105 | Invalid session command. | 5894| 600106 | The session is not activated. | 5895 5896**Example** 5897 5898```ts 5899import { Key, KeyEvent } from '@kit.InputKit'; 5900import { BusinessError } from '@kit.BasicServicesKit'; 5901 5902let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0}; 5903let 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}; 5904avsessionController.sendAVKeyEvent(event, (err: BusinessError) => { 5905 if (err) { 5906 console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); 5907 } else { 5908 console.info('SendAVKeyEvent Successfully'); 5909 } 5910}); 5911``` 5912 5913### getLaunchAbility<sup>10+</sup> 5914 5915getLaunchAbility(): Promise\<WantAgent> 5916 5917Obtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result. 5918 5919**Atomic service API**: This API can be used in atomic services since API version 12. 5920 5921**System capability**: SystemCapability.Multimedia.AVSession.Core 5922 5923**Return value** 5924 5925| Type | Description | 5926| ------------------------------------------------------- | ------------------------------------------------------------ | 5927| 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 attribute, such as the bundle name, ability name, and device ID.| 5928 5929**Error codes** 5930 5931For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5932 5933| ID| Error Message| 5934| -------- | ---------------------------------------- | 5935| 6600101 | Session service exception. | 5936| 6600102 | The session does not exist. | 5937| 6600103 | The session controller does not exist. | 5938 5939**Example** 5940 5941```ts 5942import { BusinessError } from '@kit.BasicServicesKit'; 5943 5944avsessionController.getLaunchAbility().then((agent: object) => { 5945 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 5946}).catch((err: BusinessError) => { 5947 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 5948}); 5949``` 5950 5951### getLaunchAbility<sup>10+</sup> 5952 5953getLaunchAbility(callback: AsyncCallback\<WantAgent>): void 5954 5955Obtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result. 5956 5957**System capability**: SystemCapability.Multimedia.AVSession.Core 5958 5959**Parameters** 5960 5961| Name | Type | Mandatory| Description | 5962| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 5963| 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 attribute, such as the bundle name, ability name, and device ID.| 5964 5965**Error codes** 5966 5967For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 5968 5969| ID| Error Message| 5970| -------- | ---------------------------------------- | 5971| 6600101 | Session service exception. | 5972| 6600102 | The session does not exist. | 5973| 6600103 | The session controller does not exist. | 5974 5975**Example** 5976 5977```ts 5978import { BusinessError } from '@kit.BasicServicesKit'; 5979 5980avsessionController.getLaunchAbility((err: BusinessError, agent: object) => { 5981 if (err) { 5982 console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); 5983 } else { 5984 console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); 5985 } 5986}); 5987``` 5988 5989### getRealPlaybackPositionSync<sup>10+</sup> 5990 5991getRealPlaybackPositionSync(): number 5992 5993Obtains the playback position. 5994 5995**Atomic service API**: This API can be used in atomic services since API version 12. 5996 5997**System capability**: SystemCapability.Multimedia.AVSession.Core 5998 5999**Return value** 6000 6001| Type | Description | 6002| ------ | ------------------ | 6003| number | Playback position, in milliseconds.| 6004 6005**Error codes** 6006 6007For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6008 6009| ID| Error Message| 6010| -------- | ---------------------------------------- | 6011| 6600101 | Session service exception. | 6012| 6600103 | The session controller does not exist. | 6013 6014**Example** 6015 6016```ts 6017let time: number = avsessionController.getRealPlaybackPositionSync(); 6018``` 6019 6020### isActive<sup>10+</sup> 6021 6022isActive(): Promise\<boolean> 6023 6024Checks whether the session is activated. This API uses a promise to return the result. 6025 6026**Atomic service API**: This API can be used in atomic services since API version 12. 6027 6028**System capability**: SystemCapability.Multimedia.AVSession.Core 6029 6030**Return value** 6031 6032| Type | Description | 6033| ----------------- | ------------------------------------------------------------ | 6034| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.| 6035 6036**Error codes** 6037 6038For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6039 6040| ID| Error Message| 6041| -------- | ---------------------------------------- | 6042| 6600101 | Session service exception. | 6043| 6600102 | The session does not exist. | 6044| 6600103 | The session controller does not exist. | 6045 6046**Example** 6047 6048```ts 6049import { BusinessError } from '@kit.BasicServicesKit'; 6050 6051avsessionController.isActive().then((isActive: boolean) => { 6052 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6053}).catch((err: BusinessError) => { 6054 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6055}); 6056``` 6057 6058### isActive<sup>10+</sup> 6059 6060isActive(callback: AsyncCallback\<boolean>): void 6061 6062Checks whether the session is activated. This API uses an asynchronous callback to return the result. 6063 6064**System capability**: SystemCapability.Multimedia.AVSession.Core 6065 6066**Parameters** 6067 6068| Name | Type | Mandatory| Description | 6069| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 6070| callback | AsyncCallback<boolean\> | Yes | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.| 6071 6072**Error codes** 6073 6074For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6075 6076| ID| Error Message| 6077| -------- | ---------------------------------------- | 6078| 6600101 | Session service exception. | 6079| 6600102 | The session does not exist. | 6080| 6600103 | The session controller does not exist. | 6081 6082**Example** 6083 6084```ts 6085import { BusinessError } from '@kit.BasicServicesKit'; 6086 6087avsessionController.isActive((err: BusinessError, isActive: boolean) => { 6088 if (err) { 6089 console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); 6090 } else { 6091 console.info(`IsActive : SUCCESS : isactive : ${isActive}`); 6092 } 6093}); 6094``` 6095 6096### destroy<sup>10+</sup> 6097 6098destroy(): Promise\<void> 6099 6100Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result. 6101 6102**Atomic service API**: This API can be used in atomic services since API version 12. 6103 6104**System capability**: SystemCapability.Multimedia.AVSession.Core 6105 6106**Return value** 6107 6108| Type | Description | 6109| -------------- | ----------------------------- | 6110| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.| 6111 6112**Error codes** 6113 6114For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6115 6116| ID| Error Message| 6117| -------- | ---------------------------------------- | 6118| 6600101 | Session service exception. | 6119| 6600103 | The session controller does not exist. | 6120 6121**Example** 6122 6123```ts 6124import { BusinessError } from '@kit.BasicServicesKit'; 6125 6126avsessionController.destroy().then(() => { 6127 console.info('Destroy : SUCCESS '); 6128}).catch((err: BusinessError) => { 6129 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6130}); 6131``` 6132 6133### destroy<sup>10+</sup> 6134 6135destroy(callback: AsyncCallback\<void>): void 6136 6137Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result. 6138 6139**System capability**: SystemCapability.Multimedia.AVSession.Core 6140 6141**Parameters** 6142 6143| Name | Type | Mandatory| Description | 6144| -------- | -------------------- | ---- | ---------- | 6145| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.| 6146 6147**Error codes** 6148 6149For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6150 6151| ID| Error Message| 6152| -------- | ---------------------------------------- | 6153| 6600101 | Session service exception. | 6154| 6600103 | The session controller does not exist. | 6155 6156**Example** 6157 6158```ts 6159import { BusinessError } from '@kit.BasicServicesKit'; 6160 6161avsessionController.destroy((err: BusinessError) => { 6162 if (err) { 6163 console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); 6164 } else { 6165 console.info('Destroy : SUCCESS '); 6166 } 6167}); 6168``` 6169 6170### getValidCommands<sup>10+</sup> 6171 6172getValidCommands(): Promise\<Array\<AVControlCommandType>> 6173 6174Obtains valid commands supported by the session. This API uses a promise to return the result. 6175 6176**Atomic service API**: This API can be used in atomic services since API version 12. 6177 6178**System capability**: SystemCapability.Multimedia.AVSession.Core 6179 6180**Return value** 6181 6182| Type | Description | 6183| ------------------------------------------------------------ | --------------------------------- | 6184| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands.| 6185 6186**Error codes** 6187 6188For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6189 6190| ID| Error Message| 6191| -------- | ---------------------------------------- | 6192| 6600101 | Session service exception. | 6193| 6600102 | The session does not exist. | 6194| 6600103 | The session controller does not exist. | 6195 6196**Example** 6197 6198```ts 6199import { BusinessError } from '@kit.BasicServicesKit'; 6200 6201avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => { 6202 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6203}).catch((err: BusinessError) => { 6204 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6205}); 6206``` 6207 6208### getValidCommands<sup>10+</sup> 6209 6210getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void 6211 6212Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result. 6213 6214**System capability**: SystemCapability.Multimedia.AVSession.Core 6215 6216**Parameters** 6217 6218| Name | Type | Mandatory| Description | 6219| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | 6220| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes | Callback used to return a set of valid commands.| 6221 6222**Error codes** 6223 6224For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6225 6226| ID| Error Message| 6227| -------- | ---------------------------------------- | 6228| 6600101 | Session service exception. | 6229| 6600102 | The session does not exist. | 6230| 6600103 | The session controller does not exist. | 6231 6232**Example** 6233 6234```ts 6235import { BusinessError } from '@kit.BasicServicesKit'; 6236 6237avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => { 6238 if (err) { 6239 console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); 6240 } else { 6241 console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); 6242 } 6243}); 6244``` 6245 6246### sendControlCommand<sup>10+</sup> 6247 6248sendControlCommand(command: AVControlCommand): Promise\<void> 6249 6250Sends a control command to the session through the controller. This API uses a promise to return the result. 6251 6252> **NOTE** 6253> 6254> 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. 6255 6256**Atomic service API**: This API can be used in atomic services since API version 12. 6257 6258**System capability**: SystemCapability.Multimedia.AVSession.Core 6259 6260**Parameters** 6261 6262| Name | Type | Mandatory| Description | 6263| ------- | ------------------------------------- | ---- | ------------------------------ | 6264| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| 6265 6266**Return value** 6267 6268| Type | Description | 6269| -------------- | ----------------------------- | 6270| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 6271 6272**Error codes** 6273 6274For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6275 6276| ID| Error Message| 6277| -------- | ---------------------------------------- | 6278| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6279| 6600101 | Session service exception. | 6280| 6600102 | The session does not exist. | 6281| 6600103 | The session controller does not exist. | 6282| 6600105 | Invalid session command. | 6283| 6600106 | The session is not activated. | 6284| 6600107 | Too many commands or events. | 6285 6286**Example** 6287 6288```ts 6289import { BusinessError } from '@kit.BasicServicesKit'; 6290 6291let avCommand: avSession.AVControlCommand = {command:'play'}; 6292avsessionController.sendControlCommand(avCommand).then(() => { 6293 console.info('SendControlCommand successfully'); 6294}).catch((err: BusinessError) => { 6295 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6296}); 6297``` 6298 6299### sendControlCommand<sup>10+</sup> 6300 6301sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void 6302 6303Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result. 6304 6305> **NOTE** 6306> 6307> 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. 6308 6309**System capability**: SystemCapability.Multimedia.AVSession.Core 6310 6311**Parameters** 6312 6313| Name | Type | Mandatory| Description | 6314| -------- | ------------------------------------- | ---- | ------------------------------ | 6315| command | [AVControlCommand](#avcontrolcommand10) | Yes | Command to send.| 6316| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 6317 6318**Error codes** 6319 6320For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6321 6322| ID| Error Message| 6323| -------- | ------------------------------- | 6324| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6325| 6600101 | Session service exception. | 6326| 6600102 | The session does not exist. | 6327| 6600103 | The session controller does not exist. | 6328| 6600105 | Invalid session command. | 6329| 6600106 | The session is not activated. | 6330| 6600107 | Too many commands or events. | 6331 6332**Example** 6333 6334```ts 6335import { BusinessError } from '@kit.BasicServicesKit'; 6336 6337let avCommand: avSession.AVControlCommand = {command:'play'}; 6338avsessionController.sendControlCommand(avCommand, (err: BusinessError) => { 6339 if (err) { 6340 console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6341 } else { 6342 console.info('SendControlCommand successfully'); 6343 } 6344}); 6345``` 6346 6347### sendCommonCommand<sup>10+</sup> 6348 6349sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void> 6350 6351Sends a custom control command to the session through the controller. This API uses a promise to return the result. 6352 6353**Atomic service API**: This API can be used in atomic services since API version 12. 6354 6355**System capability**: SystemCapability.Multimedia.AVSession.Core 6356 6357**Parameters** 6358 6359| Name | Type | Mandatory| Description | 6360| ------- | ------------------------------------- | ---- | ------------------------------ | 6361| command | string | Yes | Name of the custom control command.| 6362| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command.| 6363 6364> **NOTE** 6365> 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). 6366 6367**Return value** 6368 6369| Type | Description | 6370| -------------- | ----------------------------- | 6371| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 6372 6373**Error codes** 6374 6375For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6376 6377| ID| Error Message| 6378| -------- | ---------------------------------------- | 6379| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. | 6380| 6600101 | Session service exception. | 6381| 6600102 | The session does not exist. | 6382| 6600103 | The session controller does not exist. | 6383| 6600105 | Invalid session command. | 6384| 6600106 | The session is not activated. | 6385| 6600107 | Too many commands or events. | 6386 6387**Example** 6388 6389```ts 6390import { BusinessError } from '@kit.BasicServicesKit'; 6391 6392let avSessionController: avSession.AVSessionController | undefined = undefined; 6393let currentAVSession: avSession.AVSession | undefined = undefined; 6394let tag = "createNewSession"; 6395let context: Context = getContext(this); 6396let sessionId: string = ""; 6397avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6398 if (err) { 6399 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6400 } else { 6401 currentAVSession = data; 6402 } 6403}); 6404if (currentAVSession !== undefined) { 6405 sessionId = (currentAVSession as avSession.AVSession).sessionId; 6406 avSession.createController(sessionId).then((controller: avSession.AVSessionController) => { 6407 avSessionController = controller; 6408 }).catch((err: BusinessError) => { 6409 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6410 }); 6411} 6412 6413let commandName = "my_command"; 6414if (avSessionController !== undefined) { 6415 (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => { 6416 console.info('SendCommonCommand successfully'); 6417 }).catch((err: BusinessError) => { 6418 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6419 }) 6420} 6421``` 6422 6423### sendCommonCommand<sup>10+</sup> 6424 6425sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void 6426 6427Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result. 6428 6429**System capability**: SystemCapability.Multimedia.AVSession.Core 6430 6431**Parameters** 6432 6433| Name | Type | Mandatory| Description | 6434| ------- | ------------------------------------- | ---- | ------------------------------ | 6435| command | string | Yes | Name of the custom control command.| 6436| args | {[key: string]: Object} | Yes | Parameters in key-value pair format carried in the custom control command.| 6437| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object. | 6438 6439> **NOTE** 6440> 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). 6441 6442**Error codes** 6443 6444For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6445 6446| ID| Error Message| 6447| -------- | ------------------------------- | 6448| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.| 6449| 6600101 | Session service exception. | 6450| 6600102 | The session does not exist. | 6451| 6600103 | The session controller does not exist. | 6452| 6600105 | Invalid session command. | 6453| 6600106 | The session is not activated. | 6454| 6600107 | Too many commands or events. | 6455 6456**Example** 6457 6458```ts 6459import { BusinessError } from '@kit.BasicServicesKit'; 6460let avSessionController: avSession.AVSessionController | undefined = undefined; 6461let currentAVSession: avSession.AVSession | undefined = undefined; 6462let tag = "createNewSession"; 6463let context: Context = getContext(this); 6464 6465avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6466 if (err) { 6467 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6468 } else { 6469 currentAVSession = data; 6470 } 6471}); 6472if (currentAVSession !== undefined) { 6473 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6474 avSessionController = controller; 6475 }).catch((err: BusinessError) => { 6476 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6477 }); 6478} 6479 6480let commandName = "my_command"; 6481if (avSessionController !== undefined) { 6482 (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => { 6483 if (err) { 6484 console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); 6485 } 6486 }) 6487} 6488``` 6489 6490### getExtras<sup>10+</sup> 6491 6492getExtras(): Promise\<{[key: string]: Object}> 6493 6494Obtains the custom media packet set by the provider. This API uses a promise to return the result. 6495 6496**Atomic service API**: This API can be used in atomic services since API version 12. 6497 6498**System capability**: SystemCapability.Multimedia.AVSession.Core 6499 6500**Return value** 6501 6502| Type | Description | 6503| ----------------------------------- | ----------------------------- | 6504| 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**.| 6505 6506**Error codes** 6507 6508For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6509 6510| ID| Error Message| 6511| -------- | ---------------------------------------- | 6512| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6513| 6600101 | Session service exception. | 6514| 6600102 | The session does not exist. | 6515| 6600103 | The session controller does not exist. | 6516| 6600105 | Invalid session command. | 6517| 6600107 | Too many commands or events. | 6518 6519**Example** 6520 6521```ts 6522import { BusinessError } from '@kit.BasicServicesKit'; 6523 6524let avSessionController: avSession.AVSessionController | undefined = undefined; 6525let currentAVSession: avSession.AVSession | undefined = undefined; 6526let tag = "createNewSession"; 6527let context: Context = getContext(this); 6528 6529avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6530 if (err) { 6531 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6532 } else { 6533 currentAVSession = data; 6534 } 6535}); 6536if (currentAVSession !== undefined) { 6537 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6538 avSessionController = controller; 6539 }).catch((err: BusinessError) => { 6540 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6541 }); 6542} 6543 6544if (avSessionController !== undefined) { 6545 (avSessionController as avSession.AVSessionController).getExtras().then((extras) => { 6546 console.info(`getExtras : SUCCESS : ${extras}`); 6547 }).catch((err: BusinessError) => { 6548 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 6549 }); 6550} 6551``` 6552 6553### getExtras<sup>10+</sup> 6554 6555getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void 6556 6557Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result. 6558 6559**System capability**: SystemCapability.Multimedia.AVSession.Core 6560 6561**Parameters** 6562 6563| Name | Type | Mandatory| Description | 6564| -------- | ----------------------------------------- | ---- | -------------------------- | 6565| 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**.| 6566 6567**Error codes** 6568 6569For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6570 6571| ID| Error Message| 6572| -------- | ---------------------------------------- | 6573| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. | 6574| 6600101 | Session service exception. | 6575| 6600102 | The session does not exist. | 6576| 6600103 | The session controller does not exist. | 6577| 6600105 | Invalid session command. | 6578| 6600107 | Too many commands or events. | 6579 6580**Example** 6581 6582```ts 6583import { BusinessError } from '@kit.BasicServicesKit'; 6584 6585let avSessionController: avSession.AVSessionController | undefined = undefined; 6586let currentAVSession: avSession.AVSession | undefined = undefined; 6587let tag = "createNewSession"; 6588let context: Context = getContext(this); 6589 6590avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 6591 if (err) { 6592 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 6593 } else { 6594 currentAVSession = data; 6595 } 6596}); 6597if (currentAVSession !== undefined) { 6598 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 6599 avSessionController = controller; 6600 }).catch((err: BusinessError) => { 6601 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 6602 }); 6603} 6604 6605if (avSessionController !== undefined) { 6606 (avSessionController as avSession.AVSessionController).getExtras((err, extras) => { 6607 if (err) { 6608 console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); 6609 } else { 6610 console.info(`getExtras : SUCCESS : ${extras}`); 6611 } 6612 }); 6613} 6614``` 6615 6616### on('metadataChange')<sup>10+</sup> 6617 6618on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void) 6619 6620Subscribes to metadata change events. 6621 6622**Atomic service API**: This API can be used in atomic services since API version 12. 6623 6624**System capability**: SystemCapability.Multimedia.AVSession.Core 6625 6626**Parameters** 6627 6628| Name | Type | Mandatory| Description | 6629| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 6630| type | string | Yes | Event type. The event **'metadataChange'** is triggered when the session metadata changes.| 6631| 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.| 6632| callback | (data: [AVMetadata](#avmetadata10)) => void | Yes | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata. | 6633 6634**Error codes** 6635 6636For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6637 6638| ID| Error Message| 6639| -------- | ------------------------------ | 6640| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6641| 6600101 | Session service exception. | 6642| 6600103 | The session controller does not exist. | 6643 6644**Example** 6645 6646```ts 6647avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => { 6648 console.info(`on metadataChange assetId : ${metadata.assetId}`); 6649}); 6650 6651avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => { 6652 console.info(`on metadataChange assetId : ${metadata.assetId}`); 6653}); 6654 6655``` 6656 6657### off('metadataChange')<sup>10+</sup> 6658 6659off(type: 'metadataChange', callback?: (data: AVMetadata) => void) 6660 6661Unsubscribes from metadata change events. This API is called by the controller. 6662 6663**Atomic service API**: This API can be used in atomic services since API version 12. 6664 6665**System capability**: SystemCapability.Multimedia.AVSession.Core 6666 6667**Parameters** 6668 6669| Name | Type | Mandatory| Description | 6670| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 6671| type | string | Yes | Event type, which is **'metadataChange'** in this case. | 6672| 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. | 6673 6674**Error codes** 6675 6676For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6677 6678| ID| Error Message| 6679| -------- | ---------------- | 6680| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6681| 6600101 | Session service exception. | 6682| 6600103 | The session controller does not exist. | 6683 6684**Example** 6685 6686```ts 6687avsessionController.off('metadataChange'); 6688``` 6689 6690### on('playbackStateChange')<sup>10+</sup> 6691 6692on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void) 6693 6694Subscribes to playback state change events. 6695 6696**Atomic service API**: This API can be used in atomic services since API version 12. 6697 6698**System capability**: SystemCapability.Multimedia.AVSession.Core 6699 6700**Parameters** 6701 6702| Name | Type | Mandatory| Description | 6703| --------| -----------|-----|------------| 6704| type | string | Yes | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.| 6705| 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.| 6706| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | Yes | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.| 6707 6708**Error codes** 6709 6710For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6711 6712| ID| Error Message| 6713| -------- | ------------------------------ | 6714| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6715| 6600101 | Session service exception. | 6716| 6600103 | The session controller does not exist. | 6717 6718**Example** 6719 6720```ts 6721avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => { 6722 console.info(`on playbackStateChange state : ${playbackState.state}`); 6723}); 6724 6725avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => { 6726 console.info(`on playbackStateChange state : ${playbackState.state}`); 6727}); 6728``` 6729 6730### off('playbackStateChange')<sup>10+</sup> 6731 6732off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) 6733 6734Unsubscribes from playback state change events. This API is called by the controller. 6735 6736**Atomic service API**: This API can be used in atomic services since API version 12. 6737 6738**System capability**: SystemCapability.Multimedia.AVSession.Core 6739 6740**Parameters** 6741 6742| Name | Type | Mandatory| Description | 6743| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6744| type | string | Yes | Event type, which is **'playbackStateChange'** in this case. | 6745| 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. | 6746 6747**Error codes** 6748 6749For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6750 6751| ID| Error Message| 6752| -------- | ---------------- | 6753| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6754| 6600101 | Session service exception. | 6755| 6600103 | The session controller does not exist. | 6756 6757**Example** 6758 6759```ts 6760avsessionController.off('playbackStateChange'); 6761``` 6762 6763### on('callMetadataChange')<sup>11+</sup> 6764 6765on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void; 6766 6767Subscribes to call metadata change events. 6768 6769**Atomic service API**: This API can be used in atomic services since API version 12. 6770 6771**System capability**: SystemCapability.Multimedia.AVSession.Core 6772 6773**Parameters** 6774 6775| Name | Type | Mandatory| Description | 6776| --------| -----------|-----|------------| 6777| type | string | Yes | Event type. The event **'callMetadataChange'** is triggered when the call metadata changes.| 6778| 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.| 6779| callback | Callback<[CallMetadata](#callmetadata11)\>\> | Yes | Callback used for subscription. The **callmetadata** parameter in the callback indicates the changed call metadata.| 6780 6781**Error codes** 6782 6783For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6784 6785| ID| Error Message| 6786| -------- | ------------------------------ | 6787| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6788| 6600101 | Session service exception. | 6789| 6600103 | The session controller does not exist. | 6790 6791**Example** 6792 6793```ts 6794avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => { 6795 console.info(`on callMetadataChange state : ${callmetadata.name}`); 6796}); 6797 6798avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => { 6799 console.info(`on callMetadataChange state : ${callmetadata.name}`); 6800}); 6801``` 6802 6803### off('callMetadataChange')<sup>11+</sup> 6804 6805off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void; 6806 6807Unsubscribes from call metadata change events. 6808 6809**Atomic service API**: This API can be used in atomic services since API version 12. 6810 6811**System capability**: SystemCapability.Multimedia.AVSession.Core 6812 6813**Parameters** 6814 6815| Name | Type | Mandatory| Description | 6816| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6817| type | string | Yes | Event type, which is **'callMetadataChange'** in this case. | 6818| 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. | 6819 6820**Error codes** 6821 6822For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6823 6824| ID| Error Message| 6825| -------- | ---------------- | 6826| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6827| 6600101 | Session service exception. | 6828| 6600103 | The session controller does not exist. | 6829 6830**Example** 6831 6832```ts 6833avsessionController.off('callMetadataChange'); 6834``` 6835 6836### on('callStateChange')<sup>11+</sup> 6837 6838on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void; 6839 6840Subscribes to call state change events. 6841 6842**Atomic service API**: This API can be used in atomic services since API version 12. 6843 6844**System capability**: SystemCapability.Multimedia.AVSession.Core 6845 6846**Parameters** 6847 6848| Name | Type | Mandatory| Description | 6849| --------| -----------|-----|------------| 6850| type | string | Yes | Event type. The event **'callStateChange'** is triggered when the call state changes.| 6851| 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.| 6852| callback | Callback<[AVCallState](#avcallstate11)\> | Yes | Callback function, where the **callstate** parameter indicates the new call state.| 6853 6854**Error codes** 6855 6856For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6857 6858| ID| Error Message| 6859| -------- | ------------------------------ | 6860| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6861| 6600101 | Session service exception. | 6862| 6600103 | The session controller does not exist. | 6863 6864**Example** 6865 6866```ts 6867avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => { 6868 console.info(`on callStateChange state : ${callstate.state}`); 6869}); 6870 6871avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => { 6872 console.info(`on callStateChange state : ${callstate.state}`); 6873}); 6874``` 6875 6876### off('callStateChange')<sup>11+</sup> 6877 6878off(type: 'callStateChange', callback?: Callback\<AVCallState>): void; 6879 6880Unsubscribes from call state change events. 6881 6882**Atomic service API**: This API can be used in atomic services since API version 12. 6883 6884**System capability**: SystemCapability.Multimedia.AVSession.Core 6885 6886**Parameters** 6887 6888| Name | Type | Mandatory| Description | 6889| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 6890| type | string | Yes | Event type, which is **'callStateChange'** in this case. | 6891| 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. | 6892 6893**Error codes** 6894 6895For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6896 6897| ID| Error Message| 6898| -------- | ---------------- | 6899| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6900| 6600101 | Session service exception. | 6901| 6600103 | The session controller does not exist. | 6902 6903**Example** 6904 6905```ts 6906avsessionController.off('callMetadataChange'); 6907``` 6908 6909### on('sessionDestroy')<sup>10+</sup> 6910 6911on(type: 'sessionDestroy', callback: () => void) 6912 6913Subscribes to session destruction events. 6914 6915**Atomic service API**: This API can be used in atomic services since API version 12. 6916 6917**System capability**: SystemCapability.Multimedia.AVSession.Core 6918 6919**Parameters** 6920 6921| Name | Type | Mandatory| Description | 6922| -------- | ---------- | ---- | ------------------------------------------------------------ | 6923| type | string | Yes | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.| 6924| callback | () => void | Yes | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. | 6925 6926**Error codes** 6927 6928For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6929 6930| ID| Error Message| 6931| -------- | ------------------------------ | 6932| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6933| 6600101 | Session service exception. | 6934| 6600103 | The session controller does not exist. | 6935 6936**Example** 6937 6938```ts 6939avsessionController.on('sessionDestroy', () => { 6940 console.info('on sessionDestroy : SUCCESS '); 6941}); 6942``` 6943 6944### off('sessionDestroy')<sup>10+</sup> 6945 6946off(type: 'sessionDestroy', callback?: () => void) 6947 6948Unsubscribes from session destruction events. This API is called by the controller. 6949 6950**Atomic service API**: This API can be used in atomic services since API version 12. 6951 6952**System capability**: SystemCapability.Multimedia.AVSession.Core 6953 6954**Parameters** 6955 6956| Name | Type | Mandatory| Description | 6957| -------- | ---------- | ---- | ----------------------------------------------------- | 6958| type | string | Yes | Event type, which is **'sessionDestroy'** in this case. | 6959| 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. | 6960 6961**Error codes** 6962 6963For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6964 6965| ID| Error Message| 6966| -------- | ---------------- | 6967| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 6968| 6600101 | Session service exception. | 6969| 6600103 | The session controller does not exist. | 6970 6971**Example** 6972 6973```ts 6974avsessionController.off('sessionDestroy'); 6975``` 6976 6977### on('activeStateChange')<sup>10+</sup> 6978 6979on(type: 'activeStateChange', callback: (isActive: boolean) => void) 6980 6981Subscribes to session activation state change events. 6982 6983**Atomic service API**: This API can be used in atomic services since API version 12. 6984 6985**System capability**: SystemCapability.Multimedia.AVSession.Core 6986 6987**Parameters** 6988 6989| Name | Type | Mandatory| Description | 6990| -------- | --------------------------- | ---- | ------------------------------------------------------------ | 6991| type | string | Yes | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes.| 6992| 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. | 6993 6994**Error codes** 6995 6996For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 6997 6998| ID| Error Message| 6999| -------- | ----------------------------- | 7000| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7001| 6600101 | Session service exception. | 7002| 6600103 |The session controller does not exist. | 7003 7004**Example** 7005 7006```ts 7007avsessionController.on('activeStateChange', (isActive: boolean) => { 7008 console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); 7009}); 7010``` 7011 7012### off('activeStateChange')<sup>10+</sup> 7013 7014off(type: 'activeStateChange', callback?: (isActive: boolean) => void) 7015 7016Unsubscribes from session activation state change events. This API is called by the controller. 7017 7018**Atomic service API**: This API can be used in atomic services since API version 12. 7019 7020**System capability**: SystemCapability.Multimedia.AVSession.Core 7021 7022**Parameters** 7023 7024| Name | Type | Mandatory| Description | 7025| -------- | --------------------------- | ---- | ----------------------------------------------------- | 7026| type | string | Yes | Event type, which is **'activeStateChange'** in this case. | 7027| 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. | 7028 7029**Error codes** 7030 7031For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7032 7033| ID| Error Message| 7034| -------- | ---------------- | 7035| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7036| 6600101 | Session service exception. | 7037| 6600103 | The session controller does not exist. | 7038 7039**Example** 7040 7041```ts 7042avsessionController.off('activeStateChange'); 7043``` 7044 7045### on('validCommandChange')<sup>10+</sup> 7046 7047on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void) 7048 7049Subscribes to valid command change events. 7050 7051**Atomic service API**: This API can be used in atomic services since API version 12. 7052 7053**System capability**: SystemCapability.Multimedia.AVSession.Core 7054 7055**Parameters** 7056 7057| Name | Type | Mandatory| Description | 7058| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7059| type | string | Yes | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.| 7060| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands. | 7061 7062**Error codes** 7063 7064For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7065 7066| ID| Error Message| 7067| -------- | ------------------------------ | 7068| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7069| 6600101 | Session service exception. | 7070| 6600103 | The session controller does not exist. | 7071 7072**Example** 7073 7074```ts 7075avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => { 7076 console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`); 7077 console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); 7078}); 7079``` 7080 7081### off('validCommandChange')<sup>10+</sup> 7082 7083off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void) 7084 7085Unsubscribes from valid command change events. This API is called by the controller. 7086 7087**Atomic service API**: This API can be used in atomic services since API version 12. 7088 7089**System capability**: SystemCapability.Multimedia.AVSession.Core 7090 7091**Parameters** 7092 7093| Name | Type | Mandatory| Description | 7094| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | 7095| type | string | Yes | Event type, which is **'validCommandChange'** in this case. | 7096| 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. | 7097 7098**Error codes** 7099 7100For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7101 7102| ID| Error Message | 7103| -------- | ---------------- | 7104| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7105| 6600101 | Session service exception. | 7106| 6600103 | The session controller does not exist. | 7107 7108**Example** 7109 7110```ts 7111avsessionController.off('validCommandChange'); 7112``` 7113 7114### on('outputDeviceChange')<sup>10+</sup> 7115 7116on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7117 7118Subscribes to output device change events. 7119 7120**Atomic service API**: This API can be used in atomic services since API version 12. 7121 7122**System capability**: SystemCapability.Multimedia.AVSession.Core 7123 7124**Parameters** 7125 7126| Name | Type | Mandatory| Description | 7127| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | 7128| type | string | Yes | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.| 7129| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes | Callback used for subscription. The **device** parameter in the callback indicates the output device information. | 7130 7131**Error codes** 7132 7133For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7134 7135| ID| Error Message| 7136| -------- | ----------------------- | 7137| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7138| 6600101 | Session service exception. | 7139| 6600103 | The session controller does not exist. | 7140 7141**Example** 7142 7143```ts 7144avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => { 7145 console.info(`on outputDeviceChange state: ${state}, device : ${device}`); 7146}); 7147``` 7148 7149### off('outputDeviceChange')<sup>10+</sup> 7150 7151off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void 7152 7153Unsubscribes from output device change events. This API is called by the controller. 7154 7155**Atomic service API**: This API can be used in atomic services since API version 12. 7156 7157**System capability**: SystemCapability.Multimedia.AVSession.Core 7158 7159**Parameters** 7160 7161| Name | Type | Mandatory| Description | 7162| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | 7163| type | string | Yes | Event type, which is **'outputDeviceChange'** in this case. | 7164| 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. | 7165 7166**Error codes** 7167 7168For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7169 7170| ID | Error Message | 7171| -------- | ---------------- | 7172| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7173| 6600101 | Session service exception. | 7174| 6600103 | The session controller does not exist. | 7175 7176**Example** 7177 7178```ts 7179avsessionController.off('outputDeviceChange'); 7180``` 7181 7182### on('sessionEvent')<sup>10+</sup> 7183 7184on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void 7185 7186Subscribes to session event change events. This API is called by the controller. 7187 7188**Atomic service API**: This API can be used in atomic services since API version 12. 7189 7190**System capability**: SystemCapability.Multimedia.AVSession.Core 7191 7192**Parameters** 7193 7194| Name | Type | Mandatory| Description | 7195| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7196| type | string | Yes | Event type. The event **'sessionEvent'** is triggered when the session event changes.| 7197| 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. | 7198 7199**Error codes** 7200 7201For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7202 7203| ID| Error Message| 7204| -------- | ------------------------------ | 7205| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7206| 6600101 | Session service exception. | 7207| 6600103 | The session controller does not exist. | 7208 7209**Example** 7210 7211```ts 7212import { BusinessError } from '@kit.BasicServicesKit'; 7213 7214let avSessionController: avSession.AVSessionController | undefined = undefined; 7215let currentAVSession: avSession.AVSession | undefined = undefined; 7216let tag = "createNewSession"; 7217let context: Context = getContext(this); 7218 7219avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 7220 if (err) { 7221 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 7222 } else { 7223 currentAVSession = data; 7224 } 7225}); 7226if (currentAVSession !== undefined) { 7227 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 7228 avSessionController = controller; 7229 }).catch((err: BusinessError) => { 7230 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 7231 }); 7232} 7233 7234if (avSessionController !== undefined) { 7235 (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => { 7236 console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); 7237 }); 7238} 7239``` 7240 7241### off('sessionEvent')<sup>10+</sup> 7242 7243off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void 7244 7245Unsubscribes from session event change events. This API is called by the controller. 7246 7247**Atomic service API**: This API can be used in atomic services since API version 12. 7248 7249**System capability**: SystemCapability.Multimedia.AVSession.Core 7250 7251**Parameters** 7252 7253| Name | Type | Mandatory| Description | 7254| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | 7255| type | string | Yes | Event type, which is **'sessionEvent'** in this case. | 7256| 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. | 7257 7258**Error codes** 7259 7260For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7261 7262| ID| Error Message| 7263| -------- | ---------------- | 7264| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7265| 6600101 | Session service exception. | 7266| 6600103 | The session controller does not exist. | 7267 7268**Example** 7269 7270```ts 7271avsessionController.off('sessionEvent'); 7272``` 7273 7274### on('queueItemsChange')<sup>10+</sup> 7275 7276on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7277 7278Subscribes to playlist item change events. This API is called by the controller. 7279 7280**Atomic service API**: This API can be used in atomic services since API version 12. 7281 7282**System capability**: SystemCapability.Multimedia.AVSession.Core 7283 7284**Parameters** 7285 7286| Name | Type | Mandatory| Description | 7287| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | 7288| type | string | Yes | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.| 7289| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | Yes | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist. | 7290 7291**Error codes** 7292 7293For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7294 7295| ID| Error Message| 7296| -------- | ------------------------------ | 7297| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7298| 6600101 | Session service exception. | 7299| 6600103 | The session controller does not exist. | 7300 7301**Example** 7302 7303```ts 7304avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => { 7305 console.info(`OnQueueItemsChange, items length is ${items.length}`); 7306}); 7307``` 7308 7309### off('queueItemsChange')<sup>10+</sup> 7310 7311off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void 7312 7313Unsubscribes from playback item change events. This API is called by the controller. 7314 7315**Atomic service API**: This API can be used in atomic services since API version 12. 7316 7317**System capability**: SystemCapability.Multimedia.AVSession.Core 7318 7319**Parameters** 7320 7321| Name | Type | Mandatory| Description | 7322| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | 7323| type | string | Yes | Event type, which is **'queueItemsChange'** in this case. | 7324| 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.| 7325 7326**Error codes** 7327 7328For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7329 7330| ID| Error Message| 7331| -------- | ---------------- | 7332| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7333| 6600101 | Session service exception. | 7334| 6600103 | The session controller does not exist. | 7335 7336**Example** 7337 7338```ts 7339avsessionController.off('queueItemsChange'); 7340``` 7341 7342### on('queueTitleChange')<sup>10+</sup> 7343 7344on(type: 'queueTitleChange', callback: (title: string) => void): void 7345 7346Subscribes to playlist name change events. This API is called by the controller. 7347 7348**Atomic service API**: This API can be used in atomic services since API version 12. 7349 7350**System capability**: SystemCapability.Multimedia.AVSession.Core 7351 7352**Parameters** 7353 7354| Name | Type | Mandatory| Description | 7355| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | 7356| type | string | Yes | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.| 7357| callback | (title: string) => void | Yes | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name. | 7358 7359**Error codes** 7360 7361For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7362 7363| ID| Error Message| 7364| -------- | ------------------------------ | 7365| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7366| 6600101 | Session service exception. | 7367| 6600103 | The session controller does not exist. | 7368 7369**Example** 7370 7371```ts 7372avsessionController.on('queueTitleChange', (title: string) => { 7373 console.info(`queueTitleChange, title is ${title}`); 7374}); 7375``` 7376 7377### off('queueTitleChange')<sup>10+</sup> 7378 7379off(type: 'queueTitleChange', callback?: (title: string) => void): void 7380 7381Unsubscribes from playlist name change events. This API is called by the controller. 7382 7383**Atomic service API**: This API can be used in atomic services since API version 12. 7384 7385**System capability**: SystemCapability.Multimedia.AVSession.Core 7386 7387**Parameters** 7388 7389| Name | Type | Mandatory| Description | 7390| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7391| type | string | Yes | Event type, which is **'queueTitleChange'** in this case. | 7392| 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.| 7393 7394**Error codes** 7395 7396For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7397 7398| ID| Error Message| 7399| -------- | ---------------- | 7400| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7401| 6600101 | Session service exception. | 7402| 6600103 | The session controller does not exist. | 7403 7404**Example** 7405 7406```ts 7407avsessionController.off('queueTitleChange'); 7408``` 7409 7410### on('extrasChange')<sup>10+</sup> 7411 7412on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void 7413 7414Subscribes to custom media packet change events. This API is called by the controller. 7415 7416**Atomic service API**: This API can be used in atomic services since API version 12. 7417 7418**System capability**: SystemCapability.Multimedia.AVSession.Core 7419 7420**Parameters** 7421 7422| Name | Type | Mandatory| Description | 7423| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | 7424| type | string | Yes | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.| 7425| 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**. | 7426 7427**Error codes** 7428 7429For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7430 7431| ID| Error Message| 7432| -------- | ------------------------------ | 7433| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7434| 6600101 | Session service exception. | 7435| 6600103 | The session controller does not exist. | 7436 7437**Example** 7438 7439```ts 7440import { BusinessError } from '@kit.BasicServicesKit'; 7441 7442let avSessionController: avSession.AVSessionController | undefined = undefined; 7443let currentAVSession: avSession.AVSession | undefined = undefined; 7444let tag = "createNewSession"; 7445let context: Context = getContext(this); 7446 7447avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => { 7448 if (err) { 7449 console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); 7450 } else { 7451 currentAVSession = data; 7452 } 7453}); 7454if (currentAVSession !== undefined) { 7455 avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => { 7456 avSessionController = controller; 7457 }).catch((err: BusinessError) => { 7458 console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); 7459 }); 7460} 7461 7462if (avSessionController !== undefined) { 7463 (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => { 7464 console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); 7465 }); 7466} 7467``` 7468 7469### off('extrasChange')<sup>10+</sup> 7470 7471off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void 7472 7473Unsubscribes from custom media packet change events. This API is called by the controller. 7474 7475**Atomic service API**: This API can be used in atomic services since API version 12. 7476 7477**System capability**: SystemCapability.Multimedia.AVSession.Core 7478 7479**Parameters** 7480 7481| Name | Type | Mandatory| Description | 7482| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | 7483| type | string | Yes | Event type, which is **'extrasChange'** in this case. | 7484| callback | ({[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.| 7485 7486**Error codes** 7487 7488For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7489 7490| ID| Error Message| 7491| -------- | ---------------- | 7492| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 7493| 6600101 | Session service exception. | 7494| 6600103 | The session controller does not exist. | 7495 7496**Example** 7497 7498```ts 7499avsessionController.off('extrasChange'); 7500``` 7501 7502### getAVPlaybackStateSync<sup>10+</sup> 7503 7504getAVPlaybackStateSync(): AVPlaybackState; 7505 7506Obtains the playback state of this session. This API returns the result synchronously. 7507 7508**Atomic service API**: This API can be used in atomic services since API version 12. 7509 7510**System capability**: SystemCapability.Multimedia.AVSession.Core 7511 7512**Return value** 7513 7514| Type | Description | 7515| --------- | ------------------------------------------------------------ | 7516| [AVPlaybackState](#avplaybackstate10) | Playback state of the session.| 7517 7518**Error codes** 7519 7520For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7521 7522| ID| Error Message| 7523| -------- | ---------------------------------------- | 7524| 6600101 | Session service exception. | 7525| 6600102 | The session does not exist. | 7526| 6600103 | The session controller does not exist. | 7527 7528**Example** 7529 7530```ts 7531import { BusinessError } from '@kit.BasicServicesKit'; 7532 7533try { 7534 let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync(); 7535} catch (err) { 7536 let error = err as BusinessError; 7537 console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`); 7538} 7539``` 7540 7541### getAVMetadataSync<sup>10+</sup> 7542 7543getAVMetadataSync(): AVMetadata 7544 7545Obtains the session metadata. This API returns the result synchronously. 7546 7547**Atomic service API**: This API can be used in atomic services since API version 12. 7548 7549**System capability**: SystemCapability.Multimedia.AVSession.Core 7550 7551**Return value** 7552 7553| Type | Description | 7554| ----------------------------------- | ----------------------------- | 7555| [AVMetadata](#avmetadata10) | Session metadata.| 7556 7557**Error codes** 7558 7559For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7560 7561| ID| Error Message| 7562| -------- | ---------------------------------------- | 7563| 6600101 | Session service exception. | 7564| 6600102 | The session does not exist. | 7565| 6600103 | The session controller does not exist. | 7566 7567**Example** 7568```ts 7569import { BusinessError } from '@kit.BasicServicesKit'; 7570 7571try { 7572 let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync(); 7573} catch (err) { 7574 let error = err as BusinessError; 7575 console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`); 7576} 7577``` 7578 7579### getAVCallState<sup>11+</sup> 7580 7581getAVCallState(): Promise\<AVCallState> 7582 7583Obtains the call state. This API uses a promise to return the result. 7584 7585**System capability**: SystemCapability.Multimedia.AVSession.Core 7586 7587**Return value** 7588 7589| Type | Description | 7590| ----------------------------------- | ----------------------------- | 7591| Promise<[AVCallState](#avcallstate11)\> | Promise used to return the call state obtained.| 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| 6600101 | Session service exception. | 7600| 6600102 | The session does not exist. | 7601| 6600103 | The session controller does not exist. | 7602 7603**Example** 7604 7605```ts 7606import { BusinessError } from '@kit.BasicServicesKit'; 7607 7608avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => { 7609 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 7610}).catch((err: BusinessError) => { 7611 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 7612}); 7613``` 7614 7615### getAVCallState<sup>11+</sup> 7616 7617getAVCallState(callback: AsyncCallback\<AVCallState>): void 7618 7619Obtains the call state. This API uses an asynchronous callback to return the result. 7620 7621**System capability**: SystemCapability.Multimedia.AVSession.Core 7622 7623**Parameters** 7624 7625| Name | Type | Mandatory| Description | 7626| -------- | ----------------------------------------- | ---- | -------------------------- | 7627| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | Yes | Callback used to return the call state obtained.| 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| 6600101 | Session service exception. | 7636| 6600102 | The session does not exist. | 7637| 6600103 | The session controller does not exist. | 7638 7639**Example** 7640 7641```ts 7642import { BusinessError } from '@kit.BasicServicesKit'; 7643 7644avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => { 7645 if (err) { 7646 console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`); 7647 } else { 7648 console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`); 7649 } 7650}); 7651``` 7652 7653### getCallMetadata<sup>11+</sup> 7654 7655getCallMetadata(): Promise\<CallMetadata> 7656 7657Obtains the call metadata. This API uses a promise to return the result. 7658 7659**System capability**: SystemCapability.Multimedia.AVSession.Core 7660 7661**Return value** 7662 7663| Type | Description | 7664| ----------------------------------- | ----------------------------- | 7665| Promise<[CallMetadata](#callmetadata11)\> | Promise used to return the metadata obtained.| 7666 7667**Error codes** 7668 7669For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7670 7671| ID| Error Message| 7672| -------- | ---------------------------------------- | 7673| 6600101 | Session service exception. | 7674| 6600102 | The session does not exist. | 7675| 6600103 | The session controller does not exist. | 7676 7677**Example** 7678 7679```ts 7680import { BusinessError } from '@kit.BasicServicesKit'; 7681 7682avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => { 7683 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 7684}).catch((err: BusinessError) => { 7685 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 7686}); 7687``` 7688 7689### getCallMetadata<sup>11+</sup> 7690 7691getCallMetadata(callback: AsyncCallback\<CallMetadata>): void 7692 7693Obtains the call metadata. This API uses an asynchronous callback to return the result. 7694 7695**System capability**: SystemCapability.Multimedia.AVSession.Core 7696 7697**Parameters** 7698 7699| Name | Type | Mandatory| Description | 7700| -------- | ----------------------------------------- | ---- | -------------------------- | 7701| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | Yes | Callback used to return the metadata obtained.| 7702 7703**Error codes** 7704 7705For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7706 7707| ID| Error Message| 7708| -------- | ---------------------------------------- | 7709| 6600101 | Session service exception. | 7710| 6600102 | The session does not exist. | 7711| 6600103 | The session controller does not exist. | 7712 7713**Example** 7714 7715```ts 7716import { BusinessError } from '@kit.BasicServicesKit'; 7717 7718avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => { 7719 if (err) { 7720 console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`); 7721 } else { 7722 console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`); 7723 } 7724}); 7725``` 7726 7727### getAVQueueTitleSync<sup>10+</sup> 7728 7729getAVQueueTitleSync(): string 7730 7731Obtains the name of the playlist of this session. This API returns the result synchronously. 7732 7733**Atomic service API**: This API can be used in atomic services since API version 12. 7734 7735**System capability**: SystemCapability.Multimedia.AVSession.Core 7736 7737**Return value** 7738 7739| Type | Description | 7740| ---------------- | ----------------------------- | 7741| string | Playlist name.| 7742 7743**Error codes** 7744 7745For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7746 7747| ID| Error Message| 7748| -------- | ---------------------------------------- | 7749| 6600101 | Session service exception. | 7750| 6600102 | The session does not exist. | 7751| 6600103 | The session controller does not exist. | 7752 7753**Example** 7754 7755```ts 7756import { BusinessError } from '@kit.BasicServicesKit'; 7757 7758try { 7759 let currentQueueTitle: string = avsessionController.getAVQueueTitleSync(); 7760} catch (err) { 7761 let error = err as BusinessError; 7762 console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`); 7763} 7764``` 7765 7766### getAVQueueItemsSync<sup>10+</sup> 7767 7768getAVQueueItemsSync(): Array\<AVQueueItem\> 7769 7770Obtains the information related to the items in the playlist of this session. This API returns the result synchronously. 7771 7772**Atomic service API**: This API can be used in atomic services since API version 12. 7773 7774**System capability**: SystemCapability.Multimedia.AVSession.Core 7775 7776**Return value** 7777 7778| Type | Description | 7779| --------------------------------------------- | ----------------------------- | 7780| Array<[AVQueueItem](#avqueueitem10)\> | Items in the queue.| 7781 7782**Error codes** 7783 7784For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7785 7786| ID| Error Message| 7787| -------- | ---------------------------------------- | 7788| 6600101 | Session service exception. | 7789| 6600102 | The session does not exist. | 7790| 6600103 | The session controller does not exist. | 7791 7792**Example** 7793 7794```ts 7795import { BusinessError } from '@kit.BasicServicesKit'; 7796 7797try { 7798 let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync(); 7799} catch (err) { 7800 let error = err as BusinessError; 7801 console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`); 7802} 7803``` 7804 7805### getOutputDeviceSync<sup>10+</sup> 7806 7807getOutputDeviceSync(): OutputDeviceInfo 7808 7809Obtains the output device information. This API returns the result synchronously. 7810 7811**Atomic service API**: This API can be used in atomic services since API version 12. 7812 7813**System capability**: SystemCapability.Multimedia.AVSession.Core 7814 7815**Return value** 7816 7817| Type | Description | 7818| ----------------------------------------------- | --------------------------------- | 7819| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.| 7820 7821**Error codes** 7822 7823For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7824 7825| ID| Error Message| 7826| -------- | ---------------------------------------- | 7827| 6600101 | Session service exception. | 7828| 6600103 | The session controller does not exist. | 7829 7830**Example** 7831 7832```ts 7833import { BusinessError } from '@kit.BasicServicesKit'; 7834 7835try { 7836 let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync(); 7837} catch (err) { 7838 let error = err as BusinessError; 7839 console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`); 7840} 7841``` 7842 7843### isActiveSync<sup>10+</sup> 7844 7845isActiveSync(): boolean 7846 7847Checks whether the session is activated. This API returns the result synchronously. 7848 7849**Atomic service API**: This API can be used in atomic services since API version 12. 7850 7851**System capability**: SystemCapability.Multimedia.AVSession.Core 7852 7853**Return value** 7854 7855| Type | Description | 7856| ----------------- | ------------------------------------------------------------ | 7857| boolean | Returns **true** is returned if the session is activated; returns **false** otherwise.| 7858 7859**Error codes** 7860 7861For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7862 7863| ID| Error Message| 7864| -------- | ---------------------------------------- | 7865| 6600101 | Session service exception. | 7866| 6600102 | The session does not exist. | 7867| 6600103 | The session controller does not exist. | 7868 7869**Example** 7870 7871```ts 7872import { BusinessError } from '@kit.BasicServicesKit'; 7873 7874try { 7875 let isActive: boolean = avsessionController.isActiveSync(); 7876} catch (err) { 7877 let error = err as BusinessError; 7878 console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`); 7879} 7880``` 7881 7882### getValidCommandsSync<sup>10+</sup> 7883 7884getValidCommandsSync(): Array\<AVControlCommandType\> 7885 7886Obtains valid commands supported by the session. This API returns the result synchronously. 7887 7888**Atomic service API**: This API can be used in atomic services since API version 12. 7889 7890**System capability**: SystemCapability.Multimedia.AVSession.Core 7891 7892**Return value** 7893 7894| Type | Description | 7895| ------------------------------------------------------------ | --------------------------------- | 7896| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | A set of valid commands.| 7897 7898**Error codes** 7899 7900For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 7901 7902| ID| Error Message| 7903| -------- | ---------------------------------------- | 7904| 6600101 | Session service exception. | 7905| 6600102 | The session does not exist. | 7906| 6600103 | The session controller does not exist. | 7907 7908**Example** 7909 7910```ts 7911import { BusinessError } from '@kit.BasicServicesKit'; 7912 7913try { 7914 let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync(); 7915} catch (err) { 7916 let error = err as BusinessError; 7917 console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`); 7918} 7919``` 7920 7921## AVControlCommandType<sup>10+</sup> 7922 7923type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' | 7924 'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute' 7925 7926Enumerates the commands that can be sent to a session. 7927 7928You can use the union of the strings listed in the following table. 7929 7930**Atomic service API**: This API can be used in atomic services since API version 12. 7931 7932**System capability**: SystemCapability.Multimedia.AVSession.Core 7933 7934| Type | Description | 7935| ---------------- | ------------ | 7936| 'play' | Play the media. | 7937| 'pause' | Pause the playback. | 7938| 'stop' | Stop the playback. | 7939| 'playNext' | Play the next media asset. | 7940| 'playPrevious' | Play the previous media asset. | 7941| 'fastForward' | Fast-forward. | 7942| 'rewind' | Rewind. | 7943| 'seek' | Seek to a playback position.| 7944| 'setSpeed' | Set the playback speed.| 7945| 'setLoopMode' | Set the loop mode.| 7946| 'toggleFavorite' | Favorite the media asset. | 7947| 'playFromAssetId'| Play the media asset with the specified asset ID.| 7948|'answer' | Answer a call. | 7949| 'hangUp' | The call is disconnecting. | 7950|'toggleCallMute' | Set the mute status for a call.| 7951 7952## AVControlCommand<sup>10+</sup> 7953 7954Describes the command that can be sent to the session. 7955 7956**Atomic service API**: This API can be used in atomic services since API version 12. 7957 7958**System capability**: SystemCapability.Multimedia.AVSession.Core 7959 7960| Name | Type | Mandatory| Description | 7961| --------- | ------------------------------------------------- | ---- | -------------- | 7962| command | [AVControlCommandType](#avcontrolcommandtype10) | Yes | Command. | 7963| parameter | [LoopMode](#loopmode10) | string | number | No | Parameters carried in the command.| 7964 7965 7966## AVCastPickerOptions<sup>14+</sup> 7967 7968Describes the properties related to the semi-modal window that is started for casting purposes. 7969 7970**Atomic service API**: This API can be used in atomic services since API version 14. 7971 7972**System capability**: SystemCapability.Multimedia.AVSession.AVCast 7973 7974| Name | Type | Mandatory| Description | 7975| --------------- |-------------------------| ---- |---------------------------------------------------------------------| 7976| 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'**. | 7977 7978## AVCastPickerHelper<sup>14+</sup> 7979 7980Implements 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. 7981 7982**Atomic service API**: This API can be used in atomic services since API version 14. 7983 7984**System capability**: SystemCapability.Multimedia.AVSession.AVCast 7985 7986### constructor<sup>14+</sup> 7987 7988constructor(context: Context) 7989 7990Creates an **AVCastPickerHelper** instance. For details about how to obtain the context, see [getContext](../apis-arkui/js-apis-getContext.md). 7991 7992**Atomic service API**: This API can be used in atomic services since API version 14. 7993 7994**System capability**: SystemCapability.Multimedia.AVSession.AVCast 7995 7996**Parameters** 7997 7998| Name | Type | Mandatory| Description | 7999| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8000| context | Context | Yes | Application context. (Only [UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) is supported.)| 8001 8002**Error codes** 8003 8004For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8005 8006| ID| Error Message| 8007| -------- | ---------------------------------------- | 8008| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8009| 6600101 | Session service exception. | 8010 8011**Example** 8012 8013```ts 8014import { common } from '@kit.AbilityKit'; 8015import { avSession } from '@kit.AVSessionKit'; 8016@Entry 8017@Component 8018struct Index { 8019 @State message: string = 'hello world'; 8020 8021 build() { 8022 Row() { 8023 Column() { 8024 Text(this.message) 8025 .fontSize(40) 8026 .fontWeight(FontWeight.Bold) 8027 .onClick(()=>{ 8028 let context = getContext(this) as common.Context; 8029 let avCastPicker = new avSession.AVCastPickerHelper(context); 8030 }) 8031 } 8032 .width('100%') 8033 } 8034 .height('100%') 8035 } 8036} 8037``` 8038 8039### select<sup>14+</sup> 8040 8041select(options?: AVCastPickerOptions): Promise\<void> 8042 8043Starts 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. 8044 8045**Atomic service API**: This API can be used in atomic services since API version 14. 8046 8047**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8048 8049**Parameters** 8050 8051| Name | Type | Mandatory| Description | 8052| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | 8053| options | [AVCastPickerOptions](#avcastpickeroptions14) | No | AVCastPicker selection options. If this parameter is not specified, the default value of **AVCastPickerOptions** is used.| 8054 8055**Return value** 8056 8057| Type | Description | 8058| -------------- | ----------------------------- | 8059| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.| 8060 8061**Error codes** 8062 8063For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8064 8065| ID| Error Message| 8066| -------- | ---------------------------------------- | 8067| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8068 8069**Example** 8070 8071```ts 8072import { BusinessError } from '@kit.BasicServicesKit'; 8073 8074async function avCastPicker(context: common.Context) { 8075 let avCastPickerOptions : avSession.AVCastPickerOptions = { 8076 sessionType : 'video', 8077 } 8078 let avCastPicker = new avSession.AVCastPickerHelper(context); 8079 avCastPicker.select(avCastPickerOptions).then(() => { 8080 console.info('select successfully'); 8081 }).catch((err: BusinessError) => { 8082 console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`); 8083 }); 8084} 8085``` 8086### on('pickerStateChange')<sup>14+</sup> 8087 8088on(type: 'pickerStateChange', callback: Callback<AVCastPickerState\>) : void 8089 8090Subscribes to semi-modal window change events. 8091 8092**Atomic service API**: This API can be used in atomic services since API version 14. 8093 8094**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8095 8096**Parameters** 8097 8098| Name | Type | Mandatory| Description | 8099| --------| -----------|-----|------------| 8100| type | string | Yes | Event type. The event **'pickerStateChange'** is triggered when the semi-modal window changes.| 8101| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | Yes | Callback function, where the **state** parameter indicates the new state of the semi-modal window.| 8102 8103**Error codes** 8104 8105For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8106 8107| ID| Error Message| 8108| -------- | ---------------------------------------- | 8109| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8110| 6600101 | Session service exception. | 8111 8112**Example** 8113 8114```ts 8115import { AVCastPickerState } from '@kit.AVSessionKit'; 8116 8117avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => { 8118 console.info(`picker state change : ${state}`); 8119}); 8120``` 8121 8122### off('pickerStateChange')<sup>14+</sup> 8123 8124off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState\>) : void 8125 8126Unsubscribes from semi-modal window change events. After the unsubscription, the event callback is not triggered. 8127 8128**Atomic service API**: This API can be used in atomic services since API version 14. 8129 8130**System capability**: SystemCapability.Multimedia.AVSession.AVCast 8131 8132**Parameters** 8133 8134| Name | Type | Mandatory| Description | 8135| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | 8136| type | string | Yes | Event type, which is **'pickerStateChange'** in this case. | 8137| 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. | 8138 8139**Error codes** 8140 8141For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md). 8142 8143| ID| Error Message| 8144| -------- | ---------------------------------------- | 8145| 401 | parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. | 8146| 6600101 | Session service exception. | 8147 8148**Example** 8149 8150```ts 8151avCastPicker.off('pickerStateChange'); 8152``` 8153 8154## AVSessionErrorCode<sup>10+</sup> 8155 8156Enumerates the error codes used in the media session. 8157 8158| Name | Value | Description | 8159| -------------------------------------- | ------- | ------------------------------- | 8160| 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| 8161| 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| 8162| 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| 8163| 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| 8164| 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| 8165| 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| 8166| 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| 8167| 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| 8168| 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| 8169| 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| 8170| 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| 8171| 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| 8172| 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| 8173| 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| 8174| 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| 8175| 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| 8176| 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| 8177| 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| 8178| 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| 8179| 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| 8180| 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| 8181| 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| 8182| 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| 8183| 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| 8184| 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| 8185| 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| 8186| 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| 8187| 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| 8188| 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| 8189| 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| 8190| 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| 8191| 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| 8192| 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| 8193| 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| 8194| 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| 8195| 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| 8196| 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| 8197| 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| 8198| 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| 8199| 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| 8200| 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| 8201| 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| 8202| 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| 8203| 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| 8204| 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| 8205| 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| 8206| 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| 8207| 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| 8208| 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| 8209| 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| 8210| 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| 8211| 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| 8212| 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| 8213| 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| 8214| 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| 8215| 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| 8216| 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| 8217| 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| 8218| 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| 8219| 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| 8220| 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| 8221| 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| 8222| 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| 8223| 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| 8224 8225## SkipIntervals<sup>11+</sup> 8226 8227Enumerates the fast-forward or rewind intervals supported by the media session. 8228 8229**System capability**: SystemCapability.Multimedia.AVSession.Core 8230 8231| Name | Value| Description | 8232| ---------------------- | -- | ----------------------- | 8233| SECONDS_10 | 10 | The time is 10 seconds. | 8234| SECONDS_15 | 15 | The time is 15 seconds. | 8235| SECONDS_30 | 30 | The time is 30 seconds. | 8236