• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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## DistributedSessionType<sup>18+</sup>
135
136Enumerates the session types supported by the remote distributed device.
137
138**Atomic service API**: This API can be used in atomic services since API version 18.
139
140**System capability**: SystemCapability.Multimedia.AVSession.AVCast
141
142| Name                                    | Value| Description                       |
143|----------------------------------------|---|---------------------------|
144| TYPE_SESSION_REMOTE      | 0 | Session on the remote device.      |
145| TYPE_SESSION_MIGRATE_IN  | 1 | Session migrated to the local device.|
146| TYPE_SESSION_MIGRATE_OUT | 2 | Session migrated to the remote device.|
147
148## AVSessionType<sup>10+<sup>
149
150type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'
151
152Enumerates the session types supported by the session.
153
154You can use the strings listed in the following table.
155
156**Atomic service API**: This API can be used in atomic services since API version 12.
157
158**System capability**: SystemCapability.Multimedia.AVSession.Core
159
160| Type | Description|
161| -----  | ---- |
162| 'audio' | Audio session.|
163| 'video' | Video session.|
164| 'voice_call'<sup>11+<sup> | Voice call.|
165| 'video_call'<sup>12+<sup> | Video call.|
166
167## AVSession<sup>10+</sup>
168
169An **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.
170
171### Properties
172
173**Atomic service API**: This API can be used in atomic services since API version 12.
174
175**System capability**: SystemCapability.Multimedia.AVSession.Core
176
177| Name     | Type  | Readable| Writable| Description                         |
178| :-------- | :----- | :--- | :--- | :---------------------------- |
179| sessionId | string | Yes  | No  | Unique session ID of the **AVSession** object.|
180| sessionType| [AVSessionType](#avsessiontype10) | Yes  | No  | AVSession type.|
181
182**Example**
183
184```ts
185let sessionId: string = currentAVSession.sessionId;
186let sessionType: avSession.AVSessionType = currentAVSession.sessionType;
187```
188
189### setAVMetadata<sup>10+</sup>
190
191setAVMetadata(data: AVMetadata): Promise\<void>
192
193Sets session metadata. This API uses a promise to return the result.
194
195**Atomic service API**: This API can be used in atomic services since API version 12.
196
197**System capability**: SystemCapability.Multimedia.AVSession.Core
198
199**Parameters**
200
201| Name| Type                     | Mandatory| Description        |
202| ------ | ------------------------- | ---- | ------------ |
203| data   | [AVMetadata](#avmetadata10) | Yes  | Session metadata.|
204
205**Return value**
206
207| Type          | Description                         |
208| -------------- | ----------------------------- |
209| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
210
211**Error codes**
212
213For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
214
215| ID| Error Message|
216| -------- | ---------------------------------------- |
217| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
218| 6600101  | Session service exception. |
219| 6600102  | The session does not exist. |
220
221**Example**
222
223```ts
224import { BusinessError } from '@kit.BasicServicesKit';
225
226let metadata: avSession.AVMetadata = {
227  assetId: "121278",
228  title: "lose yourself",
229  artist: "Eminem",
230  author: "ST",
231  album: "Slim shady",
232  writer: "ST",
233  composer: "ST",
234  duration: 2222,
235  mediaImage: "https://www.example.com/example.jpg",
236  subtitle: "8 Mile",
237  description: "Rap",
238  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
239  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
240  lyric: "Lyrics in LRC format",
241  previousAssetId: "121277",
242  nextAssetId: "121279"
243};
244currentAVSession.setAVMetadata(metadata).then(() => {
245  console.info('SetAVMetadata successfully');
246}).catch((err: BusinessError) => {
247  console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
248});
249```
250
251### setAVMetadata<sup>10+</sup>
252
253setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
254
255Sets session metadata. This API uses an asynchronous callback to return the result.
256
257**System capability**: SystemCapability.Multimedia.AVSession.Core
258
259**Parameters**
260
261| Name  | Type                     | Mandatory| Description                                 |
262| -------- | ------------------------- | ---- | ------------------------------------- |
263| data     | [AVMetadata](#avmetadata10) | Yes  | Session metadata.                         |
264| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
265
266**Error codes**
267
268For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
269
270| ID| Error Message|
271| -------- | ---------------------------------------- |
272| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
273| 6600101  | Session service exception. |
274| 6600102  | The session does not exist. |
275
276**Example**
277
278```ts
279import { BusinessError } from '@kit.BasicServicesKit';
280
281let metadata: avSession.AVMetadata = {
282  assetId: "121278",
283  title: "lose yourself",
284  artist: "Eminem",
285  author: "ST",
286  album: "Slim shady",
287  writer: "ST",
288  composer: "ST",
289  duration: 2222,
290  mediaImage: "https://www.example.com/example.jpg",
291  subtitle: "8 Mile",
292  description: "Rap",
293  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
294  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
295  lyric: "Lyrics in LRC format",
296  previousAssetId: "121277",
297  nextAssetId: "121279"
298};
299currentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
300  if (err) {
301    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
302  } else {
303    console.info('SetAVMetadata successfully');
304  }
305});
306```
307
308### setCallMetadata<sup>11+</sup>
309
310setCallMetadata(data: CallMetadata): Promise\<void>
311
312Sets call metadata. This API uses a promise to return the result.
313
314**System capability**: SystemCapability.Multimedia.AVSession.Core
315
316**Parameters**
317
318| Name| Type                     | Mandatory| Description        |
319| ------ | ------------------------- | ---- | ------------ |
320| data   | [CallMetadata](#callmetadata11) | Yes  | Call metadata.|
321
322**Return value**
323
324| Type          | Description                         |
325| -------------- | ----------------------------- |
326| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
327
328**Error codes**
329
330For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
331
332| ID| Error Message|
333| -------- | ---------------------------------------- |
334| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
335| 6600101  | Session service exception. |
336| 6600102  | The session does not exist. |
337
338**Example**
339
340```ts
341import { image } from '@kit.ImageKit';
342import { resourceManager } from '@kit.LocalizationKit';
343import { BusinessError } from '@kit.BasicServicesKit';
344
345let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
346    let imageSource = await image.createImageSource(value.buffer);
347    let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
348    let calldata: avSession.CallMetadata = {
349      name: "xiaoming",
350      phoneNumber: "111xxxxxxxx",
351      avatar: imagePixel
352    };
353currentAVSession.setCallMetadata(calldata).then(() => {
354  console.info('setCallMetadata successfully');
355}).catch((err: BusinessError) => {
356  console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
357});
358```
359
360### setCallMetadata<sup>11+</sup>
361
362setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void
363
364Sets call metadata. This API uses an asynchronous callback to return the result.
365
366**System capability**: SystemCapability.Multimedia.AVSession.Core
367
368**Parameters**
369
370| Name  | Type                     | Mandatory| Description                                 |
371| -------- | ------------------------- | ---- | ------------------------------------- |
372| data     | [CallMetadata](#callmetadata11) | Yes  | Call metadata.                         |
373| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
374
375**Error codes**
376
377For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
378
379| ID| Error Message|
380| -------- | ---------------------------------------- |
381| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
382| 6600101  | Session service exception. |
383| 6600102  | The session does not exist. |
384
385**Example**
386
387```ts
388import { image } from '@kit.ImageKit';
389import { resourceManager } from '@kit.LocalizationKit';
390import { BusinessError } from '@kit.BasicServicesKit';
391
392async function setCallMetadata() {
393  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
394  let imageSource = await image.createImageSource(value.buffer);
395  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
396  let calldata: avSession.CallMetadata = {
397    name: "xiaoming",
398    phoneNumber: "111xxxxxxxx",
399    avatar: imagePixel
400  };
401  currentAVSession.setCallMetadata(calldata, (err: BusinessError) => {
402    if (err) {
403      console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
404    } else {
405      console.info('setCallMetadata successfully');
406    }
407  });
408}
409```
410
411### setAVCallState<sup>11+</sup>
412
413setAVCallState(state: AVCallState): Promise\<void>
414
415Sets the call state. This API uses a promise to return the result.
416
417**System capability**: SystemCapability.Multimedia.AVSession.Core
418
419**Parameters**
420
421| Name| Type                     | Mandatory| Description        |
422| ------ | ------------------------- | ---- | ------------ |
423| state   | [AVCallState](#avcallstate11) | Yes  | Call state.|
424
425**Return value**
426
427| Type          | Description                         |
428| -------------- | ----------------------------- |
429| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
430
431**Error codes**
432
433For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
434
435| ID| Error Message|
436| -------- | ---------------------------------------- |
437| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
438| 6600101  | Session service exception. |
439| 6600102  | The session does not exist. |
440
441**Example**
442
443```ts
444import { BusinessError } from '@kit.BasicServicesKit';
445
446let calldata: avSession.AVCallState = {
447  state: avSession.CallState.CALL_STATE_ACTIVE,
448  muted: false
449};
450currentAVSession.setAVCallState(calldata).then(() => {
451  console.info('setAVCallState successfully');
452}).catch((err: BusinessError) => {
453  console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
454});
455```
456
457### setAVCallState<sup>11+</sup>
458
459setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void
460
461Sets the call state. This API uses an asynchronous callback to return the result.
462
463**System capability**: SystemCapability.Multimedia.AVSession.Core
464
465**Parameters**
466
467| Name  | Type                     | Mandatory| Description                                 |
468| -------- | ------------------------- | ---- | ------------------------------------- |
469| state     | [AVCallState](#avcallstate11) | Yes  | Call state.                         |
470| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
471
472**Error codes**
473
474For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
475
476| ID| Error Message|
477| -------- | ---------------------------------------- |
478| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
479| 6600101  | Session service exception. |
480| 6600102  | The session does not exist. |
481
482**Example**
483
484```ts
485import { BusinessError } from '@kit.BasicServicesKit';
486
487let avcalldata: avSession.AVCallState = {
488  state: avSession.CallState.CALL_STATE_ACTIVE,
489  muted: false
490};
491currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => {
492  if (err) {
493    console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
494  } else {
495    console.info('setAVCallState successfully');
496  }
497});
498```
499
500### setAVPlaybackState<sup>10+</sup>
501
502setAVPlaybackState(state: AVPlaybackState): Promise\<void>
503
504Sets information related to the session playback state. This API uses a promise to return the result.
505
506**Atomic service API**: This API can be used in atomic services since API version 12.
507
508**System capability**: SystemCapability.Multimedia.AVSession.Core
509
510**Parameters**
511
512| Name| Type                               | Mandatory| Description                                          |
513| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
514| state   | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
515
516**Return value**
517
518| Type          | Description                         |
519| -------------- | ----------------------------- |
520| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
521
522**Error codes**
523
524For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
525
526| ID| Error Message|
527| -------- | ---------------------------------------- |
528| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
529| 6600101  | Session service exception. |
530| 6600102  | The session does not exist. |
531
532**Example**
533
534```ts
535import { BusinessError } from '@kit.BasicServicesKit';
536
537let playbackState: avSession.AVPlaybackState = {
538  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
539  speed: 1.0,
540  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
541  bufferedTime:1000,
542  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
543  isFavorite:true
544};
545currentAVSession.setAVPlaybackState(playbackState).then(() => {
546  console.info('SetAVPlaybackState successfully');
547}).catch((err: BusinessError) => {
548  console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
549});
550```
551
552### setAVPlaybackState<sup>10+</sup>
553
554setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
555
556Sets information related to the session playback state. This API uses an asynchronous callback to return the result.
557
558**System capability**: SystemCapability.Multimedia.AVSession.Core
559
560**Parameters**
561
562| Name  | Type                               | Mandatory| Description                                          |
563| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
564| state     | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
565| callback | AsyncCallback\<void>                | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
566
567**Error codes**
568
569For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
570
571| ID| Error Message|
572| -------- | ---------------------------------------- |
573| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
574| 6600101  | Session service exception. |
575| 6600102  | The session does not exist. |
576
577**Example**
578
579```ts
580import { BusinessError } from '@kit.BasicServicesKit';
581
582let PlaybackState: avSession.AVPlaybackState = {
583  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
584  speed: 1.0,
585  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
586  bufferedTime:1000,
587  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
588  isFavorite:true
589};
590currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
591  if (err) {
592    console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
593  } else {
594    console.info('SetAVPlaybackState successfully');
595  }
596});
597```
598
599### setLaunchAbility<sup>10+</sup>
600
601setLaunchAbility(ability: WantAgent): Promise\<void>
602
603Sets a launcher ability. This API uses a promise to return the result.
604
605**Atomic service API**: This API can be used in atomic services since API version 12.
606
607**System capability**: SystemCapability.Multimedia.AVSession.Core
608
609**Parameters**
610
611| Name | Type                                         | Mandatory| Description                                                       |
612| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
613| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID.|
614
615**Return value**
616
617| Type          | Description                         |
618| -------------- | ----------------------------- |
619| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
620
621**Error codes**
622
623For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
624
625| ID| Error Message|
626| -------- | ---------------------------------------- |
627| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
628| 6600101  | Session service exception. |
629| 6600102  | The session does not exist. |
630
631**Example**
632
633```ts
634import { wantAgent } from '@kit.AbilityKit';
635import { BusinessError } from '@kit.BasicServicesKit';
636
637// WantAgentInfo object.
638let wantAgentInfo: wantAgent.WantAgentInfo = {
639  wants: [
640    {
641      deviceId: "deviceId",
642      bundleName: "com.example.myapplication",
643      abilityName: "EntryAbility",
644      action: "action1",
645      entities: ["entity1"],
646      type: "MIMETYPE",
647      uri: "key = {true,true,false}",
648      parameters:
649        {
650          mykey0: 2222,
651          mykey1: [1, 2, 3],
652          mykey2: "[1, 2, 3]",
653          mykey3: "ssssssssssssssssssssssssss",
654          mykey4: [false, true, false],
655          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
656          mykey6: true
657        }
658    }
659  ],
660  operationType: wantAgent.OperationType.START_ABILITIES,
661  requestCode: 0,
662  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
663}
664
665wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
666  currentAVSession.setLaunchAbility(agent).then(() => {
667    console.info('SetLaunchAbility successfully');
668  }).catch((err: BusinessError) => {
669    console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
670  });
671});
672```
673
674### setLaunchAbility<sup>10+</sup>
675
676setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
677
678Sets a launcher ability. This API uses an asynchronous callback to return the result.
679
680**System capability**: SystemCapability.Multimedia.AVSession.Core
681
682**Parameters**
683
684| Name  | Type                                         | Mandatory| Description                                                        |
685| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
686| ability  | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID. |
687| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
688
689**Error codes**
690
691For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
692
693| ID| Error Message|
694| -------- | ---------------------------------------- |
695| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
696| 6600101  | Session service exception. |
697| 6600102  | The session does not exist. |
698
699**Example**
700
701```ts
702import { wantAgent } from '@kit.AbilityKit';
703import { BusinessError } from '@kit.BasicServicesKit';
704
705// WantAgentInfo object.
706let wantAgentInfo: wantAgent.WantAgentInfo = {
707  wants: [
708    {
709      deviceId: "deviceId",
710      bundleName: "com.example.myapplication",
711      abilityName: "EntryAbility",
712      action: "action1",
713      entities: ["entity1"],
714      type: "MIMETYPE",
715      uri: "key = {true,true,false}",
716      parameters:
717        {
718          mykey0: 2222,
719          mykey1: [1, 2, 3],
720          mykey2: "[1, 2, 3]",
721          mykey3: "ssssssssssssssssssssssssss",
722          mykey4: [false, true, false],
723          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
724          mykey6: true
725        }
726    }
727  ],
728  operationType: wantAgent.OperationType.START_ABILITIES,
729  requestCode: 0,
730  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
731}
732
733wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
734  currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
735    if (err) {
736      console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
737    } else {
738      console.info('SetLaunchAbility successfully');
739    }
740  });
741});
742```
743
744### dispatchSessionEvent<sup>10+</sup>
745
746dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void>
747
748Dispatches 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.
749
750**Atomic service API**: This API can be used in atomic services since API version 12.
751
752**System capability**: SystemCapability.Multimedia.AVSession.Core
753
754**Parameters**
755
756| Name | Type                                         | Mandatory| Description                                                       |
757| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
758| event | string | Yes  | Name of the session event.|
759| args | {[key: string]: Object} | Yes  | Content of the session event.|
760
761> **NOTE**
762> 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).
763
764**Return value**
765
766| Type          | Description                         |
767| -------------- | ----------------------------- |
768| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
769
770**Error codes**
771
772For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
773
774| ID| Error Message|
775| -------- | ---------------------------------------- |
776| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
777| 6600101  | Session service exception. |
778| 6600102  | The session does not exist. |
779
780**Example**
781
782```ts
783import { BusinessError } from '@kit.BasicServicesKit';
784
785let currentAVSession: avSession.AVSession | undefined = undefined;
786let tag = "createNewSession";
787let context: Context = getContext(this);
788
789avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
790  if (err) {
791    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
792  } else {
793    currentAVSession = data;
794  }
795});
796let eventName = "dynamic_lyric";
797if (currentAVSession !== undefined) {
798  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
799    console.info('dispatchSessionEvent successfully');
800  }).catch((err: BusinessError) => {
801    console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
802  })
803}
804```
805
806### dispatchSessionEvent<sup>10+</sup>
807
808dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
809
810Dispatches 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.
811
812**System capability**: SystemCapability.Multimedia.AVSession.Core
813
814**Parameters**
815
816| Name | Type                                         | Mandatory| Description                                                       |
817| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
818| event | string | Yes  | Name of the session event.|
819| args | {[key: string]: Object} | Yes  | Content of the session event.|
820| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
821
822> **NOTE**
823
824> 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).
825
826**Error codes**
827
828For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
829
830| ID| Error Message|
831| -------- | ---------------------------------------- |
832| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
833| 6600101  | Session service exception. |
834| 6600102  | The session does not exist. |
835
836**Example**
837
838```ts
839import { BusinessError } from '@kit.BasicServicesKit';
840
841let currentAVSession: avSession.AVSession | undefined = undefined;
842let tag = "createNewSession";
843let context: Context = getContext(this);
844
845avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
846  if (err) {
847    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
848  } else {
849    currentAVSession = data;
850  }
851});
852let eventName: string = "dynamic_lyric";
853if (currentAVSession !== undefined) {
854  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
855    if (err) {
856      console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
857    }
858  })
859}
860```
861
862### setAVQueueItems<sup>10+</sup>
863
864setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>
865
866Sets a playlist. This API uses a promise to return the result.
867
868**Atomic service API**: This API can be used in atomic services since API version 12.
869
870**System capability**: SystemCapability.Multimedia.AVSession.Core
871
872**Parameters**
873
874| Name | Type                                | Mandatory| Description                              |
875| ------ | ------------------------------------ | ---- | ---------------------------------- |
876| items  | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.|
877
878**Return value**
879
880| Type          | Description                         |
881| -------------- | ----------------------------- |
882| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
883
884**Error codes**
885
886For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
887
888| ID| Error Message|
889| -------- | ---------------------------------------- |
890| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
891| 6600101  | Session service exception. |
892| 6600102  | The session does not exist. |
893
894**Example**
895
896```ts
897import { image } from '@kit.ImageKit';
898import { resourceManager } from '@kit.LocalizationKit';
899import { BusinessError } from '@kit.BasicServicesKit';
900
901async function setAVQueueItems() {
902  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
903  let imageSource = await image.createImageSource(value.buffer);
904  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
905  let queueItemDescription_1: avSession.AVMediaDescription = {
906    assetId: '001',
907    title: 'music_name',
908    subtitle: 'music_sub_name',
909    description: 'music_description',
910    mediaImage : imagePixel,
911    extras: {extras:'any'}
912  };
913  let queueItem_1: avSession.AVQueueItem = {
914    itemId: 1,
915    description: queueItemDescription_1
916  };
917  let queueItemDescription_2: avSession.AVMediaDescription = {
918    assetId: '002',
919    title: 'music_name',
920    subtitle: 'music_sub_name',
921    description: 'music_description',
922    mediaImage: imagePixel,
923    extras: {extras:'any'}
924  };
925  let queueItem_2: avSession.AVQueueItem = {
926    itemId: 2,
927    description: queueItemDescription_2
928  };
929  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
930  currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
931    console.info('SetAVQueueItems successfully');
932  }).catch((err: BusinessError) => {
933    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
934  });
935}
936```
937
938### setAVQueueItems<sup>10+</sup>
939
940setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void
941
942Sets a playlist. This API uses an asynchronous callback to return the result.
943
944**System capability**: SystemCapability.Multimedia.AVSession.Core
945
946**Parameters**
947
948| Name  | Type                                 | Mandatory| Description                                                        |
949| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- |
950| items    | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.                         |
951| callback | AsyncCallback\<void>                 | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
952
953**Error codes**
954
955For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
956
957| ID| Error Message|
958| -------- | ---------------------------------------- |
959| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
960| 6600101  | Session service exception. |
961| 6600102  | The session does not exist. |
962
963**Example**
964
965```ts
966import { image } from '@kit.ImageKit';
967import { resourceManager } from '@kit.LocalizationKit';
968import { BusinessError } from '@kit.BasicServicesKit';
969
970async function setAVQueueItems() {
971  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
972  let imageSource = await image.createImageSource(value.buffer);
973  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
974  let queueItemDescription_1: avSession.AVMediaDescription = {
975    assetId: '001',
976    title: 'music_name',
977    subtitle: 'music_sub_name',
978    description: 'music_description',
979    mediaImage : imagePixel,
980    extras: {extras:'any'}
981  };
982  let queueItem_1: avSession.AVQueueItem = {
983    itemId: 1,
984    description: queueItemDescription_1
985  };
986  let queueItemDescription_2: avSession.AVMediaDescription = {
987    assetId: '002',
988    title: 'music_name',
989    subtitle: 'music_sub_name',
990    description: 'music_description',
991    mediaImage: imagePixel,
992    extras: {extras:'any'}
993  };
994  let queueItem_2: avSession.AVQueueItem = {
995    itemId: 2,
996    description: queueItemDescription_2
997  };
998  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
999  currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
1000    if (err) {
1001      console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
1002    } else {
1003      console.info('SetAVQueueItems successfully');
1004    }
1005  });
1006}
1007```
1008
1009### setAVQueueTitle<sup>10+</sup>
1010
1011setAVQueueTitle(title: string): Promise\<void>
1012
1013Sets a name for the playlist. This API uses a promise to return the result.
1014
1015**Atomic service API**: This API can be used in atomic services since API version 12.
1016
1017**System capability**: SystemCapability.Multimedia.AVSession.Core
1018
1019**Parameters**
1020
1021| Name | Type  | Mandatory| Description          |
1022| ------ | ------ | ---- | -------------- |
1023| title  | string | Yes  | Name of the playlist.|
1024
1025**Return value**
1026
1027| Type          | Description                         |
1028| -------------- | ----------------------------- |
1029| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1030
1031**Error codes**
1032
1033For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1034
1035| ID| Error Message|
1036| -------- | ---------------------------------------- |
1037| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1038| 6600101  | Session service exception. |
1039| 6600102  | The session does not exist. |
1040
1041**Example**
1042
1043```ts
1044import { BusinessError } from '@kit.BasicServicesKit';
1045
1046let queueTitle = 'QUEUE_TITLE';
1047currentAVSession.setAVQueueTitle(queueTitle).then(() => {
1048  console.info('SetAVQueueTitle successfully');
1049}).catch((err: BusinessError) => {
1050  console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1051});
1052```
1053
1054### setAVQueueTitle<sup>10+</sup>
1055
1056setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void
1057
1058Sets a name for the playlist. This API uses an asynchronous callback to return the result.
1059
1060**System capability**: SystemCapability.Multimedia.AVSession.Core
1061
1062**Parameters**
1063
1064| Name  | Type                                 | Mandatory| Description                                                        |
1065| -------- | --------------------- | ---- | ----------------------------------------------------------- |
1066| title    | string                | Yes  | Name of the playlist.                         |
1067| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1068
1069**Error codes**
1070
1071For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1072
1073| ID| Error Message|
1074| -------- | ---------------------------------------- |
1075| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1076| 6600101  | Session service exception. |
1077| 6600102  | The session does not exist. |
1078
1079**Example**
1080
1081```ts
1082import { BusinessError } from '@kit.BasicServicesKit';
1083
1084let queueTitle = 'QUEUE_TITLE';
1085currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
1086  if (err) {
1087    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1088  } else {
1089    console.info('SetAVQueueTitle successfully');
1090  }
1091});
1092```
1093
1094### setExtras<sup>10+</sup>
1095
1096setExtras(extras: {[key: string]: Object}): Promise\<void>
1097
1098Sets 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.
1099
1100**Atomic service API**: This API can be used in atomic services since API version 12.
1101
1102**System capability**: SystemCapability.Multimedia.AVSession.Core
1103
1104**Parameters**
1105
1106| Name | Type                                         | Mandatory| Description                                                       |
1107| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1108| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1109
1110> **NOTE**
1111
1112> 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).
1113
1114**Return value**
1115
1116| Type          | Description                         |
1117| -------------- | ----------------------------- |
1118| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1119
1120**Error codes**
1121
1122For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1123
1124| ID| Error Message|
1125| -------- | ---------------------------------------- |
1126| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1127| 6600101  | Session service exception. |
1128| 6600102  | The session does not exist. |
1129
1130**Example**
1131
1132```ts
1133import { BusinessError } from '@kit.BasicServicesKit';
1134
1135let currentAVSession: avSession.AVSession | undefined = undefined;
1136let tag = "createNewSession";
1137let context: Context = getContext(this);
1138
1139avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1140  if (err) {
1141    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1142  } else {
1143    currentAVSession = data;
1144  }
1145});
1146if (currentAVSession !== undefined) {
1147  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => {
1148    console.info('setExtras successfully');
1149  }).catch((err: BusinessError) => {
1150    console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1151  })
1152}
1153```
1154
1155### setExtras<sup>10+</sup>
1156
1157setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void
1158
1159Sets 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.
1160
1161**System capability**: SystemCapability.Multimedia.AVSession.Core
1162
1163**Parameters**
1164
1165| Name | Type                                         | Mandatory| Description                                                       |
1166| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1167| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1168| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1169
1170> **NOTE**
1171
1172> 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).
1173
1174**Error codes**
1175
1176For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1177
1178| ID| Error Message|
1179| -------- | ---------------------------------------- |
1180| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1181| 6600101  | Session service exception. |
1182| 6600102  | The session does not exist. |
1183
1184**Example**
1185
1186```ts
1187import { BusinessError } from '@kit.BasicServicesKit';
1188
1189let currentAVSession: avSession.AVSession | undefined = undefined;
1190let tag = "createNewSession";
1191let context: Context = getContext(this);
1192
1193avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1194  if (err) {
1195    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1196  } else {
1197    currentAVSession = data;
1198  }
1199});
1200if (currentAVSession !== undefined) {
1201  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => {
1202    if (err) {
1203      console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1204    }
1205  })
1206}
1207```
1208
1209### getController<sup>10+</sup>
1210
1211getController(): Promise\<AVSessionController>
1212
1213Obtains the controller corresponding to this session. This API uses a promise to return the result.
1214
1215**Atomic service API**: This API can be used in atomic services since API version 12.
1216
1217**System capability**: SystemCapability.Multimedia.AVSession.Core
1218
1219**Return value**
1220
1221| Type                                                | Description                         |
1222| ---------------------------------------------------- | ----------------------------- |
1223| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.|
1224
1225**Error codes**
1226
1227For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1228
1229| ID| Error Message|
1230| -------- | ---------------------------------------- |
1231| 6600101  | Session service exception. |
1232| 6600102  | The session does not exist. |
1233
1234**Example**
1235
1236```ts
1237import { BusinessError } from '@kit.BasicServicesKit';
1238
1239let avsessionController: avSession.AVSessionController;
1240currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
1241  avsessionController = avcontroller;
1242  console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1243}).catch((err: BusinessError) => {
1244  console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1245});
1246```
1247
1248### getController<sup>10+</sup>
1249
1250getController(callback: AsyncCallback\<AVSessionController>): void
1251
1252Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result.
1253
1254**System capability**: SystemCapability.Multimedia.AVSession.Core
1255
1256**Parameters**
1257
1258| Name  | Type                                                       | Mandatory| Description                      |
1259| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
1260| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes  | Callback used to return the session controller.|
1261
1262**Error codes**
1263
1264For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1265
1266| ID| Error Message|
1267| -------- | ---------------------------------------- |
1268| 6600101  | Session service exception. |
1269| 6600102  | The session does not exist. |
1270
1271**Example**
1272
1273```ts
1274import { BusinessError } from '@kit.BasicServicesKit';
1275
1276let avsessionController: avSession.AVSessionController;
1277currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
1278  if (err) {
1279    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1280  } else {
1281    avsessionController = avcontroller;
1282    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1283  }
1284});
1285```
1286
1287### getAVCastController<sup>10+</sup>
1288
1289getAVCastController(): Promise\<AVCastController>
1290
1291Obtains 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**.
1292
1293**Atomic service API**: This API can be used in atomic services since API version 12.
1294
1295**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1296
1297**Return value**
1298
1299| Type                                                       | Description                                                        |
1300| --------- | ------------------------------------------------------------ |
1301| Promise<[AVCastController](#avcastcontroller10)\>  | Promise used to return the cast controller.|
1302
1303**Error codes**
1304
1305For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1306
1307| ID| Error Message|
1308| -------- | --------------------------------------- |
1309| 6600102| The session does not exist.           |
1310| 6600109| The remote connection is not established. |
1311
1312**Example**
1313
1314```ts
1315import { BusinessError } from '@kit.BasicServicesKit';
1316
1317let aVCastController: avSession.AVCastController;
1318currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
1319  aVCastController = avcontroller;
1320  console.info('getAVCastController : SUCCESS');
1321}).catch((err: BusinessError) => {
1322  console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1323});
1324```
1325
1326### getAVCastController<sup>10+</sup>
1327
1328getAVCastController(callback: AsyncCallback\<AVCastController>): void
1329
1330Obtains 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**.
1331
1332**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1333
1334**Parameters**
1335
1336| Name   | Type                                                       | Mandatory| Description                                                        |
1337| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1338| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes  | Callback used to return the cast controller.|
1339
1340**Error codes**
1341
1342For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1343
1344| ID| Error Message                                 |
1345| -------- |---------------------------------------|
1346| 6600102| The session does not exist.           |
1347| 6600109| The remote connection is not established. |
1348
1349**Example**
1350
1351```ts
1352import { BusinessError } from '@kit.BasicServicesKit';
1353
1354let aVCastController: avSession.AVCastController;
1355currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
1356  if (err) {
1357    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1358  } else {
1359    aVCastController = avcontroller;
1360    console.info('getAVCastController : SUCCESS');
1361  }
1362});
1363```
1364
1365### getOutputDevice<sup>10+</sup>
1366
1367getOutputDevice(): Promise\<OutputDeviceInfo>
1368
1369Obtains information about the output device for this session. This API uses a promise to return the result.
1370
1371**Atomic service API**: This API can be used in atomic services since API version 12.
1372
1373**System capability**: SystemCapability.Multimedia.AVSession.Core
1374
1375**Return value**
1376
1377| Type                                          | Description                             |
1378| ---------------------------------------------- | --------------------------------- |
1379| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.|
1380
1381**Error codes**
1382
1383For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1384
1385| ID| Error Message|
1386| -------- | ---------------------------------------- |
1387| 6600101  | Session service exception. |
1388| 6600102  | The session does not exist. |
1389
1390**Example**
1391
1392```ts
1393import { BusinessError } from '@kit.BasicServicesKit';
1394
1395currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
1396  console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1397}).catch((err: BusinessError) => {
1398  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1399})
1400```
1401
1402### getOutputDevice<sup>10+</sup>
1403
1404getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
1405
1406Obtains information about the output device for this session. This API uses an asynchronous callback to return the result.
1407
1408**System capability**: SystemCapability.Multimedia.AVSession.Core
1409
1410**Parameters**
1411
1412| Name  | Type                                                 | Mandatory| Description                          |
1413| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1414| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
1415
1416**Error codes**
1417
1418For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1419
1420| ID| Error Message|
1421| -------- | ---------------------------------------- |
1422| 6600101  | Session service exception. |
1423| 6600102  | The session does not exist. |
1424
1425**Example**
1426
1427```ts
1428import { BusinessError } from '@kit.BasicServicesKit';
1429
1430currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
1431  if (err) {
1432    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1433  } else {
1434    console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1435  }
1436});
1437```
1438
1439### activate<sup>10+</sup>
1440
1441activate(): Promise\<void>
1442
1443Activates this session. A session can be used only after being activated. This API uses a promise to return the result.
1444
1445**Atomic service API**: This API can be used in atomic services since API version 12.
1446
1447**System capability**: SystemCapability.Multimedia.AVSession.Core
1448
1449**Return value**
1450
1451| Type          | Description                         |
1452| -------------- | ----------------------------- |
1453| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|
1454
1455**Error codes**
1456
1457For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1458
1459| ID| Error Message|
1460| -------- | ---------------------------------------- |
1461| 6600101  | Session service exception. |
1462| 6600102  | The session does not exist. |
1463
1464**Example**
1465
1466```ts
1467import { BusinessError } from '@kit.BasicServicesKit';
1468
1469currentAVSession.activate().then(() => {
1470  console.info('Activate : SUCCESS ');
1471}).catch((err: BusinessError) => {
1472  console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1473});
1474```
1475
1476### activate<sup>10+</sup>
1477
1478activate(callback: AsyncCallback\<void>): void
1479
1480Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result.
1481
1482**System capability**: SystemCapability.Multimedia.AVSession.Core
1483
1484**Parameters**
1485
1486| Name  | Type                | Mandatory| Description      |
1487| -------- | -------------------- | ---- | ---------- |
1488| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|
1489
1490**Error codes**
1491
1492For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1493
1494| ID| Error Message|
1495| -------- | ---------------------------------------- |
1496| 6600101  | Session service exception. |
1497| 6600102  | The session does not exist. |
1498
1499**Example**
1500
1501```ts
1502import { BusinessError } from '@kit.BasicServicesKit';
1503
1504currentAVSession.activate((err: BusinessError) => {
1505  if (err) {
1506    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1507  } else {
1508    console.info('Activate : SUCCESS ');
1509  }
1510});
1511```
1512
1513### deactivate<sup>10+</sup>
1514
1515deactivate(): Promise\<void>
1516
1517Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result.
1518
1519**Atomic service API**: This API can be used in atomic services since API version 12.
1520
1521**System capability**: SystemCapability.Multimedia.AVSession.Core
1522
1523**Return value**
1524
1525| Type          | Description                         |
1526| -------------- | ----------------------------- |
1527| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|
1528
1529**Error codes**
1530
1531For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1532
1533| ID| Error Message|
1534| -------- | ---------------------------------------- |
1535| 6600101  | Session service exception. |
1536| 6600102  | The session does not exist. |
1537
1538**Example**
1539
1540```ts
1541import { BusinessError } from '@kit.BasicServicesKit';
1542
1543currentAVSession.deactivate().then(() => {
1544  console.info('Deactivate : SUCCESS ');
1545}).catch((err: BusinessError) => {
1546  console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1547});
1548```
1549
1550### deactivate<sup>10+</sup>
1551
1552deactivate(callback: AsyncCallback\<void>): void
1553
1554Deactivates this session. This API uses an asynchronous callback to return the result.
1555
1556Deactivates this session. You can use [activate](#activate10) to activate the session again.
1557
1558**System capability**: SystemCapability.Multimedia.AVSession.Core
1559
1560**Parameters**
1561
1562| Name  | Type                | Mandatory| Description      |
1563| -------- | -------------------- | ---- | ---------- |
1564| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|
1565
1566**Error codes**
1567
1568For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1569
1570| ID| Error Message|
1571| -------- | ---------------------------------------- |
1572| 6600101  | Session service exception. |
1573| 6600102  | The session does not exist. |
1574
1575**Example**
1576
1577```ts
1578import { BusinessError } from '@kit.BasicServicesKit';
1579
1580currentAVSession.deactivate((err: BusinessError) => {
1581  if (err) {
1582    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1583  } else {
1584    console.info('Deactivate : SUCCESS ');
1585  }
1586});
1587```
1588
1589### destroy<sup>10+</sup>
1590
1591destroy(): Promise\<void>
1592
1593Destroys this session. This API uses a promise to return the result.
1594
1595**Atomic service API**: This API can be used in atomic services since API version 12.
1596
1597**System capability**: SystemCapability.Multimedia.AVSession.Core
1598
1599**Return value**
1600
1601| Type          | Description                         |
1602| -------------- | ----------------------------- |
1603| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|
1604
1605**Error codes**
1606
1607For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1608
1609| ID| Error Message|
1610| -------- | ---------------------------------------- |
1611| 6600101  | Session service exception. |
1612| 6600102  | The session does not exist. |
1613
1614**Example**
1615
1616```ts
1617import { BusinessError } from '@kit.BasicServicesKit';
1618
1619currentAVSession.destroy().then(() => {
1620  console.info('Destroy : SUCCESS ');
1621}).catch((err: BusinessError) => {
1622  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1623});
1624```
1625
1626### destroy<sup>10+</sup>
1627
1628destroy(callback: AsyncCallback\<void>): void
1629
1630Destroys this session. This API uses an asynchronous callback to return the result.
1631
1632**System capability**: SystemCapability.Multimedia.AVSession.Core
1633
1634**Parameters**
1635
1636| Name  | Type                | Mandatory| Description      |
1637| -------- | -------------------- | ---- | ---------- |
1638| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
1639
1640**Error codes**
1641
1642For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1643
1644| ID| Error Message|
1645| -------- | ---------------------------------------- |
1646| 6600101  | Session service exception. |
1647| 6600102  | The session does not exist. |
1648
1649**Example**
1650
1651```ts
1652import { BusinessError } from '@kit.BasicServicesKit';
1653
1654currentAVSession.destroy((err: BusinessError) => {
1655  if (err) {
1656    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1657  } else {
1658    console.info('Destroy : SUCCESS ');
1659  }
1660});
1661```
1662
1663### on('play')<sup>10+</sup>
1664
1665on(type: 'play', callback: () => void): void
1666
1667Subscribes to play command events. The subscription means that the application supports the play command.
1668
1669Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1670
1671**Atomic service API**: This API can be used in atomic services since API version 12.
1672
1673**System capability**: SystemCapability.Multimedia.AVSession.Core
1674
1675**Parameters**
1676
1677| Name  | Type                | Mandatory| Description                                                        |
1678| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1679| type     | string               | Yes  | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.|
1680| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                                       |
1681
1682**Error codes**
1683
1684For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1685
1686| ID| Error Message|
1687| -------- | ---------------------------------------- |
1688| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1689| 6600101  | Session service exception. |
1690| 6600102  | The session does not exist. |
1691
1692**Example**
1693
1694```ts
1695currentAVSession.on('play', () => {
1696  console.info('on play entry');
1697});
1698```
1699
1700### on('pause')<sup>10+</sup>
1701
1702on(type: 'pause', callback: () => void): void
1703
1704Subscribes to pause command events. The subscription means that the application supports the pause command.
1705
1706Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1707
1708**Atomic service API**: This API can be used in atomic services since API version 12.
1709
1710**System capability**: SystemCapability.Multimedia.AVSession.Core
1711
1712**Parameters**
1713
1714| Name  | Type                | Mandatory| Description                                                        |
1715| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1716| type     | string               | Yes  | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.|
1717| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1718
1719**Error codes**
1720
1721For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1722
1723| ID| Error Message|
1724| -------- | ---------------------------------------- |
1725| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1726| 6600101  | Session service exception. |
1727| 6600102  | The session does not exist. |
1728
1729**Example**
1730
1731```ts
1732currentAVSession.on('pause', () => {
1733  console.info('on pause entry');
1734});
1735```
1736
1737### on('stop')<sup>10+</sup>
1738
1739on(type:'stop', callback: () => void): void
1740
1741Subscribes to stop command events. The subscription means that the application supports the stop command.
1742
1743Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1744
1745**Atomic service API**: This API can be used in atomic services since API version 12.
1746
1747**System capability**: SystemCapability.Multimedia.AVSession.Core
1748
1749**Parameters**
1750
1751| Name  | Type                | Mandatory| Description                                                        |
1752| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1753| type     | string               | Yes  | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.|
1754| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
1755
1756**Error codes**
1757
1758For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1759
1760| ID| Error Message|
1761| -------- | ---------------------------------------- |
1762| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1763| 6600101  | Session service exception. |
1764| 6600102  | The session does not exist. |
1765
1766**Example**
1767
1768```ts
1769currentAVSession.on('stop', () => {
1770  console.info('on stop entry');
1771});
1772```
1773
1774### on('playNext')<sup>10+</sup>
1775
1776on(type:'playNext', callback: () => void): void
1777
1778Subscribes to playNext command events. The subscription means that the application supports the playNext command.
1779
1780Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1781
1782**Atomic service API**: This API can be used in atomic services since API version 12.
1783
1784**System capability**: SystemCapability.Multimedia.AVSession.Core
1785
1786**Parameters**
1787
1788| Name  | Type                | Mandatory| Description                                                        |
1789| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1790| type     | string               | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.|
1791| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1792
1793**Error codes**
1794
1795For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1796
1797| ID| Error Message|
1798| -------- | ---------------------------------------- |
1799| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1800| 6600101  | Session service exception. |
1801| 6600102  | The session does not exist. |
1802
1803**Example**
1804
1805```ts
1806currentAVSession.on('playNext', () => {
1807  console.info('on playNext entry');
1808});
1809```
1810
1811### on('playPrevious')<sup>10+</sup>
1812
1813on(type:'playPrevious', callback: () => void): void
1814
1815Subscribes to playPrevious command events. The subscription means that the application supports the playPrevious command.
1816
1817Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1818
1819**Atomic service API**: This API can be used in atomic services since API version 12.
1820
1821**System capability**: SystemCapability.Multimedia.AVSession.Core
1822
1823**Parameters**
1824
1825| Name  | Type                | Mandatory| Description                                                        |
1826| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1827| type     | string               | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.|
1828| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.      |
1829
1830**Error codes**
1831
1832For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1833
1834| ID| Error Message|
1835| -------- | ---------------------------------------- |
1836| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1837| 6600101  | Session service exception. |
1838| 6600102  | The session does not exist. |
1839
1840**Example**
1841
1842```ts
1843currentAVSession.on('playPrevious', () => {
1844  console.info('on playPrevious entry');
1845});
1846```
1847
1848### on('fastForward')<sup>10+</sup>
1849
1850on(type: 'fastForward', callback: (time?: number) => void): void
1851
1852Subscribes to fastForward command events. The subscription means that the application supports the fastForward command.
1853
1854Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1855
1856**Atomic service API**: This API can be used in atomic services since API version 12.
1857
1858**System capability**: SystemCapability.Multimedia.AVSession.Core
1859
1860**Parameters**
1861
1862| Name  | Type                | Mandatory| Description                                                        |
1863| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1864| type     | string               | Yes  | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.|
1865| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.   |
1866
1867**Error codes**
1868
1869For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1870
1871| ID| Error Message|
1872| -------- | ---------------------------------------- |
1873| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1874| 6600101  | Session service exception. |
1875| 6600102  | The session does not exist. |
1876
1877**Example**
1878
1879```ts
1880currentAVSession.on('fastForward', (time?: number) => {
1881  console.info('on fastForward entry');
1882});
1883```
1884
1885### on('rewind')<sup>10+</sup>
1886
1887on(type:'rewind', callback: (time?: number) => void): void
1888
1889Subscribes to rewind command events.
1890
1891**Atomic service API**: This API can be used in atomic services since API version 12.
1892
1893**System capability**: SystemCapability.Multimedia.AVSession.Core
1894
1895**Parameters**
1896
1897| Name  | Type                | Mandatory| Description                                                        |
1898| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1899| type     | string               | Yes  | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.|
1900| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.     |
1901
1902**Error codes**
1903
1904For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1905
1906| ID| Error Message|
1907| -------- | ---------------------------------------- |
1908| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1909| 6600101  | Session service exception. |
1910| 6600102  | The session does not exist. |
1911
1912**Example**
1913
1914```ts
1915currentAVSession.on('rewind', (time?: number) => {
1916  console.info('on rewind entry');
1917});
1918```
1919
1920### on('playFromAssetId')<sup>11+</sup>
1921
1922on(type:'playFromAssetId', callback: (assetId: number) => void): void
1923
1924Subscribes to playback events of a given media ID.
1925
1926**Atomic service API**: This API can be used in atomic services since API version 12.
1927
1928**System capability**: SystemCapability.Multimedia.AVSession.Core
1929
1930**Parameters**
1931
1932| Name  | Type                | Mandatory| Description                                                        |
1933| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1934| type     | string               | Yes  | Event type. The event **'playFromAssetId'** is triggered when the media ID is played.|
1935| callback | callback: (assetId: number) => void | Yes  | Callback The **assetId** parameter in the callback indicates the media asset ID.     |
1936
1937**Error codes**
1938
1939For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1940
1941| ID| Error Message|
1942| -------- | ---------------------------------------- |
1943| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1944| 6600101  | Session service exception. |
1945| 6600102  | The session does not exist. |
1946
1947**Example**
1948
1949```ts
1950currentAVSession.on('playFromAssetId', (assetId: number) => {
1951  console.info('on playFromAssetId entry');
1952});
1953```
1954
1955### off('playFromAssetId')<sup>11+</sup>
1956
1957off(type: 'playFromAssetId', callback?: (assetId: number) => void): void
1958
1959Unsubscribes from playback events of a given media ID.
1960
1961**Atomic service API**: This API can be used in atomic services since API version 12.
1962
1963**System capability**: SystemCapability.Multimedia.AVSession.Core
1964
1965**Parameters**
1966
1967| Name   | Type                 | Mandatory| Description                                                                                                                        |
1968| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
1969| type     | string               | Yes  | Event type, which is **'playFromAssetId'** in this case.|
1970| 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.                           |
1971
1972**Error codes**
1973
1974For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1975
1976| ID| Error Message|
1977| -------- | ---------------------------------------- |
1978| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1979| 6600101  | Session service exception. |
1980| 6600102  | The session does not exist. |
1981
1982**Example**
1983
1984```ts
1985currentAVSession.off('playFromAssetId');
1986```
1987
1988### on('seek')<sup>10+</sup>
1989
1990on(type: 'seek', callback: (time: number) => void): void
1991
1992Subscribes to seek command events.
1993
1994**Atomic service API**: This API can be used in atomic services since API version 12.
1995
1996**System capability**: SystemCapability.Multimedia.AVSession.Core
1997
1998**Parameters**
1999
2000| Name  | Type                  | Mandatory| Description                                                        |
2001| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
2002| type     | string                 | Yes  | Event type. The event **'seek'** is triggered when the seek command is sent to the session.|
2003| callback | (time: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.                  |
2004
2005**Error codes**
2006
2007For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2008
2009| ID| Error Message|
2010| -------- | ---------------------------------------- |
2011| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2012| 6600101  | Session service exception. |
2013| 6600102  | The session does not exist. |
2014
2015**Example**
2016
2017```ts
2018currentAVSession.on('seek', (time: number) => {
2019  console.info(`on seek entry time : ${time}`);
2020});
2021```
2022
2023### on('setSpeed')<sup>10+</sup>
2024
2025on(type: 'setSpeed', callback: (speed: number) => void): void
2026
2027Subscribes to setSpeed command events.
2028
2029**Atomic service API**: This API can be used in atomic services since API version 12.
2030
2031**System capability**: SystemCapability.Multimedia.AVSession.Core
2032
2033**Parameters**
2034
2035| Name  | Type                   | Mandatory| Description                                                        |
2036| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
2037| type     | string                  | Yes  | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.|
2038| callback | (speed: number) => void | Yes  | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed.                             |
2039
2040**Error codes**
2041
2042For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2043
2044| ID| Error Message|
2045| -------- | ---------------------------------------- |
2046| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2047| 6600101  | Session service exception. |
2048| 6600102  | The session does not exist. |
2049
2050**Example**
2051
2052```ts
2053currentAVSession.on('setSpeed', (speed: number) => {
2054  console.info(`on setSpeed speed : ${speed}`);
2055});
2056```
2057
2058### on('setLoopMode')<sup>10+</sup>
2059
2060on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
2061
2062Subscribes to setLoopMode command events.
2063
2064**Atomic service API**: This API can be used in atomic services since API version 12.
2065
2066**System capability**: SystemCapability.Multimedia.AVSession.Core
2067
2068**Parameters**
2069
2070| Name   | Type                                  | Mandatory| Description |
2071| -------- | ------------------------------------- | ---- | ---- |
2072| type     | string                                | Yes  | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.|
2073| callback | (mode: [LoopMode](#loopmode10)) => void | Yes  | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode.                              |
2074
2075**Error codes**
2076
2077For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2078
2079| ID| Error Message|
2080| -------- | ---------------------------------------- |
2081| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2082| 6600101  | Session service exception. |
2083| 6600102  | The session does not exist. |
2084
2085**Example**
2086
2087```ts
2088currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
2089  console.info(`on setLoopMode mode : ${mode}`);
2090});
2091```
2092
2093### on('toggleFavorite')<sup>10+</sup>
2094
2095on(type: 'toggleFavorite', callback: (assetId: string) => void): void
2096
2097Subscribes to toggleFavorite command events.
2098
2099**Atomic service API**: This API can be used in atomic services since API version 12.
2100
2101**System capability**: SystemCapability.Multimedia.AVSession.Core
2102
2103**Parameters**
2104
2105| Name  | Type                     | Mandatory| Description                                                        |
2106| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
2107| type     | string                    | Yes  | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.|
2108| callback | (assetId: string) => void | Yes  | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID.                             |
2109
2110**Error codes**
2111
2112For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2113
2114| ID| Error Message|
2115| -------- | ---------------------------------------- |
2116| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2117| 6600101  | Session service exception. |
2118| 6600102  | The session does not exist. |
2119
2120**Example**
2121
2122```ts
2123currentAVSession.on('toggleFavorite', (assetId: string) => {
2124  console.info(`on toggleFavorite mode : ${assetId}`);
2125});
2126```
2127
2128### on('skipToQueueItem')<sup>10+</sup>
2129
2130on(type: 'skipToQueueItem', callback: (itemId: number) => void): void
2131
2132Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item.
2133
2134**Atomic service API**: This API can be used in atomic services since API version 12.
2135
2136**System capability**: SystemCapability.Multimedia.AVSession.Core
2137
2138**Parameters**
2139
2140| Name  | Type                     | Mandatory| Description                                                                                     |
2141| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- |
2142| type     | string                   | Yes  | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.|
2143| callback | (itemId: number) => void | Yes  | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item.                                               |
2144
2145**Error codes**
2146
2147For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2148
2149| ID| Error Message|
2150| -------- | ---------------------------------------- |
2151| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2152| 6600101  | Session service exception. |
2153| 6600102  | The session does not exist. |
2154
2155**Example**
2156
2157```ts
2158currentAVSession.on('skipToQueueItem', (itemId: number) => {
2159  console.info(`on skipToQueueItem id : ${itemId}`);
2160});
2161```
2162
2163### on('handleKeyEvent')<sup>10+</sup>
2164
2165on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
2166
2167Subscribes 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.
2168
2169**Atomic service API**: This API can be used in atomic services since API version 12.
2170
2171**System capability**: SystemCapability.Multimedia.AVSession.Core
2172
2173**Parameters**
2174
2175| Name  | Type                                                        | Mandatory| Description                                                        |
2176| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2177| type     | string                                                       | Yes  | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.|
2178| 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.                             |
2179
2180**Error codes**
2181
2182For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2183
2184| ID| Error Message|
2185| -------- | ---------------------------------------- |
2186| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2187| 6600101  | Session service exception. |
2188| 6600102  | The session does not exist. |
2189
2190**Example**
2191
2192```ts
2193import { KeyEvent } from '@kit.InputKit';
2194
2195currentAVSession.on('handleKeyEvent', (event: KeyEvent) => {
2196  console.info(`on handleKeyEvent event : ${event}`);
2197});
2198
2199```
2200
2201### on('outputDeviceChange')<sup>10+</sup>
2202
2203on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2204
2205Subscribes 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.
2206
2207**Atomic service API**: This API can be used in atomic services since API version 12.
2208
2209**System capability**: SystemCapability.Multimedia.AVSession.Core
2210
2211**Parameters**
2212
2213| Name  | Type                                                   | Mandatory| Description                                                        |
2214| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2215| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
2216| 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.                        |
2217
2218**Error codes**
2219
2220For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2221
2222| ID| Error Message|
2223| -------- | ---------------------------------------- |
2224| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2225| 6600101  | Session service exception. |
2226| 6600102  | The session does not exist. |
2227
2228**Example**
2229
2230```ts
2231currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
2232  console.info(`on outputDeviceChange device : ${device}`);
2233});
2234```
2235
2236### on('commonCommand')<sup>10+</sup>
2237
2238on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void
2239
2240Subscribes to custom control command change events.
2241
2242**Atomic service API**: This API can be used in atomic services since API version 12.
2243
2244**System capability**: SystemCapability.Multimedia.AVSession.Core
2245
2246**Parameters**
2247
2248| Name  | Type                                                        | Mandatory| Description                                                        |
2249| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2250| type     | string                                                       | Yes  | Event type. The event **'commonCommand'** is triggered when a custom control command changes.|
2251| 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).         |
2252
2253**Error codes**
2254
2255For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2256
2257| ID| Error Message|
2258| -------- | ------------------------------ |
2259| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2260| 6600101  | Session service exception. |
2261| 6600102  | The session does not exist. |
2262
2263**Example**
2264
2265```ts
2266import { BusinessError } from '@kit.BasicServicesKit';
2267
2268let currentAVSession: avSession.AVSession | undefined = undefined;
2269let tag = "createNewSession";
2270let context: Context = getContext(this);
2271
2272avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
2273  if (err) {
2274    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
2275  } else {
2276    currentAVSession = data;
2277  }
2278});
2279if (currentAVSession !== undefined) {
2280  (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => {
2281    console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
2282  });
2283}
2284```
2285
2286### off('play')<sup>10+</sup>
2287
2288off(type: 'play', callback?: () => void): void
2289
2290Unsubscribes from play command events.
2291
2292After the callback is canceled, the list of supported commands must be updated.
2293
2294**Atomic service API**: This API can be used in atomic services since API version 12.
2295
2296**System capability**: SystemCapability.Multimedia.AVSession.Core
2297
2298**Parameters**
2299
2300| Name   | Type                 | Mandatory| Description                                                                                                                        |
2301| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2302| type     | string               | Yes  | Event type, which is **'play'** in this case.|
2303| 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.                           |
2304
2305**Error codes**
2306
2307For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2308
2309| ID| Error Message|
2310| -------- | ---------------------------------------- |
2311| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2312| 6600101  | Session service exception. |
2313| 6600102  | The session does not exist. |
2314
2315**Example**
2316
2317```ts
2318currentAVSession.off('play');
2319```
2320
2321### off('pause')<sup>10+</sup>
2322
2323off(type: 'pause', callback?: () => void): void
2324
2325Unsubscribes from pause command events.
2326
2327After the callback is canceled, the list of supported commands must be updated.
2328
2329**Atomic service API**: This API can be used in atomic services since API version 12.
2330
2331**System capability**: SystemCapability.Multimedia.AVSession.Core
2332
2333**Parameters**
2334
2335| Name   | Type                 | Mandatory| Description                                                                                                                        |
2336| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2337| type     | string               | Yes  | Event type, which is **'pause'** in this case.|
2338| 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.|
2339
2340**Error codes**
2341
2342For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2343
2344| ID| Error Message|
2345| -------- | ---------------------------------------- |
2346| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2347| 6600101  | Session service exception. |
2348| 6600102  | The session does not exist. |
2349
2350**Example**
2351
2352```ts
2353currentAVSession.off('pause');
2354```
2355
2356### off('stop')<sup>10+</sup>
2357
2358off(type: 'stop', callback?: () => void): void
2359
2360Unsubscribes from stop command events.
2361
2362After the callback is canceled, the list of supported commands must be updated.
2363
2364**Atomic service API**: This API can be used in atomic services since API version 12.
2365
2366**System capability**: SystemCapability.Multimedia.AVSession.Core
2367
2368**Parameters**
2369
2370| Name   | Type                 | Mandatory| Description                                                                                                                        |
2371| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2372| type     | string               | Yes  | Event type, which is **'stop'** in this case.|
2373| 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.                           |
2374
2375**Error codes**
2376
2377For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2378
2379| ID| Error Message|
2380| -------- | ---------------------------------------- |
2381| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2382| 6600101  | Session service exception. |
2383| 6600102  | The session does not exist. |
2384
2385**Example**
2386
2387```ts
2388currentAVSession.off('stop');
2389```
2390
2391### off('playNext')<sup>10+</sup>
2392
2393off(type: 'playNext', callback?: () => void): void
2394
2395Unsubscribes from playNext command events.
2396
2397After the callback is canceled, the list of supported commands must be updated.
2398
2399**Atomic service API**: This API can be used in atomic services since API version 12.
2400
2401**System capability**: SystemCapability.Multimedia.AVSession.Core
2402
2403**Parameters**
2404
2405| Name   | Type                 | Mandatory| Description                                                                                                                        |
2406| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2407| type     | string               | Yes  | Event type, which is **'playNext'** in this case.|
2408| 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.                           |
2409
2410**Error codes**
2411
2412For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2413
2414| ID| Error Message|
2415| -------- | ---------------------------------------- |
2416| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2417| 6600101  | Session service exception. |
2418| 6600102  | The session does not exist. |
2419
2420**Example**
2421
2422```ts
2423currentAVSession.off('playNext');
2424```
2425
2426### off('playPrevious')<sup>10+</sup>
2427
2428off(type: 'playPrevious', callback?: () => void): void
2429
2430Unsubscribes from playPrevious command events.
2431
2432After the callback is canceled, the list of supported commands must be updated.
2433
2434**Atomic service API**: This API can be used in atomic services since API version 12.
2435
2436**System capability**: SystemCapability.Multimedia.AVSession.Core
2437
2438**Parameters**
2439
2440| Name   | Type                 | Mandatory| Description                                                                                                                        |
2441| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2442| type     | string               | Yes  | Event type, which is **'playPrevious'** in this case.|
2443| 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.                           |
2444
2445**Error codes**
2446
2447For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2448
2449| ID| Error Message|
2450| -------- | ---------------------------------------- |
2451| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2452| 6600101  | Session service exception. |
2453| 6600102  | The session does not exist. |
2454
2455**Example**
2456
2457```ts
2458currentAVSession.off('playPrevious');
2459```
2460
2461### off('fastForward')<sup>10+</sup>
2462
2463off(type: 'fastForward', callback?: () => void): void
2464
2465Unsubscribes from fastForward command events.
2466
2467After the callback is canceled, the list of supported commands must be updated.
2468
2469**Atomic service API**: This API can be used in atomic services since API version 12.
2470
2471**System capability**: SystemCapability.Multimedia.AVSession.Core
2472
2473**Parameters**
2474
2475| Name   | Type                 | Mandatory| Description                                                                                                                        |
2476| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2477| type     | string               | Yes  | Event type, which is **'fastForward'** in this case.|
2478| 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.                           |
2479
2480**Error codes**
2481
2482For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2483
2484| ID| Error Message|
2485| -------- | ---------------------------------------- |
2486| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2487| 6600101  | Session service exception. |
2488| 6600102  | The session does not exist. |
2489
2490**Example**
2491
2492```ts
2493currentAVSession.off('fastForward');
2494```
2495
2496### off('rewind')<sup>10+</sup>
2497
2498off(type: 'rewind', callback?: () => void): void
2499
2500Unsubscribes from rewind command events.
2501
2502**Atomic service API**: This API can be used in atomic services since API version 12.
2503
2504**System capability**: SystemCapability.Multimedia.AVSession.Core
2505
2506**Parameters**
2507
2508| Name   | Type                 | Mandatory| Description                                                                                                                        |
2509| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2510| type     | string               | Yes  | Event type, which is **'rewind'** in this case.|
2511| 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.                           |
2512
2513**Error codes**
2514
2515For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2516
2517| ID| Error Message|
2518| -------- | ---------------------------------------- |
2519| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2520| 6600101  | Session service exception. |
2521| 6600102  | The session does not exist. |
2522
2523**Example**
2524
2525```ts
2526currentAVSession.off('rewind');
2527```
2528
2529### off('seek')<sup>10+</sup>
2530
2531off(type: 'seek', callback?: (time: number) => void): void
2532
2533Unsubscribes from seek command events.
2534
2535**Atomic service API**: This API can be used in atomic services since API version 12.
2536
2537**System capability**: SystemCapability.Multimedia.AVSession.Core
2538
2539**Parameters**
2540
2541| Name  | Type                  | Mandatory| Description                                         |
2542| -------- | ---------------------- | ---- | ----------------------------------------- |
2543| type     | string                 | Yes  | Event type, which is **'seek'** in this case.      |
2544| 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.       |
2545
2546**Error codes**
2547
2548For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2549
2550| ID| Error Message|
2551| -------- | ---------------------------------------- |
2552| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2553| 6600101  | Session service exception. |
2554| 6600102  | The session does not exist. |
2555
2556**Example**
2557
2558```ts
2559currentAVSession.off('seek');
2560```
2561
2562### off('setSpeed')<sup>10+</sup>
2563
2564off(type: 'setSpeed', callback?: (speed: number) => void): void
2565
2566Unsubscribes from setSpeed command events.
2567
2568**Atomic service API**: This API can be used in atomic services since API version 12.
2569
2570**System capability**: SystemCapability.Multimedia.AVSession.Core
2571
2572**Parameters**
2573
2574| Name  | Type                   | Mandatory| Description                                          |
2575| -------- | ----------------------- | ---- | -------------------------------------------|
2576| type     | string                  | Yes  | Event type, which is **'setSpeed'** in this case.   |
2577| 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.                |
2578
2579**Error codes**
2580
2581For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2582
2583| ID| Error Message|
2584| -------- | ---------------------------------------- |
2585| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2586| 6600101  | Session service exception. |
2587| 6600102  | The session does not exist. |
2588
2589**Example**
2590
2591```ts
2592currentAVSession.off('setSpeed');
2593```
2594
2595### off('setLoopMode')<sup>10+</sup>
2596
2597off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
2598
2599Unsubscribes from setSpeed command events.
2600
2601**Atomic service API**: This API can be used in atomic services since API version 12.
2602
2603**System capability**: SystemCapability.Multimedia.AVSession.Core
2604
2605**Parameters**
2606
2607| Name  | Type                                 | Mandatory| Description    |
2608| -------- | ------------------------------------- | ---- | ----- |
2609| type     | string | Yes  | Event type, which is **'setLoopMode'** in this case.|
2610| 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.|
2611
2612**Error codes**
2613
2614For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2615
2616| ID| Error Message|
2617| -------- | ---------------------------------------- |
2618| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2619| 6600101  | Session service exception. |
2620| 6600102  | The session does not exist. |
2621
2622**Example**
2623
2624```ts
2625currentAVSession.off('setLoopMode');
2626```
2627
2628### off('toggleFavorite')<sup>10+</sup>
2629
2630off(type: 'toggleFavorite', callback?: (assetId: string) => void): void
2631
2632Unsubscribes from toggleFavorite command events.
2633
2634**Atomic service API**: This API can be used in atomic services since API version 12.
2635
2636**System capability**: SystemCapability.Multimedia.AVSession.Core
2637
2638**Parameters**
2639
2640| Name  | Type                     | Mandatory| Description                                                        |
2641| -------- | ------------------------- | ---- | -------------------------------------------------------- |
2642| type     | string                    | Yes  | Event type, which is **'toggleFavorite'** in this case.           |
2643| 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.                              |
2644
2645**Error codes**
2646
2647For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2648
2649| ID| Error Message|
2650| -------- | ---------------------------------------- |
2651| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2652| 6600101  | Session service exception. |
2653| 6600102  | The session does not exist. |
2654
2655**Example**
2656
2657```ts
2658currentAVSession.off('toggleFavorite');
2659```
2660
2661### off('skipToQueueItem')<sup>10+</sup>
2662
2663off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
2664
2665Unsubscribes from the event that indicates an item in the playlist is selected.
2666
2667**Atomic service API**: This API can be used in atomic services since API version 12.
2668
2669**System capability**: SystemCapability.Multimedia.AVSession.Core
2670
2671**Parameters**
2672
2673| Name  | Type                     | Mandatory| Description                                                                                                                                                       |
2674| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
2675| type     | string                   | Yes  | Event type, which is **'skipToQueueItem'** in this case.                                                                                                         |
2676| 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.|
2677
2678**Error codes**
2679
2680For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2681
2682| ID| Error Message|
2683| -------- | ---------------------------------------- |
2684| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2685| 6600101  | Session service exception. |
2686| 6600102  | The session does not exist. |
2687
2688**Example**
2689
2690```ts
2691currentAVSession.off('skipToQueueItem');
2692```
2693
2694### off('handleKeyEvent')<sup>10+</sup>
2695
2696off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
2697
2698Unsubscribes from key events.
2699
2700**Atomic service API**: This API can be used in atomic services since API version 12.
2701
2702**System capability**: SystemCapability.Multimedia.AVSession.Core
2703
2704**Parameters**
2705
2706| Name  | Type                                                        | Mandatory| Description                                                        |
2707| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2708| type     | string                                                       | Yes  | Event type, which is **'handleKeyEvent'** in this case.            |
2709| 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.                             |
2710
2711**Error codes**
2712
2713For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2714
2715| ID| Error Message|
2716| -------- | ---------------------------------------- |
2717| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2718| 6600101  | Session service exception. |
2719| 6600102  | The session does not exist. |
2720
2721**Example**
2722
2723```ts
2724currentAVSession.off('handleKeyEvent');
2725```
2726
2727### off('outputDeviceChange')<sup>10+</sup>
2728
2729off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2730
2731Unsubscribes from playback device change events.
2732
2733**Atomic service API**: This API can be used in atomic services since API version 12.
2734
2735**System capability**: SystemCapability.Multimedia.AVSession.Core
2736
2737**Parameters**
2738
2739| Name  | Type                                                   | Mandatory| Description                                                     |
2740| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
2741| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.    |
2742| 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.                       |
2743
2744**Error codes**
2745
2746For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2747
2748| ID| Error Message|
2749| -------- | ---------------------------------------- |
2750| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2751| 6600101  | Session service exception. |
2752| 6600102  | The session does not exist. |
2753
2754**Example**
2755
2756```ts
2757currentAVSession.off('outputDeviceChange');
2758```
2759
2760
2761### off('commonCommand')<sup>10+</sup>
2762
2763off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void
2764
2765Unsubscribes from custom control command change events.
2766
2767**Atomic service API**: This API can be used in atomic services since API version 12.
2768
2769**System capability**: SystemCapability.Multimedia.AVSession.Core
2770
2771**Parameters**
2772
2773| Name  | Type                                                        | Mandatory| Description                                                    |
2774| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2775| type     | string                                                       | Yes  | Event type, which is **'commonCommand'** in this case.   |
2776| 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.                     |
2777
2778**Error codes**
2779
2780For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2781
2782| ID| Error Message|
2783| -------- | ---------------- |
2784| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2785| 6600101  | Session service exception. |
2786| 6600102  | The session does not exist. |
2787
2788**Example**
2789
2790```ts
2791currentAVSession.off('commonCommand');
2792```
2793
2794### on('answer')<sup>11+</sup>
2795
2796on(type: 'answer', callback: Callback\<void>): void;
2797
2798Subscribes to call answer events.
2799
2800**Atomic service API**: This API can be used in atomic services since API version 12.
2801
2802**System capability**: SystemCapability.Multimedia.AVSession.Core
2803
2804**Parameters**
2805
2806| Name  | Type                                                        | Mandatory| Description                                                        |
2807| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2808| type     | string                                                       | Yes  | Event type. The event **'answer'** is triggered when a call is answered.|
2809| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                     |
2810
2811**Error codes**
2812
2813For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2814
2815| ID| Error Message|
2816| -------- | ------------------------------ |
2817| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2818| 6600101  | Session service exception. |
2819| 6600102  | The session does not exist. |
2820
2821**Example**
2822
2823```ts
2824currentAVSession.on('answer', () => {
2825  console.info('on call answer');
2826});
2827```
2828
2829### off('answer')<sup>11+</sup>
2830
2831off(type: 'answer', callback?: Callback\<void>): void;
2832
2833Unsubscribes from call answer events.
2834
2835**Atomic service API**: This API can be used in atomic services since API version 12.
2836
2837**System capability**: SystemCapability.Multimedia.AVSession.Core
2838
2839**Parameters**
2840
2841| Name   | Type                 | Mandatory| Description                                                                                                                        |
2842| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2843| type     | string               | Yes  | Event type, which is **'answer'** in this case.|
2844| 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.   |
2845
2846**Error codes**
2847
2848For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2849
2850| ID| Error Message|
2851| -------- | ---------------------------------------- |
2852| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2853| 6600101  | Session service exception. |
2854| 6600102  | The session does not exist. |
2855
2856**Example**
2857
2858```ts
2859currentAVSession.off('answer');
2860```
2861
2862### on('hangUp')<sup>11+</sup>
2863
2864on(type: 'hangUp', callback: Callback\<void>): void;
2865
2866Subscribes to call hangup events.
2867
2868**Atomic service API**: This API can be used in atomic services since API version 12.
2869
2870**System capability**: SystemCapability.Multimedia.AVSession.Core
2871
2872**Parameters**
2873
2874| Name  | Type                                                        | Mandatory| Description                                                        |
2875| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2876| type     | string                                                       | Yes  | Event type. The event **'hangUp'** is triggered when a call is hung up.|
2877| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2878
2879**Error codes**
2880
2881For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2882
2883| ID| Error Message|
2884| -------- | ------------------------------ |
2885| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2886| 6600101  | Session service exception. |
2887| 6600102  | The session does not exist. |
2888
2889**Example**
2890
2891```ts
2892currentAVSession.on('hangUp', () => {
2893  console.info('on call hangUp');
2894});
2895```
2896
2897### off('hangUp')<sup>11+</sup>
2898
2899off(type: 'hangUp', callback?: Callback\<void>): void;
2900
2901Unsubscribes from call answer events.
2902
2903**Atomic service API**: This API can be used in atomic services since API version 12.
2904
2905**System capability**: SystemCapability.Multimedia.AVSession.Core
2906
2907**Parameters**
2908
2909| Name   | Type                 | Mandatory| Description                                                                                                                        |
2910| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2911| type     | string               | Yes  | Event type, which is **'hangUp'** in this case.|
2912| 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.                           |
2913
2914**Error codes**
2915
2916For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2917
2918| ID| Error Message|
2919| -------- | ---------------------------------------- |
2920| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2921| 6600101  | Session service exception. |
2922| 6600102  | The session does not exist. |
2923
2924**Example**
2925
2926```ts
2927currentAVSession.off('hangUp');
2928```
2929
2930### on('toggleCallMute')<sup>11+</sup>
2931
2932on(type: 'toggleCallMute', callback: Callback\<void>): void;
2933
2934Subscribes to call mute events.
2935
2936**Atomic service API**: This API can be used in atomic services since API version 12.
2937
2938**System capability**: SystemCapability.Multimedia.AVSession.Core
2939
2940**Parameters**
2941
2942| Name  | Type                                                        | Mandatory| Description                                                        |
2943| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2944| type     | string                                                       | Yes  | Event type. The event **'toggleCallMute'** is triggered when a call is muted or unmuted.|
2945| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2946
2947**Error codes**
2948
2949For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2950
2951| ID| Error Message|
2952| -------- | ------------------------------ |
2953| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2954| 6600101  | Session service exception. |
2955| 6600102  | The session does not exist. |
2956
2957**Example**
2958
2959```ts
2960currentAVSession.on('toggleCallMute', () => {
2961  console.info('on call toggleCallMute');
2962});
2963```
2964
2965### off('toggleCallMute')<sup>11+</sup>
2966
2967off(type: 'toggleCallMute', callback?: Callback\<void>): void;
2968
2969Unsubscribes from call mute events.
2970
2971**Atomic service API**: This API can be used in atomic services since API version 12.
2972
2973**System capability**: SystemCapability.Multimedia.AVSession.Core
2974
2975**Parameters**
2976
2977| Name   | Type                 | Mandatory| Description                                                                                                                        |
2978| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2979| type     | string               | Yes  | Event type, which is **'toggleCallMute'** in this case.|
2980| 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.                           |
2981
2982**Error codes**
2983
2984For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2985
2986| ID| Error Message|
2987| -------- | ---------------------------------------- |
2988| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2989| 6600101  | Session service exception. |
2990| 6600102  | The session does not exist. |
2991
2992**Example**
2993
2994```ts
2995currentAVSession.off('toggleCallMute');
2996```
2997
2998### on('castDisplayChange')<sup>12+</sup>
2999
3000on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void
3001
3002Subscribes to cast display change events in the case of extended screens.
3003
3004**Atomic service API**: This API can be used in atomic services since API version 12.
3005
3006**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3007
3008**Parameters**
3009
3010| Name   | Type                 | Mandatory| Description                                                                                                                        |
3011| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3012| type     | string                                                       | Yes  | Event type. The event **'castDisplayChange'** is triggered when the cast display in the case of extended screens changes.|
3013| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | Yes  | Callback used to return the information about the cast display.                           |
3014
3015**Error codes**
3016
3017For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3018
3019| ID| Error Message|
3020| -------- | ---------------------------------------- |
3021| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3022| 6600101  | Session service exception. |
3023| 6600102  | The session does not exist. |
3024
3025**Example**
3026
3027```ts
3028let castDisplay: avSession.CastDisplayInfo;
3029currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => {
3030    if (display.state === avSession.CastDisplayState.STATE_ON) {
3031        castDisplay = display;
3032        console.info(`Succeeded in castDisplayChange display : ${display.id} ON`);
3033    } else if (display.state === avSession.CastDisplayState.STATE_OFF){
3034        console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`);
3035    }
3036});
3037```
3038### off('castDisplayChange')<sup>12+</sup>
3039
3040 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void
3041
3042Unsubscribes from cast display change events in the case of extended screens.
3043
3044**Atomic service API**: This API can be used in atomic services since API version 12.
3045
3046**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3047
3048**Parameters**
3049
3050| Name   | Type                 | Mandatory| Description                                                                                                                        |
3051| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3052| type     | string                                                       | Yes  | Event type, which is **'castDisplayChange'** in this case.|
3053| 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.                           |
3054
3055**Error codes**
3056
3057For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3058
3059| ID| Error Message|
3060| -------- | ---------------------------------------- |
3061| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3062| 6600101  | Session service exception. |
3063| 6600102  | The session does not exist. |
3064
3065**Example**
3066
3067```ts
3068currentAVSession.off('castDisplayChange');
3069```
3070
3071### stopCasting<sup>10+</sup>
3072
3073stopCasting(callback: AsyncCallback\<void>): void
3074
3075Stops castings. This API uses an asynchronous callback to return the result.
3076
3077**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3078
3079**Parameters**
3080
3081| Name  | Type                                 | Mandatory| Description                                 |
3082| -------- | ------------------------------------- | ---- | ------------------------------------- |
3083| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3084
3085**Error codes**
3086
3087For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3088
3089| ID| Error Message|
3090| -------- | ---------------------------------------- |
3091| 6600109  | The remote connection is not established. |
3092
3093**Example**
3094
3095```ts
3096import { BusinessError } from '@kit.BasicServicesKit';
3097
3098currentAVSession.stopCasting((err: BusinessError) => {
3099  if (err) {
3100    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3101  } else {
3102    console.info('stopCasting successfully');
3103  }
3104});
3105```
3106
3107### stopCasting<sup>10+</sup>
3108
3109stopCasting(): Promise\<void>
3110
3111Stops castings. This API uses a promise to return the result.
3112
3113**Atomic service API**: This API can be used in atomic services since API version 12.
3114
3115**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3116
3117**Return value**
3118
3119| Type          | Description                         |
3120| -------------- | ----------------------------- |
3121| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.|
3122
3123**Error codes**
3124
3125For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3126
3127| ID| Error Message|
3128| -------- | ---------------------------------------- |
3129| 6600109  | The remote connection is not established. |
3130
3131**Example**
3132
3133```ts
3134import { BusinessError } from '@kit.BasicServicesKit';
3135
3136currentAVSession.stopCasting().then(() => {
3137  console.info('stopCasting successfully');
3138}).catch((err: BusinessError) => {
3139  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3140});
3141```
3142
3143### getOutputDeviceSync<sup>10+</sup>
3144
3145getOutputDeviceSync(): OutputDeviceInfo
3146
3147Obtains the output device information. This API returns the result synchronously.
3148
3149**Atomic service API**: This API can be used in atomic services since API version 12.
3150
3151**System capability**: SystemCapability.Multimedia.AVSession.Core
3152
3153**Return value**
3154
3155| Type                                           | Description                             |
3156| ----------------------------------------------- | --------------------------------- |
3157| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.|
3158
3159**Error codes**
3160
3161For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3162
3163| ID  | Error Message|
3164|---------| --------------------------------------- |
3165| 6600101 | Session service exception. |
3166| 6600102 | The session does not exist. |
3167
3168**Example**
3169
3170```ts
3171import { BusinessError } from '@kit.BasicServicesKit';
3172
3173try {
3174  let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync();
3175} catch (err) {
3176  let error = err as BusinessError;
3177  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
3178}
3179```
3180### getAllCastDisplays<sup>12+</sup>
3181
3182getAllCastDisplays(): Promise<Array\<CastDisplayInfo>>
3183
3184Obtains all displays that support extended screen projection in the current system. This API uses a promise to return the result.
3185
3186**Atomic service API**: This API can be used in atomic services since API version 12.
3187
3188**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3189
3190**Return value**
3191
3192| Type                                           | Description                             |
3193| ----------------------------------------------- | --------------------------------- |
3194| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise used to return the information about all the cast displays.|
3195
3196**Error codes**
3197
3198For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3199
3200| ID  | Error Message|
3201|---------| --------------------------------------- |
3202| 6600101 | Session service exception. |
3203| 6600102 | The session does not exist. |
3204
3205**Example**
3206
3207```ts
3208import { BusinessError } from '@kit.BasicServicesKit';
3209
3210let castDisplay: avSession.CastDisplayInfo;
3211currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => {
3212    if (data.length >= 1) {
3213       castDisplay = data[0];
3214     }
3215   }).catch((err: BusinessError) => {
3216     console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`);
3217   });
3218```
3219
3220## AVCastControlCommandType<sup>10+</sup>
3221
3222type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
3223  'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'
3224
3225Enumerates the commands that can be sent by a cast controller.
3226
3227**Atomic service API**: This API can be used in atomic services since API version 12.
3228
3229**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3230
3231| Type            | Description        |
3232| ---------------- | ------------ |
3233| 'play'           | Play the media.        |
3234| 'pause'          | Pause the playback.        |
3235| 'stop'           | Stop the playback.        |
3236| 'playNext'       | Play the next media asset.      |
3237| 'playPrevious'   | Play the previous media asset.      |
3238| 'fastForward'    | Fast-forward.        |
3239| 'rewind'         | Rewind.        |
3240| 'seek'           | Seek to a playback position.|
3241| 'setVolume'      | Set the volume.    |
3242| 'setSpeed'       | Set the playback speed.|
3243| 'setLoopMode'    | Set the loop mode.|
3244| 'toggleFavorite' | Favorite the media asset.    |
3245| 'toggleMute'     | Set the muted status.|
3246
3247## AVCastControlCommand<sup>10+</sup>
3248
3249Defines the command that can be sent by a cast controller.
3250
3251**Atomic service API**: This API can be used in atomic services since API version 12.
3252
3253**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3254
3255| Name     | Type                                             | Mandatory| Description          |
3256| --------- | ------------------------------------------------- | ---- | -------------- |
3257| command   | [AVCastControlCommandType](#avcastcontrolcommandtype10)     | Yes  | Command.          |
3258| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) &#124; number &#124; string &#124; [LoopMode](#loopmode10) | No  | Parameters carried in the command.|
3259
3260## AVCastController<sup>10+</sup>
3261
3262After 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.
3263
3264### getAVPlaybackState<sup>10+</sup>
3265
3266getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
3267
3268Obtains the remote playback state. This API uses an asynchronous callback to return the result.
3269
3270**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3271
3272**Parameters**
3273
3274| Name   | Type                                                       | Mandatory| Description                                                        |
3275| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3276| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
3277
3278**Error codes**
3279
3280For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3281
3282| ID| Error Message|
3283| -------- | ---------------------------------------- |
3284| 6600101  | Session service exception |
3285
3286**Example**
3287
3288```ts
3289import { BusinessError } from '@kit.BasicServicesKit';
3290
3291aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
3292  if (err) {
3293    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3294  } else {
3295    console.info('getAVPlaybackState : SUCCESS');
3296  }
3297});
3298```
3299
3300### getAVPlaybackState<sup>10+</sup>
3301
3302getAVPlaybackState(): Promise\<AVPlaybackState>
3303
3304Obtains the remote playback state. This API uses a promise to return the result.
3305
3306**Atomic service API**: This API can be used in atomic services since API version 12.
3307
3308**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3309
3310**Return value**
3311
3312| Type                                                       | Description                                                        |
3313| --------- | ------------------------------------------------------------ |
3314| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state.|
3315
3316**Error codes**
3317
3318For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3319
3320| ID| Error Message|
3321| -------- | ---------------------------------------- |
3322| 6600101  | Session service exception |
3323
3324**Example**
3325
3326```ts
3327import { BusinessError } from '@kit.BasicServicesKit';
3328
3329aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
3330  console.info('getAVPlaybackState : SUCCESS');
3331}).catch((err: BusinessError) => {
3332  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3333});
3334```
3335
3336### getSupportedDecoders<sup>18+</sup>
3337
3338getSupportedDecoders(): Promise\<Array\<DecoderType>>
3339
3340Obtains the decoding modes supported by the current remote device. This API uses a promise to return the result.
3341
3342**Atomic service API**: This API can be used in atomic services since API version 18.
3343
3344**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3345
3346**Return value**
3347
3348| Type                                                       | Description                                                        |
3349| --------- | ------------------------------------------------------------ |
3350| Promise\<Array\<[DecoderType](#decodertype18)\>\> | Promise used to return an array of decoding modes supported by the remote device.|
3351
3352**Error codes**
3353
3354For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3355
3356| ID| Error Message|
3357| -------- | ---------------------------------------- |
3358| 6600101  | Session service exception. |
3359
3360**Example**
3361
3362```ts
3363import { BusinessError } from '@kit.BasicServicesKit';
3364
3365aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => {
3366  console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`);
3367  if (descriptors.length > 0 ) {
3368    console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`);
3369  }
3370}).catch((err: BusinessError) => {
3371  console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`);
3372});
3373```
3374
3375### getRecommendedResolutionLevel<sup>18+</sup>
3376
3377getRecommendedResolutionLevel(decoderType: DecoderType): Promise\<ResolutionLevel>
3378
3379Obtains the recommended resolution level based on the passed decoding mode. This API uses a promise to return the result.
3380
3381**Atomic service API**: This API can be used in atomic services since API version 18.
3382
3383**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3384
3385**Return value**
3386
3387| Type                                                       | Description                                                        |
3388| --------- | ------------------------------------------------------------ |
3389| Promise\<[ResolutionLevel](#resolutionlevel18)\> | Promise used to return the recommended resolution level of the remote device.|
3390
3391**Error codes**
3392
3393For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3394
3395| ID| Error Message|
3396| -------- | ---------------------------------------- |
3397| 6600101  | Session service exception. |
3398
3399**Example**
3400
3401```ts
3402import { BusinessError } from '@kit.BasicServicesKit';
3403
3404let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC;
3405let resolutionLeve = avSession.ResolutionLevel;
3406aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLeve) => {
3407  console.info('getRecommendedResolutionLevel successfully');
3408}).catch((err: BusinessError) => {
3409  console.error(`getRecommendedResolutionLevel BusinessError: code: ${err.code}, message: ${err.message}`);
3410});
3411```
3412
3413### getSupportedHdrCapabilities<sup>18+</sup>
3414
3415getSupportedHdrCapabilities(): Promise\<Array\<hdrCapability.HDRFormat>>
3416
3417Obtains the HDR capabilities supported by the current remote device. This API uses a promise to return the result.
3418
3419**Atomic service API**: This API can be used in atomic services since API version 18.
3420
3421**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3422
3423**Return value**
3424
3425| Type                                                       | Description                                                        |
3426| --------- | ------------------------------------------------------------ |
3427| Promise\<Array\<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md#hdrformat)\>\> | Promise used to return an array of HDR capabilities supported by the remote device.|
3428
3429**Error codes**
3430
3431For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3432
3433| ID| Error Message|
3434| -------- | ---------------------------------------- |
3435| 6600101  | Session service exception. |
3436
3437**Example**
3438
3439```ts
3440import { BusinessError } from '@kit.BasicServicesKit';
3441import type hdrCapability from './@ohos.graphics.hdrCapability';
3442
3443aVCastController.getSupportedHdrCapabilities().then((hdrFormats: hdrCapability.HDRFormat[]) => {
3444  console.info(`getSupportedHdrCapabilities : SUCCESS : hdrFormats.length : ${hdrFormats.length}`);
3445  if (hdrFormats.length > 0 ) {
3446    console.info(`getSupportedHdrCapabilities : SUCCESS : descriptors[0] : ${hdrFormats[0]}`);
3447  }
3448}).catch((err: BusinessError) => {
3449  console.error(`getSupportedHdrCapabilities BusinessError: code: ${err.code}, message: ${err.message}`);
3450});
3451```
3452
3453### getSupportedPlaySpeeds<sup>18+</sup>
3454
3455getSupportedPlaySpeeds(): Promise\<Array\<number>>
3456
3457Obtains the playback speeds supported by the current remote device. This API uses a promise to return the result.
3458
3459**Atomic service API**: This API can be used in atomic services since API version 18.
3460
3461**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3462
3463**Return value**
3464
3465| Type                                                       | Description                                                        |
3466| --------- | ------------------------------------------------------------ |
3467| Promise\<Array\<number\>\> | Promise used to return an array of playback speeds supported by the remote device.|
3468
3469**Error codes**
3470
3471For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3472
3473| ID| Error Message|
3474| -------- | ---------------------------------------- |
3475| 6600101  | Session service exception. |
3476
3477**Example**
3478
3479```ts
3480import { BusinessError } from '@kit.BasicServicesKit';
3481
3482aVCastController.getSupportedPlaySpeeds().then((nums: number[]) => {
3483  console.info(`getSupportedPlaySpeeds : SUCCESS : hdrFormats.length : ${nums.length}`);
3484  if (nums.length > 0 ) {
3485    console.info(`getSupportedPlaySpeeds : SUCCESS : descriptors[0] : ${nums[0]}`);
3486  }
3487}).catch((err: BusinessError) => {
3488  console.error(`getSupportedPlaySpeeds BusinessError: code: ${err.code}, message: ${err.message}`);
3489});
3490```
3491
3492### sendControlCommand<sup>10+</sup>
3493
3494sendControlCommand(command: AVCastControlCommand): Promise\<void>
3495
3496Sends a control command to the session through the controller. This API uses a promise to return the result.
3497
3498
3499**Atomic service API**: This API can be used in atomic services since API version 12.
3500
3501**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3502
3503**Parameters**
3504
3505| Name   | Type                                 | Mandatory| Description                          |
3506| ------- | ------------------------------------- | ---- | ------------------------------ |
3507| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
3508
3509**Return value**
3510
3511| Type          | Description                         |
3512| -------------- | ----------------------------- |
3513| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3514
3515**Error codes**
3516
3517For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3518
3519| ID| Error Message|
3520| -------- | ---------------------------------------- |
3521| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3522| 6600101  | Session service exception. |
3523| 6600105  | Invalid session command. |
3524| 6600109  | The remote connection is not established. |
3525
3526**Example**
3527
3528```ts
3529import { BusinessError } from '@kit.BasicServicesKit';
3530
3531let avCommand: avSession.AVCastControlCommand = {command:'play'};
3532aVCastController.sendControlCommand(avCommand).then(() => {
3533  console.info('SendControlCommand successfully');
3534}).catch((err: BusinessError) => {
3535  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3536});
3537```
3538
3539### sendControlCommand<sup>10+</sup>
3540
3541sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
3542
3543Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
3544
3545
3546**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3547
3548**Parameters**
3549
3550| Name  | Type                                 | Mandatory| Description                          |
3551| -------- | ------------------------------------- | ---- | ------------------------------ |
3552| command  | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
3553| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
3554
3555**Error codes**
3556
3557For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3558
3559| ID| Error Message|
3560| -------- | ------------------------------- |
3561| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3562| 6600101  | Session service exception. |
3563| 6600105  | Invalid session command. |
3564| 6600109  | The remote connection is not established. |
3565
3566**Example**
3567
3568```ts
3569import { BusinessError } from '@kit.BasicServicesKit';
3570
3571let avCommand: avSession.AVCastControlCommand = {command:'play'};
3572aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
3573  if (err) {
3574    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3575  } else {
3576    console.info('SendControlCommand successfully');
3577  }
3578});
3579```
3580
3581### prepare<sup>10+</sup>
3582
3583prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
3584
3585Prepares 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.
3586
3587**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3588
3589**Parameters**
3590
3591| Name   | Type                                 | Mandatory| Description                          |
3592| ------- | ------------------------------------- | ---- | ------------------------------ |
3593| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3594| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3595
3596**Error codes**
3597
3598For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3599
3600| ID| Error Message|
3601| -------- | ---------------------------------------- |
3602| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3603| 6600101  | Session service exception. |
3604| 6600109  | The remote connection is not established. |
3605
3606**Example**
3607
3608```ts
3609import { BusinessError } from '@kit.BasicServicesKit';
3610
3611// Set playback parameters.
3612let playItem: avSession.AVQueueItem = {
3613  itemId: 0,
3614  description: {
3615    assetId: '12345',
3616    mediaType: 'AUDIO',
3617    mediaUri: 'http://resource1_address',
3618    mediaSize: 12345,
3619    startPosition: 0,
3620    duration: 0,
3621    artist: 'mysong',
3622    albumTitle: 'song1_title',
3623    albumCoverUri: "http://resource1_album_address",
3624    lyricUri: "http://resource1_lyric_address",
3625    appName: 'MyMusic'
3626  }
3627};
3628// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3629aVCastController.prepare(playItem, (err: BusinessError) => {
3630  if (err) {
3631    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3632  } else {
3633    console.info('prepare successfully');
3634  }
3635});
3636```
3637
3638
3639### prepare<sup>10+</sup>
3640
3641prepare(item: AVQueueItem): Promise\<void>
3642
3643Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result.
3644
3645
3646**Atomic service API**: This API can be used in atomic services since API version 12.
3647
3648**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3649
3650**Parameters**
3651
3652| Name   | Type                                 | Mandatory| Description                          |
3653| ------- | ------------------------------------- | ---- | ------------------------------ |
3654| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3655
3656**Return value**
3657
3658| Type          | Description                         |
3659| -------------- | ----------------------------- |
3660| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3661
3662**Error codes**
3663
3664For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3665
3666| ID| Error Message|
3667| -------- | ---------------------------------------- |
3668| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3669| 6600101  | Session service exception. |
3670| 6600109  | The remote connection is not established. |
3671
3672
3673**Example**
3674
3675```ts
3676import { BusinessError } from '@kit.BasicServicesKit';
3677
3678// Set playback parameters.
3679let playItem: avSession.AVQueueItem = {
3680  itemId: 0,
3681  description: {
3682    assetId: '12345',
3683    mediaType: 'AUDIO',
3684    mediaUri: 'http://resource1_address',
3685    mediaSize: 12345,
3686    startPosition: 0,
3687    duration: 0,
3688    artist: 'mysong',
3689    albumTitle: 'song1_title',
3690    albumCoverUri: "http://resource1_album_address",
3691    lyricUri: "http://resource1_lyric_address",
3692    appName: 'MyMusic'
3693  }
3694};
3695// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3696aVCastController.prepare(playItem).then(() => {
3697  console.info('prepare successfully');
3698}).catch((err: BusinessError) => {
3699  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3700});
3701```
3702
3703### start<sup>10+</sup>
3704
3705start(item: AVQueueItem, callback: AsyncCallback\<void>): void
3706
3707Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
3708
3709**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3710
3711**Parameters**
3712
3713| Name   | Type                                 | Mandatory| Description                          |
3714| ------- | ------------------------------------- | ---- | ------------------------------ |
3715| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3716| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3717
3718**Error codes**
3719
3720For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3721
3722| ID| Error Message|
3723| -------- | ---------------------------------------- |
3724| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3725| 6600101  | Session service exception. |
3726| 6600109  | The remote connection is not established. |
3727
3728**Example**
3729
3730```ts
3731import { BusinessError } from '@kit.BasicServicesKit';
3732
3733// Set playback parameters.
3734let playItem: avSession.AVQueueItem = {
3735  itemId: 0,
3736  description: {
3737    assetId: '12345',
3738    mediaType: 'AUDIO',
3739    mediaUri: 'http://resource1_address',
3740    mediaSize: 12345,
3741    startPosition: 0,
3742    duration: 0,
3743    artist: 'mysong',
3744    albumTitle: 'song1_title',
3745    albumCoverUri: "http://resource1_album_address",
3746    lyricUri: "http://resource1_lyric_address",
3747    appName: 'MyMusic'
3748  }
3749};
3750
3751// Start playback.
3752aVCastController.start(playItem, (err: BusinessError) => {
3753  if (err) {
3754    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3755  } else {
3756    console.info('start successfully');
3757  }
3758});
3759```
3760
3761### start<sup>10+</sup>
3762
3763start(item: AVQueueItem): Promise\<void>
3764
3765Prepares for the playback of a media asset. This API uses a promise to return the result.
3766
3767
3768**Atomic service API**: This API can be used in atomic services since API version 12.
3769
3770**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3771
3772**Parameters**
3773
3774| Name   | Type                                 | Mandatory| Description                          |
3775| ------- | ------------------------------------- | ---- | ------------------------------ |
3776| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3777
3778**Return value**
3779
3780| Type          | Description                         |
3781| -------------- | ----------------------------- |
3782| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3783
3784**Error codes**
3785
3786For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3787
3788| ID| Error Message|
3789| -------- | ---------------------------------------- |
3790| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3791| 6600101  | Session service exception. |
3792| 6600109  | The remote connection is not established. |
3793
3794
3795**Example**
3796
3797```ts
3798import { BusinessError } from '@kit.BasicServicesKit';
3799
3800// Set playback parameters.
3801let playItem: avSession.AVQueueItem = {
3802  itemId: 0,
3803  description: {
3804    assetId: '12345',
3805    mediaType: 'AUDIO',
3806    mediaUri: 'http://resource1_address',
3807    mediaSize: 12345,
3808    startPosition: 0,
3809    duration: 0,
3810    artist: 'mysong',
3811    albumTitle: 'song1_title',
3812    albumCoverUri: "http://resource1_album_address",
3813    lyricUri: "http://resource1_lyric_address",
3814    appName: 'MyMusic'
3815  }
3816};
3817// Start playback.
3818aVCastController.start(playItem).then(() => {
3819  console.info('start successfully');
3820}).catch((err: BusinessError) => {
3821  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3822});
3823```
3824
3825### getCurrentItem<sup>10+</sup>
3826
3827getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
3828
3829Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result.
3830
3831**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3832
3833**Parameters**
3834
3835| Name  | Type                                 | Mandatory| Description                                 |
3836| -------- | ------------------------------------- | ---- | ------------------------------------- |
3837| 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.|
3838
3839**Error codes**
3840
3841For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3842
3843| ID| Error Message|
3844| -------- | ---------------------------------------- |
3845| 6600101  | Session service exception. |
3846
3847**Example**
3848
3849```ts
3850import { BusinessError } from '@kit.BasicServicesKit';
3851
3852aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
3853  if (err) {
3854    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3855  } else {
3856    console.info('getCurrentItem successfully');
3857  }
3858});
3859```
3860
3861### getCurrentItem<sup>10+</sup>
3862
3863getCurrentItem(): Promise\<AVQueueItem>
3864
3865Obtains the information about the media asset that is being played. This API uses a promise to return the result.
3866
3867**Atomic service API**: This API can be used in atomic services since API version 12.
3868
3869**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3870
3871**Return value**
3872
3873| Type          | Description                         |
3874| -------------- | ----------------------------- |
3875| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.|
3876
3877**Error codes**
3878
3879For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3880
3881| ID| Error Message|
3882| -------- | ---------------------------------------- |
3883| 6600101  | Session service exception. |
3884
3885**Example**
3886
3887```ts
3888import { BusinessError } from '@kit.BasicServicesKit';
3889
3890aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
3891  console.info('getCurrentItem successfully');
3892}).catch((err: BusinessError) => {
3893  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3894});
3895```
3896
3897### getValidCommands<sup>11+</sup>
3898
3899getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void
3900
3901Obtains the supported commands. This API uses an asynchronous callback to return the result.
3902
3903**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3904
3905**Parameters**
3906
3907| Name| Type| Mandatory| Description|
3908| -------- | ------------------------------------- | ---- | ------------------------------------- |
3909| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | Yes| Callback return the supported commands.|
3910
3911**Error codes**
3912
3913For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3914
3915| ID| Error Message|
3916| -------- | ---------------------------------------- |
3917| 6600101  | Session service exception. |
3918
3919**Example**
3920
3921```ts
3922import { BusinessError } from '@kit.BasicServicesKit';
3923
3924aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => {
3925  if (err) {
3926    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3927  } else {
3928    console.info('getValidCommands successfully');
3929  }
3930});
3931```
3932
3933### getValidCommands<sup>11+</sup>
3934
3935getValidCommands(): Promise<Array\<AVCastControlCommandType>>
3936
3937Obtains the supported commands. This API uses a promise to return the result.
3938
3939**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3940
3941**Return value**
3942
3943| Type| Description|
3944| -------------- | ----------------------------- |
3945| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise used to return the supported commands.|
3946
3947**Error codes**
3948
3949For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3950
3951| ID| Error Message|
3952| -------- | ---------------------------------------- |
3953| 6600101  | Session service exception. |
3954
3955**Example**
3956
3957```ts
3958import { BusinessError } from '@kit.BasicServicesKit';
3959
3960aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => {
3961  console.info('getValidCommands successfully');
3962}).catch((err: BusinessError) => {
3963  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3964});
3965```
3966
3967### processMediaKeyResponse<sup>12+</sup>
3968
3969processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void>
3970
3971Processes the response to a media key request during online DRM resource projection. This API uses a promise to return the result.
3972
3973**Atomic service API**: This API can be used in atomic services since API version 12.
3974
3975**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3976
3977**Parameters**
3978
3979| Name  | Type                                 | Mandatory| Description                                 |
3980| -------- | ------------------------------------- | ---- | ------------------------------------- |
3981| assetId | string                  | Yes  | Media asset ID.|
3982| response | Uint8Array             | Yes  | Response to the media key request.|
3983
3984**Return value**
3985
3986| Type          | Description                         |
3987| -------------- | ----------------------------- |
3988| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned.|
3989
3990**Error codes**
3991
3992For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3993
3994| ID| Error Message|
3995| -------- | ---------------------------------------- |
3996| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3997| 6600101  | Session service exception. |
3998
3999**Example**
4000
4001```ts
4002let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4003  // Obtain the DRM URL based on the asset ID.
4004  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
4005  // Obtain a media key from the server. Assign a value based on service requirements.
4006  let licenseResponseData: Uint8Array = new Uint8Array();
4007  console.info(`Succeeded in get license by ${drmUrl}.`);
4008  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
4009}
4010```
4011
4012### release<sup>11+</sup>
4013
4014release(callback: AsyncCallback\<void>): void
4015
4016Releases this cast controller. This API uses an asynchronous callback to return the result.
4017
4018**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4019
4020**Parameters**
4021
4022| Name  | Type                      | Mandatory| Description                                                        |
4023| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
4024| callback | AsyncCallback\<void>       | Yes  | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object.|
4025
4026**Error codes**
4027
4028For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4029
4030| ID| Error Message|
4031| -------- | -------------------------- |
4032| 6600101  | Session service exception. |
4033
4034**Example**
4035
4036```ts
4037import { BusinessError } from '@kit.BasicServicesKit';
4038
4039aVCastController.release((err: BusinessError) => {
4040  if (err) {
4041    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
4042  } else {
4043    console.info('release successfully');
4044  }
4045});
4046```
4047
4048### release<sup>11+</sup>
4049
4050release(): Promise\<void>
4051
4052Releases this cast controller. This API uses a promise to return the result.
4053
4054**Atomic service API**: This API can be used in atomic services since API version 12.
4055
4056**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4057
4058**Return value**
4059
4060| Type          | Description                         |
4061| -------------- | ----------------------------- |
4062| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned.|
4063
4064**Error codes**
4065
4066For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4067
4068| ID| Error Message|
4069| -------- | ------------------------------ |
4070| 6600101  | Session service exception. |
4071
4072**Example**
4073
4074```ts
4075import { BusinessError } from '@kit.BasicServicesKit';
4076
4077aVCastController.release().then(() => {
4078  console.info('release successfully');
4079}).catch((err: BusinessError) => {
4080  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
4081});
4082
4083```
4084
4085### on('playbackStateChange')<sup>10+</sup>
4086
4087on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
4088
4089Subscribes to playback state change events.
4090
4091**Atomic service API**: This API can be used in atomic services since API version 12.
4092
4093**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4094
4095**Parameters**
4096
4097| Name  | Type                                                        | Mandatory| Description                                                        |
4098| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4099| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
4100| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.|
4101| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.                     |
4102
4103**Error codes**
4104
4105For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4106
4107| ID| Error Message|
4108| -------- | ------------------------------ |
4109| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4110| 6600101  | Session service exception. |
4111
4112**Example**
4113
4114```ts
4115aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
4116  console.info(`on playbackStateChange state : ${playbackState.state}`);
4117});
4118
4119let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
4120aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
4121  console.info(`on playbackStateChange state : ${playbackState.state}`);
4122});
4123```
4124
4125### off('playbackStateChange')<sup>10+</sup>
4126
4127off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
4128
4129Unsubscribes from playback state change events. This API is called by the controller.
4130
4131**Atomic service API**: This API can be used in atomic services since API version 12.
4132
4133**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4134
4135**Parameters**
4136
4137| Name  | Type                                                        | Mandatory| Description                                                    |
4138| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4139| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
4140| 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.                     |
4141
4142**Error codes**
4143
4144For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4145
4146| ID| Error Message|
4147| -------- | ---------------- |
4148| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4149| 6600101  | Session service exception. |
4150
4151**Example**
4152
4153```ts
4154aVCastController.off('playbackStateChange');
4155```
4156
4157### on('mediaItemChange')<sup>10+</sup>
4158
4159on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
4160
4161Subscribes to media asset change events.
4162
4163**Atomic service API**: This API can be used in atomic services since API version 12.
4164
4165**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4166
4167**Parameters**
4168
4169| Name  | Type                                                        | Mandatory| Description                                                        |
4170| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4171| type     | string                                                       | Yes  | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.|
4172| callback | (callback: [AVQueueItem](#avqueueitem10)) => void         | Yes  | Callback used for subscription. **AVQueueItem** is the media asset that is being played.                     |
4173
4174**Error codes**
4175
4176For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4177
4178| ID| Error Message|
4179| -------- | ------------------------------ |
4180| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4181| 6600101  | Session service exception. |
4182
4183**Example**
4184
4185```ts
4186aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
4187  console.info(`on mediaItemChange state : ${item.itemId}`);
4188});
4189```
4190
4191### off('mediaItemChange')<sup>10+</sup>
4192
4193off(type: 'mediaItemChange'): void
4194
4195Unsubscribes from media asset change events.
4196
4197**Atomic service API**: This API can be used in atomic services since API version 12.
4198
4199**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4200
4201**Parameters**
4202
4203| Name  | Type                                                        | Mandatory| Description                                                    |
4204| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4205| type     | string                                                       | Yes  | Event type, which is **'mediaItemChange'** in this case.   |
4206
4207**Error codes**
4208
4209For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4210
4211| ID| Error Message|
4212| -------- | ---------------- |
4213| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4214| 6600101  | Session service exception. |
4215
4216**Example**
4217
4218```ts
4219aVCastController.off('mediaItemChange');
4220```
4221
4222### on('playNext')<sup>10+</sup>
4223
4224on(type: 'playNext', callback: Callback\<void>): void
4225
4226Subscribes to playNext command events.
4227
4228**Atomic service API**: This API can be used in atomic services since API version 12.
4229
4230**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4231
4232**Parameters**
4233
4234| Name  | Type                                                        | Mandatory| Description                                                        |
4235| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4236| type     | string                                                       | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.|
4237| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4238
4239**Error codes**
4240
4241For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4242
4243| ID| Error Message|
4244| -------- | ------------------------------ |
4245| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4246| 6600101  | Session service exception. |
4247
4248**Example**
4249
4250```ts
4251aVCastController.on('playNext', () => {
4252  console.info('on playNext');
4253});
4254```
4255
4256### off('playNext')<sup>10+</sup>
4257
4258off(type: 'playNext'): void
4259
4260Unsubscribes from playNext command events.
4261
4262**Atomic service API**: This API can be used in atomic services since API version 12.
4263
4264**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4265
4266**Parameters**
4267
4268| Name  | Type                                                        | Mandatory| Description                                                    |
4269| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4270| type     | string                                                       | Yes  | Event type, which is **'playNext'** in this case.   |
4271
4272**Error codes**
4273
4274For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4275
4276| ID| Error Message|
4277| -------- | ---------------- |
4278| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4279| 6600101  | Session service exception. |
4280
4281**Example**
4282
4283```ts
4284aVCastController.off('playNext');
4285```
4286
4287### on('playPrevious')<sup>10+</sup>
4288
4289on(type: 'playPrevious', callback: Callback\<void>): void
4290
4291Subscribes to playPrevious command events.
4292
4293**Atomic service API**: This API can be used in atomic services since API version 12.
4294
4295**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4296
4297**Parameters**
4298
4299| Name  | Type                                                        | Mandatory| Description                                                        |
4300| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4301| type     | string                                                       | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.|
4302| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4303
4304**Error codes**
4305
4306For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4307
4308| ID| Error Message|
4309| -------- | ------------------------------ |
4310| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4311| 6600101  | Session service exception. |
4312
4313**Example**
4314
4315```ts
4316aVCastController.on('playPrevious', () => {
4317  console.info('on playPrevious');
4318});
4319```
4320
4321### off('playPrevious')<sup>10+</sup>
4322
4323off(type: 'playPrevious'): void
4324
4325Unsubscribes from playPrevious command events.
4326
4327**Atomic service API**: This API can be used in atomic services since API version 12.
4328
4329**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4330
4331**Parameters**
4332
4333| Name  | Type                                                        | Mandatory| Description                                                    |
4334| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4335| type     | string                                                       | Yes  | Event type, which is **'playPrevious'** in this case.   |
4336
4337**Error codes**
4338
4339For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4340
4341| ID| Error Message|
4342| -------- | ---------------- |
4343| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4344| 6600101  | Session service exception. |
4345
4346**Example**
4347
4348```ts
4349aVCastController.off('playPrevious');
4350```
4351
4352### on('requestPlay')<sup>11+</sup>
4353
4354on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
4355
4356Subscribes to playback request events.
4357
4358**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4359
4360**Parameters**
4361
4362| Name  | Type                                                        | Mandatory| Description                                                        |
4363| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4364| type     | string                                                       | Yes  | Event type. The event **'requestPlay'** is triggered when a playback request is received.|
4365| 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. |
4366
4367**Error codes**
4368
4369For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4370
4371| ID| Error Message|
4372| -------- | ------------------------------ |
4373| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4374| 6600101  | Session service exception. |
4375
4376**Example**
4377
4378```ts
4379aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
4380  console.info(`on requestPlay state : ${item.itemId}`);
4381});
4382```
4383
4384### off('requestPlay')<sup>11+</sup>
4385
4386off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void
4387
4388Unsubscribes from playback request events.
4389
4390**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4391
4392**Parameters**
4393
4394| Name  | Type                                                        | Mandatory| Description                                                    |
4395| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4396| type     | string                                                      | Yes  | Event type, which is **'requestPlay'** in this case.   |
4397| 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.|
4398
4399**Error codes**
4400
4401For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4402
4403| ID| Error Message|
4404| -------- | ---------------- |
4405| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4406| 6600101  | Session service exception. |
4407
4408**Example**
4409
4410```ts
4411aVCastController.off('requestPlay');
4412```
4413
4414### on('endOfStream')<sup>11+</sup>
4415
4416on(type: 'endOfStream', callback: Callback\<void>): void
4417
4418Subscribes to playback end events.
4419
4420**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4421
4422**Parameters**
4423
4424| Name  | Type                                                        | Mandatory| Description                                                        |
4425| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ |
4426| type     | string                                                      | Yes  | Event type. The event **'endOfStream'** is triggered when the playback operation is complete.|
4427| callback | Callback\<void\>                                            | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.     |
4428
4429**Error codes**
4430
4431For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4432
4433| ID| Error Message|
4434| -------- | ------------------------------ |
4435| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4436| 6600101  | Session service exception. |
4437
4438**Example**
4439
4440```ts
4441aVCastController.on('endOfStream', () => {
4442  console.info('on endOfStream');
4443});
4444```
4445
4446### off('endOfStream')<sup>11+</sup>
4447
4448off(type: 'endOfStream', callback?: Callback\<void>): void
4449
4450Unsubscribes from the playback end events.
4451
4452**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4453
4454**Parameters**
4455
4456| Name  | Type                                                        | Mandatory| Description                                                    |
4457| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4458| type     | string                                                      | Yes  | Event type, which is **'endOfStream'** in this case.   |
4459| 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.  |
4460
4461**Error codes**
4462
4463For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4464
4465| ID| Error Message|
4466| -------- | ---------------- |
4467| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4468| 6600101  | Session service exception. |
4469
4470**Example**
4471
4472```ts
4473aVCastController.off('endOfStream');
4474```
4475
4476### on('seekDone')<sup>10+</sup>
4477
4478on(type: 'seekDone', callback: Callback\<number>): void
4479
4480Subscribes to seek done events.
4481
4482**Atomic service API**: This API can be used in atomic services since API version 12.
4483
4484**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4485
4486**Parameters**
4487
4488| Name  | Type                                                        | Mandatory| Description                                                        |
4489| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4490| type     | string                                                       | Yes  | Event type. The event **'seekDone'** is triggered when the seek operation is complete.|
4491| callback | Callback\<number\>         | Yes  | Callback used to return the position after the seek operation.                     |
4492
4493**Error codes**
4494
4495For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4496
4497| ID| Error Message|
4498| -------- | ------------------------------ |
4499| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4500| 6600101  | Session service exception. |
4501
4502**Example**
4503
4504```ts
4505aVCastController.on('seekDone', (pos: number) => {
4506  console.info(`on seekDone pos: ${pos} `);
4507});
4508```
4509
4510### off('seekDone')<sup>10+</sup>
4511
4512off(type: 'seekDone'): void
4513
4514Unsubscribes from the seek done events.
4515
4516**Atomic service API**: This API can be used in atomic services since API version 12.
4517
4518**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4519
4520**Parameters**
4521
4522| Name  | Type                                                        | Mandatory| Description                                                    |
4523| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4524| type     | string                                                       | Yes  | Event type, which is **'seekDone'** in this case.   |
4525
4526**Error codes**
4527
4528For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4529
4530| ID| Error Message|
4531| -------- | ---------------- |
4532| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4533| 6600101  | Session service exception. |
4534
4535**Example**
4536
4537```ts
4538aVCastController.off('seekDone');
4539```
4540
4541### on('validCommandChange')<sup>11+</sup>
4542
4543on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
4544
4545Subscribes to valid command change events.
4546
4547**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4548
4549**Parameters**
4550
4551| Name  | Type                                                        | Mandatory| Description                                                        |
4552| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4553| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
4554| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\>   | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
4555
4556**Error codes**
4557
4558For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4559
4560| ID| Error Message|
4561| -------- | ------------------------------ |
4562| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4563| 6600101  | Session service exception. |
4564| 6600103  | The session controller does not exist. |
4565
4566**Example**
4567
4568```ts
4569aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
4570  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
4571  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
4572});
4573```
4574
4575### off('validCommandChange')<sup>11+</sup>
4576
4577off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>)
4578
4579Unsubscribes from valid command change events. This API is called by the controller.
4580
4581**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4582
4583**Parameters**
4584
4585| Name  | Type                                                        | Mandatory| Description                                                       |
4586| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
4587| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
4588| 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.         |
4589
4590**Error codes**
4591
4592For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4593
4594| ID| Error Message          |
4595| -------- | ---------------- |
4596| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4597| 6600101  | Session service exception. |
4598| 6600103  | The session controller does not exist. |
4599
4600**Example**
4601
4602```ts
4603aVCastController.off('validCommandChange');
4604```
4605
4606### on('error')<sup>10+</sup>
4607
4608on(type: 'error', callback: ErrorCallback): void
4609
4610Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control.
4611
4612**Atomic service API**: This API can be used in atomic services since API version 12.
4613
4614**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4615
4616**Parameters**
4617
4618| Name  | Type    | Mandatory| Description                                                        |
4619| -------- | -------- | ---- | ------------------------------------------------------------ |
4620| type     | string   | Yes  | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.|
4621| callback | ErrorCallback | Yes  | Callback used to return the error code ID and error message.|
4622
4623**Error codes**
4624
4625For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4626
4627| ID| Error Message             |
4628| -------- | --------------------- |
4629| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4630| 5400101  | No memory.            |
4631| 5400102  | Operation not allowed.   |
4632| 5400103  | I/O error.             |
4633| 5400104  | Time out.      |
4634| 5400105  | Service died.         |
4635| 5400106  | Unsupport format.     |
4636| 6600101  | Session service exception.     |
4637
4638**Example**
4639
4640```ts
4641import { BusinessError } from '@kit.BasicServicesKit';
4642
4643aVCastController.on('error', (error: BusinessError) => {
4644  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
4645})
4646```
4647
4648### off('error')<sup>10+</sup>
4649
4650off(type: 'error'): void
4651
4652Unsubscribes from remote AVPlayer errors.
4653
4654**Atomic service API**: This API can be used in atomic services since API version 12.
4655
4656**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4657
4658**Parameters**
4659
4660| Name| Type  | Mandatory| Description                                     |
4661| ------ | ------ | ---- | ----------------------------------------- |
4662| type   | string | Yes  | Event type, which is **'error'** in this case.|
4663
4664**Error codes**
4665
4666For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4667
4668| ID| Error Message             |
4669| -------- | --------------------- |
4670| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4671| 5400101  | No memory.            |
4672| 5400102  | Operation not allowed.   |
4673| 5400103  | I/O error.             |
4674| 5400104  | Time out.      |
4675| 5400105  | Service died.         |
4676| 5400106  | Unsupport format.     |
4677| 6600101  | Session service exception.     |
4678
4679**Example**
4680
4681```ts
4682aVCastController.off('error')
4683```
4684
4685### on('keyRequest')<sup>12+</sup>
4686
4687on(type: 'keyRequest', callback: KeyRequestCallback): void
4688
4689Subscribes to media key requests during the cast of online DRM resources.
4690
4691**Atomic service API**: This API can be used in atomic services since API version 12.
4692
4693**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4694
4695**Parameters**
4696
4697| Name| Type  | Mandatory| Description                                     |
4698| ------ | ------ | ---- | ----------------------------------------- |
4699| type     | string  | Yes  | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources.|
4700| callback | [KeyRequestCallback](#keyrequestcallback12)  | Yes  | Callback used to request the media resources and media key.|
4701
4702
4703**Error codes**
4704
4705For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4706
4707| ID| Error Message          |
4708| -------- | ---------------- |
4709| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4710| 6600101  | Session service exception. |
4711
4712**Example**
4713
4714```ts
4715let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4716  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4717}
4718aVCastController.on('keyRequest', keyRequestCallback);
4719```
4720### off('keyRequest')<sup>12+</sup>
4721
4722off(type: 'keyRequest', callback?: KeyRequestCallback): void
4723
4724Unsubscribes from media key requests during the cast of online DRM resources.
4725
4726**Atomic service API**: This API can be used in atomic services since API version 12.
4727
4728**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4729
4730**Parameters**
4731
4732| Name| Type  | Mandatory| Description                                     |
4733| ------ | ------ | ---- | ----------------------------------------- |
4734| type     | string                                                       | Yes  | Event type, which is **'keyRequest'** in this case.|
4735| 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.                           |
4736
4737**Error codes**
4738
4739For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4740
4741| ID| Error Message          |
4742| -------- | ---------------- |
4743| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4744| 6600101  | Session service exception. |
4745
4746**Example**
4747
4748```ts
4749aVCastController.off('keyRequest');
4750```
4751
4752### on('castControlGenericError')<sup>13+</sup>
4753
4754on(type: 'castControlGenericError', callback: ErrorCallback): void
4755
4756Subscribes to generic error events during cast control.
4757
4758**Atomic service API**: This API can be used in atomic services since API version 13.
4759
4760**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4761
4762**Parameters**
4763
4764| Name  | Type    | Mandatory| Description                                                        |
4765| -------- | -------- | ---- | ------------------------------------------------------------ |
4766| type     | string   | Yes  | Event type, which is **'castControlGenericError'** in this case.|
4767| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4768
4769**Error codes**
4770
4771| ID| Error Message             |
4772| -------- | --------------------- |
4773| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4774| 6611000  | The error code for cast control is unspecified.      |
4775| 6611001  | An unspecified error occurs in the remote player.   |
4776| 6611002  | The playback position falls behind the live window.     |
4777| 6611003  | The process of cast control times out.    |
4778| 6611004  | The runtime check failed.      |
4779| 6611100  | Cross-device data transmission is locked.    |
4780| 6611101  | The specified seek mode is not supported.   |
4781| 6611102  | The position to seek to is out of the range of the media asset or the specified seek mode is not supported.  |
4782| 6611103  | The specified playback mode is not supported.       |
4783| 6611104  | The specified playback speed is not supported.    |
4784| 6611105  | The action failed because either the media source device or the media sink device has been revoked.   |
4785| 6611106  | The parameter is invalid, for example, the url is illegal to play.  |
4786| 6611107  | Allocation of memory failed.  |
4787| 6611108  | Operation is not allowed.    |
4788
4789**Example**
4790
4791```ts
4792aVCastController.on('castControlGenericError', (error: BusinessError) => {
4793  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
4794})
4795```
4796
4797### off('castControlGenericError')<sup>13+</sup>
4798
4799off(type: 'castControlGenericError', callback?: ErrorCallback): void
4800
4801Unsubscribes from generic error events during cast control.
4802
4803**Atomic service API**: This API can be used in atomic services since API version 13.
4804
4805**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4806
4807**Parameters**
4808
4809| Name  | Type    | Mandatory| Description                                                        |
4810| -------- | -------- | ---- | ------------------------------------------------------------ |
4811| type     | string   | Yes  | 	Event type, which is **'castControlGenericError'** in this case.|
4812| 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.|
4813
4814**Error codes**
4815
4816| ID| Error Message             |
4817| -------- | --------------------- |
4818| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4819
4820**Example**
4821
4822```ts
4823aVCastController.off('castControlGenericError');
4824```
4825
4826### on('castControlIoError')<sup>13+</sup>
4827
4828on(type: 'castControlIoError', callback: ErrorCallback): void
4829
4830Subscribes to input/output error events during cast control.
4831
4832**Atomic service API**: This API can be used in atomic services since API version 13.
4833
4834**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4835
4836**Parameters**
4837
4838| Name  | Type    | Mandatory| Description                                                        |
4839| -------- | -------- | ---- | ------------------------------------------------------------ |
4840| type     | string   | Yes  | Event type, which is **'castControlIoError'** in this case.|
4841| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4842
4843**Error codes**
4844
4845| ID| Error Message             |
4846| -------- | --------------------- |
4847| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4848| 6612000  | An unspecified input/output error occurs.     |
4849| 6612001  | Network connection failure.   |
4850| 6612002  | Network timeout.     |
4851| 6612003  | Invalid "Content-Type" HTTP header.    |
4852| 6612004  | The HTTP server returns an unexpected HTTP response status code.      |
4853| 6612005  | The file does not exist.    |
4854| 6612006  | No permission is granted to perform the IO operation.   |
4855| 6612007  | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. |
4856| 6612008  | Reading data out of the data bound.    |
4857| 6612100  | The media does not contain any contents that can be played.   |
4858| 6612101  | The media cannot be read, for example, because of dust or scratches.   |
4859| 6612102  | This resource is already in use. |
4860| 6612103  | The content using the validity interval has expired.  |
4861| 6612104  | Using the requested content to play is not allowed.    |
4862| 6612105  | The use of the allowed content cannot be verified.  |
4863| 6612106  | The number of times this content has been used as requested has reached the maximum allowed number of uses.  |
4864| 6612107  | An error occurs when sending packet from source device to sink device.    |
4865
4866**Example**
4867
4868```ts
4869aVCastController.on('castControlIoError', (error: BusinessError) => {
4870  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
4871})
4872```
4873
4874### off('castControlIoError')<sup>13+</sup>
4875
4876off(type: 'castControlIoError', callback?: ErrorCallback): void
4877
4878Unsubscribes from input/output error events during cast control.
4879
4880**Atomic service API**: This API can be used in atomic services since API version 13.
4881
4882**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4883
4884**Parameters**
4885
4886| Name  | Type    | Mandatory| Description                                                        |
4887| -------- | -------- | ---- | ------------------------------------------------------------ |
4888| type     | string   | Yes  | 	Event type, which is **'castControlIoError'** in this case.|
4889| 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.|
4890
4891**Error codes**
4892
4893| ID| Error Message             |
4894| -------- | --------------------- |
4895| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4896
4897**Example**
4898
4899```ts
4900aVCastController.off('castControlIoError');
4901```
4902
4903### on('castControlParsingError')<sup>13+</sup>
4904
4905on(type: 'castControlParsingError', callback: ErrorCallback): void
4906
4907Subscribes to parsing error events during cast control.
4908
4909**Atomic service API**: This API can be used in atomic services since API version 13.
4910
4911**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4912
4913**Parameters**
4914
4915| Name  | Type    | Mandatory| Description                                                        |
4916| -------- | -------- | ---- | ------------------------------------------------------------ |
4917| type     | string   | Yes  | Event type, which is **'castControlParsingError'** in this case.|
4918| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4919
4920**Error codes**
4921
4922| ID | Error Message             |
4923| -------- | --------------------- |
4924| 401      |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4925| 6613000  | Unspecified error related to content parsing.     |
4926| 6613001  | Parsing error associated with media container format bit streams.   |
4927| 6613002  | Parsing error associated with the media manifest.     |
4928| 6613003  | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.    |
4929| 6613004  | Unsupported feature in the media manifest.    |
4930
4931**Example**
4932
4933```ts
4934aVCastController.on('castControlParsingError', (error: BusinessError) => {
4935  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
4936})
4937```
4938
4939### off('castControlParsingError')<sup>13+</sup>
4940
4941off(type: 'castControlParsingError', callback?: ErrorCallback): void
4942
4943Unsubscribes from parsing error events during cast control.
4944
4945**Atomic service API**: This API can be used in atomic services since API version 13.
4946
4947**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4948
4949**Parameters**
4950
4951| Name  | Type    | Mandatory| Description                                                        |
4952| -------- | -------- | ---- | ------------------------------------------------------------ |
4953| type     | string   | Yes  | 	Event type, which is **'castControlParsingError'** in this case.|
4954| 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.|
4955
4956**Error codes**
4957
4958| ID| Error Message             |
4959| -------- | --------------------- |
4960| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4961
4962**Example**
4963
4964```ts
4965aVCastController.off('castControlParsingError');
4966```
4967
4968### on('castControlDecodingError')<sup>13+</sup>
4969
4970on(type: 'castControlDecodingError', callback: ErrorCallback): void
4971
4972Subscribes to decoding 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 **'castControlDecodingError'** in this case.|
4983| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
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| 6614000  | Unspecified decoding error.     |
4991| 6614001  | Decoder initialization failed.   |
4992| 6614002  | Decoder query failed.     |
4993| 6614003  | Decoding the media samples failed.    |
4994| 6614004  | The format of the content to decode exceeds the capabilities of the device.    |
4995| 6614005  | The format of the content to decode is not supported.    |
4996
4997**Example**
4998
4999```ts
5000aVCastController.on('castControlDecodingError', (error: BusinessError) => {
5001  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
5002})
5003```
5004### off('castControlDecodingError')<sup>13+</sup>
5005
5006off(type: 'castControlDecodingError', callback?: ErrorCallback): void
5007
5008Unsubscribes from decoding error events during cast control.
5009
5010**Atomic service API**: This API can be used in atomic services since API version 13.
5011
5012**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5013
5014**Parameters**
5015
5016| Name  | Type    | Mandatory| Description                                                        |
5017| -------- | -------- | ---- | ------------------------------------------------------------ |
5018| type     | string   | Yes  | 	Event type, which is **'castControlDecodingError'** in this case.|
5019| 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.|
5020
5021**Error codes**
5022
5023| ID| Error Message             |
5024| -------- | --------------------- |
5025| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5026
5027**Example**
5028
5029```ts
5030aVCastController.off('castControlDecodingError');
5031```
5032
5033### on('castControlAudioRendererError')<sup>13+</sup>
5034
5035on(type: 'castControlAudioRendererError', callback: ErrorCallback): void
5036
5037Subscribes to audio renderer error events during cast control.
5038
5039**Atomic service API**: This API can be used in atomic services since API version 13.
5040
5041**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5042
5043**Parameters**
5044
5045| Name  | Type    | Mandatory| Description                                                        |
5046| -------- | -------- | ---- | ------------------------------------------------------------ |
5047| type     | string   | Yes  | Event type, which is **'castControlAudioRendererError'** in this case.|
5048| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
5049
5050**Error codes**
5051
5052For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
5053
5054| ID| Error Message             |
5055| -------- | --------------------- |
5056| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5057| 6615000  | Unspecified errors related to the audio renderer.     |
5058| 6615001  | Initializing the audio renderer failed.   |
5059| 6615002  | The audio renderer fails to write data.     |
5060
5061**Example**
5062
5063```ts
5064aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
5065  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
5066})
5067```
5068### off('castControlAudioRendererError')<sup>13+</sup>
5069
5070off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void
5071
5072Unsubscribes from audio renderer error events during cast control.
5073
5074**Atomic service API**: This API can be used in atomic services since API version 13.
5075
5076**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5077
5078**Parameters**
5079
5080| Name  | Type    | Mandatory| Description                                                        |
5081| -------- | -------- | ---- | ------------------------------------------------------------ |
5082| type     | string   | Yes  | 	Event type, which is **'castControlAudioRendererError'** in this case.|
5083| 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.|
5084
5085**Error codes**
5086
5087| ID| Error Message             |
5088| -------- | --------------------- |
5089| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
5090
5091**Example**
5092
5093```ts
5094aVCastController.off('castControlAudioRendererError');
5095```
5096
5097### on('castControlDrmError')<sup>13+</sup>
5098
5099on(type: 'castControlDrmError', callback: ErrorCallback): void
5100
5101Subscribes to DRM error events during cast control.
5102
5103**Atomic service API**: This API can be used in atomic services since API version 13.
5104
5105**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5106
5107**Parameters**
5108
5109| Name  | Type    | Mandatory| Description                                                        |
5110| -------- | -------- | ---- | ------------------------------------------------------------ |
5111| type     | string   | Yes  | Event type, which is **'castControlDrmError'** in this case.|
5112| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
5113
5114**Error codes**
5115
5116| ID| Error Message             |
5117| -------- | --------------------- |
5118| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5119| 6616000  | Unspecified error related to DRM.     |
5120| 6616001  | The chosen DRM protection scheme is not supported by the device.  |
5121| 6616002  | Device provisioning failed.    |
5122| 6616003  | The DRM-protected content to play is incompatible.     |
5123| 6616004  | Failed to obtain a license.   |
5124| 6616005  | The operation is disallowed by the license policy.     |
5125| 6616006  | An error occurs in the DRM system.     |
5126| 6616007  | The device has revoked DRM privileges.   |
5127| 6616008  | The DRM license being loaded into the open DRM session has expired.      |
5128| 6616100  | An error occurs when the DRM processes the key response.     |
5129
5130**Example**
5131
5132```ts
5133aVCastController.on('castControlDrmError', (error: BusinessError) => {
5134  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
5135})
5136```
5137
5138### off('castControlDrmError')<sup>13+</sup>
5139
5140off(type: 'castControlDrmError', callback?: ErrorCallback): void
5141
5142Unsubscribes from DRM error events during cast control.
5143
5144**Atomic service API**: This API can be used in atomic services since API version 13.
5145
5146**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5147
5148**Parameters**
5149
5150| Name  | Type    | Mandatory| Description                                                        |
5151| -------- | -------- | ---- | ------------------------------------------------------------ |
5152| type     | string   | Yes  | 	Event type, which is **'castControlDrmError'** in this case.|
5153| 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.|
5154
5155**Error codes**
5156
5157| ID| Error Message             |
5158| -------- | --------------------- |
5159| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5160
5161**Example**
5162
5163```ts
5164aVCastController.off('castControlDrmError');
5165```
5166
5167## ExtraInfo<sup>18+</sup>
5168type ExtraInfo = { [key: string]: Object; }
5169
5170Defines the custom media packet set by the provider.
5171
5172**Atomic service API**: This API can be used in atomic services since API version 18.
5173
5174**System capability**: SystemCapability.Multimedia.AVSession.Core
5175
5176| Type                               | Description                         |
5177| ----------------------------------- | ----------------------------- |
5178| [key: string]: Object   | **key** specifies the remote distributed event type. Currently, the following event types are supported:<br>**'AUDIO_GET_VOLUME'**: obtains the volume of the remote device.<br>**'AUDIO_GET_AVAILABLE_DEVICES'**: obtains all remote devices that can be connected.<br>**'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'**: obtains the actual remote audio device.<br>The provider returns the corresponding media packet object based on the event type.|
5179
5180## KeyRequestCallback<sup>12+</sup>
5181type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void
5182
5183Describes the callback invoked for the media key request event.
5184
5185**Atomic service API**: This API can be used in atomic services since API version 12.
5186
5187**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5188
5189**Parameters**
5190
5191| Name| Type  | Mandatory| Description                                     |
5192| ------ | ------ | ---- | ----------------------------------------- |
5193| assetId     | string  | Yes  | Media asset ID.|
5194| requestData |  Uint8Array  | Yes  | Data carried in the media key request.                           |
5195
5196**Example**
5197<!--code_no_check-->
5198```ts
5199let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
5200  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
5201}
5202```
5203
5204## CastDisplayState<sup>12+</sup>
5205
5206Enumerates the states of the cast display.
5207
5208**Atomic service API**: This API can be used in atomic services since API version 12.
5209
5210**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5211
5212| Name                       | Value  | Description        |
5213| --------------------------- | ---- | ----------- |
5214| STATE_OFF      | 1    | The device is disconnected, and the extended screen does not display any content.   |
5215| STATE_ON      | 2    | The device is connected, and the extended screen is available.|
5216
5217
5218## CastDisplayInfo<sup>12+</sup>
5219
5220Describes the information about the cast display in the case of extended screens.
5221
5222**Atomic service API**: This API can be used in atomic services since API version 12.
5223
5224**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5225
5226| Name           | Type                     | Read Only| Optional| Description                                                                 |
5227| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------|
5228| id            | number                  | No   | No   | ID of the cast display. The value must be an integer. |
5229| name     | string                  | No   | No   | Name of the cast display.          |
5230| state          | [CastDisplayState](#castdisplaystate12)          | No   | No   |State of the cast display.           |
5231| width          | number          | No   | No   | Screen width of the cast display, in px. The value must be an integer.         |
5232| height          | number          | No   | No   | Screen height of the cast display, in px. The value must be an integer.           |
5233
5234## ConnectionState<sup>10+</sup>
5235
5236Enumerates the connection states.
5237
5238**Atomic service API**: This API can be used in atomic services since API version 12.
5239
5240**System capability**: SystemCapability.Multimedia.AVSession.Core
5241
5242| Name                       | Value  | Description        |
5243| --------------------------- | ---- | ----------- |
5244| STATE_CONNECTING      | 0    | The device is connecting.   |
5245| STATE_CONNECTED      | 1    | The device is connected.|
5246| STATE_DISCONNECTED      | 6    | The device is disconnected.|
5247
5248## AVMetadata<sup>10+</sup>
5249
5250Describes the media metadata.
5251
5252**System capability**: SystemCapability.Multimedia.AVSession.Core
5253
5254| Name           | Type                     | Read Only| Optional| Description                                                                 |
5255| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------|
5256| assetId         | string                  | No  | No  | Media asset ID. It is the unique ID of a song and defined by the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                    |
5257| title           | string                  | No  | Yes  | Title.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                                |
5258| artist          | string                  | No  | Yes  | Artist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5259| author          | string                  | No  | Yes  | Author.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5260| avQueueName<sup>12+</sup>       | string                  | No  | Yes  | Playlist name.                                                              |
5261| avQueueId<sup>11+</sup>       | string                  | No  | Yes  | Unique ID of the playlist.                                                              |
5262| avQueueImage<sup>11+</sup>    | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No  | Yes  | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path). Applications call **setAVMetadata** to set the image data.<br>- If the data type is set to **PixelMap**, the data obtained by calling **getAVMetadata** is the pixel data of an image.<br>- If the data type is set to **url**, the data obtained is an image path. |
5263| album           | string                  | No  | Yes  | Album name.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5264| writer          | string                  | No  | Yes  | Writer.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5265| composer        | string                  | No  | Yes  | composer.                                                               |
5266| duration        | number                  | No  | Yes  | Media duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                 |
5267| mediaImage      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No  | Yes  | Pixel map or image path (local path or network path) of the image. Applications call **setAVMetadata** to set the image data.<br>- If the data type is set to **PixelMap**, the data obtained by calling **getAVMetadata** is the pixel data of an image.<br>- If the data type is set to **url**, the data obtained is an image path.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                            |
5268| bundleIcon<sup>18+</sup>      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes  | Yes  | Pixel data of the image that is used as the application icon. It is read-only and cannot be set on the application side.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
5269| publishDate     | Date                    | No  | Yes  | Release date.                                                            |
5270| subtitle        | string                  | No  | Yes  | Subtitle.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5271| description     | string                  | No  | Yes  | Media description.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5272| lyric           | string                  | No  | Yes  | Lyrics. The application needs to combine the lyrics into a string.<br>The string length must not exceed 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.|
5273| singleLyricText<sup>18+</sup> | string    | No  | Yes  | Lyrics of a single media asset. The application must combine the lyrics into a string (excluding the timestamp).<br>The string length must not exceed 40960 bytes.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
5274| previousAssetId | string                  | No  | Yes  | ID of the previous media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                           |
5275| nextAssetId     | string                  | No  | Yes  | ID of the next media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                           |
5276| filter<sup>11+</sup>        | number         | No  | Yes  | Protocol supported by the media session. The default value is **TYPE_CAST_PLUS_STREAM**. For details, see [ProtocolType](#protocoltype11).<br>**Atomic service API**: This API can be used in atomic services since API version 12.                  |
5277| drmSchemes<sup>12+</sup>        | Array\<string>         | No  | Yes  | DRM scheme supported by the media session. The value is the UUID of the DRM scheme.|
5278| skipIntervals<sup>11+</sup>  | [SkipIntervals](#skipintervals11)        | No  | Yes  | Intervals supported for fast-forwarding and rewinding. The default value is **SECONDS_15**, that is, 15 seconds.                           |
5279|displayTags<sup>11+</sup>     | number                           | No  | Yes  | Display tags of the media asset. For details, see [DisplayTag](#displaytag11).                                                         |
5280
5281## AVMediaDescription<sup>10+</sup>
5282
5283Describes the attributes related to the media metadata in the playlist.
5284
5285**System capability**: SystemCapability.Multimedia.AVSession.Core
5286
5287| Name        | Type                   | Mandatory | Description                    |
5288| ------------ | ----------------------- | ---- | ----------------------- |
5289| assetId      | string                  | Yes  | Media ID in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.         |
5290| 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.       |
5291| 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.     |
5292| 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.  |
5293| 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.|
5294| extras       | {[key: string]: Object}    | No  | Additional fields of the media asset in the playlist.    |
5295| 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.        |
5296| 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.        |
5297| 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.        |
5298| 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.        |
5299| 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.   |
5300| 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.        |
5301| 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.        |
5302| 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.        |
5303| 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.        |
5304| dataSrc<sup>12+</sup>     | media.AVDataSrcDescriptor        | No  | Descriptor of the data source in the playlist.        |
5305| drmScheme<sup>12+</sup>     | string        | No  | DRM scheme supported by the playlist. The value is the UUID of the DRM scheme.      |
5306| 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.        |
5307| 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.        |
5308| 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.        |
5309| 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.        |
5310|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.       |
5311
5312## AVQueueItem<sup>10+</sup>
5313
5314Describes the attributes of an item in the playlist.
5315
5316**Atomic service API**: This API can be used in atomic services since API version 12.
5317
5318**System capability**: SystemCapability.Multimedia.AVSession.Core
5319
5320| Name        | Type                                       | Mandatory| Description                       |
5321| ------------ | ------------------------------------------ | ---- | --------------------------- |
5322| itemId       | number                                     | Yes  | ID of an item in the playlist.         |
5323| description  | [AVMediaDescription](#avmediadescription10)  | No  | Media metadata of the item in the playlist.  |
5324
5325## AVPlaybackState<sup>10+</sup>
5326
5327Describes the information related to the media playback state.
5328
5329**System capability**: SystemCapability.Multimedia.AVSession.Core
5330
5331| Name        | Type                                 | Mandatory| Description    |
5332| ------------ | ------------------------------------- | ---- | ------- |
5333| state        | [PlaybackState](#playbackstate10)       | No  | Playback state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5334| speed        | number                                | No  | Playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5335| position     | [PlaybackPosition](#playbackposition10) | No  | Playback position.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5336| bufferedTime | number                                | No  | Buffered time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5337| loopMode     | [LoopMode](#loopmode10)                 | No  | Loop mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5338| 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.|
5339| 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.|
5340| volume<sup>10+</sup> | number                  | No  | Media volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5341| maxVolume<sup>11+</sup> | number                    | No  | Maximum volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5342| 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.|
5343| duration<sup>11+</sup>     | number                   | No  | Duration of the media asset.|
5344| 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.|
5345| 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.|
5346| 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.|
5347
5348## PlaybackPosition<sup>10+</sup>
5349
5350Describes the information related to the playback position.
5351
5352**Atomic service API**: This API can be used in atomic services since API version 12.
5353
5354**System capability**: SystemCapability.Multimedia.AVSession.Core
5355
5356| Name       | Type  | Mandatory| Description              |
5357| ----------- | ------ | ---- | ------------------ |
5358| elapsedTime | number | Yes  | Elapsed time, in ms.|
5359| updateTime  | number | Yes  | Updated time, in ms.|
5360
5361## CallMetadata<sup>11+</sup>
5362
5363Defines the attributes related to call metadata.
5364
5365**Atomic service API**: This API can be used in atomic services since API version 12.
5366
5367**System capability**: SystemCapability.Multimedia.AVSession.Core
5368
5369| Name           | Type                     | Mandatory| Description                                                                 |
5370| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
5371| name            | string                  | No   | Name (alias) of the caller.   |
5372| phoneNumber     | string                  | No   | Phone number of the caller.           |
5373| avatar          | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)          | No   | Profile picture of the caller.           |
5374
5375## AVCallState<sup>11+</sup>
5376
5377Defines the attributes related to the call state.
5378
5379**Atomic service API**: This API can be used in atomic services since API version 12.
5380
5381**System capability**: SystemCapability.Multimedia.AVSession.Core
5382
5383| Name           | Type                     | Mandatory| Description                                                                 |
5384| --------------- |-------------------------  | ---- |---------------------------------------------------------------------|
5385| state           | [CallState](#callstate11)                 | Yes   | Call state.     |
5386| muted           | boolean                   | Yes   | Whether the microphone is muted.<br>**true**: The microphone is muted.<br>**false**: The microphone is not muted.|
5387
5388## CallState<sup>11+</sup>
5389
5390Enumerates the call states.
5391
5392**Atomic service API**: This API can be used in atomic services since API version 12.
5393
5394**System capability**: SystemCapability.Multimedia.AVSession.Core
5395
5396| Name                       | Value  | Description     |
5397| --------------------------  | ---- | -------- |
5398| CALL_STATE_IDLE             | 0    | The phone is idle.  |
5399| CALL_STATE_INCOMING         | 1    | The phone is ringing.    |
5400| CALL_STATE_ACTIVE           | 2    | The call is connected.    |
5401| CALL_STATE_DIALING          | 3    | The caller is dialing.    |
5402| CALL_STATE_WAITING          | 4    | The call is waiting for connection. |
5403| CALL_STATE_HOLDING          | 5    | The call is placed on hold.    |
5404| CALL_STATE_DISCONNECTING    | 6    | The call is disconnecting.    |
5405
5406## DisplayTag<sup>11+</sup>
5407
5408Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source.
5409
5410**System capability**: SystemCapability.Multimedia.AVSession.Core
5411
5412| Name                       | Value  | Description          |
5413| --------------------------  | ---- | ------------ |
5414| TAG_AUDIO_VIVID             | 1    | AUDIO VIVID  |
5415
5416## DecoderType<sup>18+</sup>
5417
5418Enumerates the decoding formats supported by the device.
5419
5420**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5421
5422| Name                       | Value  | Description          |
5423| --------------------------  | ---- | ------------ |
5424| OH_AVCODEC_MIMETYPE_VIDEO_AVC      | "video/avc"  | VIDEO AVC. |
5425| OH_AVCODEC_MIMETYPE_VIDEO_HEVC     | "video/hevc" | VIDEO HEVC. |
5426| OH_AVCODEC_MIMETYPE_AUDIO_VIVID    | "audio/av3a" | AUDIO AV3A. |
5427
5428
5429## ResolutionLevel<sup>18+</sup>
5430
5431Enumerates the resolution levels supported by the device.
5432
5433**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5434
5435| Name                       | Value  | Description          |
5436| --------------------------  | ---- | ------------ |
5437| RESOLUTION_480P             | 0    | 480p (640 x 480 dpi).    |
5438| RESOLUTION_720P             | 1    | 720p (1280 x 720 dpi).   |
5439| RESOLUTION_1080P            | 2    | 1080p (1920 x 1080 dpi).  |
5440| RESOLUTION_2K               | 3    | 2K (2560 x 1440 dpi).  |
5441| RESOLUTION_4K               | 4    | 4K (4096 x 3840 dpi).  |
5442
5443## AVCastCategory<sup>10+</sup>
5444
5445Enumerates the cast categories.
5446
5447**Atomic service API**: This API can be used in atomic services since API version 12.
5448
5449**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5450
5451| Name                       | Value  | Description        |
5452| --------------------------- | ---- | ----------- |
5453| CATEGORY_LOCAL      | 0    | Local playback. The sound is played from the local device or a connected Bluetooth headset by default.    |
5454| CATEGORY_REMOTE      | 1    | Remote playback. The sound or images are played from a remote device. |
5455
5456## DeviceType<sup>10+</sup>
5457
5458Enumerates the output device types.
5459
5460**Atomic service API**: This API can be used in atomic services since API version 12.
5461
5462| Name                       | Value  | Description        |
5463| --------------------------- | ---- | ----------- |
5464| DEVICE_TYPE_LOCAL      | 0    | Local device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core|
5465| DEVICE_TYPE_BLUETOOTH      | 10   | Bluetooth device.<br> **System capability**: SystemCapability.Multimedia.AVSession.Core|
5466| DEVICE_TYPE_TV      | 2    | TV.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast|
5467| DEVICE_TYPE_SMART_SPEAKER      | 3   | Speaker.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast|
5468
5469## DeviceInfo<sup>10+</sup>
5470
5471Describes the information related to the output device.
5472
5473| Name      | Type          | Mandatory| Description                  |
5474| ---------- | -------------- | ---- | ---------------------- |
5475| 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.|
5476| 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.|
5477| 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.|
5478| 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.|
5479| 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.|
5480| 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.|
5481| 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.|
5482| 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.|
5483
5484## OutputDeviceInfo<sup>10+</sup>
5485
5486Describes the information related to the output device.
5487
5488**Atomic service API**: This API can be used in atomic services since API version 12.
5489
5490**System capability**: SystemCapability.Multimedia.AVSession.Core
5491
5492| Name      | Type          | Mandatory| Description                  |
5493| ---------- | -------------- | ---- | ---------------------- |
5494| devices | Array\<DeviceInfo\> | Yes  | Output devices.   |
5495
5496## LoopMode<sup>10+</sup>
5497
5498Enumerates the loop modes of media playback.
5499
5500**Atomic service API**: This API can be used in atomic services since API version 12.
5501
5502**System capability**: SystemCapability.Multimedia.AVSession.Core
5503
5504| Name              | Value  | Description    |
5505| ------------------ | ---- | -------- |
5506| LOOP_MODE_SEQUENCE | 0    | Sequential playback.|
5507| LOOP_MODE_SINGLE   | 1    | Single loop.|
5508| LOOP_MODE_LIST     | 2    | Playlist loop.|
5509| LOOP_MODE_SHUFFLE  | 3    | Shuffle.|
5510| LOOP_MODE_CUSTOM<sup>11+</sup>   | 4    | Custom playback. |
5511
5512## PlaybackState<sup>10+</sup>
5513
5514Enumerates the media playback states.
5515
5516**Atomic service API**: This API can be used in atomic services since API version 12.
5517
5518**System capability**: SystemCapability.Multimedia.AVSession.Core
5519
5520| Name                       | Value  | Description        |
5521| --------------------------- | ---- | ----------- |
5522| PLAYBACK_STATE_INITIAL      | 0    | Initial.    |
5523| PLAYBACK_STATE_PREPARE      | 1    | Preparing. |
5524| PLAYBACK_STATE_PLAY         | 2    | Playing.    |
5525| PLAYBACK_STATE_PAUSE        | 3    | Paused.        |
5526| PLAYBACK_STATE_FAST_FORWARD | 4    | Fast-forwarding.        |
5527| PLAYBACK_STATE_REWIND       | 5    | Rewinding.        |
5528| PLAYBACK_STATE_STOP         | 6    | Stopped.        |
5529| PLAYBACK_STATE_COMPLETED    | 7    | Playback complete.    |
5530| PLAYBACK_STATE_RELEASED     | 8    | Released.        |
5531| PLAYBACK_STATE_ERROR        | 9    | Error.        |
5532| PLAYBACK_STATE_IDLE<sup>11+</sup>        | 10    | Idle.    |
5533| PLAYBACK_STATE_BUFFERING<sup>11+</sup>         | 11    | Buffering.  |
5534
5535## AVSessionController<sup>10+</sup>
5536
5537Through 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.
5538
5539### Attributes
5540
5541**Atomic service API**: This API can be used in atomic services since API version 12.
5542
5543**System capability**: SystemCapability.Multimedia.AVSession.Core
5544
5545| Name     | Type  | Readable| Writable| Description                                   |
5546| :-------- | :----- | :--- | :--- | :-------------------------------------- |
5547| sessionId | string | Yes  | No  | Unique session ID of the **AVSessionController** object.|
5548
5549
5550**Example**
5551
5552```ts
5553import { BusinessError } from '@kit.BasicServicesKit';
5554
5555let AVSessionController: avSession.AVSessionController;
5556avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
5557  AVSessionController = controller;
5558}).catch((err: BusinessError) => {
5559  console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
5560});
5561```
5562
5563### getAVPlaybackState<sup>10+</sup>
5564
5565getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
5566
5567Obtains the remote playback state. This API uses an asynchronous callback to return the result.
5568
5569**System capability**: SystemCapability.Multimedia.AVSession.Core
5570
5571**Parameters**
5572
5573| Name   | Type                                                       | Mandatory| Description                                                        |
5574| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5575| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
5576
5577**Error codes**
5578
5579For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5580
5581| ID| Error Message|
5582| -------- | ---------------------------------------- |
5583| 6600101  | Session service exception. |
5584| 6600102  | The session does not exist. |
5585| 6600103  | The session controller does not exist. |
5586
5587**Example**
5588
5589```ts
5590import { BusinessError } from '@kit.BasicServicesKit';
5591
5592avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
5593  if (err) {
5594    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5595  } else {
5596    console.info('getAVPlaybackState : SUCCESS');
5597  }
5598});
5599```
5600
5601### getAVPlaybackState<sup>10+</sup>
5602
5603getAVPlaybackState(): Promise\<AVPlaybackState>
5604
5605Obtains the remote playback state. This API uses a promise to return the result.
5606
5607**Atomic service API**: This API can be used in atomic services since API version 12.
5608
5609**System capability**: SystemCapability.Multimedia.AVSession.Core
5610
5611**Return value**
5612
5613| Type                                                       | Description                                                        |
5614| --------- | ------------------------------------------------------------ |
5615| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state. |
5616
5617**Error codes**
5618
5619For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5620
5621| ID| Error Message|
5622| -------- | ---------------------------------------- |
5623| 6600101  | Session service exception. |
5624| 6600102  | The session does not exist. |
5625| 6600103  | The session controller does not exist. |
5626
5627**Example**
5628
5629```ts
5630import { BusinessError } from '@kit.BasicServicesKit';
5631
5632avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
5633  console.info('getAVPlaybackState : SUCCESS');
5634}).catch((err: BusinessError) => {
5635  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5636});
5637```
5638
5639### getAVMetadata<sup>10+</sup>
5640
5641getAVMetadata(): Promise\<AVMetadata>
5642
5643Obtains the session metadata. This API uses a promise to return the result.
5644
5645**Atomic service API**: This API can be used in atomic services since API version 12.
5646
5647**System capability**: SystemCapability.Multimedia.AVSession.Core
5648
5649**Return value**
5650
5651| Type                               | Description                         |
5652| ----------------------------------- | ----------------------------- |
5653| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.|
5654
5655**Error codes**
5656
5657For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5658
5659| ID| Error Message|
5660| -------- | ---------------------------------------- |
5661| 6600101  | Session service exception. |
5662| 6600102  | The session does not exist. |
5663| 6600103  | The session controller does not exist. |
5664
5665**Example**
5666
5667```ts
5668import { BusinessError } from '@kit.BasicServicesKit';
5669
5670avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
5671  console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5672}).catch((err: BusinessError) => {
5673  console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5674});
5675```
5676
5677### getAVMetadata<sup>10+</sup>
5678
5679getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
5680
5681Obtains the session metadata. This API uses an asynchronous callback to return the result.
5682
5683**System capability**: SystemCapability.Multimedia.AVSession.Core
5684
5685**Parameters**
5686
5687| Name  | Type                                     | Mandatory| Description                      |
5688| -------- | ----------------------------------------- | ---- | -------------------------- |
5689| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes  | Callback used to return the metadata obtained.|
5690
5691**Error codes**
5692
5693For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5694
5695| ID| Error Message|
5696| -------- | ---------------------------------------- |
5697| 6600101  | Session service exception. |
5698| 6600102  | The session does not exist. |
5699| 6600103  | The session controller does not exist. |
5700
5701**Example**
5702
5703```ts
5704import { BusinessError } from '@kit.BasicServicesKit';
5705
5706avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
5707  if (err) {
5708    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5709  } else {
5710    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5711  }
5712});
5713```
5714
5715### getAVQueueTitle<sup>10+</sup>
5716
5717getAVQueueTitle(): Promise\<string>
5718
5719Obtains the name of the playlist. This API uses a promise to return the result.
5720
5721**Atomic service API**: This API can be used in atomic services since API version 12.
5722
5723**System capability**: SystemCapability.Multimedia.AVSession.Core
5724
5725**Return value**
5726
5727| Type            | Description                          |
5728| ---------------- | ----------------------------- |
5729| Promise<string\> | Promise used to return the playlist name.|
5730
5731**Error codes**
5732
5733For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5734
5735| ID| Error Message|
5736| -------- | ---------------------------------------- |
5737| 6600101  | Session service exception. |
5738| 6600102  | The session does not exist. |
5739| 6600103  | The session controller does not exist. |
5740
5741**Example**
5742
5743```ts
5744import { BusinessError } from '@kit.BasicServicesKit';
5745
5746avsessionController.getAVQueueTitle().then((title: string) => {
5747  console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5748}).catch((err: BusinessError) => {
5749  console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5750});
5751```
5752
5753### getAVQueueTitle<sup>10+</sup>
5754
5755getAVQueueTitle(callback: AsyncCallback\<string>): void
5756
5757Obtains the name of the playlist. This API uses an asynchronous callback to return the result.
5758
5759**System capability**: SystemCapability.Multimedia.AVSession.Core
5760
5761**Parameters**
5762
5763| Name  | Type                   | Mandatory| Description                     |
5764| -------- | ---------------------- | ---- | ------------------------- |
5765| callback | AsyncCallback<string\> | Yes  | Callback used to return the playlist name.|
5766
5767**Error codes**
5768
5769For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5770
5771| ID| Error Message|
5772| -------- | ---------------------------------------- |
5773| 6600101  | Session service exception. |
5774| 6600102  | The session does not exist. |
5775| 6600103  | The session controller does not exist. |
5776
5777**Example**
5778
5779```ts
5780import { BusinessError } from '@kit.BasicServicesKit';
5781
5782avsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
5783  if (err) {
5784    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5785  } else {
5786    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5787  }
5788});
5789```
5790
5791### getAVQueueItems<sup>10+</sup>
5792
5793getAVQueueItems(): Promise\<Array\<AVQueueItem>>
5794
5795Obtains the information related to the items in the queue. This API uses a promise to return the result.
5796
5797**Atomic service API**: This API can be used in atomic services since API version 12.
5798
5799**System capability**: SystemCapability.Multimedia.AVSession.Core
5800
5801**Return value**
5802
5803| Type                                         | Description                          |
5804| --------------------------------------------- | ----------------------------- |
5805| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue.|
5806
5807**Error codes**
5808
5809For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5810
5811| ID| Error Message|
5812| -------- | ---------------------------------------- |
5813| 6600101  | Session service exception. |
5814| 6600102  | The session does not exist. |
5815| 6600103  | The session controller does not exist. |
5816
5817**Example**
5818
5819```ts
5820import { BusinessError } from '@kit.BasicServicesKit';
5821
5822avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
5823  console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5824}).catch((err: BusinessError) => {
5825  console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5826});
5827```
5828
5829### getAVQueueItems<sup>10+</sup>
5830
5831getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
5832
5833Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result.
5834
5835**System capability**: SystemCapability.Multimedia.AVSession.Core
5836
5837**Parameters**
5838
5839| Name  | Type                                                | Mandatory| Description                     |
5840| -------- | --------------------------------------------------- | ---- | ------------------------- |
5841| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes  | Callback used to return the items in the playlist.|
5842
5843**Error codes**
5844
5845For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5846
5847| ID| Error Message|
5848| -------- | ---------------------------------------- |
5849| 6600101  | Session service exception. |
5850| 6600102  | The session does not exist. |
5851| 6600103  | The session controller does not exist. |
5852
5853**Example**
5854
5855```ts
5856import { BusinessError } from '@kit.BasicServicesKit';
5857
5858avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
5859  if (err) {
5860    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5861  } else {
5862    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5863  }
5864});
5865```
5866
5867### skipToQueueItem<sup>10+</sup>
5868
5869skipToQueueItem(itemId: number): Promise\<void>
5870
5871Sends 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.
5872
5873**Atomic service API**: This API can be used in atomic services since API version 12.
5874
5875**System capability**: SystemCapability.Multimedia.AVSession.Core
5876
5877**Parameters**
5878
5879| Name | Type   | Mandatory| Description                                       |
5880| ------ | ------- | ---- | ------------------------------------------- |
5881| itemId | number  | Yes  | ID of an item in the playlist.|
5882
5883**Return value**
5884
5885| Type          | Description                                                            |
5886| -------------- | --------------------------------------------------------------- |
5887| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.|
5888
5889**Error codes**
5890
5891For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5892
5893| ID| Error Message|
5894| -------- | ---------------------------------------- |
5895| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5896| 6600101  | Session service exception. |
5897| 6600102  | The session does not exist. |
5898| 6600103  | The session controller does not exist. |
5899
5900**Example**
5901
5902```ts
5903import { BusinessError } from '@kit.BasicServicesKit';
5904
5905let queueItemId = 0;
5906avsessionController.skipToQueueItem(queueItemId).then(() => {
5907  console.info('SkipToQueueItem successfully');
5908}).catch((err: BusinessError) => {
5909  console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5910});
5911```
5912
5913### skipToQueueItem<sup>10+</sup>
5914
5915skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
5916
5917Sends 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.
5918
5919**System capability**: SystemCapability.Multimedia.AVSession.Core
5920
5921**Parameters**
5922
5923| Name   | Type                 | Mandatory| Description                                                       |
5924| -------- | --------------------- | ---- | ----------------------------------------------------------- |
5925| itemId   | number                | Yes  | ID of an item in the playlist.               |
5926| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
5927
5928**Error codes**
5929
5930For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5931
5932| ID| Error Message|
5933| -------- | ---------------------------------------- |
5934| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
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
5944let queueItemId = 0;
5945avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
5946  if (err) {
5947    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5948  } else {
5949    console.info('SkipToQueueItem successfully');
5950  }
5951});
5952```
5953
5954### getOutputDevice<sup>10+</sup>
5955
5956getOutputDevice(): Promise\<OutputDeviceInfo>
5957
5958Obtains the output device information. This API uses a promise to return the result.
5959
5960**Atomic service API**: This API can be used in atomic services since API version 12.
5961
5962**System capability**: SystemCapability.Multimedia.AVSession.Core
5963
5964**Return value**
5965
5966| Type                                           | Description                             |
5967| ----------------------------------------------- | --------------------------------- |
5968| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.|
5969
5970**Error codes**
5971
5972For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5973
5974| ID| Error Message|
5975| -------- | ---------------------------------------- |
5976| 600101  | Session service exception. |
5977| 600103  | The session controller does not exist. |
5978
5979**Example**
5980
5981```ts
5982import { BusinessError } from '@kit.BasicServicesKit';
5983
5984avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
5985  console.info('GetOutputDevice : SUCCESS');
5986}).catch((err: BusinessError) => {
5987  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5988});
5989```
5990
5991### getOutputDevice<sup>10+</sup>
5992
5993getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
5994
5995Obtains the output device information. This API uses an asynchronous callback to return the result.
5996
5997**System capability**: SystemCapability.Multimedia.AVSession.Core
5998
5999**Parameters**
6000
6001| Name  | Type                                                 | Mandatory| Description                          |
6002| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
6003| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
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| 600101  | Session service exception. |
6012| 600103  | The session controller does not exist. |
6013
6014**Example**
6015
6016```ts
6017import { BusinessError } from '@kit.BasicServicesKit';
6018
6019avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
6020  if (err) {
6021    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
6022  } else {
6023    console.info('GetOutputDevice : SUCCESS');
6024  }
6025});
6026```
6027
6028### sendAVKeyEvent<sup>10+</sup>
6029
6030sendAVKeyEvent(event: KeyEvent): Promise\<void>
6031
6032Sends a key event to the session corresponding to this controller. This API uses a promise to return the result.
6033
6034**Atomic service API**: This API can be used in atomic services since API version 12.
6035
6036**System capability**: SystemCapability.Multimedia.AVSession.Core
6037
6038**Parameters**
6039
6040| Name| Type                                                        | Mandatory| Description      |
6041| ------ | ------------------------------------------------------------ | ---- | ---------- |
6042| event  | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes  | Key event.|
6043
6044**Error codes**
6045
6046For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6047
6048| ID| Error Message|
6049| -------- | ---------------------------------------- |
6050| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6051| 600101  | Session service exception. |
6052| 600102  | The session does not exist. |
6053| 600103  | The session controller does not exist. |
6054| 600105  | Invalid session command. |
6055| 600106  | The session is not activated. |
6056
6057**Return value**
6058
6059| Type          | Description                         |
6060| -------------- | ----------------------------- |
6061| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
6062
6063**Example**
6064
6065```ts
6066import { Key, KeyEvent } from '@kit.InputKit';
6067import { BusinessError } from '@kit.BasicServicesKit';
6068
6069let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
6070let 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};
6071
6072
6073avsessionController.sendAVKeyEvent(event).then(() => {
6074  console.info('SendAVKeyEvent Successfully');
6075}).catch((err: BusinessError) => {
6076  console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
6077});
6078```
6079
6080### sendAVKeyEvent<sup>10+</sup>
6081
6082sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
6083
6084Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.
6085
6086**System capability**: SystemCapability.Multimedia.AVSession.Core
6087
6088**Parameters**
6089
6090| Name  | Type                                                        | Mandatory| Description      |
6091| -------- | ------------------------------------------------------------ | ---- | ---------- |
6092| event    | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes  | Key event.|
6093| callback | AsyncCallback\<void>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
6094
6095**Error codes**
6096
6097For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6098
6099| ID| Error Message|
6100| -------- | ---------------------------------------- |
6101| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6102| 600101  | Session service exception. |
6103| 600102  | The session does not exist. |
6104| 600103  | The session controller does not exist. |
6105| 600105  | Invalid session command. |
6106| 600106  | The session is not activated. |
6107
6108**Example**
6109
6110```ts
6111import { Key, KeyEvent } from '@kit.InputKit';
6112import { BusinessError } from '@kit.BasicServicesKit';
6113
6114let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
6115let 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};
6116avsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
6117  if (err) {
6118    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
6119  } else {
6120    console.info('SendAVKeyEvent Successfully');
6121  }
6122});
6123```
6124
6125### getLaunchAbility<sup>10+</sup>
6126
6127getLaunchAbility(): Promise\<WantAgent>
6128
6129Obtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result.
6130
6131**Atomic service API**: This API can be used in atomic services since API version 12.
6132
6133**System capability**: SystemCapability.Multimedia.AVSession.Core
6134
6135**Return value**
6136
6137| Type                                                   | Description                                                        |
6138| ------------------------------------------------------- | ------------------------------------------------------------ |
6139| 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.|
6140
6141**Error codes**
6142
6143For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6144
6145| ID| Error Message|
6146| -------- | ---------------------------------------- |
6147| 6600101  | Session service exception. |
6148| 6600102  | The session does not exist. |
6149| 6600103  | The session controller does not exist. |
6150
6151**Example**
6152
6153```ts
6154import { BusinessError } from '@kit.BasicServicesKit';
6155
6156avsessionController.getLaunchAbility().then((agent: object) => {
6157  console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
6158}).catch((err: BusinessError) => {
6159  console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
6160});
6161```
6162
6163### getLaunchAbility<sup>10+</sup>
6164
6165getLaunchAbility(callback: AsyncCallback\<WantAgent>): void
6166
6167Obtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result.
6168
6169**System capability**: SystemCapability.Multimedia.AVSession.Core
6170
6171**Parameters**
6172
6173| Name  | Type                                                        | Mandatory| Description                                                        |
6174| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6175| 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.|
6176
6177**Error codes**
6178
6179For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6180
6181| ID| Error Message|
6182| -------- | ---------------------------------------- |
6183| 6600101  | Session service exception. |
6184| 6600102  | The session does not exist. |
6185| 6600103  | The session controller does not exist. |
6186
6187**Example**
6188
6189```ts
6190import { BusinessError } from '@kit.BasicServicesKit';
6191
6192avsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
6193  if (err) {
6194    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
6195  } else {
6196    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
6197  }
6198});
6199```
6200
6201### getRealPlaybackPositionSync<sup>10+</sup>
6202
6203getRealPlaybackPositionSync(): number
6204
6205Obtains the playback position.
6206
6207**Atomic service API**: This API can be used in atomic services since API version 12.
6208
6209**System capability**: SystemCapability.Multimedia.AVSession.Core
6210
6211**Return value**
6212
6213| Type  | Description              |
6214| ------ | ------------------ |
6215| number | Playback position, in milliseconds.|
6216
6217**Error codes**
6218
6219For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6220
6221| ID| Error Message|
6222| -------- | ---------------------------------------- |
6223| 6600101  | Session service exception. |
6224| 6600103  | The session controller does not exist. |
6225
6226**Example**
6227
6228```ts
6229let time: number = avsessionController.getRealPlaybackPositionSync();
6230```
6231
6232### isActive<sup>10+</sup>
6233
6234isActive(): Promise\<boolean>
6235
6236Checks whether the session is activated. This API uses a promise to return the result.
6237
6238**Atomic service API**: This API can be used in atomic services since API version 12.
6239
6240**System capability**: SystemCapability.Multimedia.AVSession.Core
6241
6242**Return value**
6243
6244| Type             | Description                                                        |
6245| ----------------- | ------------------------------------------------------------ |
6246| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
6247
6248**Error codes**
6249
6250For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6251
6252| ID| Error Message|
6253| -------- | ---------------------------------------- |
6254| 6600101  | Session service exception. |
6255| 6600102  | The session does not exist. |
6256| 6600103  | The session controller does not exist. |
6257
6258**Example**
6259
6260```ts
6261import { BusinessError } from '@kit.BasicServicesKit';
6262
6263avsessionController.isActive().then((isActive: boolean) => {
6264  console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6265}).catch((err: BusinessError) => {
6266  console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6267});
6268```
6269
6270### isActive<sup>10+</sup>
6271
6272isActive(callback: AsyncCallback\<boolean>): void
6273
6274Checks whether the session is activated. This API uses an asynchronous callback to return the result.
6275
6276**System capability**: SystemCapability.Multimedia.AVSession.Core
6277
6278**Parameters**
6279
6280| Name  | Type                   | Mandatory| Description                                                        |
6281| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
6282| callback | AsyncCallback<boolean\> | Yes  | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
6283
6284**Error codes**
6285
6286For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6287
6288| ID| Error Message|
6289| -------- | ---------------------------------------- |
6290| 6600101  | Session service exception. |
6291| 6600102  | The session does not exist. |
6292| 6600103  | The session controller does not exist. |
6293
6294**Example**
6295
6296```ts
6297import { BusinessError } from '@kit.BasicServicesKit';
6298
6299avsessionController.isActive((err: BusinessError, isActive: boolean) => {
6300  if (err) {
6301    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6302  } else {
6303    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6304  }
6305});
6306```
6307
6308### destroy<sup>10+</sup>
6309
6310destroy(): Promise\<void>
6311
6312Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.
6313
6314**Atomic service API**: This API can be used in atomic services since API version 12.
6315
6316**System capability**: SystemCapability.Multimedia.AVSession.Core
6317
6318**Return value**
6319
6320| Type          | Description                         |
6321| -------------- | ----------------------------- |
6322| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.|
6323
6324**Error codes**
6325
6326For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6327
6328| ID| Error Message|
6329| -------- | ---------------------------------------- |
6330| 6600101  | Session service exception. |
6331| 6600103  | The session controller does not exist. |
6332
6333**Example**
6334
6335```ts
6336import { BusinessError } from '@kit.BasicServicesKit';
6337
6338avsessionController.destroy().then(() => {
6339  console.info('Destroy : SUCCESS ');
6340}).catch((err: BusinessError) => {
6341  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6342});
6343```
6344
6345### destroy<sup>10+</sup>
6346
6347destroy(callback: AsyncCallback\<void>): void
6348
6349Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.
6350
6351**System capability**: SystemCapability.Multimedia.AVSession.Core
6352
6353**Parameters**
6354
6355| Name  | Type                | Mandatory| Description      |
6356| -------- | -------------------- | ---- | ---------- |
6357| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
6358
6359**Error codes**
6360
6361For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6362
6363| ID| Error Message|
6364| -------- | ---------------------------------------- |
6365| 6600101  | Session service exception. |
6366| 6600103  | The session controller does not exist. |
6367
6368**Example**
6369
6370```ts
6371import { BusinessError } from '@kit.BasicServicesKit';
6372
6373avsessionController.destroy((err: BusinessError) => {
6374  if (err) {
6375    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6376  } else {
6377    console.info('Destroy : SUCCESS ');
6378  }
6379});
6380```
6381
6382### getValidCommands<sup>10+</sup>
6383
6384getValidCommands(): Promise\<Array\<AVControlCommandType>>
6385
6386Obtains valid commands supported by the session. This API uses a promise to return the result.
6387
6388**Atomic service API**: This API can be used in atomic services since API version 12.
6389
6390**System capability**: SystemCapability.Multimedia.AVSession.Core
6391
6392**Return value**
6393
6394| Type                                                        | Description                             |
6395| ------------------------------------------------------------ | --------------------------------- |
6396| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands.|
6397
6398**Error codes**
6399
6400For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6401
6402| ID| Error Message|
6403| -------- | ---------------------------------------- |
6404| 6600101  | Session service exception. |
6405| 6600102  | The session does not exist. |
6406| 6600103  | The session controller does not exist. |
6407
6408**Example**
6409
6410```ts
6411import { BusinessError } from '@kit.BasicServicesKit';
6412
6413avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
6414  console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6415}).catch((err: BusinessError) => {
6416  console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6417});
6418```
6419
6420### getValidCommands<sup>10+</sup>
6421
6422getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
6423
6424Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result.
6425
6426**System capability**: SystemCapability.Multimedia.AVSession.Core
6427
6428**Parameters**
6429
6430| Name  | Type                                                        | Mandatory| Description                          |
6431| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
6432| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes  | Callback used to return a set of valid commands.|
6433
6434**Error codes**
6435
6436For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6437
6438| ID| Error Message|
6439| -------- | ---------------------------------------- |
6440| 6600101  | Session service exception. |
6441| 6600102  | The session does not exist. |
6442| 6600103  | The session controller does not exist. |
6443
6444**Example**
6445
6446```ts
6447import { BusinessError } from '@kit.BasicServicesKit';
6448
6449avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
6450  if (err) {
6451    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6452  } else {
6453    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6454  }
6455});
6456```
6457
6458### sendControlCommand<sup>10+</sup>
6459
6460sendControlCommand(command: AVControlCommand): Promise\<void>
6461
6462Sends a control command to the session through the controller. This API uses a promise to return the result.
6463
6464> **NOTE**
6465>
6466> 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.
6467
6468**Atomic service API**: This API can be used in atomic services since API version 12.
6469
6470**System capability**: SystemCapability.Multimedia.AVSession.Core
6471
6472**Parameters**
6473
6474| Name   | Type                                 | Mandatory| Description                          |
6475| ------- | ------------------------------------- | ---- | ------------------------------ |
6476| command | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
6477
6478**Return value**
6479
6480| Type          | Description                         |
6481| -------------- | ----------------------------- |
6482| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
6483
6484**Error codes**
6485
6486For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6487
6488| ID| Error Message|
6489| -------- | ---------------------------------------- |
6490| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6491| 6600101  | Session service exception. |
6492| 6600102  | The session does not exist. |
6493| 6600103  | The session controller does not exist. |
6494| 6600105  | Invalid session command. |
6495| 6600106  | The session is not activated. |
6496| 6600107  | Too many commands or events. |
6497
6498**Example**
6499
6500```ts
6501import { BusinessError } from '@kit.BasicServicesKit';
6502
6503let avCommand: avSession.AVControlCommand = {command:'play'};
6504avsessionController.sendControlCommand(avCommand).then(() => {
6505  console.info('SendControlCommand successfully');
6506}).catch((err: BusinessError) => {
6507  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6508});
6509```
6510
6511### sendControlCommand<sup>10+</sup>
6512
6513sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
6514
6515Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
6516
6517> **NOTE**
6518>
6519> 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.
6520
6521**System capability**: SystemCapability.Multimedia.AVSession.Core
6522
6523**Parameters**
6524
6525| Name  | Type                                 | Mandatory| Description                          |
6526| -------- | ------------------------------------- | ---- | ------------------------------ |
6527| command  | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
6528| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
6529
6530**Error codes**
6531
6532For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6533
6534| ID| Error Message|
6535| -------- | ------------------------------- |
6536| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6537| 6600101  | Session service exception.                |
6538| 6600102  | The session does not exist.     |
6539| 6600103  | The session controller does not exist.   |
6540| 6600105  | Invalid session command.           |
6541| 6600106  | The session is not activated.                |
6542| 6600107  | Too many commands or events.      |
6543
6544**Example**
6545
6546```ts
6547import { BusinessError } from '@kit.BasicServicesKit';
6548
6549let avCommand: avSession.AVControlCommand = {command:'play'};
6550avsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
6551  if (err) {
6552    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6553  } else {
6554    console.info('SendControlCommand successfully');
6555  }
6556});
6557```
6558
6559### sendCommonCommand<sup>10+</sup>
6560
6561sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void>
6562
6563Sends a custom control command to the session through the controller. This API uses a promise to return the result.
6564
6565**Atomic service API**: This API can be used in atomic services since API version 12.
6566
6567**System capability**: SystemCapability.Multimedia.AVSession.Core
6568
6569**Parameters**
6570
6571| Name   | Type                                 | Mandatory| Description                          |
6572| ------- | ------------------------------------- | ---- | ------------------------------ |
6573| command | string | Yes  | Name of the custom control command.|
6574| args | {[key: string]: Object} | Yes  | Parameters in key-value pair format carried in the custom control command.|
6575
6576> **NOTE**
6577> 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).
6578
6579**Return value**
6580
6581| Type          | Description                         |
6582| -------------- | ----------------------------- |
6583| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
6584
6585**Error codes**
6586
6587For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6588
6589| ID| Error Message|
6590| -------- | ---------------------------------------- |
6591| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6592| 6600101  | Session service exception. |
6593| 6600102  | The session does not exist. |
6594| 6600103  | The session controller does not exist. |
6595| 6600105  | Invalid session command. |
6596| 6600106  | The session is not activated. |
6597| 6600107  | Too many commands or events. |
6598
6599**Example**
6600
6601```ts
6602import { BusinessError } from '@kit.BasicServicesKit';
6603
6604let avSessionController: avSession.AVSessionController | undefined = undefined;
6605let currentAVSession: avSession.AVSession | undefined = undefined;
6606let tag = "createNewSession";
6607let context: Context = getContext(this);
6608let sessionId: string = "";
6609avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6610  if (err) {
6611    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6612  } else {
6613    currentAVSession = data;
6614  }
6615});
6616if (currentAVSession !== undefined) {
6617  sessionId = (currentAVSession as avSession.AVSession).sessionId;
6618  avSession.createController(sessionId).then((controller: avSession.AVSessionController) => {
6619    avSessionController = controller;
6620  }).catch((err: BusinessError) => {
6621    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6622  });
6623}
6624
6625let commandName = "my_command";
6626if (avSessionController !== undefined) {
6627  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
6628    console.info('SendCommonCommand successfully');
6629  }).catch((err: BusinessError) => {
6630    console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6631  })
6632}
6633```
6634
6635### sendCommonCommand<sup>10+</sup>
6636
6637sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
6638
6639Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result.
6640
6641**System capability**: SystemCapability.Multimedia.AVSession.Core
6642
6643**Parameters**
6644
6645| Name   | Type                                 | Mandatory| Description                          |
6646| ------- | ------------------------------------- | ---- | ------------------------------ |
6647| command | string | Yes  | Name of the custom control command.|
6648| args | {[key: string]: Object} | Yes  | Parameters in key-value pair format carried in the custom control command.|
6649| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
6650
6651> **NOTE**
6652> 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).
6653
6654**Error codes**
6655
6656For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6657
6658| ID| Error Message|
6659| -------- | ------------------------------- |
6660| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.|
6661| 6600101  | Session service exception.                |
6662| 6600102  | The session does not exist.     |
6663| 6600103  | The session controller does not exist.   |
6664| 6600105  | Invalid session command.           |
6665| 6600106  | The session is not activated.                |
6666| 6600107  | Too many commands or events.      |
6667
6668**Example**
6669
6670```ts
6671import { BusinessError } from '@kit.BasicServicesKit';
6672let avSessionController: avSession.AVSessionController | undefined = undefined;
6673let currentAVSession: avSession.AVSession | undefined = undefined;
6674let tag = "createNewSession";
6675let context: Context = getContext(this);
6676
6677avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6678  if (err) {
6679    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6680  } else {
6681    currentAVSession = data;
6682  }
6683});
6684if (currentAVSession !== undefined) {
6685  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6686    avSessionController = controller;
6687  }).catch((err: BusinessError) => {
6688    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6689  });
6690}
6691
6692let commandName = "my_command";
6693if (avSessionController !== undefined) {
6694  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
6695    if (err) {
6696        console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6697    }
6698  })
6699}
6700```
6701
6702### getExtras<sup>10+</sup>
6703
6704getExtras(): Promise\<{[key: string]: Object}>
6705
6706Obtains the custom media packet set by the provider. This API uses a promise to return the result.
6707
6708**Atomic service API**: This API can be used in atomic services since API version 12.
6709
6710**System capability**: SystemCapability.Multimedia.AVSession.Core
6711
6712**Return value**
6713
6714| Type                               | Description                         |
6715| ----------------------------------- | ----------------------------- |
6716| 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**.|
6717
6718**Error codes**
6719
6720For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6721
6722| ID| Error Message|
6723| -------- | ---------------------------------------- |
6724| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6725| 6600101  | Session service exception. |
6726| 6600102  | The session does not exist. |
6727| 6600103  | The session controller does not exist. |
6728| 6600105  | Invalid session command. |
6729| 6600107  | Too many commands or events. |
6730
6731**Example**
6732
6733```ts
6734import { BusinessError } from '@kit.BasicServicesKit';
6735
6736let avSessionController: avSession.AVSessionController | undefined = undefined;
6737let currentAVSession: avSession.AVSession | undefined = undefined;
6738let tag = "createNewSession";
6739let context: Context = getContext(this);
6740
6741avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6742  if (err) {
6743    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6744  } else {
6745    currentAVSession = data;
6746  }
6747});
6748if (currentAVSession !== undefined) {
6749  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6750    avSessionController = controller;
6751  }).catch((err: BusinessError) => {
6752    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6753  });
6754}
6755
6756if (avSessionController !== undefined) {
6757  (avSessionController as avSession.AVSessionController).getExtras().then((extras) => {
6758    console.info(`getExtras : SUCCESS : ${extras}`);
6759  }).catch((err: BusinessError) => {
6760    console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6761  });
6762}
6763```
6764
6765### getExtras<sup>10+</sup>
6766
6767getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
6768
6769Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result.
6770
6771**System capability**: SystemCapability.Multimedia.AVSession.Core
6772
6773**Parameters**
6774
6775| Name  | Type                                     | Mandatory| Description                      |
6776| -------- | ----------------------------------------- | ---- | -------------------------- |
6777| 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**.|
6778
6779**Error codes**
6780
6781For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6782
6783| ID| Error Message|
6784| -------- | ---------------------------------------- |
6785| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6786| 6600101  | Session service exception. |
6787| 6600102  | The session does not exist. |
6788| 6600103  | The session controller does not exist. |
6789| 6600105  | Invalid session command. |
6790| 6600107  | Too many commands or events. |
6791
6792**Example**
6793
6794```ts
6795import { BusinessError } from '@kit.BasicServicesKit';
6796
6797let avSessionController: avSession.AVSessionController | undefined = undefined;
6798let currentAVSession: avSession.AVSession | undefined = undefined;
6799let tag = "createNewSession";
6800let context: Context = getContext(this);
6801
6802avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6803  if (err) {
6804    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6805  } else {
6806    currentAVSession = data;
6807  }
6808});
6809if (currentAVSession !== undefined) {
6810  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6811    avSessionController = controller;
6812  }).catch((err: BusinessError) => {
6813    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6814  });
6815}
6816
6817if (avSessionController !== undefined) {
6818  (avSessionController as avSession.AVSessionController).getExtras((err, extras) => {
6819    if (err) {
6820      console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6821    } else {
6822      console.info(`getExtras : SUCCESS : ${extras}`);
6823    }
6824  });
6825}
6826```
6827
6828### getExtrasWithEvent<sup>18+</sup>
6829
6830getExtrasWithEvent(extraEvent: string): Promise\<ExtraInfo>
6831
6832Obtains the custom media packet set by the remote distributed media provider based on the remote distributed event type. This API uses a promise to return the result.
6833
6834**Atomic service API**: This API can be used in atomic services since API version 18.
6835
6836**System capability**: SystemCapability.Multimedia.AVSession.Core
6837
6838**Parameters**
6839
6840| Name  | Type                                     | Mandatory| Description                      |
6841| -------- | ----------------------------------------- | ---- | -------------------------- |
6842| extraEvent | string | Yes| Remote distributed event type.<br>Currently, the following event types are supported:<br>**'AUDIO_GET_VOLUME'**: obtains the volume of the remote device.<br>**'AUDIO_GET_AVAILABLE_DEVICES'**: obtains all remote devices that can be connected.<br>**'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO'**: obtains the actual remote audio device.|
6843
6844**Return value**
6845
6846| Type                               | Description                         |
6847| ----------------------------------- | ----------------------------- |
6848| Promise<[ExtraInfo](#extrainfo18)\>   | Promise used to return the custom media packet set by the remote distributed media provider.<br>The **ExtraInfo** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).|
6849
6850**Error codes**
6851
6852For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6853
6854| ID| Error Message|
6855| -------- | ---------------------------------------- |
6856| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6857| 6600101  | Session service exception. |
6858| 6600102  | The session does not exist. |
6859| 6600103  | The session controller does not exist. |
6860| 6600105  | Invalid session command. |
6861
6862**Example**
6863
6864```ts
6865import { BusinessError } from '@kit.BasicServicesKit';
6866
6867@Entry
6868@Component
6869struct Index {
6870  @State message: string = 'hello world';
6871
6872  build() {
6873    Row() {
6874      Column() {
6875        Text(this.message)
6876          .fontSize(40)
6877          .fontWeight(FontWeight.Bold)
6878          .onClick(() => {
6879            getExtrasWithEventTest();
6880          })
6881      }
6882    }
6883  }
6884}
6885
6886async function getExtrasWithEventTest() {
6887  let controllerList: Array<avSession.AVSessionController>;
6888  let controller: avSession.AVSessionController | ESObject;
6889
6890  try {
6891    controllerList = await avSession.getDistributedSessionController(avSession.DistributedSessionType.TYPE_SESSION_REMOTE);
6892    controller = controllerList[0];
6893  } catch (err) {
6894    console.info(`getDistributedSessionController fail with err: ${err}`);
6895  }
6896
6897  const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME';
6898  const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES';
6899  const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO';
6900  if (controller !== undefined) {
6901    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then((extras: avSession.ExtraInfo) => {
6902      console.info(`${extras[COMMON_COMMAND_STRING_1]}`);
6903    }).catch((err: BusinessError) => {
6904      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6905    })
6906
6907    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then((extras: avSession.ExtraInfo) => {
6908      console.info(`${extras[COMMON_COMMAND_STRING_2]}`);
6909    }).catch((err: BusinessError) => {
6910      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6911    })
6912
6913    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then((extras: avSession.ExtraInfo) => {
6914      console.info(`${extras[COMMON_COMMAND_STRING_3]}`);
6915    }).catch((err: BusinessError) => {
6916      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6917    })
6918  }
6919}
6920```
6921
6922### on('metadataChange')<sup>10+</sup>
6923
6924on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
6925
6926Subscribes to metadata change events.
6927
6928**Atomic service API**: This API can be used in atomic services since API version 12.
6929
6930**System capability**: SystemCapability.Multimedia.AVSession.Core
6931
6932**Parameters**
6933
6934| Name  | Type                                                        | Mandatory| Description                                                        |
6935| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6936| type     | string                                                       | Yes  | Event type. The event **'metadataChange'** is triggered when the session metadata changes.|
6937| filter   | Array\<keyof&nbsp;[AVMetadata](#avmetadata10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any metadata field change will trigger the event, and **Array<keyof&nbsp;[AVMetadata](#avmetadata10)\>** indicates that only changes to the listed metadata field will trigger the event.|
6938| callback | (data: [AVMetadata](#avmetadata10)) => void                    | Yes  | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.                        |
6939
6940**Error codes**
6941
6942For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6943
6944| ID| Error Message|
6945| -------- | ------------------------------ |
6946| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6947| 6600101  | Session service exception. |
6948| 6600103  | The session controller does not exist. |
6949
6950**Example**
6951
6952```ts
6953avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
6954  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6955});
6956
6957avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
6958  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6959});
6960
6961```
6962
6963### off('metadataChange')<sup>10+</sup>
6964
6965off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
6966
6967Unsubscribes from metadata change events. This API is called by the controller.
6968
6969**Atomic service API**: This API can be used in atomic services since API version 12.
6970
6971**System capability**: SystemCapability.Multimedia.AVSession.Core
6972
6973**Parameters**
6974
6975| Name  | Type                                              | Mandatory| Description                                                   |
6976| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
6977| type     | string                                           | Yes  | Event type, which is **'metadataChange'** in this case.        |
6978| 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.                        |
6979
6980**Error codes**
6981
6982For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6983
6984| ID| Error Message|
6985| -------- | ---------------- |
6986| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6987| 6600101  | Session service exception. |
6988| 6600103  | The session controller does not exist. |
6989
6990**Example**
6991
6992```ts
6993avsessionController.off('metadataChange');
6994```
6995
6996### on('playbackStateChange')<sup>10+</sup>
6997
6998on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
6999
7000Subscribes to playback state change events.
7001
7002**Atomic service API**: This API can be used in atomic services since API version 12.
7003
7004**System capability**: SystemCapability.Multimedia.AVSession.Core
7005
7006**Parameters**
7007
7008| Name  | Type      | Mandatory| Description     |
7009| --------| -----------|-----|------------|
7010| type     | string    | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
7011| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.|
7012| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.|
7013
7014**Error codes**
7015
7016For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7017
7018| ID| Error Message|
7019| -------- | ------------------------------ |
7020| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7021| 6600101  | Session service exception. |
7022| 6600103  | The session controller does not exist. |
7023
7024**Example**
7025
7026```ts
7027avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
7028  console.info(`on playbackStateChange state : ${playbackState.state}`);
7029});
7030
7031avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
7032  console.info(`on playbackStateChange state : ${playbackState.state}`);
7033});
7034```
7035
7036### off('playbackStateChange')<sup>10+</sup>
7037
7038off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
7039
7040Unsubscribes from playback state change events. This API is called by the controller.
7041
7042**Atomic service API**: This API can be used in atomic services since API version 12.
7043
7044**System capability**: SystemCapability.Multimedia.AVSession.Core
7045
7046**Parameters**
7047
7048| Name  | Type                                                        | Mandatory| Description                                                    |
7049| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7050| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
7051| 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.                     |
7052
7053**Error codes**
7054
7055For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7056
7057| ID| Error Message|
7058| -------- | ---------------- |
7059| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7060| 6600101  | Session service exception. |
7061| 6600103  | The session controller does not exist. |
7062
7063**Example**
7064
7065```ts
7066avsessionController.off('playbackStateChange');
7067```
7068
7069### on('callMetadataChange')<sup>11+</sup>
7070
7071on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void;
7072
7073Subscribes to call metadata change events.
7074
7075**Atomic service API**: This API can be used in atomic services since API version 12.
7076
7077**System capability**: SystemCapability.Multimedia.AVSession.Core
7078
7079**Parameters**
7080
7081| Name  | Type      | Mandatory| Description     |
7082| --------| -----------|-----|------------|
7083| type     | string    | Yes  | Event type. The event **'callMetadataChange'** is triggered when the call metadata changes.|
7084| filter   | Array\<keyof&nbsp;[CallMetadata](#callmetadata11)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any call metadata field change will trigger the event, and **Array<keyof&nbsp;[CallMetadata](#callmetadata11)\>** indicates that only changes to the listed metadata field will trigger the event.|
7085| callback | Callback<[CallMetadata](#callmetadata11)\>\>   | Yes  | Callback used for subscription. The **callmetadata** parameter in the callback indicates the changed call metadata.|
7086
7087**Error codes**
7088
7089For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7090
7091| ID| Error Message|
7092| -------- | ------------------------------ |
7093| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7094| 6600101  | Session service exception. |
7095| 6600103  | The session controller does not exist. |
7096
7097**Example**
7098
7099```ts
7100avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
7101  console.info(`on callMetadataChange state : ${callmetadata.name}`);
7102});
7103
7104avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
7105  console.info(`on callMetadataChange state : ${callmetadata.name}`);
7106});
7107```
7108
7109### off('callMetadataChange')<sup>11+</sup>
7110
7111off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void;
7112
7113Unsubscribes from call metadata change events.
7114
7115**Atomic service API**: This API can be used in atomic services since API version 12.
7116
7117**System capability**: SystemCapability.Multimedia.AVSession.Core
7118
7119**Parameters**
7120
7121| Name  | Type                                                        | Mandatory| Description                                                    |
7122| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7123| type     | string                                                       | Yes  | Event type, which is **'callMetadataChange'** in this case.   |
7124| 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.     |
7125
7126**Error codes**
7127
7128For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7129
7130| ID| Error Message|
7131| -------- | ---------------- |
7132| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7133| 6600101  | Session service exception. |
7134| 6600103  | The session controller does not exist. |
7135
7136**Example**
7137
7138```ts
7139avsessionController.off('callMetadataChange');
7140```
7141
7142### on('callStateChange')<sup>11+</sup>
7143
7144on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void;
7145
7146Subscribes to call state change events.
7147
7148**Atomic service API**: This API can be used in atomic services since API version 12.
7149
7150**System capability**: SystemCapability.Multimedia.AVSession.Core
7151
7152**Parameters**
7153
7154| Name  | Type      | Mandatory| Description     |
7155| --------| -----------|-----|------------|
7156| type     | string    | Yes  | Event type. The event **'callStateChange'** is triggered when the call state changes.|
7157| filter   | Array<keyof&nbsp;[AVCallState](#avcallstate11)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any call state field change will trigger the event, and **Array<keyof&nbsp;[AVCallState](#avcallstate11)\>** indicates that only changes to the listed call state field will trigger the event.|
7158| callback | Callback<[AVCallState](#avcallstate11)\>       | Yes  | Callback function, where the **callstate** parameter indicates the new call state.|
7159
7160**Error codes**
7161
7162For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7163
7164| ID| Error Message|
7165| -------- | ------------------------------ |
7166| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7167| 6600101  | Session service exception. |
7168| 6600103  | The session controller does not exist. |
7169
7170**Example**
7171
7172```ts
7173avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
7174  console.info(`on callStateChange state : ${callstate.state}`);
7175});
7176
7177avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
7178  console.info(`on callStateChange state : ${callstate.state}`);
7179});
7180```
7181
7182### off('callStateChange')<sup>11+</sup>
7183
7184off(type: 'callStateChange', callback?: Callback\<AVCallState>): void;
7185
7186Unsubscribes from call state change events.
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, which is **'callStateChange'** in this case.   |
7197| 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.     |
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
7212avsessionController.off('callMetadataChange');
7213```
7214
7215### on('sessionDestroy')<sup>10+</sup>
7216
7217on(type: 'sessionDestroy', callback: () => void)
7218
7219Subscribes to session destruction events.
7220
7221**Atomic service API**: This API can be used in atomic services since API version 12.
7222
7223**System capability**: SystemCapability.Multimedia.AVSession.Core
7224
7225**Parameters**
7226
7227| Name  | Type      | Mandatory| Description                                                        |
7228| -------- | ---------- | ---- | ------------------------------------------------------------ |
7229| type     | string     | Yes  | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.|
7230| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                 |
7231
7232**Error codes**
7233
7234For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7235
7236| ID| Error Message|
7237| -------- | ------------------------------ |
7238| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7239| 6600101  | Session service exception. |
7240| 6600103  | The session controller does not exist. |
7241
7242**Example**
7243
7244```ts
7245avsessionController.on('sessionDestroy', () => {
7246  console.info('on sessionDestroy : SUCCESS ');
7247});
7248```
7249
7250### off('sessionDestroy')<sup>10+</sup>
7251
7252off(type: 'sessionDestroy', callback?: () => void)
7253
7254Unsubscribes from session destruction events. This API is called by the controller.
7255
7256**Atomic service API**: This API can be used in atomic services since API version 12.
7257
7258**System capability**: SystemCapability.Multimedia.AVSession.Core
7259
7260**Parameters**
7261
7262| Name  | Type      | Mandatory| Description                                                     |
7263| -------- | ---------- | ---- | ----------------------------------------------------- |
7264| type     | string     | Yes  | Event type, which is **'sessionDestroy'** in this case.        |
7265| 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.                                              |
7266
7267**Error codes**
7268
7269For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7270
7271| ID| Error Message|
7272| -------- | ---------------- |
7273| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7274| 6600101  | Session service exception. |
7275| 6600103  | The session controller does not exist. |
7276
7277**Example**
7278
7279```ts
7280avsessionController.off('sessionDestroy');
7281```
7282
7283### on('activeStateChange')<sup>10+</sup>
7284
7285on(type: 'activeStateChange', callback: (isActive: boolean) => void)
7286
7287Subscribes to session activation state change events.
7288
7289**Atomic service API**: This API can be used in atomic services since API version 12.
7290
7291**System capability**: SystemCapability.Multimedia.AVSession.Core
7292
7293**Parameters**
7294
7295| Name  | Type                       | Mandatory| Description                                                        |
7296| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
7297| type     | string                      | Yes  | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes.|
7298| 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.                  |
7299
7300**Error codes**
7301
7302For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7303
7304| ID| Error Message|
7305| -------- | ----------------------------- |
7306| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7307| 6600101  | Session service exception. |
7308| 6600103  |The session controller does not exist. |
7309
7310**Example**
7311
7312```ts
7313avsessionController.on('activeStateChange', (isActive: boolean) => {
7314  console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
7315});
7316```
7317
7318### off('activeStateChange')<sup>10+</sup>
7319
7320off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
7321
7322Unsubscribes from session activation state change events. This API is called by the controller.
7323
7324**Atomic service API**: This API can be used in atomic services since API version 12.
7325
7326**System capability**: SystemCapability.Multimedia.AVSession.Core
7327
7328**Parameters**
7329
7330| Name  | Type                       | Mandatory| Description                                                     |
7331| -------- | --------------------------- | ---- | ----------------------------------------------------- |
7332| type     | string                      | Yes  | Event type, which is **'activeStateChange'** in this case.     |
7333| 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.                  |
7334
7335**Error codes**
7336
7337For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7338
7339| ID| Error Message|
7340| -------- | ---------------- |
7341| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7342| 6600101  | Session service exception. |
7343| 6600103  | The session controller does not exist. |
7344
7345**Example**
7346
7347```ts
7348avsessionController.off('activeStateChange');
7349```
7350
7351### on('validCommandChange')<sup>10+</sup>
7352
7353on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
7354
7355Subscribes to valid command change events.
7356
7357**Atomic service API**: This API can be used in atomic services since API version 12.
7358
7359**System capability**: SystemCapability.Multimedia.AVSession.Core
7360
7361**Parameters**
7362
7363| Name  | Type                                                        | Mandatory| Description                                                        |
7364| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7365| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
7366| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
7367
7368**Error codes**
7369
7370For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7371
7372| ID| Error Message|
7373| -------- | ------------------------------ |
7374| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7375| 6600101  | Session service exception. |
7376| 6600103  | The session controller does not exist. |
7377
7378**Example**
7379
7380```ts
7381avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
7382  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
7383  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
7384});
7385```
7386
7387### off('validCommandChange')<sup>10+</sup>
7388
7389off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
7390
7391Unsubscribes from valid command change events. This API is called by the controller.
7392
7393**Atomic service API**: This API can be used in atomic services since API version 12.
7394
7395**System capability**: SystemCapability.Multimedia.AVSession.Core
7396
7397**Parameters**
7398
7399| Name  | Type                                                        | Mandatory| Description                                                       |
7400| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
7401| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
7402| 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.         |
7403
7404**Error codes**
7405
7406For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7407
7408| ID| Error Message          |
7409| -------- | ---------------- |
7410| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7411| 6600101  | Session service exception. |
7412| 6600103  | The session controller does not exist. |
7413
7414**Example**
7415
7416```ts
7417avsessionController.off('validCommandChange');
7418```
7419
7420### on('outputDeviceChange')<sup>10+</sup>
7421
7422on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7423
7424Subscribes to output device change events.
7425
7426**Atomic service API**: This API can be used in atomic services since API version 12.
7427
7428**System capability**: SystemCapability.Multimedia.AVSession.Core
7429
7430**Parameters**
7431
7432| Name  | Type                                                   | Mandatory| Description                                                        |
7433| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
7434| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
7435| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.                        |
7436
7437**Error codes**
7438
7439For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7440
7441| ID| Error Message|
7442| -------- | ----------------------- |
7443| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7444| 6600101  | Session service exception. |
7445| 6600103  | The session controller does not exist. |
7446
7447**Example**
7448
7449```ts
7450avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
7451  console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
7452});
7453```
7454
7455### off('outputDeviceChange')<sup>10+</sup>
7456
7457off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7458
7459Unsubscribes from output device change events. This API is called by the controller.
7460
7461**Atomic service API**: This API can be used in atomic services since API version 12.
7462
7463**System capability**: SystemCapability.Multimedia.AVSession.Core
7464
7465**Parameters**
7466
7467| Name  | Type                                                   | Mandatory| Description                                                     |
7468| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
7469| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.     |
7470| 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.                        |
7471
7472**Error codes**
7473
7474For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7475
7476| ID | Error Message         |
7477| -------- | ---------------- |
7478| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7479| 6600101  | Session service exception. |
7480| 6600103  | The session controller does not exist. |
7481
7482**Example**
7483
7484```ts
7485avsessionController.off('outputDeviceChange');
7486```
7487
7488### on('sessionEvent')<sup>10+</sup>
7489
7490on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7491
7492Subscribes to session event change events. This API is called by the controller.
7493
7494**Atomic service API**: This API can be used in atomic services since API version 12.
7495
7496**System capability**: SystemCapability.Multimedia.AVSession.Core
7497
7498**Parameters**
7499
7500| Name  | Type                                                        | Mandatory| Description                                                        |
7501| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7502| type     | string                                                       | Yes  | Event type. The event **'sessionEvent'** is triggered when the session event changes.|
7503| 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.         |
7504
7505**Error codes**
7506
7507For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7508
7509| ID| Error Message|
7510| -------- | ------------------------------ |
7511| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7512| 6600101  | Session service exception. |
7513| 6600103  | The session controller does not exist. |
7514
7515**Example**
7516
7517```ts
7518import { BusinessError } from '@kit.BasicServicesKit';
7519
7520let avSessionController: avSession.AVSessionController | undefined = undefined;
7521let currentAVSession: avSession.AVSession | undefined = undefined;
7522let tag = "createNewSession";
7523let context: Context = getContext(this);
7524
7525avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
7526  if (err) {
7527    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
7528  } else {
7529    currentAVSession = data;
7530  }
7531});
7532if (currentAVSession !== undefined) {
7533  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
7534    avSessionController = controller;
7535  }).catch((err: BusinessError) => {
7536    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
7537  });
7538}
7539
7540if (avSessionController !== undefined) {
7541  (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => {
7542    console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
7543  });
7544}
7545```
7546
7547### off('sessionEvent')<sup>10+</sup>
7548
7549off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7550
7551Unsubscribes from session event change events. This API is called by the controller.
7552
7553**Atomic service API**: This API can be used in atomic services since API version 12.
7554
7555**System capability**: SystemCapability.Multimedia.AVSession.Core
7556
7557**Parameters**
7558
7559| Name  | Type                                                        | Mandatory| Description                                                    |
7560| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7561| type     | string                                                       | Yes  | Event type, which is **'sessionEvent'** in this case.   |
7562| 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.                     |
7563
7564**Error codes**
7565
7566For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7567
7568| ID| Error Message|
7569| -------- | ---------------- |
7570| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7571| 6600101  | Session service exception. |
7572| 6600103  | The session controller does not exist. |
7573
7574**Example**
7575
7576```ts
7577avsessionController.off('sessionEvent');
7578```
7579
7580### on('queueItemsChange')<sup>10+</sup>
7581
7582on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7583
7584Subscribes to playlist item change events. This API is called by the controller.
7585
7586**Atomic service API**: This API can be used in atomic services since API version 12.
7587
7588**System capability**: SystemCapability.Multimedia.AVSession.Core
7589
7590**Parameters**
7591
7592| Name  | Type                                                  | Mandatory| Description                                                                        |
7593| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
7594| type     | string                                                | Yes  | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.|
7595| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void  | Yes  | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist.                           |
7596
7597**Error codes**
7598
7599For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7600
7601| ID| Error Message|
7602| -------- | ------------------------------ |
7603| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7604| 6600101  | Session service exception. |
7605| 6600103  | The session controller does not exist. |
7606
7607**Example**
7608
7609```ts
7610avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
7611  console.info(`OnQueueItemsChange, items length is ${items.length}`);
7612});
7613```
7614
7615### off('queueItemsChange')<sup>10+</sup>
7616
7617off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7618
7619Unsubscribes from playback item change events. This API is called by the controller.
7620
7621**Atomic service API**: This API can be used in atomic services since API version 12.
7622
7623**System capability**: SystemCapability.Multimedia.AVSession.Core
7624
7625**Parameters**
7626
7627| Name   | Type                                                | Mandatory| Description                                                                                               |
7628| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- |
7629| type     | string                                               | Yes  | Event type, which is **'queueItemsChange'** in this case.                                                    |
7630| 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.|
7631
7632**Error codes**
7633
7634For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7635
7636| ID| Error Message|
7637| -------- | ---------------- |
7638| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7639| 6600101  | Session service exception. |
7640| 6600103  | The session controller does not exist. |
7641
7642**Example**
7643
7644```ts
7645avsessionController.off('queueItemsChange');
7646```
7647
7648### on('queueTitleChange')<sup>10+</sup>
7649
7650on(type: 'queueTitleChange', callback: (title: string) => void): void
7651
7652Subscribes to playlist name change events. This API is called by the controller.
7653
7654**Atomic service API**: This API can be used in atomic services since API version 12.
7655
7656**System capability**: SystemCapability.Multimedia.AVSession.Core
7657
7658**Parameters**
7659
7660| Name  | Type                    | Mandatory| Description                                                                            |
7661| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- |
7662| type     | string                  | Yes  | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.|
7663| callback | (title: string) => void | Yes  | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name.                               |
7664
7665**Error codes**
7666
7667For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7668
7669| ID| Error Message|
7670| -------- | ------------------------------ |
7671| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7672| 6600101  | Session service exception. |
7673| 6600103  | The session controller does not exist. |
7674
7675**Example**
7676
7677```ts
7678avsessionController.on('queueTitleChange', (title: string) => {
7679  console.info(`queueTitleChange, title is ${title}`);
7680});
7681```
7682
7683### off('queueTitleChange')<sup>10+</sup>
7684
7685off(type: 'queueTitleChange', callback?: (title: string) => void): void
7686
7687Unsubscribes from playlist name change events. This API is called by the controller.
7688
7689**Atomic service API**: This API can be used in atomic services since API version 12.
7690
7691**System capability**: SystemCapability.Multimedia.AVSession.Core
7692
7693**Parameters**
7694
7695| Name   | Type                   | Mandatory| Description                                                                                                   |
7696| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7697| type     | string                  | Yes  | Event type, which is **'queueTitleChange'** in this case.                                                        |
7698| 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.|
7699
7700**Error codes**
7701
7702For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7703
7704| ID| Error Message|
7705| -------- | ---------------- |
7706| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7707| 6600101  | Session service exception. |
7708| 6600103  | The session controller does not exist. |
7709
7710**Example**
7711
7712```ts
7713avsessionController.off('queueTitleChange');
7714```
7715
7716### on('extrasChange')<sup>10+</sup>
7717
7718on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void
7719
7720Subscribes to custom media packet change events. This API is called by the controller.
7721
7722**Atomic service API**: This API can be used in atomic services since API version 12.
7723
7724**System capability**: SystemCapability.Multimedia.AVSession.Core
7725
7726**Parameters**
7727
7728| Name  | Type                                                        | Mandatory| Description                                                        |
7729| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7730| type     | string                                                       | Yes  | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.|
7731| 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**.         |
7732
7733**Error codes**
7734
7735For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7736
7737| ID| Error Message|
7738| -------- | ------------------------------ |
7739| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7740| 6600101  | Session service exception. |
7741| 6600103  | The session controller does not exist. |
7742
7743**Example**
7744
7745```ts
7746import { BusinessError } from '@kit.BasicServicesKit';
7747
7748let avSessionController: avSession.AVSessionController | undefined = undefined;
7749let currentAVSession: avSession.AVSession | undefined = undefined;
7750let tag = "createNewSession";
7751let context: Context = getContext(this);
7752
7753avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
7754  if (err) {
7755    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
7756  } else {
7757    currentAVSession = data;
7758  }
7759});
7760if (currentAVSession !== undefined) {
7761  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
7762    avSessionController = controller;
7763  }).catch((err: BusinessError) => {
7764    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
7765  });
7766}
7767
7768if (avSessionController !== undefined) {
7769  (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => {
7770    console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
7771  });
7772}
7773```
7774
7775### off('extrasChange')<sup>10+</sup>
7776
7777off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void
7778
7779Unsubscribes from custom media packet change events. This API is called by the controller.
7780
7781**Atomic service API**: This API can be used in atomic services since API version 12.
7782
7783**System capability**: SystemCapability.Multimedia.AVSession.Core
7784
7785**Parameters**
7786
7787| Name   | Type                   | Mandatory| Description                                                                                                   |
7788| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7789| type     | string                  | Yes  | Event type, which is **'extrasChange'** in this case.                                                        |
7790| 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.|
7791
7792**Error codes**
7793
7794For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7795
7796| ID| Error Message|
7797| -------- | ----------------                       |
7798| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7799| 6600101  | Session service exception.             |
7800| 6600103  | The session controller does not exist. |
7801
7802**Example**
7803
7804```ts
7805avsessionController.off('extrasChange');
7806```
7807
7808### getAVPlaybackStateSync<sup>10+</sup>
7809
7810getAVPlaybackStateSync(): AVPlaybackState;
7811
7812Obtains the playback state of this session. This API returns the result synchronously.
7813
7814**Atomic service API**: This API can be used in atomic services since API version 12.
7815
7816**System capability**: SystemCapability.Multimedia.AVSession.Core
7817
7818**Return value**
7819
7820| Type                                                       | Description                                                        |
7821| --------- | ------------------------------------------------------------ |
7822| [AVPlaybackState](#avplaybackstate10)  | Playback state of the session.|
7823
7824**Error codes**
7825
7826For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7827
7828| ID| Error Message|
7829| -------- | ---------------------------------------- |
7830| 6600101  | Session service exception. |
7831| 6600102  | The session does not exist. |
7832| 6600103  | The session controller does not exist. |
7833
7834**Example**
7835
7836```ts
7837import { BusinessError } from '@kit.BasicServicesKit';
7838
7839try {
7840  let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync();
7841} catch (err) {
7842  let error = err as BusinessError;
7843  console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`);
7844}
7845```
7846
7847### getAVMetadataSync<sup>10+</sup>
7848
7849getAVMetadataSync(): AVMetadata
7850
7851Obtains the session metadata. This API returns the result synchronously.
7852
7853**Atomic service API**: This API can be used in atomic services since API version 12.
7854
7855**System capability**: SystemCapability.Multimedia.AVSession.Core
7856
7857**Return value**
7858
7859| Type                               | Description                         |
7860| ----------------------------------- | ----------------------------- |
7861| [AVMetadata](#avmetadata10) | Session metadata.|
7862
7863**Error codes**
7864
7865For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7866
7867| ID| Error Message|
7868| -------- | ---------------------------------------- |
7869| 6600101  | Session service exception. |
7870| 6600102  | The session does not exist. |
7871| 6600103  | The session controller does not exist. |
7872
7873**Example**
7874```ts
7875import { BusinessError } from '@kit.BasicServicesKit';
7876
7877try {
7878  let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync();
7879} catch (err) {
7880  let error = err as BusinessError;
7881  console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`);
7882}
7883```
7884
7885### getAVCallState<sup>11+</sup>
7886
7887getAVCallState(): Promise\<AVCallState>
7888
7889Obtains the call state. This API uses a promise to return the result.
7890
7891**System capability**: SystemCapability.Multimedia.AVSession.Core
7892
7893**Return value**
7894
7895| Type                               | Description                         |
7896| ----------------------------------- | ----------------------------- |
7897| Promise<[AVCallState](#avcallstate11)\> | Promise used to return the call state obtained.|
7898
7899**Error codes**
7900
7901For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7902
7903| ID| Error Message|
7904| -------- | ---------------------------------------- |
7905| 6600101  | Session service exception. |
7906| 6600102  | The session does not exist. |
7907| 6600103  | The session controller does not exist. |
7908
7909**Example**
7910
7911```ts
7912import { BusinessError } from '@kit.BasicServicesKit';
7913
7914avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => {
7915  console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7916}).catch((err: BusinessError) => {
7917  console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7918});
7919```
7920
7921### getAVCallState<sup>11+</sup>
7922
7923getAVCallState(callback: AsyncCallback\<AVCallState>): void
7924
7925Obtains the call state. This API uses an asynchronous callback to return the result.
7926
7927**System capability**: SystemCapability.Multimedia.AVSession.Core
7928
7929**Parameters**
7930
7931| Name  | Type                                     | Mandatory| Description                      |
7932| -------- | ----------------------------------------- | ---- | -------------------------- |
7933| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | Yes  | Callback used to return the call state obtained.|
7934
7935**Error codes**
7936
7937For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7938
7939| ID| Error Message|
7940| -------- | ---------------------------------------- |
7941| 6600101  | Session service exception. |
7942| 6600102  | The session does not exist. |
7943| 6600103  | The session controller does not exist. |
7944
7945**Example**
7946
7947```ts
7948import { BusinessError } from '@kit.BasicServicesKit';
7949
7950avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
7951  if (err) {
7952    console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7953  } else {
7954    console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7955  }
7956});
7957```
7958
7959### getCallMetadata<sup>11+</sup>
7960
7961getCallMetadata(): Promise\<CallMetadata>
7962
7963Obtains the call metadata. This API uses a promise to return the result.
7964
7965**System capability**: SystemCapability.Multimedia.AVSession.Core
7966
7967**Return value**
7968
7969| Type                               | Description                         |
7970| ----------------------------------- | ----------------------------- |
7971| Promise<[CallMetadata](#callmetadata11)\> | Promise used to return the metadata obtained.|
7972
7973**Error codes**
7974
7975For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7976
7977| ID| Error Message|
7978| -------- | ---------------------------------------- |
7979| 6600101  | Session service exception. |
7980| 6600102  | The session does not exist. |
7981| 6600103  | The session controller does not exist. |
7982
7983**Example**
7984
7985```ts
7986import { BusinessError } from '@kit.BasicServicesKit';
7987
7988avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => {
7989  console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
7990}).catch((err: BusinessError) => {
7991  console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
7992});
7993```
7994
7995### getCallMetadata<sup>11+</sup>
7996
7997getCallMetadata(callback: AsyncCallback\<CallMetadata>): void
7998
7999Obtains the call metadata. This API uses an asynchronous callback to return the result.
8000
8001**System capability**: SystemCapability.Multimedia.AVSession.Core
8002
8003**Parameters**
8004
8005| Name  | Type                                     | Mandatory| Description                      |
8006| -------- | ----------------------------------------- | ---- | -------------------------- |
8007| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | Yes  | Callback used to return the metadata obtained.|
8008
8009**Error codes**
8010
8011For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8012
8013| ID| Error Message|
8014| -------- | ---------------------------------------- |
8015| 6600101  | Session service exception. |
8016| 6600102  | The session does not exist. |
8017| 6600103  | The session controller does not exist. |
8018
8019**Example**
8020
8021```ts
8022import { BusinessError } from '@kit.BasicServicesKit';
8023
8024avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
8025  if (err) {
8026    console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
8027  } else {
8028    console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
8029  }
8030});
8031```
8032
8033### getAVQueueTitleSync<sup>10+</sup>
8034
8035getAVQueueTitleSync(): string
8036
8037Obtains the name of the playlist of this session. This API returns the result synchronously.
8038
8039**Atomic service API**: This API can be used in atomic services since API version 12.
8040
8041**System capability**: SystemCapability.Multimedia.AVSession.Core
8042
8043**Return value**
8044
8045| Type            | Description                          |
8046| ---------------- | ----------------------------- |
8047| string | Playlist name.|
8048
8049**Error codes**
8050
8051For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8052
8053| ID| Error Message|
8054| -------- | ---------------------------------------- |
8055| 6600101  | Session service exception. |
8056| 6600102  | The session does not exist. |
8057| 6600103  | The session controller does not exist. |
8058
8059**Example**
8060
8061```ts
8062import { BusinessError } from '@kit.BasicServicesKit';
8063
8064try {
8065  let currentQueueTitle: string = avsessionController.getAVQueueTitleSync();
8066} catch (err) {
8067  let error = err as BusinessError;
8068  console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`);
8069}
8070```
8071
8072### getAVQueueItemsSync<sup>10+</sup>
8073
8074getAVQueueItemsSync(): Array\<AVQueueItem\>
8075
8076Obtains the information related to the items in the playlist of this session. This API returns the result synchronously.
8077
8078**Atomic service API**: This API can be used in atomic services since API version 12.
8079
8080**System capability**: SystemCapability.Multimedia.AVSession.Core
8081
8082**Return value**
8083
8084| Type                                         | Description                          |
8085| --------------------------------------------- | ----------------------------- |
8086| Array<[AVQueueItem](#avqueueitem10)\> | Items in the queue.|
8087
8088**Error codes**
8089
8090For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8091
8092| ID| Error Message|
8093| -------- | ---------------------------------------- |
8094| 6600101  | Session service exception. |
8095| 6600102  | The session does not exist. |
8096| 6600103  | The session controller does not exist. |
8097
8098**Example**
8099
8100```ts
8101import { BusinessError } from '@kit.BasicServicesKit';
8102
8103try {
8104  let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync();
8105} catch (err) {
8106  let error = err as BusinessError;
8107  console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`);
8108}
8109```
8110
8111### getOutputDeviceSync<sup>10+</sup>
8112
8113getOutputDeviceSync(): OutputDeviceInfo
8114
8115Obtains the output device information. This API returns the result synchronously.
8116
8117**Atomic service API**: This API can be used in atomic services since API version 12.
8118
8119**System capability**: SystemCapability.Multimedia.AVSession.Core
8120
8121**Return value**
8122
8123| Type                                           | Description                             |
8124| ----------------------------------------------- | --------------------------------- |
8125| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.|
8126
8127**Error codes**
8128
8129For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8130
8131| ID| Error Message|
8132| -------- | ---------------------------------------- |
8133| 6600101  | Session service exception. |
8134| 6600103  | The session controller does not exist. |
8135
8136**Example**
8137
8138```ts
8139import { BusinessError } from '@kit.BasicServicesKit';
8140
8141try {
8142  let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync();
8143} catch (err) {
8144  let error = err as BusinessError;
8145  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
8146}
8147```
8148
8149### isActiveSync<sup>10+</sup>
8150
8151isActiveSync(): boolean
8152
8153Checks whether the session is activated. This API returns the result synchronously.
8154
8155**Atomic service API**: This API can be used in atomic services since API version 12.
8156
8157**System capability**: SystemCapability.Multimedia.AVSession.Core
8158
8159**Return value**
8160
8161| Type             | Description                                                        |
8162| ----------------- | ------------------------------------------------------------ |
8163| boolean | Returns **true** is returned if the session is activated; returns **false** otherwise.|
8164
8165**Error codes**
8166
8167For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8168
8169| ID| Error Message|
8170| -------- | ---------------------------------------- |
8171| 6600101  | Session service exception. |
8172| 6600102  | The session does not exist. |
8173| 6600103  | The session controller does not exist. |
8174
8175**Example**
8176
8177```ts
8178import { BusinessError } from '@kit.BasicServicesKit';
8179
8180try {
8181  let isActive: boolean = avsessionController.isActiveSync();
8182} catch (err) {
8183  let error = err as BusinessError;
8184  console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`);
8185}
8186```
8187
8188### getValidCommandsSync<sup>10+</sup>
8189
8190getValidCommandsSync(): Array\<AVControlCommandType\>
8191
8192Obtains valid commands supported by the session. This API returns the result synchronously.
8193
8194**Atomic service API**: This API can be used in atomic services since API version 12.
8195
8196**System capability**: SystemCapability.Multimedia.AVSession.Core
8197
8198**Return value**
8199
8200| Type                                                        | Description                             |
8201| ------------------------------------------------------------ | --------------------------------- |
8202| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | A set of valid commands.|
8203
8204**Error codes**
8205
8206For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8207
8208| ID| Error Message|
8209| -------- | ---------------------------------------- |
8210| 6600101  | Session service exception. |
8211| 6600102  | The session does not exist. |
8212| 6600103  | The session controller does not exist. |
8213
8214**Example**
8215
8216```ts
8217import { BusinessError } from '@kit.BasicServicesKit';
8218
8219try {
8220  let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync();
8221} catch (err) {
8222  let error = err as BusinessError;
8223  console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`);
8224}
8225```
8226
8227## AVControlCommandType<sup>10+</sup>
8228
8229type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
8230  'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute'
8231
8232Enumerates the commands that can be sent to a session.
8233
8234You can use the union of the strings listed in the following table.
8235
8236**Atomic service API**: This API can be used in atomic services since API version 12.
8237
8238**System capability**: SystemCapability.Multimedia.AVSession.Core
8239
8240| Type            | Description        |
8241| ---------------- | ------------ |
8242| 'play'           | Play the media.        |
8243| 'pause'          | Pause the playback.        |
8244| 'stop'           | Stop the playback.        |
8245| 'playNext'       | Play the next media asset.      |
8246| 'playPrevious'   | Play the previous media asset.      |
8247| 'fastForward'    | Fast-forward.        |
8248| 'rewind'         | Rewind.        |
8249| 'seek'           | Seek to a playback position.|
8250| 'setSpeed'       | Set the playback speed.|
8251| 'setLoopMode'    | Set the loop mode.|
8252| 'toggleFavorite' | Favorite the media asset.    |
8253| 'playFromAssetId'| Play the media asset with the specified asset ID.|
8254|'answer'          | Answer a call.       |
8255| 'hangUp'         | The call is disconnecting.       |
8256|'toggleCallMute'  | Set the mute status for a call.|
8257
8258## AVControlCommand<sup>10+</sup>
8259
8260Describes the command that can be sent to the session.
8261
8262**Atomic service API**: This API can be used in atomic services since API version 12.
8263
8264**System capability**: SystemCapability.Multimedia.AVSession.Core
8265
8266| Name     | Type                                             | Mandatory| Description          |
8267| --------- | ------------------------------------------------- | ---- | -------------- |
8268| command   | [AVControlCommandType](#avcontrolcommandtype10)     | Yes  | Command.          |
8269| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | No  | Parameters carried in the command.|
8270
8271
8272## AVCastPickerOptions<sup>14+</sup>
8273
8274Describes the properties related to the semi-modal window that is started for casting purposes.
8275
8276**Atomic service API**: This API can be used in atomic services since API version 14.
8277
8278**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8279
8280| Name           | Type                     | Mandatory| Description                                                                 |
8281| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
8282| 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'**.           |
8283
8284## AVCastPickerHelper<sup>14+</sup>
8285
8286Implements 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.
8287
8288**Atomic service API**: This API can be used in atomic services since API version 14.
8289
8290**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8291
8292### constructor<sup>14+</sup>
8293
8294constructor(context: Context)
8295
8296Creates an **AVCastPickerHelper** instance. For details about how to obtain the context, see [getContext](../apis-arkui/js-apis-getContext.md).
8297
8298**Atomic service API**: This API can be used in atomic services since API version 14.
8299
8300**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8301
8302**Parameters**
8303
8304| Name   | Type                                                       | Mandatory| Description                                                        |
8305| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
8306| context  | Context | Yes  | Application context. (Only [UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md) is supported.)|
8307
8308**Example**
8309
8310```ts
8311import { common } from '@kit.AbilityKit';
8312import { avSession } from '@kit.AVSessionKit';
8313@Entry
8314@Component
8315struct Index {
8316  @State message: string = 'hello world';
8317
8318  build() {
8319    Row() {
8320      Column() {
8321        Text(this.message)
8322          .fontSize(40)
8323          .fontWeight(FontWeight.Bold)
8324          .onClick(()=>{
8325            let context = getContext(this) as common.Context;
8326            let avCastPicker = new avSession.AVCastPickerHelper(context);
8327          })
8328      }
8329      .width('100%')
8330    }
8331    .height('100%')
8332  }
8333}
8334```
8335
8336### select<sup>14+</sup>
8337
8338select(options?: AVCastPickerOptions): Promise\<void>
8339
8340Starts 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.
8341
8342**Atomic service API**: This API can be used in atomic services since API version 14.
8343
8344**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8345
8346**Parameters**
8347
8348| Name   | Type                                                       | Mandatory| Description                                                        |
8349| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
8350| options  | [AVCastPickerOptions](#avcastpickeroptions14) | No  | AVCastPicker selection options. If this parameter is not specified, the default value of **AVCastPickerOptions** is used.|
8351
8352**Return value**
8353
8354| Type          | Description                         |
8355| -------------- | ----------------------------- |
8356| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
8357
8358**Error codes**
8359
8360For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8361
8362| ID| Error Message|
8363| -------- | ---------------------------------------- |
8364| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8365
8366**Example**
8367
8368```ts
8369import { common } from '@kit.AbilityKit';
8370import { BusinessError } from '@kit.BasicServicesKit';
8371
8372async function avCastPicker(context: common.Context) {
8373  let avCastPickerOptions : avSession.AVCastPickerOptions = {
8374    sessionType : 'video',
8375  }
8376  let avCastPicker = new avSession.AVCastPickerHelper(context);
8377  avCastPicker.select(avCastPickerOptions).then(() => {
8378    console.info('select successfully');
8379  }).catch((err: BusinessError) => {
8380    console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`);
8381  });
8382}
8383```
8384### on('pickerStateChange')<sup>14+</sup>
8385
8386on(type: 'pickerStateChange', callback: Callback<AVCastPickerState\>) : void
8387
8388Subscribes to semi-modal window change events.
8389
8390**Atomic service API**: This API can be used in atomic services since API version 14.
8391
8392**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8393
8394**Parameters**
8395
8396| Name  | Type      | Mandatory| Description     |
8397| --------| -----------|-----|------------|
8398| type     | string    | Yes  | Event type. The event **'pickerStateChange'** is triggered when the semi-modal window changes.|
8399| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)>       | Yes  | Callback function, where the **state** parameter indicates the new state of the semi-modal window.|
8400
8401**Error codes**
8402
8403For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8404
8405| ID| Error Message|
8406| -------- | ---------------------------------------- |
8407| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8408
8409**Example**
8410
8411```ts
8412import { common } from '@kit.AbilityKit';
8413import { AVCastPickerState } from '@kit.AVSessionKit';
8414
8415async function onPickerStateChange(context: common.Context) {
8416  let avCastPicker = new avSession.AVCastPickerHelper(context);
8417  avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => {
8418    console.info(`picker state change : ${state}`);
8419  });
8420}
8421```
8422
8423### off('pickerStateChange')<sup>14+</sup>
8424
8425off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState\>) : void
8426
8427Unsubscribes from semi-modal window change events. After the unsubscription, the event callback is not triggered.
8428
8429**Atomic service API**: This API can be used in atomic services since API version 14.
8430
8431**System capability**: SystemCapability.Multimedia.AVSession.AVCast
8432
8433**Parameters**
8434
8435| Name  | Type                                              | Mandatory| Description                                                   |
8436| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
8437| type     | string                                           | Yes  | Event type, which is **'pickerStateChange'** in this case.        |
8438| 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.                          |
8439
8440**Error codes**
8441
8442For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
8443
8444| ID| Error Message|
8445| -------- | ---------------------------------------- |
8446| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8447
8448**Example**
8449
8450```ts
8451import { common } from '@kit.AbilityKit';
8452
8453async function onPickerStateChange(context: common.Context) {
8454  let avCastPicker = new avSession.AVCastPickerHelper(context);
8455  avCastPicker.off('pickerStateChange');
8456}
8457```
8458
8459## AVSessionErrorCode<sup>10+</sup>
8460
8461Enumerates the error codes used in the media session.
8462
8463| Name                                  | Value     | Description                            |
8464| -------------------------------------- | ------- | ------------------------------- |
8465| 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|
8466| 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|
8467| 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|
8468| 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|
8469| 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|
8470| 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|
8471| 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|
8472| 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|
8473| 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|
8474| 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|
8475| 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|
8476| 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|
8477| 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|
8478| 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|
8479| 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|
8480| 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|
8481| 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|
8482| 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|
8483| 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|
8484| 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|
8485| 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|
8486| 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|
8487| 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|
8488| 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|
8489| 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|
8490| 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|
8491| 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|
8492| 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|
8493| 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|
8494| 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|
8495| 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|
8496| 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|
8497| 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|
8498| 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|
8499| 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|
8500| 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|
8501| 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|
8502| 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|
8503| 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|
8504| 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|
8505| 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|
8506| 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|
8507| 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|
8508| 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|
8509| 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|
8510| 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|
8511| 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|
8512| 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|
8513| 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|
8514| 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|
8515| 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|
8516| 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|
8517| 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|
8518| 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|
8519| 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|
8520| 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|
8521| 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|
8522| 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|
8523| 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|
8524| 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|
8525| 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|
8526| 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|
8527| 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|
8528| 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|
8529
8530## SkipIntervals<sup>11+</sup>
8531
8532Enumerates the fast-forward or rewind intervals supported by the media session.
8533
8534**System capability**: SystemCapability.Multimedia.AVSession.Core
8535
8536| Name                  | Value| Description                    |
8537| ---------------------- | -- | ----------------------- |
8538| SECONDS_10             | 10 | The time is 10 seconds.            |
8539| SECONDS_15             | 15 | The time is 15 seconds.            |
8540| SECONDS_30             | 30 | The time is 30 seconds.            |
8541