• 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## AVSessionType<sup>10+<sup>
135
136type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'
137
138Enumerates the session types supported by the session.
139
140You can use the strings listed in the following table.
141
142**Atomic service API**: This API can be used in atomic services since API version 12.
143
144**System capability**: SystemCapability.Multimedia.AVSession.Core
145
146| Type | Description|
147| -----  | ---- |
148| 'audio' | Audio session.|
149| 'video' | Video session.|
150| 'voice_call'<sup>11+<sup> | Voice call.|
151| 'video_call'<sup>12+<sup> | Video call.|
152
153## AVSession<sup>10+</sup>
154
155An **AVSession** object is created by calling [avSession.createAVSession](#avsessioncreateavsession10). The object enables you to obtain the session ID and set the metadata and playback state.
156
157### Attributes
158
159**Atomic service API**: This API can be used in atomic services since API version 12.
160
161**System capability**: SystemCapability.Multimedia.AVSession.Core
162
163| Name     | Type  | Readable| Writable| Description                         |
164| :-------- | :----- | :--- | :--- | :---------------------------- |
165| sessionId | string | Yes  | No  | Unique session ID of the **AVSession** object.|
166| sessionType| [AVSessionType](#avsessiontype10) | Yes  | No  | AVSession type.|
167
168**Example**
169
170```ts
171let sessionId: string = currentAVSession.sessionId;
172let sessionType: avSession.AVSessionType = currentAVSession.sessionType;
173```
174
175### setAVMetadata<sup>10+</sup>
176
177setAVMetadata(data: AVMetadata): Promise\<void>
178
179Sets session metadata. This API uses a promise to return the result.
180
181**Atomic service API**: This API can be used in atomic services since API version 12.
182
183**System capability**: SystemCapability.Multimedia.AVSession.Core
184
185**Parameters**
186
187| Name| Type                     | Mandatory| Description        |
188| ------ | ------------------------- | ---- | ------------ |
189| data   | [AVMetadata](#avmetadata10) | Yes  | Session metadata.|
190
191**Return value**
192
193| Type          | Description                         |
194| -------------- | ----------------------------- |
195| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
196
197**Error codes**
198
199For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
200
201| ID| Error Message|
202| -------- | ---------------------------------------- |
203| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
204| 6600101  | Session service exception. |
205| 6600102  | The session does not exist. |
206
207**Example**
208
209```ts
210import { BusinessError } from '@kit.BasicServicesKit';
211
212let metadata: avSession.AVMetadata = {
213  assetId: "121278",
214  title: "lose yourself",
215  artist: "Eminem",
216  author: "ST",
217  album: "Slim shady",
218  writer: "ST",
219  composer: "ST",
220  duration: 2222,
221  mediaImage: "https://www.example.com/example.jpg",
222  subtitle: "8 Mile",
223  description: "Rap",
224  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
225  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
226  lyric: "Lyrics in LRC format",
227  previousAssetId: "121277",
228  nextAssetId: "121279"
229};
230currentAVSession.setAVMetadata(metadata).then(() => {
231  console.info('SetAVMetadata successfully');
232}).catch((err: BusinessError) => {
233  console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
234});
235```
236
237### setAVMetadata<sup>10+</sup>
238
239setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
240
241Sets session metadata. This API uses an asynchronous callback to return the result.
242
243**System capability**: SystemCapability.Multimedia.AVSession.Core
244
245**Parameters**
246
247| Name  | Type                     | Mandatory| Description                                 |
248| -------- | ------------------------- | ---- | ------------------------------------- |
249| data     | [AVMetadata](#avmetadata10) | Yes  | Session metadata.                         |
250| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
251
252**Error codes**
253
254For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
255
256| ID| Error Message|
257| -------- | ---------------------------------------- |
258| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
259| 6600101  | Session service exception. |
260| 6600102  | The session does not exist. |
261
262**Example**
263
264```ts
265import { BusinessError } from '@kit.BasicServicesKit';
266
267let metadata: avSession.AVMetadata = {
268  assetId: "121278",
269  title: "lose yourself",
270  artist: "Eminem",
271  author: "ST",
272  album: "Slim shady",
273  writer: "ST",
274  composer: "ST",
275  duration: 2222,
276  mediaImage: "https://www.example.com/example.jpg",
277  subtitle: "8 Mile",
278  description: "Rap",
279  // The LRC contains two types of elements: time tag + lyrics, and ID tag.
280  // Example: [00:25.44]xxx\r\n[00:26.44]xxx\r\n
281  lyric: "Lyrics in LRC format",
282  previousAssetId: "121277",
283  nextAssetId: "121279"
284};
285currentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
286  if (err) {
287    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
288  } else {
289    console.info('SetAVMetadata successfully');
290  }
291});
292```
293
294### setCallMetadata<sup>11+</sup>
295
296setCallMetadata(data: CallMetadata): Promise\<void>
297
298Sets call metadata. This API uses a promise to return the result.
299
300**System capability**: SystemCapability.Multimedia.AVSession.Core
301
302**Parameters**
303
304| Name| Type                     | Mandatory| Description        |
305| ------ | ------------------------- | ---- | ------------ |
306| data   | [CallMetadata](#callmetadata11) | Yes  | Call metadata.|
307
308**Return value**
309
310| Type          | Description                         |
311| -------------- | ----------------------------- |
312| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
313
314**Error codes**
315
316For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
317
318| ID| Error Message|
319| -------- | ---------------------------------------- |
320| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
321| 6600101  | Session service exception. |
322| 6600102  | The session does not exist. |
323
324**Example**
325
326```ts
327import { image } from '@kit.ImageKit';
328import { resourceManager } from '@kit.LocalizationKit';
329import { BusinessError } from '@kit.BasicServicesKit';
330
331let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
332    let imageSource = await image.createImageSource(value.buffer);
333    let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
334    let calldata: avSession.CallMetadata = {
335      name: "xiaoming",
336      phoneNumber: "111xxxxxxxx",
337      avatar: imagePixel
338    };
339currentAVSession.setCallMetadata(calldata).then(() => {
340  console.info('setCallMetadata successfully');
341}).catch((err: BusinessError) => {
342  console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
343});
344```
345
346### setCallMetadata<sup>11+</sup>
347
348setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void
349
350Sets call metadata. This API uses an asynchronous callback to return the result.
351
352**System capability**: SystemCapability.Multimedia.AVSession.Core
353
354**Parameters**
355
356| Name  | Type                     | Mandatory| Description                                 |
357| -------- | ------------------------- | ---- | ------------------------------------- |
358| data     | [CallMetadata](#callmetadata11) | Yes  | Call metadata.                         |
359| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
360
361**Error codes**
362
363For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
364
365| ID| Error Message|
366| -------- | ---------------------------------------- |
367| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
368| 6600101  | Session service exception. |
369| 6600102  | The session does not exist. |
370
371**Example**
372
373```ts
374import { image } from '@kit.ImageKit';
375import { resourceManager } from '@kit.LocalizationKit';
376import { BusinessError } from '@kit.BasicServicesKit';
377
378async function setCallMetadata() {
379  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
380  let imageSource = await image.createImageSource(value.buffer);
381  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
382  let calldata: avSession.CallMetadata = {
383    name: "xiaoming",
384    phoneNumber: "111xxxxxxxx",
385    avatar: imagePixel
386  };
387  currentAVSession.setCallMetadata(calldata, (err: BusinessError) => {
388    if (err) {
389      console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
390    } else {
391      console.info('setCallMetadata successfully');
392    }
393  });
394}
395```
396
397### setAVCallState<sup>11+</sup>
398
399setAVCallState(state: AVCallState): Promise\<void>
400
401Sets the call state. This API uses a promise to return the result.
402
403**System capability**: SystemCapability.Multimedia.AVSession.Core
404
405**Parameters**
406
407| Name| Type                     | Mandatory| Description        |
408| ------ | ------------------------- | ---- | ------------ |
409| state   | [AVCallState](#avcallstate11) | Yes  | Call state.|
410
411**Return value**
412
413| Type          | Description                         |
414| -------------- | ----------------------------- |
415| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
416
417**Error codes**
418
419For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
420
421| ID| Error Message|
422| -------- | ---------------------------------------- |
423| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
424| 6600101  | Session service exception. |
425| 6600102  | The session does not exist. |
426
427**Example**
428
429```ts
430import { BusinessError } from '@kit.BasicServicesKit';
431
432let calldata: avSession.AVCallState = {
433  state: avSession.CallState.CALL_STATE_ACTIVE,
434  muted: false
435};
436currentAVSession.setAVCallState(calldata).then(() => {
437  console.info('setAVCallState successfully');
438}).catch((err: BusinessError) => {
439  console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
440});
441```
442
443### setAVCallState<sup>11+</sup>
444
445setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void
446
447Sets the call state. This API uses an asynchronous callback to return the result.
448
449**System capability**: SystemCapability.Multimedia.AVSession.Core
450
451**Parameters**
452
453| Name  | Type                     | Mandatory| Description                                 |
454| -------- | ------------------------- | ---- | ------------------------------------- |
455| state     | [AVCallState](#avcallstate11) | Yes  | Call state.                         |
456| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
457
458**Error codes**
459
460For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
461
462| ID| Error Message|
463| -------- | ---------------------------------------- |
464| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
465| 6600101  | Session service exception. |
466| 6600102  | The session does not exist. |
467
468**Example**
469
470```ts
471import { BusinessError } from '@kit.BasicServicesKit';
472
473let avcalldata: avSession.AVCallState = {
474  state: avSession.CallState.CALL_STATE_ACTIVE,
475  muted: false
476};
477currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => {
478  if (err) {
479    console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
480  } else {
481    console.info('setAVCallState successfully');
482  }
483});
484```
485
486### setAVPlaybackState<sup>10+</sup>
487
488setAVPlaybackState(state: AVPlaybackState): Promise\<void>
489
490Sets information related to the session playback state. This API uses a promise to return the result.
491
492**Atomic service API**: This API can be used in atomic services since API version 12.
493
494**System capability**: SystemCapability.Multimedia.AVSession.Core
495
496**Parameters**
497
498| Name| Type                               | Mandatory| Description                                          |
499| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
500| state   | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
501
502**Return value**
503
504| Type          | Description                         |
505| -------------- | ----------------------------- |
506| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
507
508**Error codes**
509
510For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
511
512| ID| Error Message|
513| -------- | ---------------------------------------- |
514| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
515| 6600101  | Session service exception. |
516| 6600102  | The session does not exist. |
517
518**Example**
519
520```ts
521import { BusinessError } from '@kit.BasicServicesKit';
522
523let playbackState: avSession.AVPlaybackState = {
524  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
525  speed: 1.0,
526  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
527  bufferedTime:1000,
528  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
529  isFavorite:true
530};
531currentAVSession.setAVPlaybackState(playbackState).then(() => {
532  console.info('SetAVPlaybackState successfully');
533}).catch((err: BusinessError) => {
534  console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
535});
536```
537
538### setAVPlaybackState<sup>10+</sup>
539
540setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
541
542Sets information related to the session playback state. This API uses an asynchronous callback to return the result.
543
544**System capability**: SystemCapability.Multimedia.AVSession.Core
545
546**Parameters**
547
548| Name  | Type                               | Mandatory| Description                                          |
549| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
550| state     | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
551| callback | AsyncCallback\<void>                | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
552
553**Error codes**
554
555For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
556
557| ID| Error Message|
558| -------- | ---------------------------------------- |
559| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
560| 6600101  | Session service exception. |
561| 6600102  | The session does not exist. |
562
563**Example**
564
565```ts
566import { BusinessError } from '@kit.BasicServicesKit';
567
568let PlaybackState: avSession.AVPlaybackState = {
569  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
570  speed: 1.0,
571  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
572  bufferedTime:1000,
573  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
574  isFavorite:true
575};
576currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
577  if (err) {
578    console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
579  } else {
580    console.info('SetAVPlaybackState successfully');
581  }
582});
583```
584
585### setLaunchAbility<sup>10+</sup>
586
587setLaunchAbility(ability: WantAgent): Promise\<void>
588
589Sets a launcher ability. This API uses a promise to return the result.
590
591**Atomic service API**: This API can be used in atomic services since API version 12.
592
593**System capability**: SystemCapability.Multimedia.AVSession.Core
594
595**Parameters**
596
597| Name | Type                                         | Mandatory| Description                                                       |
598| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
599| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID.|
600
601**Return value**
602
603| Type          | Description                         |
604| -------------- | ----------------------------- |
605| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
606
607**Error codes**
608
609For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
610
611| ID| Error Message|
612| -------- | ---------------------------------------- |
613| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
614| 6600101  | Session service exception. |
615| 6600102  | The session does not exist. |
616
617**Example**
618
619```ts
620import { wantAgent } from '@kit.AbilityKit';
621import { BusinessError } from '@kit.BasicServicesKit';
622
623// WantAgentInfo object.
624let wantAgentInfo: wantAgent.WantAgentInfo = {
625  wants: [
626    {
627      deviceId: "deviceId",
628      bundleName: "com.example.myapplication",
629      abilityName: "EntryAbility",
630      action: "action1",
631      entities: ["entity1"],
632      type: "MIMETYPE",
633      uri: "key = {true,true,false}",
634      parameters:
635        {
636          mykey0: 2222,
637          mykey1: [1, 2, 3],
638          mykey2: "[1, 2, 3]",
639          mykey3: "ssssssssssssssssssssssssss",
640          mykey4: [false, true, false],
641          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
642          mykey6: true
643        }
644    }
645  ],
646  operationType: wantAgent.OperationType.START_ABILITIES,
647  requestCode: 0,
648  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
649}
650
651wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
652  currentAVSession.setLaunchAbility(agent).then(() => {
653    console.info('SetLaunchAbility successfully');
654  }).catch((err: BusinessError) => {
655    console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
656  });
657});
658```
659
660### setLaunchAbility<sup>10+</sup>
661
662setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
663
664Sets a launcher ability. This API uses an asynchronous callback to return the result.
665
666**System capability**: SystemCapability.Multimedia.AVSession.Core
667
668**Parameters**
669
670| Name  | Type                                         | Mandatory| Description                                                        |
671| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
672| ability  | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID. |
673| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
674
675**Error codes**
676
677For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
678
679| ID| Error Message|
680| -------- | ---------------------------------------- |
681| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
682| 6600101  | Session service exception. |
683| 6600102  | The session does not exist. |
684
685**Example**
686
687```ts
688import { wantAgent } from '@kit.AbilityKit';
689import { BusinessError } from '@kit.BasicServicesKit';
690
691// WantAgentInfo object.
692let wantAgentInfo: wantAgent.WantAgentInfo = {
693  wants: [
694    {
695      deviceId: "deviceId",
696      bundleName: "com.example.myapplication",
697      abilityName: "EntryAbility",
698      action: "action1",
699      entities: ["entity1"],
700      type: "MIMETYPE",
701      uri: "key = {true,true,false}",
702      parameters:
703        {
704          mykey0: 2222,
705          mykey1: [1, 2, 3],
706          mykey2: "[1, 2, 3]",
707          mykey3: "ssssssssssssssssssssssssss",
708          mykey4: [false, true, false],
709          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
710          mykey6: true
711        }
712    }
713  ],
714  operationType: wantAgent.OperationType.START_ABILITIES,
715  requestCode: 0,
716  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
717}
718
719wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
720  currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
721    if (err) {
722      console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
723    } else {
724      console.info('SetLaunchAbility successfully');
725    }
726  });
727});
728```
729
730### dispatchSessionEvent<sup>10+</sup>
731
732dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void>
733
734Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses a promise to return the result. It is called by the provider.
735
736**Atomic service API**: This API can be used in atomic services since API version 12.
737
738**System capability**: SystemCapability.Multimedia.AVSession.Core
739
740**Parameters**
741
742| Name | Type                                         | Mandatory| Description                                                       |
743| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
744| event | string | Yes  | Name of the session event.|
745| args | {[key: string]: Object} | Yes  | Content of the session event.|
746
747> **NOTE**
748> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
749
750**Return value**
751
752| Type          | Description                         |
753| -------------- | ----------------------------- |
754| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
755
756**Error codes**
757
758For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
759
760| ID| Error Message|
761| -------- | ---------------------------------------- |
762| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
763| 6600101  | Session service exception. |
764| 6600102  | The session does not exist. |
765
766**Example**
767
768```ts
769import { BusinessError } from '@kit.BasicServicesKit';
770
771let currentAVSession: avSession.AVSession | undefined = undefined;
772let tag = "createNewSession";
773let context: Context = getContext(this);
774
775avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
776  if (err) {
777    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
778  } else {
779    currentAVSession = data;
780  }
781});
782let eventName = "dynamic_lyric";
783if (currentAVSession !== undefined) {
784  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
785    console.info('dispatchSessionEvent successfully');
786  }).catch((err: BusinessError) => {
787    console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
788  })
789}
790```
791
792### dispatchSessionEvent<sup>10+</sup>
793
794dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
795
796Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses an asynchronous callback to return the result. It is called by the provider.
797
798**System capability**: SystemCapability.Multimedia.AVSession.Core
799
800**Parameters**
801
802| Name | Type                                         | Mandatory| Description                                                       |
803| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
804| event | string | Yes  | Name of the session event.|
805| args | {[key: string]: Object} | Yes  | Content of the session event.|
806| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
807
808> **NOTE**
809
810> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
811
812**Error codes**
813
814For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
815
816| ID| Error Message|
817| -------- | ---------------------------------------- |
818| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
819| 6600101  | Session service exception. |
820| 6600102  | The session does not exist. |
821
822**Example**
823
824```ts
825import { BusinessError } from '@kit.BasicServicesKit';
826
827let currentAVSession: avSession.AVSession | undefined = undefined;
828let tag = "createNewSession";
829let context: Context = getContext(this);
830
831avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
832  if (err) {
833    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
834  } else {
835    currentAVSession = data;
836  }
837});
838let eventName: string = "dynamic_lyric";
839if (currentAVSession !== undefined) {
840  (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
841    if (err) {
842      console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
843    }
844  })
845}
846```
847
848### setAVQueueItems<sup>10+</sup>
849
850setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>
851
852Sets a playlist. This API uses a promise to return the result.
853
854**Atomic service API**: This API can be used in atomic services since API version 12.
855
856**System capability**: SystemCapability.Multimedia.AVSession.Core
857
858**Parameters**
859
860| Name | Type                                | Mandatory| Description                              |
861| ------ | ------------------------------------ | ---- | ---------------------------------- |
862| items  | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.|
863
864**Return value**
865
866| Type          | Description                         |
867| -------------- | ----------------------------- |
868| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
869
870**Error codes**
871
872For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
873
874| ID| Error Message|
875| -------- | ---------------------------------------- |
876| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
877| 6600101  | Session service exception. |
878| 6600102  | The session does not exist. |
879
880**Example**
881
882```ts
883import { image } from '@kit.ImageKit';
884import { resourceManager } from '@kit.LocalizationKit';
885import { BusinessError } from '@kit.BasicServicesKit';
886
887async function setAVQueueItems() {
888  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
889  let imageSource = await image.createImageSource(value.buffer);
890  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
891  let queueItemDescription_1: avSession.AVMediaDescription = {
892    assetId: '001',
893    title: 'music_name',
894    subtitle: 'music_sub_name',
895    description: 'music_description',
896    mediaImage : imagePixel,
897    extras: {extras:'any'}
898  };
899  let queueItem_1: avSession.AVQueueItem = {
900    itemId: 1,
901    description: queueItemDescription_1
902  };
903  let queueItemDescription_2: avSession.AVMediaDescription = {
904    assetId: '002',
905    title: 'music_name',
906    subtitle: 'music_sub_name',
907    description: 'music_description',
908    mediaImage: imagePixel,
909    extras: {extras:'any'}
910  };
911  let queueItem_2: avSession.AVQueueItem = {
912    itemId: 2,
913    description: queueItemDescription_2
914  };
915  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
916  currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
917    console.info('SetAVQueueItems successfully');
918  }).catch((err: BusinessError) => {
919    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
920  });
921}
922```
923
924### setAVQueueItems<sup>10+</sup>
925
926setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void
927
928Sets a playlist. This API uses an asynchronous callback to return the result.
929
930**System capability**: SystemCapability.Multimedia.AVSession.Core
931
932**Parameters**
933
934| Name  | Type                                 | Mandatory| Description                                                        |
935| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- |
936| items    | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.                         |
937| callback | AsyncCallback\<void>                 | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
938
939**Error codes**
940
941For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
942
943| ID| Error Message|
944| -------- | ---------------------------------------- |
945| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
946| 6600101  | Session service exception. |
947| 6600102  | The session does not exist. |
948
949**Example**
950
951```ts
952import { image } from '@kit.ImageKit';
953import { resourceManager } from '@kit.LocalizationKit';
954import { BusinessError } from '@kit.BasicServicesKit';
955
956async function setAVQueueItems() {
957  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
958  let imageSource = await image.createImageSource(value.buffer);
959  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
960  let queueItemDescription_1: avSession.AVMediaDescription = {
961    assetId: '001',
962    title: 'music_name',
963    subtitle: 'music_sub_name',
964    description: 'music_description',
965    mediaImage : imagePixel,
966    extras: {extras:'any'}
967  };
968  let queueItem_1: avSession.AVQueueItem = {
969    itemId: 1,
970    description: queueItemDescription_1
971  };
972  let queueItemDescription_2: avSession.AVMediaDescription = {
973    assetId: '002',
974    title: 'music_name',
975    subtitle: 'music_sub_name',
976    description: 'music_description',
977    mediaImage: imagePixel,
978    extras: {extras:'any'}
979  };
980  let queueItem_2: avSession.AVQueueItem = {
981    itemId: 2,
982    description: queueItemDescription_2
983  };
984  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
985  currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
986    if (err) {
987      console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
988    } else {
989      console.info('SetAVQueueItems successfully');
990    }
991  });
992}
993```
994
995### setAVQueueTitle<sup>10+</sup>
996
997setAVQueueTitle(title: string): Promise\<void>
998
999Sets a name for the playlist. This API uses a promise to return the result.
1000
1001**Atomic service API**: This API can be used in atomic services since API version 12.
1002
1003**System capability**: SystemCapability.Multimedia.AVSession.Core
1004
1005**Parameters**
1006
1007| Name | Type  | Mandatory| Description          |
1008| ------ | ------ | ---- | -------------- |
1009| title  | string | Yes  | Name of the playlist.|
1010
1011**Return value**
1012
1013| Type          | Description                         |
1014| -------------- | ----------------------------- |
1015| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1016
1017**Error codes**
1018
1019For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1020
1021| ID| Error Message|
1022| -------- | ---------------------------------------- |
1023| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1024| 6600101  | Session service exception. |
1025| 6600102  | The session does not exist. |
1026
1027**Example**
1028
1029```ts
1030import { BusinessError } from '@kit.BasicServicesKit';
1031
1032let queueTitle = 'QUEUE_TITLE';
1033currentAVSession.setAVQueueTitle(queueTitle).then(() => {
1034  console.info('SetAVQueueTitle successfully');
1035}).catch((err: BusinessError) => {
1036  console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1037});
1038```
1039
1040### setAVQueueTitle<sup>10+</sup>
1041
1042setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void
1043
1044Sets a name for the playlist. This API uses an asynchronous callback to return the result.
1045
1046**System capability**: SystemCapability.Multimedia.AVSession.Core
1047
1048**Parameters**
1049
1050| Name  | Type                                 | Mandatory| Description                                                        |
1051| -------- | --------------------- | ---- | ----------------------------------------------------------- |
1052| title    | string                | Yes  | Name of the playlist.                         |
1053| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1054
1055**Error codes**
1056
1057For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1058
1059| ID| Error Message|
1060| -------- | ---------------------------------------- |
1061| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1062| 6600101  | Session service exception. |
1063| 6600102  | The session does not exist. |
1064
1065**Example**
1066
1067```ts
1068import { BusinessError } from '@kit.BasicServicesKit';
1069
1070let queueTitle = 'QUEUE_TITLE';
1071currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
1072  if (err) {
1073    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1074  } else {
1075    console.info('SetAVQueueTitle successfully');
1076  }
1077});
1078```
1079
1080### setExtras<sup>10+</sup>
1081
1082setExtras(extras: {[key: string]: Object}): Promise\<void>
1083
1084Sets a custom media packet in the form of key-value pairs. This API uses a promise to return the result. It is called by the provider.
1085
1086**Atomic service API**: This API can be used in atomic services since API version 12.
1087
1088**System capability**: SystemCapability.Multimedia.AVSession.Core
1089
1090**Parameters**
1091
1092| Name | Type                                         | Mandatory| Description                                                       |
1093| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1094| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1095
1096> **NOTE**
1097
1098> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
1099
1100**Return value**
1101
1102| Type          | Description                         |
1103| -------------- | ----------------------------- |
1104| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1105
1106**Error codes**
1107
1108For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1109
1110| ID| Error Message|
1111| -------- | ---------------------------------------- |
1112| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1113| 6600101  | Session service exception. |
1114| 6600102  | The session does not exist. |
1115
1116**Example**
1117
1118```ts
1119import { BusinessError } from '@kit.BasicServicesKit';
1120
1121let currentAVSession: avSession.AVSession | undefined = undefined;
1122let tag = "createNewSession";
1123let context: Context = getContext(this);
1124
1125avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1126  if (err) {
1127    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1128  } else {
1129    currentAVSession = data;
1130  }
1131});
1132if (currentAVSession !== undefined) {
1133  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => {
1134    console.info('setExtras successfully');
1135  }).catch((err: BusinessError) => {
1136    console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1137  })
1138}
1139```
1140
1141### setExtras<sup>10+</sup>
1142
1143setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void
1144
1145Sets a custom media packet in the form of key-value pairs. This API uses an asynchronous callback to return the result. It is called by the provider.
1146
1147**System capability**: SystemCapability.Multimedia.AVSession.Core
1148
1149**Parameters**
1150
1151| Name | Type                                         | Mandatory| Description                                                       |
1152| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1153| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|
1154| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1155
1156> **NOTE**
1157
1158> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md).
1159
1160**Error codes**
1161
1162For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1163
1164| ID| Error Message|
1165| -------- | ---------------------------------------- |
1166| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1167| 6600101  | Session service exception. |
1168| 6600102  | The session does not exist. |
1169
1170**Example**
1171
1172```ts
1173import { BusinessError } from '@kit.BasicServicesKit';
1174
1175let currentAVSession: avSession.AVSession | undefined = undefined;
1176let tag = "createNewSession";
1177let context: Context = getContext(this);
1178
1179avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1180  if (err) {
1181    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1182  } else {
1183    currentAVSession = data;
1184  }
1185});
1186if (currentAVSession !== undefined) {
1187  (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => {
1188    if (err) {
1189      console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1190    }
1191  })
1192}
1193```
1194
1195### getController<sup>10+</sup>
1196
1197getController(): Promise\<AVSessionController>
1198
1199Obtains the controller corresponding to this session. This API uses a promise to return the result.
1200
1201**Atomic service API**: This API can be used in atomic services since API version 12.
1202
1203**System capability**: SystemCapability.Multimedia.AVSession.Core
1204
1205**Return value**
1206
1207| Type                                                | Description                         |
1208| ---------------------------------------------------- | ----------------------------- |
1209| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.|
1210
1211**Error codes**
1212
1213For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1214
1215| ID| Error Message|
1216| -------- | ---------------------------------------- |
1217| 6600101  | Session service exception. |
1218| 6600102  | The session does not exist. |
1219
1220**Example**
1221
1222```ts
1223import { BusinessError } from '@kit.BasicServicesKit';
1224
1225let avsessionController: avSession.AVSessionController;
1226currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
1227  avsessionController = avcontroller;
1228  console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1229}).catch((err: BusinessError) => {
1230  console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1231});
1232```
1233
1234### getController<sup>10+</sup>
1235
1236getController(callback: AsyncCallback\<AVSessionController>): void
1237
1238Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result.
1239
1240**System capability**: SystemCapability.Multimedia.AVSession.Core
1241
1242**Parameters**
1243
1244| Name  | Type                                                       | Mandatory| Description                      |
1245| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
1246| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes  | Callback used to return the session controller.|
1247
1248**Error codes**
1249
1250For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1251
1252| ID| Error Message|
1253| -------- | ---------------------------------------- |
1254| 6600101  | Session service exception. |
1255| 6600102  | The session does not exist. |
1256
1257**Example**
1258
1259```ts
1260import { BusinessError } from '@kit.BasicServicesKit';
1261
1262let avsessionController: avSession.AVSessionController;
1263currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
1264  if (err) {
1265    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1266  } else {
1267    avsessionController = avcontroller;
1268    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1269  }
1270});
1271```
1272
1273### getAVCastController<sup>10+</sup>
1274
1275getAVCastController(): Promise\<AVCastController>
1276
1277Obtains the cast controller when a casting connection is set up. This API uses a promise to return the result. If the session is not in the cast state, the controller returns **null**.
1278
1279**Atomic service API**: This API can be used in atomic services since API version 12.
1280
1281**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1282
1283**Return value**
1284
1285| Type                                                       | Description                                                        |
1286| --------- | ------------------------------------------------------------ |
1287| Promise<[AVCastController](#avcastcontroller10)\>  | Promise used to return the cast controller.|
1288
1289**Error codes**
1290
1291For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1292
1293| ID| Error Message|
1294| -------- | --------------------------------------- |
1295| 6600102| The session does not exist.           |
1296| 6600109| The remote connection is not established. |
1297
1298**Example**
1299
1300```ts
1301import { BusinessError } from '@kit.BasicServicesKit';
1302
1303let aVCastController: avSession.AVCastController;
1304currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
1305  aVCastController = avcontroller;
1306  console.info('getAVCastController : SUCCESS');
1307}).catch((err: BusinessError) => {
1308  console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1309});
1310```
1311
1312### getAVCastController<sup>10+</sup>
1313
1314getAVCastController(callback: AsyncCallback\<AVCastController>): void
1315
1316Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result. If the session is not in the cast state, the controller returns **null**.
1317
1318**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1319
1320**Parameters**
1321
1322| Name   | Type                                                       | Mandatory| Description                                                        |
1323| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1324| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes  | Callback used to return the cast controller.|
1325
1326**Error codes**
1327
1328For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1329
1330| ID| Error Message                                 |
1331| -------- |---------------------------------------|
1332| 6600102| The session does not exist.           |
1333| 6600109| The remote connection is not established. |
1334
1335**Example**
1336
1337```ts
1338import { BusinessError } from '@kit.BasicServicesKit';
1339
1340let aVCastController: avSession.AVCastController;
1341currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
1342  if (err) {
1343    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1344  } else {
1345    aVCastController = avcontroller;
1346    console.info('getAVCastController : SUCCESS');
1347  }
1348});
1349```
1350
1351### getOutputDevice<sup>10+</sup>
1352
1353getOutputDevice(): Promise\<OutputDeviceInfo>
1354
1355Obtains information about the output device for this session. This API uses a promise to return the result.
1356
1357**Atomic service API**: This API can be used in atomic services since API version 12.
1358
1359**System capability**: SystemCapability.Multimedia.AVSession.Core
1360
1361**Return value**
1362
1363| Type                                          | Description                             |
1364| ---------------------------------------------- | --------------------------------- |
1365| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.|
1366
1367**Error codes**
1368
1369For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1370
1371| ID| Error Message|
1372| -------- | ---------------------------------------- |
1373| 6600101  | Session service exception. |
1374| 6600102  | The session does not exist. |
1375
1376**Example**
1377
1378```ts
1379import { BusinessError } from '@kit.BasicServicesKit';
1380
1381currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
1382  console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1383}).catch((err: BusinessError) => {
1384  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1385})
1386```
1387
1388### getOutputDevice<sup>10+</sup>
1389
1390getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
1391
1392Obtains information about the output device for this session. This API uses an asynchronous callback to return the result.
1393
1394**System capability**: SystemCapability.Multimedia.AVSession.Core
1395
1396**Parameters**
1397
1398| Name  | Type                                                 | Mandatory| Description                          |
1399| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1400| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
1401
1402**Error codes**
1403
1404For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1405
1406| ID| Error Message|
1407| -------- | ---------------------------------------- |
1408| 6600101  | Session service exception. |
1409| 6600102  | The session does not exist. |
1410
1411**Example**
1412
1413```ts
1414import { BusinessError } from '@kit.BasicServicesKit';
1415
1416currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
1417  if (err) {
1418    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1419  } else {
1420    console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1421  }
1422});
1423```
1424
1425### activate<sup>10+</sup>
1426
1427activate(): Promise\<void>
1428
1429Activates this session. A session can be used only after being activated. This API uses a promise to return the result.
1430
1431**Atomic service API**: This API can be used in atomic services since API version 12.
1432
1433**System capability**: SystemCapability.Multimedia.AVSession.Core
1434
1435**Return value**
1436
1437| Type          | Description                         |
1438| -------------- | ----------------------------- |
1439| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|
1440
1441**Error codes**
1442
1443For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1444
1445| ID| Error Message|
1446| -------- | ---------------------------------------- |
1447| 6600101  | Session service exception. |
1448| 6600102  | The session does not exist. |
1449
1450**Example**
1451
1452```ts
1453import { BusinessError } from '@kit.BasicServicesKit';
1454
1455currentAVSession.activate().then(() => {
1456  console.info('Activate : SUCCESS ');
1457}).catch((err: BusinessError) => {
1458  console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1459});
1460```
1461
1462### activate<sup>10+</sup>
1463
1464activate(callback: AsyncCallback\<void>): void
1465
1466Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result.
1467
1468**System capability**: SystemCapability.Multimedia.AVSession.Core
1469
1470**Parameters**
1471
1472| Name  | Type                | Mandatory| Description      |
1473| -------- | -------------------- | ---- | ---------- |
1474| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|
1475
1476**Error codes**
1477
1478For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1479
1480| ID| Error Message|
1481| -------- | ---------------------------------------- |
1482| 6600101  | Session service exception. |
1483| 6600102  | The session does not exist. |
1484
1485**Example**
1486
1487```ts
1488import { BusinessError } from '@kit.BasicServicesKit';
1489
1490currentAVSession.activate((err: BusinessError) => {
1491  if (err) {
1492    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1493  } else {
1494    console.info('Activate : SUCCESS ');
1495  }
1496});
1497```
1498
1499### deactivate<sup>10+</sup>
1500
1501deactivate(): Promise\<void>
1502
1503Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result.
1504
1505**Atomic service API**: This API can be used in atomic services since API version 12.
1506
1507**System capability**: SystemCapability.Multimedia.AVSession.Core
1508
1509**Return value**
1510
1511| Type          | Description                         |
1512| -------------- | ----------------------------- |
1513| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|
1514
1515**Error codes**
1516
1517For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1518
1519| ID| Error Message|
1520| -------- | ---------------------------------------- |
1521| 6600101  | Session service exception. |
1522| 6600102  | The session does not exist. |
1523
1524**Example**
1525
1526```ts
1527import { BusinessError } from '@kit.BasicServicesKit';
1528
1529currentAVSession.deactivate().then(() => {
1530  console.info('Deactivate : SUCCESS ');
1531}).catch((err: BusinessError) => {
1532  console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1533});
1534```
1535
1536### deactivate<sup>10+</sup>
1537
1538deactivate(callback: AsyncCallback\<void>): void
1539
1540Deactivates this session. This API uses an asynchronous callback to return the result.
1541
1542Deactivates this session. You can use [activate](#activate10) to activate the session again.
1543
1544**System capability**: SystemCapability.Multimedia.AVSession.Core
1545
1546**Parameters**
1547
1548| Name  | Type                | Mandatory| Description      |
1549| -------- | -------------------- | ---- | ---------- |
1550| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|
1551
1552**Error codes**
1553
1554For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1555
1556| ID| Error Message|
1557| -------- | ---------------------------------------- |
1558| 6600101  | Session service exception. |
1559| 6600102  | The session does not exist. |
1560
1561**Example**
1562
1563```ts
1564import { BusinessError } from '@kit.BasicServicesKit';
1565
1566currentAVSession.deactivate((err: BusinessError) => {
1567  if (err) {
1568    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1569  } else {
1570    console.info('Deactivate : SUCCESS ');
1571  }
1572});
1573```
1574
1575### destroy<sup>10+</sup>
1576
1577destroy(): Promise\<void>
1578
1579Destroys this session. This API uses a promise to return the result.
1580
1581**Atomic service API**: This API can be used in atomic services since API version 12.
1582
1583**System capability**: SystemCapability.Multimedia.AVSession.Core
1584
1585**Return value**
1586
1587| Type          | Description                         |
1588| -------------- | ----------------------------- |
1589| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|
1590
1591**Error codes**
1592
1593For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1594
1595| ID| Error Message|
1596| -------- | ---------------------------------------- |
1597| 6600101  | Session service exception. |
1598| 6600102  | The session does not exist. |
1599
1600**Example**
1601
1602```ts
1603import { BusinessError } from '@kit.BasicServicesKit';
1604
1605currentAVSession.destroy().then(() => {
1606  console.info('Destroy : SUCCESS ');
1607}).catch((err: BusinessError) => {
1608  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1609});
1610```
1611
1612### destroy<sup>10+</sup>
1613
1614destroy(callback: AsyncCallback\<void>): void
1615
1616Destroys this session. This API uses an asynchronous callback to return the result.
1617
1618**System capability**: SystemCapability.Multimedia.AVSession.Core
1619
1620**Parameters**
1621
1622| Name  | Type                | Mandatory| Description      |
1623| -------- | -------------------- | ---- | ---------- |
1624| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
1625
1626**Error codes**
1627
1628For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1629
1630| ID| Error Message|
1631| -------- | ---------------------------------------- |
1632| 6600101  | Session service exception. |
1633| 6600102  | The session does not exist. |
1634
1635**Example**
1636
1637```ts
1638import { BusinessError } from '@kit.BasicServicesKit';
1639
1640currentAVSession.destroy((err: BusinessError) => {
1641  if (err) {
1642    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1643  } else {
1644    console.info('Destroy : SUCCESS ');
1645  }
1646});
1647```
1648
1649### on('play')<sup>10+</sup>
1650
1651on(type: 'play', callback: () => void): void
1652
1653Subscribes to play command events. The subscription means that the application supports the play command.
1654
1655Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1656
1657**Atomic service API**: This API can be used in atomic services since API version 12.
1658
1659**System capability**: SystemCapability.Multimedia.AVSession.Core
1660
1661**Parameters**
1662
1663| Name  | Type                | Mandatory| Description                                                        |
1664| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1665| type     | string               | Yes  | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.|
1666| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                                       |
1667
1668**Error codes**
1669
1670For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1671
1672| ID| Error Message|
1673| -------- | ---------------------------------------- |
1674| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1675| 6600101  | Session service exception. |
1676| 6600102  | The session does not exist. |
1677
1678**Example**
1679
1680```ts
1681currentAVSession.on('play', () => {
1682  console.info('on play entry');
1683});
1684```
1685
1686### on('pause')<sup>10+</sup>
1687
1688on(type: 'pause', callback: () => void): void
1689
1690Subscribes to pause command events. The subscription means that the application supports the pause command.
1691
1692Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1693
1694**Atomic service API**: This API can be used in atomic services since API version 12.
1695
1696**System capability**: SystemCapability.Multimedia.AVSession.Core
1697
1698**Parameters**
1699
1700| Name  | Type                | Mandatory| Description                                                        |
1701| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1702| type     | string               | Yes  | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.|
1703| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1704
1705**Error codes**
1706
1707For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1708
1709| ID| Error Message|
1710| -------- | ---------------------------------------- |
1711| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1712| 6600101  | Session service exception. |
1713| 6600102  | The session does not exist. |
1714
1715**Example**
1716
1717```ts
1718currentAVSession.on('pause', () => {
1719  console.info('on pause entry');
1720});
1721```
1722
1723### on('stop')<sup>10+</sup>
1724
1725on(type:'stop', callback: () => void): void
1726
1727Subscribes to stop command events. The subscription means that the application supports the stop command.
1728
1729Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1730
1731**Atomic service API**: This API can be used in atomic services since API version 12.
1732
1733**System capability**: SystemCapability.Multimedia.AVSession.Core
1734
1735**Parameters**
1736
1737| Name  | Type                | Mandatory| Description                                                        |
1738| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1739| type     | string               | Yes  | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.|
1740| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
1741
1742**Error codes**
1743
1744For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1745
1746| ID| Error Message|
1747| -------- | ---------------------------------------- |
1748| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1749| 6600101  | Session service exception. |
1750| 6600102  | The session does not exist. |
1751
1752**Example**
1753
1754```ts
1755currentAVSession.on('stop', () => {
1756  console.info('on stop entry');
1757});
1758```
1759
1760### on('playNext')<sup>10+</sup>
1761
1762on(type:'playNext', callback: () => void): void
1763
1764Subscribes to playNext command events. The subscription means that the application supports the playNext command.
1765
1766Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1767
1768**Atomic service API**: This API can be used in atomic services since API version 12.
1769
1770**System capability**: SystemCapability.Multimedia.AVSession.Core
1771
1772**Parameters**
1773
1774| Name  | Type                | Mandatory| Description                                                        |
1775| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1776| type     | string               | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.|
1777| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |
1778
1779**Error codes**
1780
1781For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1782
1783| ID| Error Message|
1784| -------- | ---------------------------------------- |
1785| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1786| 6600101  | Session service exception. |
1787| 6600102  | The session does not exist. |
1788
1789**Example**
1790
1791```ts
1792currentAVSession.on('playNext', () => {
1793  console.info('on playNext entry');
1794});
1795```
1796
1797### on('playPrevious')<sup>10+</sup>
1798
1799on(type:'playPrevious', callback: () => void): void
1800
1801Subscribes to playPrevious command events. The subscription means that the application supports the playPrevious command.
1802
1803Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1804
1805**Atomic service API**: This API can be used in atomic services since API version 12.
1806
1807**System capability**: SystemCapability.Multimedia.AVSession.Core
1808
1809**Parameters**
1810
1811| Name  | Type                | Mandatory| Description                                                        |
1812| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1813| type     | string               | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.|
1814| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.      |
1815
1816**Error codes**
1817
1818For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1819
1820| ID| Error Message|
1821| -------- | ---------------------------------------- |
1822| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1823| 6600101  | Session service exception. |
1824| 6600102  | The session does not exist. |
1825
1826**Example**
1827
1828```ts
1829currentAVSession.on('playPrevious', () => {
1830  console.info('on playPrevious entry');
1831});
1832```
1833
1834### on('fastForward')<sup>10+</sup>
1835
1836on(type: 'fastForward', callback: (time?: number) => void): void
1837
1838Subscribes to fastForward command events. The subscription means that the application supports the fastForward command.
1839
1840Only one callback can be registered for each playback command. If a new callback is registered, the previous callback is replaced.
1841
1842**Atomic service API**: This API can be used in atomic services since API version 12.
1843
1844**System capability**: SystemCapability.Multimedia.AVSession.Core
1845
1846**Parameters**
1847
1848| Name  | Type                | Mandatory| Description                                                        |
1849| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1850| type     | string               | Yes  | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.|
1851| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.   |
1852
1853**Error codes**
1854
1855For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1856
1857| ID| Error Message|
1858| -------- | ---------------------------------------- |
1859| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1860| 6600101  | Session service exception. |
1861| 6600102  | The session does not exist. |
1862
1863**Example**
1864
1865```ts
1866currentAVSession.on('fastForward', (time?: number) => {
1867  console.info('on fastForward entry');
1868});
1869```
1870
1871### on('rewind')<sup>10+</sup>
1872
1873on(type:'rewind', callback: (time?: number) => void): void
1874
1875Subscribes to rewind command events.
1876
1877**Atomic service API**: This API can be used in atomic services since API version 12.
1878
1879**System capability**: SystemCapability.Multimedia.AVSession.Core
1880
1881**Parameters**
1882
1883| Name  | Type                | Mandatory| Description                                                        |
1884| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1885| type     | string               | Yes  | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.|
1886| callback | (time?: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in seconds.     |
1887
1888**Error codes**
1889
1890For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1891
1892| ID| Error Message|
1893| -------- | ---------------------------------------- |
1894| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1895| 6600101  | Session service exception. |
1896| 6600102  | The session does not exist. |
1897
1898**Example**
1899
1900```ts
1901currentAVSession.on('rewind', (time?: number) => {
1902  console.info('on rewind entry');
1903});
1904```
1905
1906### on('playFromAssetId')<sup>11+</sup>
1907
1908on(type:'playFromAssetId', callback: (assetId: number) => void): void
1909
1910Subscribes to playback events of a given media ID.
1911
1912**Atomic service API**: This API can be used in atomic services since API version 12.
1913
1914**System capability**: SystemCapability.Multimedia.AVSession.Core
1915
1916**Parameters**
1917
1918| Name  | Type                | Mandatory| Description                                                        |
1919| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1920| type     | string               | Yes  | Event type. The event **'playFromAssetId'** is triggered when the media ID is played.|
1921| callback | callback: (assetId: number) => void | Yes  | Callback The **assetId** parameter in the callback indicates the media asset ID.     |
1922
1923**Error codes**
1924
1925For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1926
1927| ID| Error Message|
1928| -------- | ---------------------------------------- |
1929| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1930| 6600101  | Session service exception. |
1931| 6600102  | The session does not exist. |
1932
1933**Example**
1934
1935```ts
1936currentAVSession.on('playFromAssetId', (assetId: number) => {
1937  console.info('on playFromAssetId entry');
1938});
1939```
1940
1941### off('playFromAssetId')<sup>11+</sup>
1942
1943off(type: 'playFromAssetId', callback?: (assetId: number) => void): void
1944
1945Unsubscribes from playback events of a given media ID.
1946
1947**Atomic service API**: This API can be used in atomic services since API version 12.
1948
1949**System capability**: SystemCapability.Multimedia.AVSession.Core
1950
1951**Parameters**
1952
1953| Name   | Type                 | Mandatory| Description                                                                                                                        |
1954| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
1955| type     | string               | Yes  | Event type, which is **'playFromAssetId'** in this case.|
1956| callback | callback: (assetId: number) => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session. The **assetId** parameter in the callback indicates the media asset ID.                           |
1957
1958**Error codes**
1959
1960For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1961
1962| ID| Error Message|
1963| -------- | ---------------------------------------- |
1964| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1965| 6600101  | Session service exception. |
1966| 6600102  | The session does not exist. |
1967
1968**Example**
1969
1970```ts
1971currentAVSession.off('playFromAssetId');
1972```
1973
1974### on('seek')<sup>10+</sup>
1975
1976on(type: 'seek', callback: (time: number) => void): void
1977
1978Subscribes to seek command events.
1979
1980**Atomic service API**: This API can be used in atomic services since API version 12.
1981
1982**System capability**: SystemCapability.Multimedia.AVSession.Core
1983
1984**Parameters**
1985
1986| Name  | Type                  | Mandatory| Description                                                        |
1987| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1988| type     | string                 | Yes  | Event type. The event **'seek'** is triggered when the seek command is sent to the session.|
1989| callback | (time: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.                  |
1990
1991**Error codes**
1992
1993For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1994
1995| ID| Error Message|
1996| -------- | ---------------------------------------- |
1997| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1998| 6600101  | Session service exception. |
1999| 6600102  | The session does not exist. |
2000
2001**Example**
2002
2003```ts
2004currentAVSession.on('seek', (time: number) => {
2005  console.info(`on seek entry time : ${time}`);
2006});
2007```
2008
2009### on('setSpeed')<sup>10+</sup>
2010
2011on(type: 'setSpeed', callback: (speed: number) => void): void
2012
2013Subscribes to setSpeed command events.
2014
2015**Atomic service API**: This API can be used in atomic services since API version 12.
2016
2017**System capability**: SystemCapability.Multimedia.AVSession.Core
2018
2019**Parameters**
2020
2021| Name  | Type                   | Mandatory| Description                                                        |
2022| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
2023| type     | string                  | Yes  | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.|
2024| callback | (speed: number) => void | Yes  | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed.                             |
2025
2026**Error codes**
2027
2028For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2029
2030| ID| Error Message|
2031| -------- | ---------------------------------------- |
2032| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2033| 6600101  | Session service exception. |
2034| 6600102  | The session does not exist. |
2035
2036**Example**
2037
2038```ts
2039currentAVSession.on('setSpeed', (speed: number) => {
2040  console.info(`on setSpeed speed : ${speed}`);
2041});
2042```
2043
2044### on('setLoopMode')<sup>10+</sup>
2045
2046on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
2047
2048Subscribes to setLoopMode command events.
2049
2050**Atomic service API**: This API can be used in atomic services since API version 12.
2051
2052**System capability**: SystemCapability.Multimedia.AVSession.Core
2053
2054**Parameters**
2055
2056| Name   | Type                                  | Mandatory| Description |
2057| -------- | ------------------------------------- | ---- | ---- |
2058| type     | string                                | Yes  | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.|
2059| callback | (mode: [LoopMode](#loopmode10)) => void | Yes  | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode.                              |
2060
2061**Error codes**
2062
2063For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2064
2065| ID| Error Message|
2066| -------- | ---------------------------------------- |
2067| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2068| 6600101  | Session service exception. |
2069| 6600102  | The session does not exist. |
2070
2071**Example**
2072
2073```ts
2074currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
2075  console.info(`on setLoopMode mode : ${mode}`);
2076});
2077```
2078
2079### on('toggleFavorite')<sup>10+</sup>
2080
2081on(type: 'toggleFavorite', callback: (assetId: string) => void): void
2082
2083Subscribes to toggleFavorite command events.
2084
2085**Atomic service API**: This API can be used in atomic services since API version 12.
2086
2087**System capability**: SystemCapability.Multimedia.AVSession.Core
2088
2089**Parameters**
2090
2091| Name  | Type                     | Mandatory| Description                                                        |
2092| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
2093| type     | string                    | Yes  | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.|
2094| callback | (assetId: string) => void | Yes  | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID.                             |
2095
2096**Error codes**
2097
2098For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2099
2100| ID| Error Message|
2101| -------- | ---------------------------------------- |
2102| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2103| 6600101  | Session service exception. |
2104| 6600102  | The session does not exist. |
2105
2106**Example**
2107
2108```ts
2109currentAVSession.on('toggleFavorite', (assetId: string) => {
2110  console.info(`on toggleFavorite mode : ${assetId}`);
2111});
2112```
2113
2114### on('skipToQueueItem')<sup>10+</sup>
2115
2116on(type: 'skipToQueueItem', callback: (itemId: number) => void): void
2117
2118Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item.
2119
2120**Atomic service API**: This API can be used in atomic services since API version 12.
2121
2122**System capability**: SystemCapability.Multimedia.AVSession.Core
2123
2124**Parameters**
2125
2126| Name  | Type                     | Mandatory| Description                                                                                     |
2127| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- |
2128| type     | string                   | Yes  | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.|
2129| callback | (itemId: number) => void | Yes  | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item.                                               |
2130
2131**Error codes**
2132
2133For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2134
2135| ID| Error Message|
2136| -------- | ---------------------------------------- |
2137| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2138| 6600101  | Session service exception. |
2139| 6600102  | The session does not exist. |
2140
2141**Example**
2142
2143```ts
2144currentAVSession.on('skipToQueueItem', (itemId: number) => {
2145  console.info(`on skipToQueueItem id : ${itemId}`);
2146});
2147```
2148
2149### on('handleKeyEvent')<sup>10+</sup>
2150
2151on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
2152
2153Subscribes to key events of external devices such as Bluetooth and wired devices to listen for the play, pause, previous, next, fast-forward, and rewind commands in the key events.
2154
2155**Atomic service API**: This API can be used in atomic services since API version 12.
2156
2157**System capability**: SystemCapability.Multimedia.AVSession.Core
2158
2159**Parameters**
2160
2161| Name  | Type                                                        | Mandatory| Description                                                        |
2162| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2163| type     | string                                                       | Yes  | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.|
2164| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | Yes  | Callback used for subscription. The **event** parameter in the callback indicates the key event.                             |
2165
2166**Error codes**
2167
2168For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2169
2170| ID| Error Message|
2171| -------- | ---------------------------------------- |
2172| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2173| 6600101  | Session service exception. |
2174| 6600102  | The session does not exist. |
2175
2176**Example**
2177
2178```ts
2179import { KeyEvent } from '@kit.InputKit';
2180
2181currentAVSession.on('handleKeyEvent', (event: KeyEvent) => {
2182  console.info(`on handleKeyEvent event : ${event}`);
2183});
2184
2185```
2186
2187### on('outputDeviceChange')<sup>10+</sup>
2188
2189on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2190
2191Subscribes to output device change events. After the application integrates the [**AVCastPicker** component](ohos-multimedia-avcastpicker.md), the application receives the device change callback when the user switches the device through the component.
2192
2193**Atomic service API**: This API can be used in atomic services since API version 12.
2194
2195**System capability**: SystemCapability.Multimedia.AVSession.Core
2196
2197**Parameters**
2198
2199| Name  | Type                                                   | Mandatory| Description                                                        |
2200| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2201| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
2202| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                        |
2203
2204**Error codes**
2205
2206For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2207
2208| ID| Error Message|
2209| -------- | ---------------------------------------- |
2210| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2211| 6600101  | Session service exception. |
2212| 6600102  | The session does not exist. |
2213
2214**Example**
2215
2216```ts
2217currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
2218  console.info(`on outputDeviceChange device : ${device}`);
2219});
2220```
2221
2222### on('commonCommand')<sup>10+</sup>
2223
2224on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void
2225
2226Subscribes to custom control command change events.
2227
2228**Atomic service API**: This API can be used in atomic services since API version 12.
2229
2230**System capability**: SystemCapability.Multimedia.AVSession.Core
2231
2232**Parameters**
2233
2234| Name  | Type                                                        | Mandatory| Description                                                        |
2235| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2236| type     | string                                                       | Yes  | Event type. The event **'commonCommand'** is triggered when a custom control command changes.|
2237| callback | (command: string, args: {[key:string]: Object}) => void         | Yes  | Callback used for subscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command. The parameters must be the same as those set in [sendCommonCommand](#sendcommoncommand10).         |
2238
2239**Error codes**
2240
2241For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2242
2243| ID| Error Message|
2244| -------- | ------------------------------ |
2245| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2246| 6600101  | Session service exception. |
2247| 6600102  | The session does not exist. |
2248
2249**Example**
2250
2251```ts
2252import { BusinessError } from '@kit.BasicServicesKit';
2253
2254let currentAVSession: avSession.AVSession | undefined = undefined;
2255let tag = "createNewSession";
2256let context: Context = getContext(this);
2257
2258avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
2259  if (err) {
2260    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
2261  } else {
2262    currentAVSession = data;
2263  }
2264});
2265if (currentAVSession !== undefined) {
2266  (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => {
2267    console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
2268  });
2269}
2270```
2271
2272### off('play')<sup>10+</sup>
2273
2274off(type: 'play', callback?: () => void): void
2275
2276Unsubscribes from play command events.
2277
2278After the callback is canceled, the list of supported commands must be updated.
2279
2280**Atomic service API**: This API can be used in atomic services since API version 12.
2281
2282**System capability**: SystemCapability.Multimedia.AVSession.Core
2283
2284**Parameters**
2285
2286| Name   | Type                 | Mandatory| Description                                                                                                                        |
2287| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2288| type     | string               | Yes  | Event type, which is **'play'** in this case.|
2289| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2290
2291**Error codes**
2292
2293For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2294
2295| ID| Error Message|
2296| -------- | ---------------------------------------- |
2297| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2298| 6600101  | Session service exception. |
2299| 6600102  | The session does not exist. |
2300
2301**Example**
2302
2303```ts
2304currentAVSession.off('play');
2305```
2306
2307### off('pause')<sup>10+</sup>
2308
2309off(type: 'pause', callback?: () => void): void
2310
2311Unsubscribes from pause command events.
2312
2313After the callback is canceled, the list of supported commands must be updated.
2314
2315**Atomic service API**: This API can be used in atomic services since API version 12.
2316
2317**System capability**: SystemCapability.Multimedia.AVSession.Core
2318
2319**Parameters**
2320
2321| Name   | Type                 | Mandatory| Description                                                                                                                        |
2322| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2323| type     | string               | Yes  | Event type, which is **'pause'** in this case.|
2324| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
2325
2326**Error codes**
2327
2328For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2329
2330| ID| Error Message|
2331| -------- | ---------------------------------------- |
2332| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2333| 6600101  | Session service exception. |
2334| 6600102  | The session does not exist. |
2335
2336**Example**
2337
2338```ts
2339currentAVSession.off('pause');
2340```
2341
2342### off('stop')<sup>10+</sup>
2343
2344off(type: 'stop', callback?: () => void): void
2345
2346Unsubscribes from stop command events.
2347
2348After the callback is canceled, the list of supported commands must be updated.
2349
2350**Atomic service API**: This API can be used in atomic services since API version 12.
2351
2352**System capability**: SystemCapability.Multimedia.AVSession.Core
2353
2354**Parameters**
2355
2356| Name   | Type                 | Mandatory| Description                                                                                                                        |
2357| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2358| type     | string               | Yes  | Event type, which is **'stop'** in this case.|
2359| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2360
2361**Error codes**
2362
2363For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2364
2365| ID| Error Message|
2366| -------- | ---------------------------------------- |
2367| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2368| 6600101  | Session service exception. |
2369| 6600102  | The session does not exist. |
2370
2371**Example**
2372
2373```ts
2374currentAVSession.off('stop');
2375```
2376
2377### off('playNext')<sup>10+</sup>
2378
2379off(type: 'playNext', callback?: () => void): void
2380
2381Unsubscribes from playNext command events.
2382
2383After the callback is canceled, the list of supported commands must be updated.
2384
2385**Atomic service API**: This API can be used in atomic services since API version 12.
2386
2387**System capability**: SystemCapability.Multimedia.AVSession.Core
2388
2389**Parameters**
2390
2391| Name   | Type                 | Mandatory| Description                                                                                                                        |
2392| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2393| type     | string               | Yes  | Event type, which is **'playNext'** in this case.|
2394| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2395
2396**Error codes**
2397
2398For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2399
2400| ID| Error Message|
2401| -------- | ---------------------------------------- |
2402| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2403| 6600101  | Session service exception. |
2404| 6600102  | The session does not exist. |
2405
2406**Example**
2407
2408```ts
2409currentAVSession.off('playNext');
2410```
2411
2412### off('playPrevious')<sup>10+</sup>
2413
2414off(type: 'playPrevious', callback?: () => void): void
2415
2416Unsubscribes from playPrevious command events.
2417
2418After the callback is canceled, the list of supported commands must be updated.
2419
2420**Atomic service API**: This API can be used in atomic services since API version 12.
2421
2422**System capability**: SystemCapability.Multimedia.AVSession.Core
2423
2424**Parameters**
2425
2426| Name   | Type                 | Mandatory| Description                                                                                                                        |
2427| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2428| type     | string               | Yes  | Event type, which is **'playPrevious'** in this case.|
2429| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2430
2431**Error codes**
2432
2433For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2434
2435| ID| Error Message|
2436| -------- | ---------------------------------------- |
2437| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2438| 6600101  | Session service exception. |
2439| 6600102  | The session does not exist. |
2440
2441**Example**
2442
2443```ts
2444currentAVSession.off('playPrevious');
2445```
2446
2447### off('fastForward')<sup>10+</sup>
2448
2449off(type: 'fastForward', callback?: () => void): void
2450
2451Unsubscribes from fastForward command events.
2452
2453After the callback is canceled, the list of supported commands must be updated.
2454
2455**Atomic service API**: This API can be used in atomic services since API version 12.
2456
2457**System capability**: SystemCapability.Multimedia.AVSession.Core
2458
2459**Parameters**
2460
2461| Name   | Type                 | Mandatory| Description                                                                                                                        |
2462| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2463| type     | string               | Yes  | Event type, which is **'fastForward'** in this case.|
2464| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2465
2466**Error codes**
2467
2468For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2469
2470| ID| Error Message|
2471| -------- | ---------------------------------------- |
2472| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2473| 6600101  | Session service exception. |
2474| 6600102  | The session does not exist. |
2475
2476**Example**
2477
2478```ts
2479currentAVSession.off('fastForward');
2480```
2481
2482### off('rewind')<sup>10+</sup>
2483
2484off(type: 'rewind', callback?: () => void): void
2485
2486Unsubscribes from rewind command events.
2487
2488**Atomic service API**: This API can be used in atomic services since API version 12.
2489
2490**System capability**: SystemCapability.Multimedia.AVSession.Core
2491
2492**Parameters**
2493
2494| Name   | Type                 | Mandatory| Description                                                                                                                        |
2495| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2496| type     | string               | Yes  | Event type, which is **'rewind'** in this case.|
2497| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2498
2499**Error codes**
2500
2501For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2502
2503| ID| Error Message|
2504| -------- | ---------------------------------------- |
2505| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2506| 6600101  | Session service exception. |
2507| 6600102  | The session does not exist. |
2508
2509**Example**
2510
2511```ts
2512currentAVSession.off('rewind');
2513```
2514
2515### off('seek')<sup>10+</sup>
2516
2517off(type: 'seek', callback?: (time: number) => void): void
2518
2519Unsubscribes from seek command events.
2520
2521**Atomic service API**: This API can be used in atomic services since API version 12.
2522
2523**System capability**: SystemCapability.Multimedia.AVSession.Core
2524
2525**Parameters**
2526
2527| Name  | Type                  | Mandatory| Description                                         |
2528| -------- | ---------------------- | ---- | ----------------------------------------- |
2529| type     | string                 | Yes  | Event type, which is **'seek'** in this case.      |
2530| callback | (time: number) => void | No  | Callback used for unsubscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.       |
2531
2532**Error codes**
2533
2534For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2535
2536| ID| Error Message|
2537| -------- | ---------------------------------------- |
2538| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2539| 6600101  | Session service exception. |
2540| 6600102  | The session does not exist. |
2541
2542**Example**
2543
2544```ts
2545currentAVSession.off('seek');
2546```
2547
2548### off('setSpeed')<sup>10+</sup>
2549
2550off(type: 'setSpeed', callback?: (speed: number) => void): void
2551
2552Unsubscribes from setSpeed command events.
2553
2554**Atomic service API**: This API can be used in atomic services since API version 12.
2555
2556**System capability**: SystemCapability.Multimedia.AVSession.Core
2557
2558**Parameters**
2559
2560| Name  | Type                   | Mandatory| Description                                          |
2561| -------- | ----------------------- | ---- | -------------------------------------------|
2562| type     | string                  | Yes  | Event type, which is **'setSpeed'** in this case.   |
2563| callback | (speed: number) => void | No  | Callback used for unsubscription. The **speed** parameter in the callback indicates the playback speed.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                |
2564
2565**Error codes**
2566
2567For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2568
2569| ID| Error Message|
2570| -------- | ---------------------------------------- |
2571| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2572| 6600101  | Session service exception. |
2573| 6600102  | The session does not exist. |
2574
2575**Example**
2576
2577```ts
2578currentAVSession.off('setSpeed');
2579```
2580
2581### off('setLoopMode')<sup>10+</sup>
2582
2583off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
2584
2585Unsubscribes from setSpeed command events.
2586
2587**Atomic service API**: This API can be used in atomic services since API version 12.
2588
2589**System capability**: SystemCapability.Multimedia.AVSession.Core
2590
2591**Parameters**
2592
2593| Name  | Type                                 | Mandatory| Description    |
2594| -------- | ------------------------------------- | ---- | ----- |
2595| type     | string | Yes  | Event type, which is **'setLoopMode'** in this case.|
2596| callback | (mode: [LoopMode](#loopmode10)) => void | No  | Callback used for unsubscription. The **mode** parameter in the callback indicates the loop mode.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
2597
2598**Error codes**
2599
2600For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2601
2602| ID| Error Message|
2603| -------- | ---------------------------------------- |
2604| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2605| 6600101  | Session service exception. |
2606| 6600102  | The session does not exist. |
2607
2608**Example**
2609
2610```ts
2611currentAVSession.off('setLoopMode');
2612```
2613
2614### off('toggleFavorite')<sup>10+</sup>
2615
2616off(type: 'toggleFavorite', callback?: (assetId: string) => void): void
2617
2618Unsubscribes from toggleFavorite command events.
2619
2620**Atomic service API**: This API can be used in atomic services since API version 12.
2621
2622**System capability**: SystemCapability.Multimedia.AVSession.Core
2623
2624**Parameters**
2625
2626| Name  | Type                     | Mandatory| Description                                                        |
2627| -------- | ------------------------- | ---- | -------------------------------------------------------- |
2628| type     | string                    | Yes  | Event type, which is **'toggleFavorite'** in this case.           |
2629| callback | (assetId: string) => void | No  | Callback used for unsubscription. The **assetId** parameter in the callback indicates the media asset ID.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                              |
2630
2631**Error codes**
2632
2633For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2634
2635| ID| Error Message|
2636| -------- | ---------------------------------------- |
2637| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2638| 6600101  | Session service exception. |
2639| 6600102  | The session does not exist. |
2640
2641**Example**
2642
2643```ts
2644currentAVSession.off('toggleFavorite');
2645```
2646
2647### off('skipToQueueItem')<sup>10+</sup>
2648
2649off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
2650
2651Unsubscribes from the event that indicates an item in the playlist is selected.
2652
2653**Atomic service API**: This API can be used in atomic services since API version 12.
2654
2655**System capability**: SystemCapability.Multimedia.AVSession.Core
2656
2657**Parameters**
2658
2659| Name  | Type                     | Mandatory| Description                                                                                                                                                       |
2660| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
2661| type     | string                   | Yes  | Event type, which is **'skipToQueueItem'** in this case.                                                                                                         |
2662| callback | (itemId: number) => void | No  | Callback used for unsubscription. The **itemId** parameter in the callback indicates the ID of the item.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
2663
2664**Error codes**
2665
2666For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2667
2668| ID| Error Message|
2669| -------- | ---------------------------------------- |
2670| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2671| 6600101  | Session service exception. |
2672| 6600102  | The session does not exist. |
2673
2674**Example**
2675
2676```ts
2677currentAVSession.off('skipToQueueItem');
2678```
2679
2680### off('handleKeyEvent')<sup>10+</sup>
2681
2682off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
2683
2684Unsubscribes from key events.
2685
2686**Atomic service API**: This API can be used in atomic services since API version 12.
2687
2688**System capability**: SystemCapability.Multimedia.AVSession.Core
2689
2690**Parameters**
2691
2692| Name  | Type                                                        | Mandatory| Description                                                        |
2693| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2694| type     | string                                                       | Yes  | Event type, which is **'handleKeyEvent'** in this case.            |
2695| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | No  | Callback used for unsubscription. The **event** parameter in the callback indicates the key event.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                             |
2696
2697**Error codes**
2698
2699For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2700
2701| ID| Error Message|
2702| -------- | ---------------------------------------- |
2703| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2704| 6600101  | Session service exception. |
2705| 6600102  | The session does not exist. |
2706
2707**Example**
2708
2709```ts
2710currentAVSession.off('handleKeyEvent');
2711```
2712
2713### off('outputDeviceChange')<sup>10+</sup>
2714
2715off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2716
2717Unsubscribes from playback device change events.
2718
2719**Atomic service API**: This API can be used in atomic services since API version 12.
2720
2721**System capability**: SystemCapability.Multimedia.AVSession.Core
2722
2723**Parameters**
2724
2725| Name  | Type                                                   | Mandatory| Description                                                     |
2726| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
2727| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.    |
2728| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No  | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                       |
2729
2730**Error codes**
2731
2732For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2733
2734| ID| Error Message|
2735| -------- | ---------------------------------------- |
2736| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2737| 6600101  | Session service exception. |
2738| 6600102  | The session does not exist. |
2739
2740**Example**
2741
2742```ts
2743currentAVSession.off('outputDeviceChange');
2744```
2745
2746
2747### off('commonCommand')<sup>10+</sup>
2748
2749off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void
2750
2751Unsubscribes from custom control command change events.
2752
2753**Atomic service API**: This API can be used in atomic services since API version 12.
2754
2755**System capability**: SystemCapability.Multimedia.AVSession.Core
2756
2757**Parameters**
2758
2759| Name  | Type                                                        | Mandatory| Description                                                    |
2760| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2761| type     | string                                                       | Yes  | Event type, which is **'commonCommand'** in this case.   |
2762| callback | (command: string, args: {[key:string]: Object}) => void         | No  | Callback used for unsubscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
2763
2764**Error codes**
2765
2766For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2767
2768| ID| Error Message|
2769| -------- | ---------------- |
2770| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2771| 6600101  | Session service exception. |
2772| 6600102  | The session does not exist. |
2773
2774**Example**
2775
2776```ts
2777currentAVSession.off('commonCommand');
2778```
2779
2780### on('answer')<sup>11+</sup>
2781
2782on(type: 'answer', callback: Callback\<void>): void;
2783
2784Subscribes to call answer events.
2785
2786**Atomic service API**: This API can be used in atomic services since API version 12.
2787
2788**System capability**: SystemCapability.Multimedia.AVSession.Core
2789
2790**Parameters**
2791
2792| Name  | Type                                                        | Mandatory| Description                                                        |
2793| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2794| type     | string                                                       | Yes  | Event type. The event **'answer'** is triggered when a call is answered.|
2795| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                     |
2796
2797**Error codes**
2798
2799For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2800
2801| ID| Error Message|
2802| -------- | ------------------------------ |
2803| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2804| 6600101  | Session service exception. |
2805| 6600102  | The session does not exist. |
2806
2807**Example**
2808
2809```ts
2810currentAVSession.on('answer', () => {
2811  console.info('on call answer');
2812});
2813```
2814
2815### off('answer')<sup>11+</sup>
2816
2817off(type: 'answer', callback?: Callback\<void>): void;
2818
2819Unsubscribes from call answer events.
2820
2821**Atomic service API**: This API can be used in atomic services since API version 12.
2822
2823**System capability**: SystemCapability.Multimedia.AVSession.Core
2824
2825**Parameters**
2826
2827| Name   | Type                 | Mandatory| Description                                                                                                                        |
2828| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2829| type     | string               | Yes  | Event type, which is **'answer'** in this case.|
2830| callback | Callback\<void>     | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.   |
2831
2832**Error codes**
2833
2834For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2835
2836| ID| Error Message|
2837| -------- | ---------------------------------------- |
2838| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2839| 6600101  | Session service exception. |
2840| 6600102  | The session does not exist. |
2841
2842**Example**
2843
2844```ts
2845currentAVSession.off('answer');
2846```
2847
2848### on('hangUp')<sup>11+</sup>
2849
2850on(type: 'hangUp', callback: Callback\<void>): void;
2851
2852Subscribes to call hangup events.
2853
2854**Atomic service API**: This API can be used in atomic services since API version 12.
2855
2856**System capability**: SystemCapability.Multimedia.AVSession.Core
2857
2858**Parameters**
2859
2860| Name  | Type                                                        | Mandatory| Description                                                        |
2861| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2862| type     | string                                                       | Yes  | Event type. The event **'hangUp'** is triggered when a call is hung up.|
2863| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2864
2865**Error codes**
2866
2867For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2868
2869| ID| Error Message|
2870| -------- | ------------------------------ |
2871| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2872| 6600101  | Session service exception. |
2873| 6600102  | The session does not exist. |
2874
2875**Example**
2876
2877```ts
2878currentAVSession.on('hangUp', () => {
2879  console.info('on call hangUp');
2880});
2881```
2882
2883### off('hangUp')<sup>11+</sup>
2884
2885off(type: 'hangUp', callback?: Callback\<void>): void;
2886
2887Unsubscribes from call answer events.
2888
2889**Atomic service API**: This API can be used in atomic services since API version 12.
2890
2891**System capability**: SystemCapability.Multimedia.AVSession.Core
2892
2893**Parameters**
2894
2895| Name   | Type                 | Mandatory| Description                                                                                                                        |
2896| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2897| type     | string               | Yes  | Event type, which is **'hangUp'** in this case.|
2898| callback | Callback\<void>      | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2899
2900**Error codes**
2901
2902For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2903
2904| ID| Error Message|
2905| -------- | ---------------------------------------- |
2906| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2907| 6600101  | Session service exception. |
2908| 6600102  | The session does not exist. |
2909
2910**Example**
2911
2912```ts
2913currentAVSession.off('hangUp');
2914```
2915
2916### on('toggleCallMute')<sup>11+</sup>
2917
2918on(type: 'toggleCallMute', callback: Callback\<void>): void;
2919
2920Subscribes to call mute events.
2921
2922**Atomic service API**: This API can be used in atomic services since API version 12.
2923
2924**System capability**: SystemCapability.Multimedia.AVSession.Core
2925
2926**Parameters**
2927
2928| Name  | Type                                                        | Mandatory| Description                                                        |
2929| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2930| type     | string                                                       | Yes  | Event type. The event **'toggleCallMute'** is triggered when a call is muted or unmuted.|
2931| callback | Callback\<void>                                               | Yes  | Callback used to return the result.                                            |
2932
2933**Error codes**
2934
2935For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2936
2937| ID| Error Message|
2938| -------- | ------------------------------ |
2939| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2940| 6600101  | Session service exception. |
2941| 6600102  | The session does not exist. |
2942
2943**Example**
2944
2945```ts
2946currentAVSession.on('toggleCallMute', () => {
2947  console.info('on call toggleCallMute');
2948});
2949```
2950
2951### off('toggleCallMute')<sup>11+</sup>
2952
2953off(type: 'toggleCallMute', callback?: Callback\<void>): void;
2954
2955Unsubscribes from call mute events.
2956
2957**Atomic service API**: This API can be used in atomic services since API version 12.
2958
2959**System capability**: SystemCapability.Multimedia.AVSession.Core
2960
2961**Parameters**
2962
2963| Name   | Type                 | Mandatory| Description                                                                                                                        |
2964| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2965| type     | string               | Yes  | Event type, which is **'toggleCallMute'** in this case.|
2966| callback | Callback\<void>    | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
2967
2968**Error codes**
2969
2970For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2971
2972| ID| Error Message|
2973| -------- | ---------------------------------------- |
2974| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2975| 6600101  | Session service exception. |
2976| 6600102  | The session does not exist. |
2977
2978**Example**
2979
2980```ts
2981currentAVSession.off('toggleCallMute');
2982```
2983
2984### on('castDisplayChange')<sup>12+</sup>
2985
2986on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void
2987
2988Subscribes to cast display change events in the case of extended screens.
2989
2990**Atomic service API**: This API can be used in atomic services since API version 12.
2991
2992**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
2993
2994**Parameters**
2995
2996| Name   | Type                 | Mandatory| Description                                                                                                                        |
2997| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2998| type     | string                                                       | Yes  | Event type. The event **'castDisplayChange'** is triggered when the cast display in the case of extended screens changes.|
2999| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | Yes  | Callback used to return the information about the cast display.                           |
3000
3001**Error codes**
3002
3003For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3004
3005| ID| Error Message|
3006| -------- | ---------------------------------------- |
3007| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3008| 6600101  | Session service exception. |
3009| 6600102  | The session does not exist. |
3010
3011**Example**
3012
3013```ts
3014let castDisplay: avSession.CastDisplayInfo;
3015currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => {
3016    if (display.state === avSession.CastDisplayState.STATE_ON) {
3017        castDisplay = display;
3018        console.info(`Succeeded in castDisplayChange display : ${display.id} ON`);
3019    } else if (display.state === avSession.CastDisplayState.STATE_OFF){
3020        console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`);
3021    }
3022});
3023```
3024### off('castDisplayChange')<sup>12+</sup>
3025
3026 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void
3027
3028Unsubscribes from cast display change events in the case of extended screens.
3029
3030**Atomic service API**: This API can be used in atomic services since API version 12.
3031
3032**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3033
3034**Parameters**
3035
3036| Name   | Type                 | Mandatory| Description                                                                                                                        |
3037| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3038| type     | string                                                       | Yes  | Event type, which is **'castDisplayChange'** in this case.|
3039| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
3040
3041**Error codes**
3042
3043For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3044
3045| ID| Error Message|
3046| -------- | ---------------------------------------- |
3047| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3048| 6600101  | Session service exception. |
3049| 6600102  | The session does not exist. |
3050
3051**Example**
3052
3053```ts
3054currentAVSession.off('castDisplayChange');
3055```
3056
3057### stopCasting<sup>10+</sup>
3058
3059stopCasting(callback: AsyncCallback\<void>): void
3060
3061Stops castings. This API uses an asynchronous callback to return the result.
3062
3063**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3064
3065**Parameters**
3066
3067| Name  | Type                                 | Mandatory| Description                                 |
3068| -------- | ------------------------------------- | ---- | ------------------------------------- |
3069| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3070
3071**Error codes**
3072
3073For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3074
3075| ID| Error Message|
3076| -------- | ---------------------------------------- |
3077| 6600109  | The remote connection is not established. |
3078
3079**Example**
3080
3081```ts
3082import { BusinessError } from '@kit.BasicServicesKit';
3083
3084currentAVSession.stopCasting((err: BusinessError) => {
3085  if (err) {
3086    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3087  } else {
3088    console.info('stopCasting successfully');
3089  }
3090});
3091```
3092
3093### stopCasting<sup>10+</sup>
3094
3095stopCasting(): Promise\<void>
3096
3097Stops castings. This API uses a promise to return the result.
3098
3099**Atomic service API**: This API can be used in atomic services since API version 12.
3100
3101**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3102
3103**Return value**
3104
3105| Type          | Description                         |
3106| -------------- | ----------------------------- |
3107| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.|
3108
3109**Error codes**
3110
3111For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3112
3113| ID| Error Message|
3114| -------- | ---------------------------------------- |
3115| 6600109  | The remote connection is not established. |
3116
3117**Example**
3118
3119```ts
3120import { BusinessError } from '@kit.BasicServicesKit';
3121
3122currentAVSession.stopCasting().then(() => {
3123  console.info('stopCasting successfully');
3124}).catch((err: BusinessError) => {
3125  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3126});
3127```
3128
3129### getOutputDeviceSync<sup>10+</sup>
3130
3131getOutputDeviceSync(): OutputDeviceInfo
3132
3133Obtains the output device information. This API returns the result synchronously.
3134
3135**Atomic service API**: This API can be used in atomic services since API version 12.
3136
3137**System capability**: SystemCapability.Multimedia.AVSession.Core
3138
3139**Return value**
3140
3141| Type                                           | Description                             |
3142| ----------------------------------------------- | --------------------------------- |
3143| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.|
3144
3145**Error codes**
3146
3147For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3148
3149| ID  | Error Message|
3150|---------| --------------------------------------- |
3151| 6600101 | Session service exception. |
3152| 6600102 | The session does not exist. |
3153
3154**Example**
3155
3156```ts
3157import { BusinessError } from '@kit.BasicServicesKit';
3158
3159try {
3160  let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync();
3161} catch (err) {
3162  let error = err as BusinessError;
3163  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
3164}
3165```
3166### getAllCastDisplays<sup>12+</sup>
3167
3168getAllCastDisplays(): Promise<Array\<CastDisplayInfo>>
3169
3170Obtains all displays that support extended screen projection in the current system. This API uses a promise to return the result.
3171
3172**Atomic service API**: This API can be used in atomic services since API version 12.
3173
3174**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3175
3176**Return value**
3177
3178| Type                                           | Description                             |
3179| ----------------------------------------------- | --------------------------------- |
3180| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise used to return the information about all the cast displays.|
3181
3182**Error codes**
3183
3184For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3185
3186| ID  | Error Message|
3187|---------| --------------------------------------- |
3188| 6600101 | Session service exception. |
3189| 6600102 | The session does not exist. |
3190
3191**Example**
3192
3193```ts
3194import { BusinessError } from '@kit.BasicServicesKit';
3195
3196let castDisplay: avSession.CastDisplayInfo;
3197currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => {
3198    if (data.length >= 1) {
3199       castDisplay = data[0];
3200     }
3201   }).catch((err: BusinessError) => {
3202     console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`);
3203   });
3204```
3205
3206## AVCastControlCommandType<sup>10+</sup>
3207
3208type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
3209  'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'
3210
3211Enumerates the commands that can be sent by a cast controller.
3212
3213**Atomic service API**: This API can be used in atomic services since API version 12.
3214
3215**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3216
3217| Type            | Description        |
3218| ---------------- | ------------ |
3219| 'play'           | Play the media.        |
3220| 'pause'          | Pause the playback.        |
3221| 'stop'           | Stop the playback.        |
3222| 'playNext'       | Play the next media asset.      |
3223| 'playPrevious'   | Play the previous media asset.      |
3224| 'fastForward'    | Fast-forward.        |
3225| 'rewind'         | Rewind.        |
3226| 'seek'           | Seek to a playback position.|
3227| 'setVolume'      | Set the volume.    |
3228| 'setSpeed'       | Set the playback speed.|
3229| 'setLoopMode'    | Set the loop mode.|
3230| 'toggleFavorite' | Favorite the media asset.    |
3231| 'toggleMute'     | Set the muted status.|
3232
3233## AVCastControlCommand<sup>10+</sup>
3234
3235Defines the command that can be sent by a cast controller.
3236
3237**Atomic service API**: This API can be used in atomic services since API version 12.
3238
3239**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3240
3241| Name     | Type                                             | Mandatory| Description          |
3242| --------- | ------------------------------------------------- | ---- | -------------- |
3243| command   | [AVCastControlCommandType](#avcastcontrolcommandtype10)     | Yes  | Command.          |
3244| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) &#124; number &#124; string &#124; [LoopMode](#loopmode10) | No  | Parameters carried in the command.|
3245
3246## AVCastController<sup>10+</sup>
3247
3248After a casting connection is set up, you can call [avSession.getAVCastController](#getavcastcontroller10) to obtain the cast controller. Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
3249
3250### getAVPlaybackState<sup>10+</sup>
3251
3252getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
3253
3254Obtains the remote playback state. This API uses an asynchronous callback to return the result.
3255
3256**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3257
3258**Parameters**
3259
3260| Name   | Type                                                       | Mandatory| Description                                                        |
3261| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3262| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
3263
3264**Error codes**
3265
3266For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3267
3268| ID| Error Message|
3269| -------- | ---------------------------------------- |
3270| 6600101  | Session service exception |
3271
3272**Example**
3273
3274```ts
3275import { BusinessError } from '@kit.BasicServicesKit';
3276
3277aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
3278  if (err) {
3279    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3280  } else {
3281    console.info('getAVPlaybackState : SUCCESS');
3282  }
3283});
3284```
3285
3286### getAVPlaybackState<sup>10+</sup>
3287
3288getAVPlaybackState(): Promise\<AVPlaybackState>
3289
3290Obtains the remote playback state. This API uses a promise to return the result.
3291
3292**Atomic service API**: This API can be used in atomic services since API version 12.
3293
3294**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3295
3296**Return value**
3297
3298| Type                                                       | Description                                                        |
3299| --------- | ------------------------------------------------------------ |
3300| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state.|
3301
3302**Error codes**
3303
3304For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3305
3306| ID| Error Message|
3307| -------- | ---------------------------------------- |
3308| 6600101  | Session service exception |
3309
3310**Example**
3311
3312```ts
3313import { BusinessError } from '@kit.BasicServicesKit';
3314
3315aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
3316  console.info('getAVPlaybackState : SUCCESS');
3317}).catch((err: BusinessError) => {
3318  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3319});
3320```
3321
3322### sendControlCommand<sup>10+</sup>
3323
3324sendControlCommand(command: AVCastControlCommand): Promise\<void>
3325
3326Sends a control command to the session through the controller. This API uses a promise to return the result.
3327
3328
3329**Atomic service API**: This API can be used in atomic services since API version 12.
3330
3331**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3332
3333**Parameters**
3334
3335| Name   | Type                                 | Mandatory| Description                          |
3336| ------- | ------------------------------------- | ---- | ------------------------------ |
3337| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
3338
3339**Return value**
3340
3341| Type          | Description                         |
3342| -------------- | ----------------------------- |
3343| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3344
3345**Error codes**
3346
3347For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3348
3349| ID| Error Message|
3350| -------- | ---------------------------------------- |
3351| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3352| 6600101  | Session service exception. |
3353| 6600105  | Invalid session command. |
3354| 6600109  | The remote connection is not established. |
3355
3356**Example**
3357
3358```ts
3359import { BusinessError } from '@kit.BasicServicesKit';
3360
3361let avCommand: avSession.AVCastControlCommand = {command:'play'};
3362aVCastController.sendControlCommand(avCommand).then(() => {
3363  console.info('SendControlCommand successfully');
3364}).catch((err: BusinessError) => {
3365  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3366});
3367```
3368
3369### sendControlCommand<sup>10+</sup>
3370
3371sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
3372
3373Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
3374
3375
3376**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3377
3378**Parameters**
3379
3380| Name  | Type                                 | Mandatory| Description                          |
3381| -------- | ------------------------------------- | ---- | ------------------------------ |
3382| command  | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
3383| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
3384
3385**Error codes**
3386
3387For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3388
3389| ID| Error Message|
3390| -------- | ------------------------------- |
3391| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3392| 6600101  | Session service exception. |
3393| 6600105  | Invalid session command. |
3394| 6600109  | The remote connection is not established. |
3395
3396**Example**
3397
3398```ts
3399import { BusinessError } from '@kit.BasicServicesKit';
3400
3401let avCommand: avSession.AVCastControlCommand = {command:'play'};
3402aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
3403  if (err) {
3404    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3405  } else {
3406    console.info('SendControlCommand successfully');
3407  }
3408});
3409```
3410
3411### prepare<sup>10+</sup>
3412
3413prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
3414
3415Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses an asynchronous callback to return the result.
3416
3417**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3418
3419**Parameters**
3420
3421| Name   | Type                                 | Mandatory| Description                          |
3422| ------- | ------------------------------------- | ---- | ------------------------------ |
3423| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3424| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3425
3426**Error codes**
3427
3428For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3429
3430| ID| Error Message|
3431| -------- | ---------------------------------------- |
3432| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3433| 6600101  | Session service exception. |
3434| 6600109  | The remote connection is not established. |
3435
3436**Example**
3437
3438```ts
3439import { BusinessError } from '@kit.BasicServicesKit';
3440
3441// Set playback parameters.
3442let playItem: avSession.AVQueueItem = {
3443  itemId: 0,
3444  description: {
3445    assetId: '12345',
3446    mediaType: 'AUDIO',
3447    mediaUri: 'http://resource1_address',
3448    mediaSize: 12345,
3449    startPosition: 0,
3450    duration: 0,
3451    artist: 'mysong',
3452    albumTitle: 'song1_title',
3453    albumCoverUri: "http://resource1_album_address",
3454    lyricUri: "http://resource1_lyric_address",
3455    appName: 'MyMusic'
3456  }
3457};
3458// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3459aVCastController.prepare(playItem, (err: BusinessError) => {
3460  if (err) {
3461    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3462  } else {
3463    console.info('prepare successfully');
3464  }
3465});
3466```
3467
3468
3469### prepare<sup>10+</sup>
3470
3471prepare(item: AVQueueItem): Promise\<void>
3472
3473Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result.
3474
3475
3476**Atomic service API**: This API can be used in atomic services since API version 12.
3477
3478**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3479
3480**Parameters**
3481
3482| Name   | Type                                 | Mandatory| Description                          |
3483| ------- | ------------------------------------- | ---- | ------------------------------ |
3484| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3485
3486**Return value**
3487
3488| Type          | Description                         |
3489| -------------- | ----------------------------- |
3490| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3491
3492**Error codes**
3493
3494For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3495
3496| ID| Error Message|
3497| -------- | ---------------------------------------- |
3498| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3499| 6600101  | Session service exception. |
3500| 6600109  | The remote connection is not established. |
3501
3502
3503**Example**
3504
3505```ts
3506import { BusinessError } from '@kit.BasicServicesKit';
3507
3508// Set playback parameters.
3509let playItem: avSession.AVQueueItem = {
3510  itemId: 0,
3511  description: {
3512    assetId: '12345',
3513    mediaType: 'AUDIO',
3514    mediaUri: 'http://resource1_address',
3515    mediaSize: 12345,
3516    startPosition: 0,
3517    duration: 0,
3518    artist: 'mysong',
3519    albumTitle: 'song1_title',
3520    albumCoverUri: "http://resource1_album_address",
3521    lyricUri: "http://resource1_lyric_address",
3522    appName: 'MyMusic'
3523  }
3524};
3525// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
3526aVCastController.prepare(playItem).then(() => {
3527  console.info('prepare successfully');
3528}).catch((err: BusinessError) => {
3529  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3530});
3531```
3532
3533### start<sup>10+</sup>
3534
3535start(item: AVQueueItem, callback: AsyncCallback\<void>): void
3536
3537Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
3538
3539**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3540
3541**Parameters**
3542
3543| Name   | Type                                 | Mandatory| Description                          |
3544| ------- | ------------------------------------- | ---- | ------------------------------ |
3545| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3546| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3547
3548**Error codes**
3549
3550For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3551
3552| ID| Error Message|
3553| -------- | ---------------------------------------- |
3554| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3555| 6600101  | Session service exception. |
3556| 6600109  | The remote connection is not established. |
3557
3558**Example**
3559
3560```ts
3561import { BusinessError } from '@kit.BasicServicesKit';
3562
3563// Set playback parameters.
3564let playItem: avSession.AVQueueItem = {
3565  itemId: 0,
3566  description: {
3567    assetId: '12345',
3568    mediaType: 'AUDIO',
3569    mediaUri: 'http://resource1_address',
3570    mediaSize: 12345,
3571    startPosition: 0,
3572    duration: 0,
3573    artist: 'mysong',
3574    albumTitle: 'song1_title',
3575    albumCoverUri: "http://resource1_album_address",
3576    lyricUri: "http://resource1_lyric_address",
3577    appName: 'MyMusic'
3578  }
3579};
3580
3581// Start playback.
3582aVCastController.start(playItem, (err: BusinessError) => {
3583  if (err) {
3584    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3585  } else {
3586    console.info('start successfully');
3587  }
3588});
3589```
3590
3591### start<sup>10+</sup>
3592
3593start(item: AVQueueItem): Promise\<void>
3594
3595Prepares for the playback of a media asset. This API uses a promise to return the result.
3596
3597
3598**Atomic service API**: This API can be used in atomic services since API version 12.
3599
3600**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3601
3602**Parameters**
3603
3604| Name   | Type                                 | Mandatory| Description                          |
3605| ------- | ------------------------------------- | ---- | ------------------------------ |
3606| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
3607
3608**Return value**
3609
3610| Type          | Description                         |
3611| -------------- | ----------------------------- |
3612| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
3613
3614**Error codes**
3615
3616For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3617
3618| ID| Error Message|
3619| -------- | ---------------------------------------- |
3620| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3621| 6600101  | Session service exception. |
3622| 6600109  | The remote connection is not established. |
3623
3624
3625**Example**
3626
3627```ts
3628import { BusinessError } from '@kit.BasicServicesKit';
3629
3630// Set playback parameters.
3631let playItem: avSession.AVQueueItem = {
3632  itemId: 0,
3633  description: {
3634    assetId: '12345',
3635    mediaType: 'AUDIO',
3636    mediaUri: 'http://resource1_address',
3637    mediaSize: 12345,
3638    startPosition: 0,
3639    duration: 0,
3640    artist: 'mysong',
3641    albumTitle: 'song1_title',
3642    albumCoverUri: "http://resource1_album_address",
3643    lyricUri: "http://resource1_lyric_address",
3644    appName: 'MyMusic'
3645  }
3646};
3647// Start playback.
3648aVCastController.start(playItem).then(() => {
3649  console.info('start successfully');
3650}).catch((err: BusinessError) => {
3651  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3652});
3653```
3654
3655### getCurrentItem<sup>10+</sup>
3656
3657getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
3658
3659Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result.
3660
3661**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3662
3663**Parameters**
3664
3665| Name  | Type                                 | Mandatory| Description                                 |
3666| -------- | ------------------------------------- | ---- | ------------------------------------- |
3667| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3668
3669**Error codes**
3670
3671For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3672
3673| ID| Error Message|
3674| -------- | ---------------------------------------- |
3675| 6600101  | Session service exception. |
3676
3677**Example**
3678
3679```ts
3680import { BusinessError } from '@kit.BasicServicesKit';
3681
3682aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
3683  if (err) {
3684    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3685  } else {
3686    console.info('getCurrentItem successfully');
3687  }
3688});
3689```
3690
3691### getCurrentItem<sup>10+</sup>
3692
3693getCurrentItem(): Promise\<AVQueueItem>
3694
3695Obtains the information about the media asset that is being played. This API uses a promise to return the result.
3696
3697**Atomic service API**: This API can be used in atomic services since API version 12.
3698
3699**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3700
3701**Return value**
3702
3703| Type          | Description                         |
3704| -------------- | ----------------------------- |
3705| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.|
3706
3707**Error codes**
3708
3709For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3710
3711| ID| Error Message|
3712| -------- | ---------------------------------------- |
3713| 6600101  | Session service exception. |
3714
3715**Example**
3716
3717```ts
3718import { BusinessError } from '@kit.BasicServicesKit';
3719
3720aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
3721  console.info('getCurrentItem successfully');
3722}).catch((err: BusinessError) => {
3723  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3724});
3725```
3726
3727### getValidCommands<sup>11+</sup>
3728
3729getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void
3730
3731Obtains the supported commands. This API uses an asynchronous callback to return the result.
3732
3733**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3734
3735**Parameters**
3736
3737| Name| Type| Mandatory| Description|
3738| -------- | ------------------------------------- | ---- | ------------------------------------- |
3739| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | Yes| Callback return the supported commands.|
3740
3741**Error codes**
3742
3743For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3744
3745| ID| Error Message|
3746| -------- | ---------------------------------------- |
3747| 6600101  | Session service exception. |
3748
3749**Example**
3750
3751```ts
3752import { BusinessError } from '@kit.BasicServicesKit';
3753
3754aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => {
3755  if (err) {
3756    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3757  } else {
3758    console.info('getValidCommands successfully');
3759  }
3760});
3761```
3762
3763### getValidCommands<sup>11+</sup>
3764
3765getValidCommands(): Promise<Array\<AVCastControlCommandType>>
3766
3767Obtains the supported commands. This API uses a promise to return the result.
3768
3769**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3770
3771**Return value**
3772
3773| Type| Description|
3774| -------------- | ----------------------------- |
3775| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise used to return the supported commands.|
3776
3777**Error codes**
3778
3779For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3780
3781| ID| Error Message|
3782| -------- | ---------------------------------------- |
3783| 6600101  | Session service exception. |
3784
3785**Example**
3786
3787```ts
3788import { BusinessError } from '@kit.BasicServicesKit';
3789
3790aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => {
3791  console.info('getValidCommands successfully');
3792}).catch((err: BusinessError) => {
3793  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3794});
3795```
3796
3797### processMediaKeyResponse<sup>12+</sup>
3798
3799processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void>
3800
3801Processes the response to a media key request during online DRM resource projection. This API uses a promise to return the result.
3802
3803**Atomic service API**: This API can be used in atomic services since API version 12.
3804
3805**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3806
3807**Parameters**
3808
3809| Name  | Type                                 | Mandatory| Description                                 |
3810| -------- | ------------------------------------- | ---- | ------------------------------------- |
3811| assetId | string                  | Yes  | Media asset ID.|
3812| response | Uint8Array             | Yes  | Response to the media key request.|
3813
3814**Return value**
3815
3816| Type          | Description                         |
3817| -------------- | ----------------------------- |
3818| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned.|
3819
3820**Error codes**
3821
3822For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3823
3824| ID| Error Message|
3825| -------- | ---------------------------------------- |
3826| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3827| 6600101  | Session service exception. |
3828
3829**Example**
3830
3831```ts
3832let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
3833  // Obtain the DRM URL based on the asset ID.
3834  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
3835  // Obtain a media key from the server. Assign a value based on service requirements.
3836  let licenseResponseData: Uint8Array = new Uint8Array();
3837  console.info(`Succeeded in get license by ${drmUrl}.`);
3838  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
3839}
3840```
3841
3842### release<sup>11+</sup>
3843
3844release(callback: AsyncCallback\<void>): void
3845
3846Releases this cast controller. This API uses an asynchronous callback to return the result.
3847
3848**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3849
3850**Parameters**
3851
3852| Name  | Type                      | Mandatory| Description                                                        |
3853| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
3854| callback | AsyncCallback\<void>       | Yes  | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object.|
3855
3856**Error codes**
3857
3858For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3859
3860| ID| Error Message|
3861| -------- | -------------------------- |
3862| 6600101  | Session service exception. |
3863
3864**Example**
3865
3866```ts
3867import { BusinessError } from '@kit.BasicServicesKit';
3868
3869aVCastController.release((err: BusinessError) => {
3870  if (err) {
3871    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
3872  } else {
3873    console.info('release successfully');
3874  }
3875});
3876```
3877
3878### release<sup>11+</sup>
3879
3880release(): Promise\<void>
3881
3882Releases this cast controller. This API uses a promise to return the result.
3883
3884**Atomic service API**: This API can be used in atomic services since API version 12.
3885
3886**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3887
3888**Return value**
3889
3890| Type          | Description                         |
3891| -------------- | ----------------------------- |
3892| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned.|
3893
3894**Error codes**
3895
3896For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3897
3898| ID| Error Message|
3899| -------- | ------------------------------ |
3900| 6600101  | Session service exception. |
3901
3902**Example**
3903
3904```ts
3905import { BusinessError } from '@kit.BasicServicesKit';
3906
3907aVCastController.release().then(() => {
3908  console.info('release successfully');
3909}).catch((err: BusinessError) => {
3910  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
3911});
3912
3913```
3914
3915### on('playbackStateChange')<sup>10+</sup>
3916
3917on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
3918
3919Subscribes to playback state change events.
3920
3921**Atomic service API**: This API can be used in atomic services since API version 12.
3922
3923**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3924
3925**Parameters**
3926
3927| Name  | Type                                                        | Mandatory| Description                                                        |
3928| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3929| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
3930| filter   | Array\<keyof&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.|
3931| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.                     |
3932
3933**Error codes**
3934
3935For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3936
3937| ID| Error Message|
3938| -------- | ------------------------------ |
3939| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3940| 6600101  | Session service exception. |
3941
3942**Example**
3943
3944```ts
3945aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
3946  console.info(`on playbackStateChange state : ${playbackState.state}`);
3947});
3948
3949let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
3950aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
3951  console.info(`on playbackStateChange state : ${playbackState.state}`);
3952});
3953```
3954
3955### off('playbackStateChange')<sup>10+</sup>
3956
3957off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
3958
3959Unsubscribes from playback state change events. This API is called by the controller.
3960
3961**Atomic service API**: This API can be used in atomic services since API version 12.
3962
3963**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3964
3965**Parameters**
3966
3967| Name  | Type                                                        | Mandatory| Description                                                    |
3968| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
3969| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
3970| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | No  | Callback used for unsubscription. The **state** parameter in the callback indicates the changed playback state.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
3971
3972**Error codes**
3973
3974For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
3975
3976| ID| Error Message|
3977| -------- | ---------------- |
3978| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3979| 6600101  | Session service exception. |
3980
3981**Example**
3982
3983```ts
3984aVCastController.off('playbackStateChange');
3985```
3986
3987### on('mediaItemChange')<sup>10+</sup>
3988
3989on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
3990
3991Subscribes to media asset change events.
3992
3993**Atomic service API**: This API can be used in atomic services since API version 12.
3994
3995**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3996
3997**Parameters**
3998
3999| Name  | Type                                                        | Mandatory| Description                                                        |
4000| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4001| type     | string                                                       | Yes  | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.|
4002| callback | (callback: [AVQueueItem](#avqueueitem10)) => void         | Yes  | Callback used for subscription. **AVQueueItem** is the media asset that is being played.                     |
4003
4004**Error codes**
4005
4006For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4007
4008| ID| Error Message|
4009| -------- | ------------------------------ |
4010| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4011| 6600101  | Session service exception. |
4012
4013**Example**
4014
4015```ts
4016aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
4017  console.info(`on mediaItemChange state : ${item.itemId}`);
4018});
4019```
4020
4021### off('mediaItemChange')<sup>10+</sup>
4022
4023off(type: 'mediaItemChange'): void
4024
4025Unsubscribes from media asset change events.
4026
4027**Atomic service API**: This API can be used in atomic services since API version 12.
4028
4029**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4030
4031**Parameters**
4032
4033| Name  | Type                                                        | Mandatory| Description                                                    |
4034| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4035| type     | string                                                       | Yes  | Event type, which is **'mediaItemChange'** in this case.   |
4036
4037**Error codes**
4038
4039For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4040
4041| ID| Error Message|
4042| -------- | ---------------- |
4043| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4044| 6600101  | Session service exception. |
4045
4046**Example**
4047
4048```ts
4049aVCastController.off('mediaItemChange');
4050```
4051
4052### on('playNext')<sup>10+</sup>
4053
4054on(type: 'playNext', callback: Callback\<void>): void
4055
4056Subscribes to playNext command events.
4057
4058**Atomic service API**: This API can be used in atomic services since API version 12.
4059
4060**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4061
4062**Parameters**
4063
4064| Name  | Type                                                        | Mandatory| Description                                                        |
4065| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4066| type     | string                                                       | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.|
4067| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4068
4069**Error codes**
4070
4071For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4072
4073| ID| Error Message|
4074| -------- | ------------------------------ |
4075| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4076| 6600101  | Session service exception. |
4077
4078**Example**
4079
4080```ts
4081aVCastController.on('playNext', () => {
4082  console.info('on playNext');
4083});
4084```
4085
4086### off('playNext')<sup>10+</sup>
4087
4088off(type: 'playNext'): void
4089
4090Unsubscribes from playNext command events.
4091
4092**Atomic service API**: This API can be used in atomic services since API version 12.
4093
4094**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4095
4096**Parameters**
4097
4098| Name  | Type                                                        | Mandatory| Description                                                    |
4099| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4100| type     | string                                                       | Yes  | Event type, which is **'playNext'** in this case.   |
4101
4102**Error codes**
4103
4104For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4105
4106| ID| Error Message|
4107| -------- | ---------------- |
4108| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4109| 6600101  | Session service exception. |
4110
4111**Example**
4112
4113```ts
4114aVCastController.off('playNext');
4115```
4116
4117### on('playPrevious')<sup>10+</sup>
4118
4119on(type: 'playPrevious', callback: Callback\<void>): void
4120
4121Subscribes to playPrevious command events.
4122
4123**Atomic service API**: This API can be used in atomic services since API version 12.
4124
4125**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4126
4127**Parameters**
4128
4129| Name  | Type                                                        | Mandatory| Description                                                        |
4130| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4131| type     | string                                                       | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.|
4132| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4133
4134**Error codes**
4135
4136For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4137
4138| ID| Error Message|
4139| -------- | ------------------------------ |
4140| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4141| 6600101  | Session service exception. |
4142
4143**Example**
4144
4145```ts
4146aVCastController.on('playPrevious', () => {
4147  console.info('on playPrevious');
4148});
4149```
4150
4151### off('playPrevious')<sup>10+</sup>
4152
4153off(type: 'playPrevious'): void
4154
4155Unsubscribes from playPrevious command events.
4156
4157**Atomic service API**: This API can be used in atomic services since API version 12.
4158
4159**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4160
4161**Parameters**
4162
4163| Name  | Type                                                        | Mandatory| Description                                                    |
4164| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4165| type     | string                                                       | Yes  | Event type, which is **'playPrevious'** in this case.   |
4166
4167**Error codes**
4168
4169For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4170
4171| ID| Error Message|
4172| -------- | ---------------- |
4173| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4174| 6600101  | Session service exception. |
4175
4176**Example**
4177
4178```ts
4179aVCastController.off('playPrevious');
4180```
4181
4182### on('requestPlay')<sup>11+</sup>
4183
4184on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
4185
4186Subscribes to playback request events.
4187
4188**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4189
4190**Parameters**
4191
4192| Name  | Type                                                        | Mandatory| Description                                                        |
4193| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4194| type     | string                                                       | Yes  | Event type. The event **'requestPlay'** is triggered when a playback request is received.|
4195| callback | (state: [AVQueueItem](#avqueueitem10)) => void               | Yes  | Callback used for subscription. **AVQueueItem** is the media asset that is being played. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
4196
4197**Error codes**
4198
4199For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4200
4201| ID| Error Message|
4202| -------- | ------------------------------ |
4203| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4204| 6600101  | Session service exception. |
4205
4206**Example**
4207
4208```ts
4209aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
4210  console.info(`on requestPlay state : ${item.itemId}`);
4211});
4212```
4213
4214### off('requestPlay')<sup>11+</sup>
4215
4216off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void
4217
4218Unsubscribes from playback request events.
4219
4220**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4221
4222**Parameters**
4223
4224| Name  | Type                                                        | Mandatory| Description                                                    |
4225| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4226| type     | string                                                      | Yes  | Event type, which is **'requestPlay'** in this case.   |
4227| callback | (state: [AVQueueItem](#avqueueitem10)) => void              | No  | Callback used for unsubscription. **AVQueueItem** is the media asset that is being played. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
4228
4229**Error codes**
4230
4231For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4232
4233| ID| Error Message|
4234| -------- | ---------------- |
4235| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4236| 6600101  | Session service exception. |
4237
4238**Example**
4239
4240```ts
4241aVCastController.off('requestPlay');
4242```
4243
4244### on('endOfStream')<sup>11+</sup>
4245
4246on(type: 'endOfStream', callback: Callback\<void>): void
4247
4248Subscribes to playback end events.
4249
4250**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4251
4252**Parameters**
4253
4254| Name  | Type                                                        | Mandatory| Description                                                        |
4255| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ |
4256| type     | string                                                      | Yes  | Event type. The event **'endOfStream'** is triggered when the playback operation is complete.|
4257| callback | Callback\<void\>                                            | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.     |
4258
4259**Error codes**
4260
4261For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4262
4263| ID| Error Message|
4264| -------- | ------------------------------ |
4265| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4266| 6600101  | Session service exception. |
4267
4268**Example**
4269
4270```ts
4271aVCastController.on('endOfStream', () => {
4272  console.info('on endOfStream');
4273});
4274```
4275
4276### off('endOfStream')<sup>11+</sup>
4277
4278off(type: 'endOfStream', callback?: Callback\<void>): void
4279
4280Unsubscribes from the playback end events.
4281
4282**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4283
4284**Parameters**
4285
4286| Name  | Type                                                        | Mandatory| Description                                                    |
4287| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4288| type     | string                                                      | Yes  | Event type, which is **'endOfStream'** in this case.   |
4289| callback | Callback\<void\>                                            | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.  |
4290
4291**Error codes**
4292
4293For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4294
4295| ID| Error Message|
4296| -------- | ---------------- |
4297| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4298| 6600101  | Session service exception. |
4299
4300**Example**
4301
4302```ts
4303aVCastController.off('endOfStream');
4304```
4305
4306### on('seekDone')<sup>10+</sup>
4307
4308on(type: 'seekDone', callback: Callback\<number>): void
4309
4310Subscribes to seek done events.
4311
4312**Atomic service API**: This API can be used in atomic services since API version 12.
4313
4314**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4315
4316**Parameters**
4317
4318| Name  | Type                                                        | Mandatory| Description                                                        |
4319| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4320| type     | string                                                       | Yes  | Event type. The event **'seekDone'** is triggered when the seek operation is complete.|
4321| callback | Callback\<number\>         | Yes  | Callback used to return the position after the seek operation.                     |
4322
4323**Error codes**
4324
4325For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4326
4327| ID| Error Message|
4328| -------- | ------------------------------ |
4329| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4330| 6600101  | Session service exception. |
4331
4332**Example**
4333
4334```ts
4335aVCastController.on('seekDone', (pos: number) => {
4336  console.info(`on seekDone pos: ${pos} `);
4337});
4338```
4339
4340### off('seekDone')<sup>10+</sup>
4341
4342off(type: 'seekDone'): void
4343
4344Unsubscribes from the seek done events.
4345
4346**Atomic service API**: This API can be used in atomic services since API version 12.
4347
4348**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4349
4350**Parameters**
4351
4352| Name  | Type                                                        | Mandatory| Description                                                    |
4353| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4354| type     | string                                                       | Yes  | Event type, which is **'seekDone'** in this case.   |
4355
4356**Error codes**
4357
4358For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4359
4360| ID| Error Message|
4361| -------- | ---------------- |
4362| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4363| 6600101  | Session service exception. |
4364
4365**Example**
4366
4367```ts
4368aVCastController.off('seekDone');
4369```
4370
4371### on('validCommandChange')<sup>11+</sup>
4372
4373on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
4374
4375Subscribes to valid command change events.
4376
4377**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4378
4379**Parameters**
4380
4381| Name  | Type                                                        | Mandatory| Description                                                        |
4382| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4383| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
4384| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\>   | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
4385
4386**Error codes**
4387
4388For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4389
4390| ID| Error Message|
4391| -------- | ------------------------------ |
4392| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4393| 6600101  | Session service exception. |
4394| 6600103  | The session controller does not exist. |
4395
4396**Example**
4397
4398```ts
4399aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
4400  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
4401  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
4402});
4403```
4404
4405### off('validCommandChange')<sup>11+</sup>
4406
4407off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>)
4408
4409Unsubscribes from valid command change events. This API is called by the controller.
4410
4411**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4412
4413**Parameters**
4414
4415| Name  | Type                                                        | Mandatory| Description                                                       |
4416| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
4417| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
4418| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | No  | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.         |
4419
4420**Error codes**
4421
4422For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4423
4424| ID| Error Message          |
4425| -------- | ---------------- |
4426| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4427| 6600101  | Session service exception. |
4428| 6600103  | The session controller does not exist. |
4429
4430**Example**
4431
4432```ts
4433aVCastController.off('validCommandChange');
4434```
4435
4436### on('error')<sup>10+</sup>
4437
4438on(type: 'error', callback: ErrorCallback): void
4439
4440Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control.
4441
4442**Atomic service API**: This API can be used in atomic services since API version 12.
4443
4444**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4445
4446**Parameters**
4447
4448| Name  | Type    | Mandatory| Description                                                        |
4449| -------- | -------- | ---- | ------------------------------------------------------------ |
4450| type     | string   | Yes  | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.|
4451| callback | ErrorCallback | Yes  | Callback used to return the error code ID and error message.|
4452
4453**Error codes**
4454
4455For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4456
4457| ID| Error Message             |
4458| -------- | --------------------- |
4459| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4460| 5400101  | No memory.            |
4461| 5400102  | Operation not allowed.   |
4462| 5400103  | I/O error.             |
4463| 5400104  | Time out.      |
4464| 5400105  | Service died.         |
4465| 5400106  | Unsupport format.     |
4466| 6600101  | Session service exception.     |
4467
4468**Example**
4469
4470```ts
4471import { BusinessError } from '@kit.BasicServicesKit';
4472
4473aVCastController.on('error', (error: BusinessError) => {
4474  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
4475})
4476```
4477
4478### off('error')<sup>10+</sup>
4479
4480off(type: 'error'): void
4481
4482Unsubscribes from remote AVPlayer errors.
4483
4484**Atomic service API**: This API can be used in atomic services since API version 12.
4485
4486**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4487
4488**Parameters**
4489
4490| Name| Type  | Mandatory| Description                                     |
4491| ------ | ------ | ---- | ----------------------------------------- |
4492| type   | string | Yes  | Event type, which is **'error'** in this case.|
4493
4494**Error codes**
4495
4496For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4497
4498| ID| Error Message             |
4499| -------- | --------------------- |
4500| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4501| 5400101  | No memory.            |
4502| 5400102  | Operation not allowed.   |
4503| 5400103  | I/O error.             |
4504| 5400104  | Time out.      |
4505| 5400105  | Service died.         |
4506| 5400106  | Unsupport format.     |
4507| 6600101  | Session service exception.     |
4508
4509**Example**
4510
4511```ts
4512aVCastController.off('error')
4513```
4514
4515### on('keyRequest')<sup>12+</sup>
4516
4517on(type: 'keyRequest', callback: KeyRequestCallback): void
4518
4519Subscribes to media key requests during the cast of online DRM resources.
4520
4521**Atomic service API**: This API can be used in atomic services since API version 12.
4522
4523**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4524
4525**Parameters**
4526
4527| Name| Type  | Mandatory| Description                                     |
4528| ------ | ------ | ---- | ----------------------------------------- |
4529| type     | string  | Yes  | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources.|
4530| callback | [KeyRequestCallback](#keyrequestcallback12)  | Yes  | Callback used to request the media resources and media key.|
4531
4532
4533**Error codes**
4534
4535For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4536
4537| ID| Error Message          |
4538| -------- | ---------------- |
4539| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4540| 6600101  | Session service exception. |
4541
4542**Example**
4543
4544```ts
4545let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4546  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4547}
4548aVCastController.on('keyRequest', keyRequestCallback);
4549```
4550### off('keyRequest')<sup>12+</sup>
4551
4552off(type: 'keyRequest', callback?: KeyRequestCallback): void
4553
4554Unsubscribes from media key requests during the cast of online DRM resources.
4555
4556**Atomic service API**: This API can be used in atomic services since API version 12.
4557
4558**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4559
4560**Parameters**
4561
4562| Name| Type  | Mandatory| Description                                     |
4563| ------ | ------ | ---- | ----------------------------------------- |
4564| type     | string                                                       | Yes  | Event type, which is **'keyRequest'** in this case.|
4565| callback |  [KeyRequestCallback](#keyrequestcallback12)  | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
4566
4567**Error codes**
4568
4569For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
4570
4571| ID| Error Message          |
4572| -------- | ---------------- |
4573| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4574| 6600101  | Session service exception. |
4575
4576**Example**
4577
4578```ts
4579aVCastController.off('keyRequest');
4580```
4581## KeyRequestCallback<sup>12+</sup>
4582type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void
4583
4584Describes the callback invoked for the media key request event.
4585
4586**Atomic service API**: This API can be used in atomic services since API version 12.
4587
4588**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4589
4590**Parameters**
4591
4592| Name| Type  | Mandatory| Description                                     |
4593| ------ | ------ | ---- | ----------------------------------------- |
4594| assetId     | string  | Yes  | Media asset ID.|
4595| requestData |  Uint8Array  | Yes  | Data carried in the media key request.                           |
4596
4597**Example**
4598<!--code_no_check-->
4599```ts
4600let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4601  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4602}
4603```
4604
4605### on('castControlGenericError')<sup>13+</sup>
4606
4607on(type: 'castControlGenericError', callback: ErrorCallback): void
4608
4609Subscribes to generic error events during cast control.
4610
4611**Atomic service API**: This API can be used in atomic services since API version 13.
4612
4613**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4614
4615**Parameters**
4616
4617| Name  | Type    | Mandatory| Description                                                        |
4618| -------- | -------- | ---- | ------------------------------------------------------------ |
4619| type     | string   | Yes  | Event type, which is **'castControlGenericError'** in this case.|
4620| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4621
4622**Error codes**
4623
4624| ID| Error Message             |
4625| -------- | --------------------- |
4626| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4627| 6611000  | The error code for cast control is unspecified.      |
4628| 6611001  | An unspecified error occurs in the remote player.   |
4629| 6611002  | The playback position falls behind the live window.     |
4630| 6611003  | The process of cast control times out.    |
4631| 6611004  | The runtime check failed.      |
4632| 6611100  | Cross-device data transmission is locked.    |
4633| 6611101  | The specified seek mode is not supported.   |
4634| 6611102  | The position to seek to is out of the range of the media asset or the specified seek mode is not supported.  |
4635| 6611103  | The specified playback mode is not supported.       |
4636| 6611104  | The specified playback speed is not supported.    |
4637| 6611105  | The action failed because either the media source device or the media sink device has been revoked.   |
4638| 6611106  | The parameter is invalid, for example, the url is illegal to play.  |
4639| 6611107  | Allocation of memory failed.  |
4640| 6611108  | Operation is not allowed.    |
4641
4642**Example**
4643
4644```ts
4645aVCastController.on('castControlGenericError', (error: BusinessError) => {
4646  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
4647})
4648```
4649
4650### off('castControlGenericError')<sup>13+</sup>
4651
4652off(type: 'castControlGenericError', callback?: ErrorCallback): void
4653
4654Unsubscribes from generic error events during cast control.
4655
4656**Atomic service API**: This API can be used in atomic services since API version 13.
4657
4658**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4659
4660**Parameters**
4661
4662| Name  | Type    | Mandatory| Description                                                        |
4663| -------- | -------- | ---- | ------------------------------------------------------------ |
4664| type     | string   | Yes  | 	Event type, which is **'castControlGenericError'** in this case.|
4665| 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.|
4666
4667**Error codes**
4668
4669| ID| Error Message             |
4670| -------- | --------------------- |
4671| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4672
4673**Example**
4674
4675```ts
4676aVCastController.off('castControlGenericError');
4677```
4678
4679### on('castControlIoError')<sup>13+</sup>
4680
4681on(type: 'castControlIoError', callback: ErrorCallback): void
4682
4683Subscribes to input/output error events during cast control.
4684
4685**Atomic service API**: This API can be used in atomic services since API version 13.
4686
4687**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4688
4689**Parameters**
4690
4691| Name  | Type    | Mandatory| Description                                                        |
4692| -------- | -------- | ---- | ------------------------------------------------------------ |
4693| type     | string   | Yes  | Event type, which is **'castControlIoError'** in this case.|
4694| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4695
4696**Error codes**
4697
4698| ID| Error Message             |
4699| -------- | --------------------- |
4700| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4701| 6612000  | An unspecified input/output error occurs.     |
4702| 6612001  | Network connection failure.   |
4703| 6612002  | Network timeout.     |
4704| 6612003  | Invalid "Content-Type" HTTP header.    |
4705| 6612004  | The HTTP server returns an unexpected HTTP response status code.      |
4706| 6612005  | The file does not exist.    |
4707| 6612006  | No permission is granted to perform the IO operation.   |
4708| 6612007  | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. |
4709| 6612008  | Reading data out of the data bound.    |
4710| 6612100  | The media does not contain any contents that can be played.   |
4711| 6612101  | The media cannot be read, for example, because of dust or scratches.   |
4712| 6612102  | This resource is already in use. |
4713| 6612103  | The content using the validity interval has expired.  |
4714| 6612104  | Using the requested content to play is not allowed.    |
4715| 6612105  | The use of the allowed content cannot be verified.  |
4716| 6612106  | The number of times this content has been used as requested has reached the maximum allowed number of uses.  |
4717| 6612107  | An error occurs when sending packet from source device to sink device.    |
4718
4719**Example**
4720
4721```ts
4722aVCastController.on('castControlIoError', (error: BusinessError) => {
4723  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
4724})
4725```
4726
4727### off('castControlIoError')<sup>13+</sup>
4728
4729off(type: 'castControlIoError', callback?: ErrorCallback): void
4730
4731Unsubscribes from input/output error events during cast control.
4732
4733**Atomic service API**: This API can be used in atomic services since API version 13.
4734
4735**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4736
4737**Parameters**
4738
4739| Name  | Type    | Mandatory| Description                                                        |
4740| -------- | -------- | ---- | ------------------------------------------------------------ |
4741| type     | string   | Yes  | 	Event type, which is **'castControlIoError'** in this case.|
4742| 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.|
4743
4744**Error codes**
4745
4746| ID| Error Message             |
4747| -------- | --------------------- |
4748| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4749
4750**Example**
4751
4752```ts
4753aVCastController.off('castControlIoError');
4754```
4755
4756### on('castControlParsingError')<sup>13+</sup>
4757
4758on(type: 'castControlParsingError', callback: ErrorCallback): void
4759
4760Subscribes to parsing error events during cast control.
4761
4762**Atomic service API**: This API can be used in atomic services since API version 13.
4763
4764**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4765
4766**Parameters**
4767
4768| Name  | Type    | Mandatory| Description                                                        |
4769| -------- | -------- | ---- | ------------------------------------------------------------ |
4770| type     | string   | Yes  | Event type, which is **'castControlParsingError'** in this case.|
4771| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4772
4773**Error codes**
4774
4775| ID | Error Message             |
4776| -------- | --------------------- |
4777| 401      |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4778| 6613000  | Unspecified error related to content parsing.     |
4779| 6613001  | Parsing error associated with media container format bit streams.   |
4780| 6613002  | Parsing error associated with the media manifest.     |
4781| 6613003  | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.    |
4782| 6613004  | Unsupported feature in the media manifest.    |
4783
4784**Example**
4785
4786```ts
4787aVCastController.on('castControlParsingError', (error: BusinessError) => {
4788  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
4789})
4790```
4791
4792### off('castControlParsingError')<sup>13+</sup>
4793
4794off(type: 'castControlParsingError', callback?: ErrorCallback): void
4795
4796Unsubscribes from parsing error events during cast control.
4797
4798**Atomic service API**: This API can be used in atomic services since API version 13.
4799
4800**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4801
4802**Parameters**
4803
4804| Name  | Type    | Mandatory| Description                                                        |
4805| -------- | -------- | ---- | ------------------------------------------------------------ |
4806| type     | string   | Yes  | 	Event type, which is **'castControlParsingError'** in this case.|
4807| 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.|
4808
4809**Error codes**
4810
4811| ID| Error Message             |
4812| -------- | --------------------- |
4813| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4814
4815**Example**
4816
4817```ts
4818aVCastController.off('castControlParsingError');
4819```
4820
4821### on('castControlDecodingError')<sup>13+</sup>
4822
4823on(type: 'castControlDecodingError', callback: ErrorCallback): void
4824
4825Subscribes to decoding error events during cast control.
4826
4827**Atomic service API**: This API can be used in atomic services since API version 13.
4828
4829**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4830
4831**Parameters**
4832
4833| Name  | Type    | Mandatory| Description                                                        |
4834| -------- | -------- | ---- | ------------------------------------------------------------ |
4835| type     | string   | Yes  | Event type, which is **'castControlDecodingError'** in this case.|
4836| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4837
4838**Error codes**
4839
4840| ID| Error Message             |
4841| -------- | --------------------- |
4842| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4843| 6614000  | Unspecified decoding error.     |
4844| 6614001  | Decoder initialization failed.   |
4845| 6614002  | Decoder query failed.     |
4846| 6614003  | Decoding the media samples failed.    |
4847| 6614004  | The format of the content to decode exceeds the capabilities of the device.    |
4848| 6614005  | The format of the content to decode is not supported.    |
4849
4850**Example**
4851
4852```ts
4853aVCastController.on('castControlDecodingError', (error: BusinessError) => {
4854  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
4855})
4856```
4857### off('castControlDecodingError')<sup>13+</sup>
4858
4859off(type: 'castControlDecodingError', callback?: ErrorCallback): void
4860
4861Unsubscribes from decoding error events during cast control.
4862
4863**Atomic service API**: This API can be used in atomic services since API version 13.
4864
4865**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4866
4867**Parameters**
4868
4869| Name  | Type    | Mandatory| Description                                                        |
4870| -------- | -------- | ---- | ------------------------------------------------------------ |
4871| type     | string   | Yes  | 	Event type, which is **'castControlDecodingError'** in this case.|
4872| 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.|
4873
4874**Error codes**
4875
4876| ID| Error Message             |
4877| -------- | --------------------- |
4878| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4879
4880**Example**
4881
4882```ts
4883aVCastController.off('castControlDecodingError');
4884```
4885
4886### on('castControlAudioRendererError')<sup>13+</sup>
4887
4888on(type: 'castControlAudioRendererError', callback: ErrorCallback): void
4889
4890Subscribes to audio renderer error events during cast control.
4891
4892**Atomic service API**: This API can be used in atomic services since API version 13.
4893
4894**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4895
4896**Parameters**
4897
4898| Name  | Type    | Mandatory| Description                                                        |
4899| -------- | -------- | ---- | ------------------------------------------------------------ |
4900| type     | string   | Yes  | Event type, which is **'castControlAudioRendererError'** in this case.|
4901| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4902
4903**Error codes**
4904
4905For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
4906
4907| ID| Error Message             |
4908| -------- | --------------------- |
4909| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4910| 6615000  | Unspecified errors related to the audio renderer.     |
4911| 6615001  | Initializing the audio renderer failed.   |
4912| 6615002  | The audio renderer fails to write data.     |
4913
4914**Example**
4915
4916```ts
4917aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
4918  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
4919})
4920```
4921### off('castControlAudioRendererError')<sup>13+</sup>
4922
4923off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void
4924
4925Unsubscribes from audio renderer error events during cast control.
4926
4927**Atomic service API**: This API can be used in atomic services since API version 13.
4928
4929**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4930
4931**Parameters**
4932
4933| Name  | Type    | Mandatory| Description                                                        |
4934| -------- | -------- | ---- | ------------------------------------------------------------ |
4935| type     | string   | Yes  | 	Event type, which is **'castControlAudioRendererError'** in this case.|
4936| 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.|
4937
4938**Error codes**
4939
4940| ID| Error Message             |
4941| -------- | --------------------- |
4942| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4943
4944**Example**
4945
4946```ts
4947aVCastController.off('castControlAudioRendererError');
4948```
4949
4950### on('castControlDrmError')<sup>13+</sup>
4951
4952on(type: 'castControlDrmError', callback: ErrorCallback): void
4953
4954Subscribes to DRM error events during cast control.
4955
4956**Atomic service API**: This API can be used in atomic services since API version 13.
4957
4958**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4959
4960**Parameters**
4961
4962| Name  | Type    | Mandatory| Description                                                        |
4963| -------- | -------- | ---- | ------------------------------------------------------------ |
4964| type     | string   | Yes  | Event type, which is **'castControlDrmError'** in this case.|
4965| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
4966
4967**Error codes**
4968
4969| ID| Error Message             |
4970| -------- | --------------------- |
4971| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4972| 6616000  | Unspecified error related to DRM.     |
4973| 6616001  | The chosen DRM protection scheme is not supported by the device.  |
4974| 6615002  | Device provisioning failed.    |
4975| 6616003  | The DRM-protected content to play is incompatible.     |
4976| 6616004  | Failed to obtain a license.   |
4977| 6616005  | The operation is disallowed by the license policy.     |
4978| 6616006  | An error occurs in the DRM system.     |
4979| 6616007  | The device has revoked DRM privileges.   |
4980| 6616008  | The DRM license being loaded into the open DRM session has expired.      |
4981| 6616100  | An error occurs when the DRM processes the key response.     |
4982
4983**Example**
4984
4985```ts
4986aVCastController.on('castControlDrmError', (error: BusinessError) => {
4987  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
4988})
4989```
4990
4991### off('castControlDrmError')<sup>13+</sup>
4992
4993off(type: 'castControlDrmError', callback?: ErrorCallback): void
4994
4995Unsubscribes from DRM error events during cast control.
4996
4997**Atomic service API**: This API can be used in atomic services since API version 13.
4998
4999**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5000
5001**Parameters**
5002
5003| Name  | Type    | Mandatory| Description                                                        |
5004| -------- | -------- | ---- | ------------------------------------------------------------ |
5005| type     | string   | Yes  | 	Event type, which is **'castControlDrmError'** in this case.|
5006| 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.|
5007
5008**Error codes**
5009
5010| ID| Error Message             |
5011| -------- | --------------------- |
5012| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
5013
5014**Example**
5015
5016```ts
5017aVCastController.off('castControlDrmError');
5018```
5019
5020## CastDisplayState<sup>12+</sup>
5021
5022Enumerates the states of the cast display.
5023
5024**Atomic service API**: This API can be used in atomic services since API version 12.
5025
5026**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5027
5028| Name                       | Value  | Description        |
5029| --------------------------- | ---- | ----------- |
5030| STATE_OFF      | 1    | The device is disconnected, and the extended screen does not display any content.   |
5031| STATE_ON      | 2    | The device is connected, and the extended screen is available.|
5032
5033
5034## CastDisplayInfo<sup>12+</sup>
5035
5036Describes the information about the cast display in the case of extended screens.
5037
5038**Atomic service API**: This API can be used in atomic services since API version 12.
5039
5040**System capability**: SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5041
5042| Name           | Type                     | Read Only| Optional| Description                                                                 |
5043| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------|
5044| id            | number                  | No   | No   | ID of the cast display. The value must be an integer. |
5045| name     | string                  | No   | No   | Name of the cast display.          |
5046| state          | [CastDisplayState](#castdisplaystate12)          | No   | No   |State of the cast display.           |
5047| width          | number          | No   | No   | Screen width of the cast display, in px. The value must be an integer.         |
5048| height          | number          | No   | No   | Screen height of the cast display, in px. The value must be an integer.           |
5049
5050## ConnectionState<sup>10+</sup>
5051
5052Enumerates the connection states.
5053
5054**Atomic service API**: This API can be used in atomic services since API version 12.
5055
5056**System capability**: SystemCapability.Multimedia.AVSession.Core
5057
5058| Name                       | Value  | Description        |
5059| --------------------------- | ---- | ----------- |
5060| STATE_CONNECTING      | 0    | The device is connecting.   |
5061| STATE_CONNECTED      | 1    | The device is connected.|
5062| STATE_DISCONNECTED      | 6    | The device is disconnected.|
5063
5064## AVMetadata<sup>10+</sup>
5065
5066Describes the media metadata.
5067
5068**System capability**: SystemCapability.Multimedia.AVSession.Core
5069
5070| Name           | Type                     | Mandatory| Description                                                                 |
5071| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
5072| assetId         | string                  | Yes  | Media asset ID. It is the unique ID of a song and defined by the application.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                    |
5073| title           | string                  | No  | Title.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                                |
5074| artist          | string                  | No  | Artist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5075| author          | string                  | No  | Author.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5076| avQueueName<sup>12+</sup>       | string                  | No  | Playlist name.                                                              |
5077| avQueueId<sup>11+</sup>       | string                  | No  | Unique ID of the playlist.                                                              |
5078| avQueueImage<sup>11+</sup>    | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No  | Cover image of the playlist, which can be pixel data of an image or an image path (local path or Internet path).<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL. |
5079| album           | string                  | No  | Album name.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5080| writer          | string                  | No  | Writer.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5081| composer        | string                  | No  | composer.                                                               |
5082| duration        | number                  | No  | Media duration, in ms.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                 |
5083| mediaImage      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | No  | Pixel map or image path (local path or network path) of the image.<br>When the data type configured by running **setAVMetadata** is **PixelMap**, the data obtained by calling **getAVMetadata** is a pixel map. When the configured data type is **string**, the data obtained is a URL.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                            |
5084| publishDate     | Date                    | No  | Release date.                                                            |
5085| subtitle        | string                  | No  | Subtitle.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                               |
5086| description     | string                  | No  | Media description.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                              |
5087| lyric           | string                  | No  | Lyrics. The application needs to combine the lyrics into a string with less than or equal to 40960 bytes.<br>**NOTE**: The system supports lyrics in the simple LRC format. If the lyrics are not standard (for example, having duplicate timestamps), the lyrics fail to be parsed and cannot be displayed properly in the system.|
5088| previousAssetId | string                  | No  | ID of the previous media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                           |
5089| nextAssetId     | string                  | No  | ID of the next media asset.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                                           |
5090| filter<sup>11+</sup>        | number         | No  | Protocol supported by the media session. The default value is **TYPE_CAST_PLUS_STREAM**. For details, see [ProtocolType](#protocoltype11).<br>**Atomic service API**: This API can be used in atomic services since API version 12.                  |
5091| drmSchemes<sup>12+</sup>        | Array\<string>         | No  | DRM scheme supported by the media session. The value is the UUID of the DRM scheme.|
5092| skipIntervals<sup>11+</sup>  | [SkipIntervals](#skipintervals11)        | No  | Fast-forward or rewind interval supported by the media session. The default value is **SECONDS_15**, that is, 15 seconds.                           |
5093|displayTags<sup>11+</sup>     | number                           | No  | Display tags of the media asset. For details, see [DisplayTag](#displaytag11).                                                         |
5094
5095## AVMediaDescription<sup>10+</sup>
5096
5097Describes the attributes related to the media metadata in the playlist.
5098
5099**System capability**: SystemCapability.Multimedia.AVSession.Core
5100
5101| Name        | Type                   | Mandatory | Description                    |
5102| ------------ | ----------------------- | ---- | ----------------------- |
5103| assetId      | string                  | Yes  | Media ID in the playlist.<br>**Atomic service API**: This API can be used in atomic services since API version 12.         |
5104| 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.       |
5105| 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.     |
5106| 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.  |
5107| 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.|
5108| extras       | {[key: string]: Object}    | No  | Additional fields of the media asset in the playlist.    |
5109| 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.        |
5110| 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.        |
5111| 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.        |
5112| 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.        |
5113| 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.   |
5114| 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.        |
5115| 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.        |
5116| 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.        |
5117| 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.        |
5118| dataSrc<sup>12+</sup>     | media.AVDataSrcDescriptor        | No  | Descriptor of the data source in the playlist.        |
5119| drmScheme<sup>12+</sup>     | string        | No  | DRM scheme supported by the playlist. The value is the UUID of the DRM scheme.      |
5120| 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.        |
5121| 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.        |
5122| 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.        |
5123| 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.        |
5124|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.       |
5125
5126## AVQueueItem<sup>10+</sup>
5127
5128Describes the attributes of an item in the playlist.
5129
5130**Atomic service API**: This API can be used in atomic services since API version 12.
5131
5132**System capability**: SystemCapability.Multimedia.AVSession.Core
5133
5134| Name        | Type                                       | Mandatory| Description                       |
5135| ------------ | ------------------------------------------ | ---- | --------------------------- |
5136| itemId       | number                                     | Yes  | ID of an item in the playlist.         |
5137| description  | [AVMediaDescription](#avmediadescription10)  | No  | Media metadata of the item in the playlist.  |
5138
5139## AVPlaybackState<sup>10+</sup>
5140
5141Describes the information related to the media playback state.
5142
5143**System capability**: SystemCapability.Multimedia.AVSession.Core
5144
5145| Name        | Type                                 | Mandatory| Description    |
5146| ------------ | ------------------------------------- | ---- | ------- |
5147| state        | [PlaybackState](#playbackstate10)       | No  | Playback state.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5148| speed        | number                                | No  | Playback speed.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5149| position     | [PlaybackPosition](#playbackposition10) | No  | Playback position.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5150| bufferedTime | number                                | No  | Buffered time.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5151| loopMode     | [LoopMode](#loopmode10)                 | No  | Loop mode.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5152| 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.|
5153| 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.|
5154| volume<sup>10+</sup> | number                  | No  | Media volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5155| maxVolume<sup>11+</sup> | number                    | No  | Maximum volume.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
5156| 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.|
5157| duration<sup>11+</sup>     | number                   | No  | Duration of the media asset.|
5158| 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.|
5159| 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.|
5160| 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.|
5161
5162## PlaybackPosition<sup>10+</sup>
5163
5164Describes the information related to the playback position.
5165
5166**Atomic service API**: This API can be used in atomic services since API version 12.
5167
5168**System capability**: SystemCapability.Multimedia.AVSession.Core
5169
5170| Name       | Type  | Mandatory| Description              |
5171| ----------- | ------ | ---- | ------------------ |
5172| elapsedTime | number | Yes  | Elapsed time, in ms.|
5173| updateTime  | number | Yes  | Updated time, in ms.|
5174
5175## CallMetadata<sup>11+</sup>
5176
5177Defines the attributes related to call metadata.
5178
5179**Atomic service API**: This API can be used in atomic services since API version 12.
5180
5181**System capability**: SystemCapability.Multimedia.AVSession.Core
5182
5183| Name           | Type                     | Mandatory| Description                                                                 |
5184| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
5185| name            | string                  | No   | Name (alias) of the caller.   |
5186| phoneNumber     | string                  | No   | Phone number of the caller.           |
5187| avatar          | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)          | No   | Profile picture of the caller.           |
5188
5189## AVCallState<sup>11+</sup>
5190
5191Defines the attributes related to the call state.
5192
5193**Atomic service API**: This API can be used in atomic services since API version 12.
5194
5195**System capability**: SystemCapability.Multimedia.AVSession.Core
5196
5197| Name           | Type                     | Mandatory| Description                                                                 |
5198| --------------- |-------------------------  | ---- |---------------------------------------------------------------------|
5199| state           | [CallState](#callstate11)                 | Yes   | Call state.     |
5200| muted           | boolean                   | Yes   | Whether the microphone is muted.<br>**true**: The microphone is muted.<br>**false**: The microphone is not muted.|
5201
5202## CallState<sup>11+</sup>
5203
5204Enumerates the call states.
5205
5206**Atomic service API**: This API can be used in atomic services since API version 12.
5207
5208**System capability**: SystemCapability.Multimedia.AVSession.Core
5209
5210| Name                       | Value  | Description     |
5211| --------------------------  | ---- | -------- |
5212| CALL_STATE_IDLE             | 0    | The phone is idle.  |
5213| CALL_STATE_INCOMING         | 1    | The phone is ringing.    |
5214| CALL_STATE_ACTIVE           | 2    | The call is connected.    |
5215| CALL_STATE_DIALING          | 3    | The caller is dialing.    |
5216| CALL_STATE_WAITING          | 4    | The call is waiting for connection. |
5217| CALL_STATE_HOLDING          | 5    | The call is placed on hold.    |
5218| CALL_STATE_DISCONNECTING    | 6    | The call is disconnecting.    |
5219
5220## DisplayTag<sup>11+</sup>
5221
5222Enumerates the display tags of the media asset. The display tag is a special type identifier of the media audio source.
5223
5224**System capability**: SystemCapability.Multimedia.AVSession.Core
5225
5226| Name                       | Value  | Description          |
5227| --------------------------  | ---- | ------------ |
5228| TAG_AUDIO_VIVID             | 1    | AUDIO VIVID  |
5229
5230## AVCastCategory<sup>10+</sup>
5231
5232Enumerates the cast categories.
5233
5234**Atomic service API**: This API can be used in atomic services since API version 12.
5235
5236**System capability**: SystemCapability.Multimedia.AVSession.AVCast
5237
5238| Name                       | Value  | Description        |
5239| --------------------------- | ---- | ----------- |
5240| CATEGORY_LOCAL      | 0    | Local playback. The sound is played from the local device or a connected Bluetooth headset by default.    |
5241| CATEGORY_REMOTE      | 1    | Remote playback. The sound or images are played from a remote device. |
5242
5243## DeviceType<sup>10+</sup>
5244
5245Enumerates the output device types.
5246
5247**Atomic service API**: This API can be used in atomic services since API version 12.
5248
5249| Name                       | Value  | Description        |
5250| --------------------------- | ---- | ----------- |
5251| DEVICE_TYPE_LOCAL      | 0    | Local device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core|
5252| DEVICE_TYPE_BLUETOOTH      | 10   | Bluetooth device.<br>**System capability**: SystemCapability.Multimedia.AVSession.Core|
5253| DEVICE_TYPE_TV      | 2    | TV.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast|
5254| DEVICE_TYPE_SMART_SPEAKER      | 3   | Speaker.<br>**System capability**: SystemCapability.Multimedia.AVSession.AVCast|
5255
5256## DeviceInfo<sup>10+</sup>
5257
5258Describes the information related to the output device.
5259
5260| Name      | Type          | Mandatory| Description                  |
5261| ---------- | -------------- | ---- | ---------------------- |
5262| 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.|
5263| 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.|
5264| 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.|
5265| 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.|
5266| 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.|
5267| 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.|
5268| 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.|
5269| 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.|
5270
5271## OutputDeviceInfo<sup>10+</sup>
5272
5273Describes the information related to the output device.
5274
5275**Atomic service API**: This API can be used in atomic services since API version 12.
5276
5277**System capability**: SystemCapability.Multimedia.AVSession.Core
5278
5279| Name      | Type          | Mandatory| Description                  |
5280| ---------- | -------------- | ---- | ---------------------- |
5281| devices | Array\<DeviceInfo\> | Yes  | Output devices.   |
5282
5283## LoopMode<sup>10+</sup>
5284
5285Enumerates the loop modes of media playback.
5286
5287**Atomic service API**: This API can be used in atomic services since API version 12.
5288
5289**System capability**: SystemCapability.Multimedia.AVSession.Core
5290
5291| Name              | Value  | Description    |
5292| ------------------ | ---- | -------- |
5293| LOOP_MODE_SEQUENCE | 0    | Sequential playback.|
5294| LOOP_MODE_SINGLE   | 1    | Single loop.|
5295| LOOP_MODE_LIST     | 2    | Playlist loop.|
5296| LOOP_MODE_SHUFFLE  | 3    | Shuffle.|
5297| LOOP_MODE_CUSTOM<sup>11+</sup>   | 4    | Custom playback. |
5298
5299## PlaybackState<sup>10+</sup>
5300
5301Enumerates the media playback states.
5302
5303**Atomic service API**: This API can be used in atomic services since API version 12.
5304
5305**System capability**: SystemCapability.Multimedia.AVSession.Core
5306
5307| Name                       | Value  | Description        |
5308| --------------------------- | ---- | ----------- |
5309| PLAYBACK_STATE_INITIAL      | 0    | Initial.    |
5310| PLAYBACK_STATE_PREPARE      | 1    | Preparing. |
5311| PLAYBACK_STATE_PLAY         | 2    | Playing.    |
5312| PLAYBACK_STATE_PAUSE        | 3    | Paused.        |
5313| PLAYBACK_STATE_FAST_FORWARD | 4    | Fast-forwarding.        |
5314| PLAYBACK_STATE_REWIND       | 5    | Rewinded.        |
5315| PLAYBACK_STATE_STOP         | 6    | Stopped.        |
5316| PLAYBACK_STATE_COMPLETED    | 7    | Playback complete.    |
5317| PLAYBACK_STATE_RELEASED     | 8    | Released.        |
5318| PLAYBACK_STATE_ERROR        | 9    | Error.        |
5319| PLAYBACK_STATE_IDLE<sup>11+</sup>        | 10    | Idle.    |
5320| PLAYBACK_STATE_BUFFERING<sup>11+</sup>         | 11    | Buffering.  |
5321
5322## AVSessionController<sup>10+</sup>
5323
5324Through 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.
5325
5326### Attributes
5327
5328**Atomic service API**: This API can be used in atomic services since API version 12.
5329
5330**System capability**: SystemCapability.Multimedia.AVSession.Core
5331
5332| Name     | Type  | Readable| Writable| Description                                   |
5333| :-------- | :----- | :--- | :--- | :-------------------------------------- |
5334| sessionId | string | Yes  | No  | Unique session ID of the **AVSessionController** object.|
5335
5336
5337**Example**
5338
5339```ts
5340import { BusinessError } from '@kit.BasicServicesKit';
5341
5342let AVSessionController: avSession.AVSessionController;
5343avSession.createController(currentAVSession.sessionId).then((controller: avSession.AVSessionController) => {
5344  AVSessionController = controller;
5345}).catch((err: BusinessError) => {
5346  console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
5347});
5348```
5349
5350### getAVPlaybackState<sup>10+</sup>
5351
5352getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
5353
5354Obtains the remote playback state. This API uses an asynchronous callback to return the result.
5355
5356**System capability**: SystemCapability.Multimedia.AVSession.Core
5357
5358**Parameters**
5359
5360| Name   | Type                                                       | Mandatory| Description                                                        |
5361| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5362| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
5363
5364**Error codes**
5365
5366For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5367
5368| ID| Error Message|
5369| -------- | ---------------------------------------- |
5370| 6600101  | Session service exception. |
5371| 6600102  | The session does not exist. |
5372| 6600103  | The session controller does not exist. |
5373
5374**Example**
5375
5376```ts
5377import { BusinessError } from '@kit.BasicServicesKit';
5378
5379avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
5380  if (err) {
5381    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5382  } else {
5383    console.info('getAVPlaybackState : SUCCESS');
5384  }
5385});
5386```
5387
5388### getAVPlaybackState<sup>10+</sup>
5389
5390getAVPlaybackState(): Promise\<AVPlaybackState>
5391
5392Obtains the remote playback state. This API uses a promise to return the result.
5393
5394**Atomic service API**: This API can be used in atomic services since API version 12.
5395
5396**System capability**: SystemCapability.Multimedia.AVSession.Core
5397
5398**Return value**
5399
5400| Type                                                       | Description                                                        |
5401| --------- | ------------------------------------------------------------ |
5402| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state. |
5403
5404**Error codes**
5405
5406For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5407
5408| ID| Error Message|
5409| -------- | ---------------------------------------- |
5410| 6600101  | Session service exception. |
5411| 6600102  | The session does not exist. |
5412| 6600103  | The session controller does not exist. |
5413
5414**Example**
5415
5416```ts
5417import { BusinessError } from '@kit.BasicServicesKit';
5418
5419avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
5420  console.info('getAVPlaybackState : SUCCESS');
5421}).catch((err: BusinessError) => {
5422  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5423});
5424```
5425
5426### getAVMetadata<sup>10+</sup>
5427
5428getAVMetadata(): Promise\<AVMetadata>
5429
5430Obtains the session metadata. This API uses a promise to return the result.
5431
5432**Atomic service API**: This API can be used in atomic services since API version 12.
5433
5434**System capability**: SystemCapability.Multimedia.AVSession.Core
5435
5436**Return value**
5437
5438| Type                               | Description                         |
5439| ----------------------------------- | ----------------------------- |
5440| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.|
5441
5442**Error codes**
5443
5444For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5445
5446| ID| Error Message|
5447| -------- | ---------------------------------------- |
5448| 6600101  | Session service exception. |
5449| 6600102  | The session does not exist. |
5450| 6600103  | The session controller does not exist. |
5451
5452**Example**
5453
5454```ts
5455import { BusinessError } from '@kit.BasicServicesKit';
5456
5457avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
5458  console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5459}).catch((err: BusinessError) => {
5460  console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5461});
5462```
5463
5464### getAVMetadata<sup>10+</sup>
5465
5466getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
5467
5468Obtains the session metadata. This API uses an asynchronous callback to return the result.
5469
5470**System capability**: SystemCapability.Multimedia.AVSession.Core
5471
5472**Parameters**
5473
5474| Name  | Type                                     | Mandatory| Description                      |
5475| -------- | ----------------------------------------- | ---- | -------------------------- |
5476| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes  | Callback used to return the metadata obtained.|
5477
5478**Error codes**
5479
5480For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5481
5482| ID| Error Message|
5483| -------- | ---------------------------------------- |
5484| 6600101  | Session service exception. |
5485| 6600102  | The session does not exist. |
5486| 6600103  | The session controller does not exist. |
5487
5488**Example**
5489
5490```ts
5491import { BusinessError } from '@kit.BasicServicesKit';
5492
5493avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
5494  if (err) {
5495    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5496  } else {
5497    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5498  }
5499});
5500```
5501
5502### getAVQueueTitle<sup>10+</sup>
5503
5504getAVQueueTitle(): Promise\<string>
5505
5506Obtains the name of the playlist. This API uses a promise to return the result.
5507
5508**Atomic service API**: This API can be used in atomic services since API version 12.
5509
5510**System capability**: SystemCapability.Multimedia.AVSession.Core
5511
5512**Return value**
5513
5514| Type            | Description                          |
5515| ---------------- | ----------------------------- |
5516| Promise<string\> | Promise used to return the playlist name.|
5517
5518**Error codes**
5519
5520For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5521
5522| ID| Error Message|
5523| -------- | ---------------------------------------- |
5524| 6600101  | Session service exception. |
5525| 6600102  | The session does not exist. |
5526| 6600103  | The session controller does not exist. |
5527
5528**Example**
5529
5530```ts
5531import { BusinessError } from '@kit.BasicServicesKit';
5532
5533avsessionController.getAVQueueTitle().then((title: string) => {
5534  console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5535}).catch((err: BusinessError) => {
5536  console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5537});
5538```
5539
5540### getAVQueueTitle<sup>10+</sup>
5541
5542getAVQueueTitle(callback: AsyncCallback\<string>): void
5543
5544Obtains the name of the playlist. This API uses an asynchronous callback to return the result.
5545
5546**System capability**: SystemCapability.Multimedia.AVSession.Core
5547
5548**Parameters**
5549
5550| Name  | Type                   | Mandatory| Description                     |
5551| -------- | ---------------------- | ---- | ------------------------- |
5552| callback | AsyncCallback<string\> | Yes  | Callback used to return the playlist name.|
5553
5554**Error codes**
5555
5556For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5557
5558| ID| Error Message|
5559| -------- | ---------------------------------------- |
5560| 6600101  | Session service exception. |
5561| 6600102  | The session does not exist. |
5562| 6600103  | The session controller does not exist. |
5563
5564**Example**
5565
5566```ts
5567import { BusinessError } from '@kit.BasicServicesKit';
5568
5569avsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
5570  if (err) {
5571    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5572  } else {
5573    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5574  }
5575});
5576```
5577
5578### getAVQueueItems<sup>10+</sup>
5579
5580getAVQueueItems(): Promise\<Array\<AVQueueItem>>
5581
5582Obtains the information related to the items in the queue. This API uses a promise to return the result.
5583
5584**Atomic service API**: This API can be used in atomic services since API version 12.
5585
5586**System capability**: SystemCapability.Multimedia.AVSession.Core
5587
5588**Return value**
5589
5590| Type                                         | Description                          |
5591| --------------------------------------------- | ----------------------------- |
5592| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue.|
5593
5594**Error codes**
5595
5596For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5597
5598| ID| Error Message|
5599| -------- | ---------------------------------------- |
5600| 6600101  | Session service exception. |
5601| 6600102  | The session does not exist. |
5602| 6600103  | The session controller does not exist. |
5603
5604**Example**
5605
5606```ts
5607import { BusinessError } from '@kit.BasicServicesKit';
5608
5609avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
5610  console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5611}).catch((err: BusinessError) => {
5612  console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5613});
5614```
5615
5616### getAVQueueItems<sup>10+</sup>
5617
5618getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
5619
5620Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result.
5621
5622**System capability**: SystemCapability.Multimedia.AVSession.Core
5623
5624**Parameters**
5625
5626| Name  | Type                                                | Mandatory| Description                     |
5627| -------- | --------------------------------------------------- | ---- | ------------------------- |
5628| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes  | Callback used to return the items in the playlist.|
5629
5630**Error codes**
5631
5632For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5633
5634| ID| Error Message|
5635| -------- | ---------------------------------------- |
5636| 6600101  | Session service exception. |
5637| 6600102  | The session does not exist. |
5638| 6600103  | The session controller does not exist. |
5639
5640**Example**
5641
5642```ts
5643import { BusinessError } from '@kit.BasicServicesKit';
5644
5645avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
5646  if (err) {
5647    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5648  } else {
5649    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5650  }
5651});
5652```
5653
5654### skipToQueueItem<sup>10+</sup>
5655
5656skipToQueueItem(itemId: number): Promise\<void>
5657
5658Sends 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.
5659
5660**Atomic service API**: This API can be used in atomic services since API version 12.
5661
5662**System capability**: SystemCapability.Multimedia.AVSession.Core
5663
5664**Parameters**
5665
5666| Name | Type   | Mandatory| Description                                       |
5667| ------ | ------- | ---- | ------------------------------------------- |
5668| itemId | number  | Yes  | ID of an item in the playlist.|
5669
5670**Return value**
5671
5672| Type          | Description                                                            |
5673| -------------- | --------------------------------------------------------------- |
5674| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.|
5675
5676**Error codes**
5677
5678For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5679
5680| ID| Error Message|
5681| -------- | ---------------------------------------- |
5682| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5683| 6600101  | Session service exception. |
5684| 6600102  | The session does not exist. |
5685| 6600103  | The session controller does not exist. |
5686
5687**Example**
5688
5689```ts
5690import { BusinessError } from '@kit.BasicServicesKit';
5691
5692let queueItemId = 0;
5693avsessionController.skipToQueueItem(queueItemId).then(() => {
5694  console.info('SkipToQueueItem successfully');
5695}).catch((err: BusinessError) => {
5696  console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5697});
5698```
5699
5700### skipToQueueItem<sup>10+</sup>
5701
5702skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
5703
5704Sends 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.
5705
5706**System capability**: SystemCapability.Multimedia.AVSession.Core
5707
5708**Parameters**
5709
5710| Name   | Type                 | Mandatory| Description                                                       |
5711| -------- | --------------------- | ---- | ----------------------------------------------------------- |
5712| itemId   | number                | Yes  | ID of an item in the playlist.               |
5713| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
5714
5715**Error codes**
5716
5717For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5718
5719| ID| Error Message|
5720| -------- | ---------------------------------------- |
5721| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5722| 6600101  | Session service exception. |
5723| 6600102  | The session does not exist. |
5724| 6600103  | The session controller does not exist. |
5725
5726**Example**
5727
5728```ts
5729import { BusinessError } from '@kit.BasicServicesKit';
5730
5731let queueItemId = 0;
5732avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
5733  if (err) {
5734    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5735  } else {
5736    console.info('SkipToQueueItem successfully');
5737  }
5738});
5739```
5740
5741### getOutputDevice<sup>10+</sup>
5742
5743getOutputDevice(): Promise\<OutputDeviceInfo>
5744
5745Obtains the output device information. This API uses a promise to return the result.
5746
5747**Atomic service API**: This API can be used in atomic services since API version 12.
5748
5749**System capability**: SystemCapability.Multimedia.AVSession.Core
5750
5751**Return value**
5752
5753| Type                                           | Description                             |
5754| ----------------------------------------------- | --------------------------------- |
5755| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.|
5756
5757**Error codes**
5758
5759For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5760
5761| ID| Error Message|
5762| -------- | ---------------------------------------- |
5763| 600101  | Session service exception. |
5764| 600103  | The session controller does not exist. |
5765
5766**Example**
5767
5768```ts
5769import { BusinessError } from '@kit.BasicServicesKit';
5770
5771avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
5772  console.info('GetOutputDevice : SUCCESS');
5773}).catch((err: BusinessError) => {
5774  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5775});
5776```
5777
5778### getOutputDevice<sup>10+</sup>
5779
5780getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
5781
5782Obtains the output device information. This API uses an asynchronous callback to return the result.
5783
5784**System capability**: SystemCapability.Multimedia.AVSession.Core
5785
5786**Parameters**
5787
5788| Name  | Type                                                 | Mandatory| Description                          |
5789| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
5790| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
5791
5792**Error codes**
5793
5794For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5795
5796| ID| Error Message|
5797| -------- | ---------------------------------------- |
5798| 600101  | Session service exception. |
5799| 600103  | The session controller does not exist. |
5800
5801**Example**
5802
5803```ts
5804import { BusinessError } from '@kit.BasicServicesKit';
5805
5806avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
5807  if (err) {
5808    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5809  } else {
5810    console.info('GetOutputDevice : SUCCESS');
5811  }
5812});
5813```
5814
5815### sendAVKeyEvent<sup>10+</sup>
5816
5817sendAVKeyEvent(event: KeyEvent): Promise\<void>
5818
5819Sends a key event to the session corresponding to this controller. This API uses a promise to return the result.
5820
5821**Atomic service API**: This API can be used in atomic services since API version 12.
5822
5823**System capability**: SystemCapability.Multimedia.AVSession.Core
5824
5825**Parameters**
5826
5827| Name| Type                                                        | Mandatory| Description      |
5828| ------ | ------------------------------------------------------------ | ---- | ---------- |
5829| event  | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes  | Key event.|
5830
5831**Error codes**
5832
5833For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5834
5835| ID| Error Message|
5836| -------- | ---------------------------------------- |
5837| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5838| 600101  | Session service exception. |
5839| 600102  | The session does not exist. |
5840| 600103  | The session controller does not exist. |
5841| 600105  | Invalid session command. |
5842| 600106  | The session is not activated. |
5843
5844**Return value**
5845
5846| Type          | Description                         |
5847| -------------- | ----------------------------- |
5848| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
5849
5850**Example**
5851
5852```ts
5853import { Key, KeyEvent } from '@kit.InputKit';
5854import { BusinessError } from '@kit.BasicServicesKit';
5855
5856let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
5857let 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};
5858
5859
5860avsessionController.sendAVKeyEvent(event).then(() => {
5861  console.info('SendAVKeyEvent Successfully');
5862}).catch((err: BusinessError) => {
5863  console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5864});
5865```
5866
5867### sendAVKeyEvent<sup>10+</sup>
5868
5869sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
5870
5871Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.
5872
5873**System capability**: SystemCapability.Multimedia.AVSession.Core
5874
5875**Parameters**
5876
5877| Name  | Type                                                        | Mandatory| Description      |
5878| -------- | ------------------------------------------------------------ | ---- | ---------- |
5879| event    | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | Yes  | Key event.|
5880| callback | AsyncCallback\<void>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
5881
5882**Error codes**
5883
5884For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5885
5886| ID| Error Message|
5887| -------- | ---------------------------------------- |
5888| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5889| 600101  | Session service exception. |
5890| 600102  | The session does not exist. |
5891| 600103  | The session controller does not exist. |
5892| 600105  | Invalid session command. |
5893| 600106  | The session is not activated. |
5894
5895**Example**
5896
5897```ts
5898import { Key, KeyEvent } from '@kit.InputKit';
5899import { BusinessError } from '@kit.BasicServicesKit';
5900
5901let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
5902let 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};
5903avsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
5904  if (err) {
5905    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5906  } else {
5907    console.info('SendAVKeyEvent Successfully');
5908  }
5909});
5910```
5911
5912### getLaunchAbility<sup>10+</sup>
5913
5914getLaunchAbility(): Promise\<WantAgent>
5915
5916Obtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result.
5917
5918**Atomic service API**: This API can be used in atomic services since API version 12.
5919
5920**System capability**: SystemCapability.Multimedia.AVSession.Core
5921
5922**Return value**
5923
5924| Type                                                   | Description                                                        |
5925| ------------------------------------------------------- | ------------------------------------------------------------ |
5926| 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.|
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| 6600101  | Session service exception. |
5935| 6600102  | The session does not exist. |
5936| 6600103  | The session controller does not exist. |
5937
5938**Example**
5939
5940```ts
5941import { BusinessError } from '@kit.BasicServicesKit';
5942
5943avsessionController.getLaunchAbility().then((agent: object) => {
5944  console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
5945}).catch((err: BusinessError) => {
5946  console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5947});
5948```
5949
5950### getLaunchAbility<sup>10+</sup>
5951
5952getLaunchAbility(callback: AsyncCallback\<WantAgent>): void
5953
5954Obtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result.
5955
5956**System capability**: SystemCapability.Multimedia.AVSession.Core
5957
5958**Parameters**
5959
5960| Name  | Type                                                        | Mandatory| Description                                                        |
5961| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
5962| 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.|
5963
5964**Error codes**
5965
5966For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
5967
5968| ID| Error Message|
5969| -------- | ---------------------------------------- |
5970| 6600101  | Session service exception. |
5971| 6600102  | The session does not exist. |
5972| 6600103  | The session controller does not exist. |
5973
5974**Example**
5975
5976```ts
5977import { BusinessError } from '@kit.BasicServicesKit';
5978
5979avsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
5980  if (err) {
5981    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5982  } else {
5983    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
5984  }
5985});
5986```
5987
5988### getRealPlaybackPositionSync<sup>10+</sup>
5989
5990getRealPlaybackPositionSync(): number
5991
5992Obtains the playback position.
5993
5994**Atomic service API**: This API can be used in atomic services since API version 12.
5995
5996**System capability**: SystemCapability.Multimedia.AVSession.Core
5997
5998**Return value**
5999
6000| Type  | Description              |
6001| ------ | ------------------ |
6002| number | Playback position, in milliseconds.|
6003
6004**Error codes**
6005
6006For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6007
6008| ID| Error Message|
6009| -------- | ---------------------------------------- |
6010| 6600101  | Session service exception. |
6011| 6600103  | The session controller does not exist. |
6012
6013**Example**
6014
6015```ts
6016let time: number = avsessionController.getRealPlaybackPositionSync();
6017```
6018
6019### isActive<sup>10+</sup>
6020
6021isActive(): Promise\<boolean>
6022
6023Checks whether the session is activated. This API uses a promise to return the result.
6024
6025**Atomic service API**: This API can be used in atomic services since API version 12.
6026
6027**System capability**: SystemCapability.Multimedia.AVSession.Core
6028
6029**Return value**
6030
6031| Type             | Description                                                        |
6032| ----------------- | ------------------------------------------------------------ |
6033| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
6034
6035**Error codes**
6036
6037For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6038
6039| ID| Error Message|
6040| -------- | ---------------------------------------- |
6041| 6600101  | Session service exception. |
6042| 6600102  | The session does not exist. |
6043| 6600103  | The session controller does not exist. |
6044
6045**Example**
6046
6047```ts
6048import { BusinessError } from '@kit.BasicServicesKit';
6049
6050avsessionController.isActive().then((isActive: boolean) => {
6051  console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6052}).catch((err: BusinessError) => {
6053  console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6054});
6055```
6056
6057### isActive<sup>10+</sup>
6058
6059isActive(callback: AsyncCallback\<boolean>): void
6060
6061Checks whether the session is activated. This API uses an asynchronous callback to return the result.
6062
6063**System capability**: SystemCapability.Multimedia.AVSession.Core
6064
6065**Parameters**
6066
6067| Name  | Type                   | Mandatory| Description                                                        |
6068| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
6069| callback | AsyncCallback<boolean\> | Yes  | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
6070
6071**Error codes**
6072
6073For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6074
6075| ID| Error Message|
6076| -------- | ---------------------------------------- |
6077| 6600101  | Session service exception. |
6078| 6600102  | The session does not exist. |
6079| 6600103  | The session controller does not exist. |
6080
6081**Example**
6082
6083```ts
6084import { BusinessError } from '@kit.BasicServicesKit';
6085
6086avsessionController.isActive((err: BusinessError, isActive: boolean) => {
6087  if (err) {
6088    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6089  } else {
6090    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6091  }
6092});
6093```
6094
6095### destroy<sup>10+</sup>
6096
6097destroy(): Promise\<void>
6098
6099Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.
6100
6101**Atomic service API**: This API can be used in atomic services since API version 12.
6102
6103**System capability**: SystemCapability.Multimedia.AVSession.Core
6104
6105**Return value**
6106
6107| Type          | Description                         |
6108| -------------- | ----------------------------- |
6109| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.|
6110
6111**Error codes**
6112
6113For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6114
6115| ID| Error Message|
6116| -------- | ---------------------------------------- |
6117| 6600101  | Session service exception. |
6118| 6600103  | The session controller does not exist. |
6119
6120**Example**
6121
6122```ts
6123import { BusinessError } from '@kit.BasicServicesKit';
6124
6125avsessionController.destroy().then(() => {
6126  console.info('Destroy : SUCCESS ');
6127}).catch((err: BusinessError) => {
6128  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6129});
6130```
6131
6132### destroy<sup>10+</sup>
6133
6134destroy(callback: AsyncCallback\<void>): void
6135
6136Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.
6137
6138**System capability**: SystemCapability.Multimedia.AVSession.Core
6139
6140**Parameters**
6141
6142| Name  | Type                | Mandatory| Description      |
6143| -------- | -------------------- | ---- | ---------- |
6144| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
6145
6146**Error codes**
6147
6148For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6149
6150| ID| Error Message|
6151| -------- | ---------------------------------------- |
6152| 6600101  | Session service exception. |
6153| 6600103  | The session controller does not exist. |
6154
6155**Example**
6156
6157```ts
6158import { BusinessError } from '@kit.BasicServicesKit';
6159
6160avsessionController.destroy((err: BusinessError) => {
6161  if (err) {
6162    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6163  } else {
6164    console.info('Destroy : SUCCESS ');
6165  }
6166});
6167```
6168
6169### getValidCommands<sup>10+</sup>
6170
6171getValidCommands(): Promise\<Array\<AVControlCommandType>>
6172
6173Obtains valid commands supported by the session. This API uses a promise to return the result.
6174
6175**Atomic service API**: This API can be used in atomic services since API version 12.
6176
6177**System capability**: SystemCapability.Multimedia.AVSession.Core
6178
6179**Return value**
6180
6181| Type                                                        | Description                             |
6182| ------------------------------------------------------------ | --------------------------------- |
6183| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands.|
6184
6185**Error codes**
6186
6187For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6188
6189| ID| Error Message|
6190| -------- | ---------------------------------------- |
6191| 6600101  | Session service exception. |
6192| 6600102  | The session does not exist. |
6193| 6600103  | The session controller does not exist. |
6194
6195**Example**
6196
6197```ts
6198import { BusinessError } from '@kit.BasicServicesKit';
6199
6200avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
6201  console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6202}).catch((err: BusinessError) => {
6203  console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6204});
6205```
6206
6207### getValidCommands<sup>10+</sup>
6208
6209getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
6210
6211Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result.
6212
6213**System capability**: SystemCapability.Multimedia.AVSession.Core
6214
6215**Parameters**
6216
6217| Name  | Type                                                        | Mandatory| Description                          |
6218| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
6219| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes  | Callback used to return a set of valid commands.|
6220
6221**Error codes**
6222
6223For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6224
6225| ID| Error Message|
6226| -------- | ---------------------------------------- |
6227| 6600101  | Session service exception. |
6228| 6600102  | The session does not exist. |
6229| 6600103  | The session controller does not exist. |
6230
6231**Example**
6232
6233```ts
6234import { BusinessError } from '@kit.BasicServicesKit';
6235
6236avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
6237  if (err) {
6238    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6239  } else {
6240    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6241  }
6242});
6243```
6244
6245### sendControlCommand<sup>10+</sup>
6246
6247sendControlCommand(command: AVControlCommand): Promise\<void>
6248
6249Sends a control command to the session through the controller. This API uses a promise to return the result.
6250
6251> **NOTE**
6252>
6253> 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.
6254
6255**Atomic service API**: This API can be used in atomic services since API version 12.
6256
6257**System capability**: SystemCapability.Multimedia.AVSession.Core
6258
6259**Parameters**
6260
6261| Name   | Type                                 | Mandatory| Description                          |
6262| ------- | ------------------------------------- | ---- | ------------------------------ |
6263| command | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
6264
6265**Return value**
6266
6267| Type          | Description                         |
6268| -------------- | ----------------------------- |
6269| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
6270
6271**Error codes**
6272
6273For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6274
6275| ID| Error Message|
6276| -------- | ---------------------------------------- |
6277| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6278| 6600101  | Session service exception. |
6279| 6600102  | The session does not exist. |
6280| 6600103  | The session controller does not exist. |
6281| 6600105  | Invalid session command. |
6282| 6600106  | The session is not activated. |
6283| 6600107  | Too many commands or events. |
6284
6285**Example**
6286
6287```ts
6288import { BusinessError } from '@kit.BasicServicesKit';
6289
6290let avCommand: avSession.AVControlCommand = {command:'play'};
6291avsessionController.sendControlCommand(avCommand).then(() => {
6292  console.info('SendControlCommand successfully');
6293}).catch((err: BusinessError) => {
6294  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6295});
6296```
6297
6298### sendControlCommand<sup>10+</sup>
6299
6300sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
6301
6302Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
6303
6304> **NOTE**
6305>
6306> 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.
6307
6308**System capability**: SystemCapability.Multimedia.AVSession.Core
6309
6310**Parameters**
6311
6312| Name  | Type                                 | Mandatory| Description                          |
6313| -------- | ------------------------------------- | ---- | ------------------------------ |
6314| command  | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
6315| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
6316
6317**Error codes**
6318
6319For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6320
6321| ID| Error Message|
6322| -------- | ------------------------------- |
6323| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6324| 6600101  | Session service exception.                |
6325| 6600102  | The session does not exist.     |
6326| 6600103  | The session controller does not exist.   |
6327| 6600105  | Invalid session command.           |
6328| 6600106  | The session is not activated.                |
6329| 6600107  | Too many commands or events.      |
6330
6331**Example**
6332
6333```ts
6334import { BusinessError } from '@kit.BasicServicesKit';
6335
6336let avCommand: avSession.AVControlCommand = {command:'play'};
6337avsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
6338  if (err) {
6339    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6340  } else {
6341    console.info('SendControlCommand successfully');
6342  }
6343});
6344```
6345
6346### sendCommonCommand<sup>10+</sup>
6347
6348sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void>
6349
6350Sends a custom control command to the session through the controller. This API uses a promise to return the result.
6351
6352**Atomic service API**: This API can be used in atomic services since API version 12.
6353
6354**System capability**: SystemCapability.Multimedia.AVSession.Core
6355
6356**Parameters**
6357
6358| Name   | Type                                 | Mandatory| Description                          |
6359| ------- | ------------------------------------- | ---- | ------------------------------ |
6360| command | string | Yes  | Name of the custom control command.|
6361| args | {[key: string]: Object} | Yes  | Parameters in key-value pair format carried in the custom control command.|
6362
6363> **NOTE**
6364> 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).
6365
6366**Return value**
6367
6368| Type          | Description                         |
6369| -------------- | ----------------------------- |
6370| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
6371
6372**Error codes**
6373
6374For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6375
6376| ID| Error Message|
6377| -------- | ---------------------------------------- |
6378| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6379| 6600101  | Session service exception. |
6380| 6600102  | The session does not exist. |
6381| 6600103  | The session controller does not exist. |
6382| 6600105  | Invalid session command. |
6383| 6600106  | The session is not activated. |
6384| 6600107  | Too many commands or events. |
6385
6386**Example**
6387
6388```ts
6389import { BusinessError } from '@kit.BasicServicesKit';
6390
6391let avSessionController: avSession.AVSessionController | undefined = undefined;
6392let currentAVSession: avSession.AVSession | undefined = undefined;
6393let tag = "createNewSession";
6394let context: Context = getContext(this);
6395let sessionId: string = "";
6396avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6397  if (err) {
6398    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6399  } else {
6400    currentAVSession = data;
6401  }
6402});
6403if (currentAVSession !== undefined) {
6404  sessionId = (currentAVSession as avSession.AVSession).sessionId;
6405  avSession.createController(sessionId).then((controller: avSession.AVSessionController) => {
6406    avSessionController = controller;
6407  }).catch((err: BusinessError) => {
6408    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6409  });
6410}
6411
6412let commandName = "my_command";
6413if (avSessionController !== undefined) {
6414  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
6415    console.info('SendCommonCommand successfully');
6416  }).catch((err: BusinessError) => {
6417    console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6418  })
6419}
6420```
6421
6422### sendCommonCommand<sup>10+</sup>
6423
6424sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
6425
6426Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result.
6427
6428**System capability**: SystemCapability.Multimedia.AVSession.Core
6429
6430**Parameters**
6431
6432| Name   | Type                                 | Mandatory| Description                          |
6433| ------- | ------------------------------------- | ---- | ------------------------------ |
6434| command | string | Yes  | Name of the custom control command.|
6435| args | {[key: string]: Object} | Yes  | Parameters in key-value pair format carried in the custom control command.|
6436| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
6437
6438> **NOTE**
6439> 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).
6440
6441**Error codes**
6442
6443For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6444
6445| ID| Error Message|
6446| -------- | ------------------------------- |
6447| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.|
6448| 6600101  | Session service exception.                |
6449| 6600102  | The session does not exist.     |
6450| 6600103  | The session controller does not exist.   |
6451| 6600105  | Invalid session command.           |
6452| 6600106  | The session is not activated.                |
6453| 6600107  | Too many commands or events.      |
6454
6455**Example**
6456
6457```ts
6458import { BusinessError } from '@kit.BasicServicesKit';
6459let avSessionController: avSession.AVSessionController | undefined = undefined;
6460let currentAVSession: avSession.AVSession | undefined = undefined;
6461let tag = "createNewSession";
6462let context: Context = getContext(this);
6463
6464avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6465  if (err) {
6466    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6467  } else {
6468    currentAVSession = data;
6469  }
6470});
6471if (currentAVSession !== undefined) {
6472  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6473    avSessionController = controller;
6474  }).catch((err: BusinessError) => {
6475    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6476  });
6477}
6478
6479let commandName = "my_command";
6480if (avSessionController !== undefined) {
6481  (avSessionController as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
6482    if (err) {
6483        console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6484    }
6485  })
6486}
6487```
6488
6489### getExtras<sup>10+</sup>
6490
6491getExtras(): Promise\<{[key: string]: Object}>
6492
6493Obtains the custom media packet set by the provider. This API uses a promise to return the result.
6494
6495**Atomic service API**: This API can be used in atomic services since API version 12.
6496
6497**System capability**: SystemCapability.Multimedia.AVSession.Core
6498
6499**Return value**
6500
6501| Type                               | Description                         |
6502| ----------------------------------- | ----------------------------- |
6503| 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**.|
6504
6505**Error codes**
6506
6507For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6508
6509| ID| Error Message|
6510| -------- | ---------------------------------------- |
6511| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6512| 6600101  | Session service exception. |
6513| 6600102  | The session does not exist. |
6514| 6600103  | The session controller does not exist. |
6515| 6600105  | Invalid session command. |
6516| 6600107  | Too many commands or events. |
6517
6518**Example**
6519
6520```ts
6521import { BusinessError } from '@kit.BasicServicesKit';
6522
6523let avSessionController: avSession.AVSessionController | undefined = undefined;
6524let currentAVSession: avSession.AVSession | undefined = undefined;
6525let tag = "createNewSession";
6526let context: Context = getContext(this);
6527
6528avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6529  if (err) {
6530    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6531  } else {
6532    currentAVSession = data;
6533  }
6534});
6535if (currentAVSession !== undefined) {
6536  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6537    avSessionController = controller;
6538  }).catch((err: BusinessError) => {
6539    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6540  });
6541}
6542
6543if (avSessionController !== undefined) {
6544  (avSessionController as avSession.AVSessionController).getExtras().then((extras) => {
6545    console.info(`getExtras : SUCCESS : ${extras}`);
6546  }).catch((err: BusinessError) => {
6547    console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6548  });
6549}
6550```
6551
6552### getExtras<sup>10+</sup>
6553
6554getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
6555
6556Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result.
6557
6558**System capability**: SystemCapability.Multimedia.AVSession.Core
6559
6560**Parameters**
6561
6562| Name  | Type                                     | Mandatory| Description                      |
6563| -------- | ----------------------------------------- | ---- | -------------------------- |
6564| 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**.|
6565
6566**Error codes**
6567
6568For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6569
6570| ID| Error Message|
6571| -------- | ---------------------------------------- |
6572| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6573| 6600101  | Session service exception. |
6574| 6600102  | The session does not exist. |
6575| 6600103  | The session controller does not exist. |
6576| 6600105  | Invalid session command. |
6577| 6600107  | Too many commands or events. |
6578
6579**Example**
6580
6581```ts
6582import { BusinessError } from '@kit.BasicServicesKit';
6583
6584let avSessionController: avSession.AVSessionController | undefined = undefined;
6585let currentAVSession: avSession.AVSession | undefined = undefined;
6586let tag = "createNewSession";
6587let context: Context = getContext(this);
6588
6589avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
6590  if (err) {
6591    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
6592  } else {
6593    currentAVSession = data;
6594  }
6595});
6596if (currentAVSession !== undefined) {
6597  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
6598    avSessionController = controller;
6599  }).catch((err: BusinessError) => {
6600    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
6601  });
6602}
6603
6604if (avSessionController !== undefined) {
6605  (avSessionController as avSession.AVSessionController).getExtras((err, extras) => {
6606    if (err) {
6607      console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6608    } else {
6609      console.info(`getExtras : SUCCESS : ${extras}`);
6610    }
6611  });
6612}
6613```
6614
6615### on('metadataChange')<sup>10+</sup>
6616
6617on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
6618
6619Subscribes to metadata change events.
6620
6621**Atomic service API**: This API can be used in atomic services since API version 12.
6622
6623**System capability**: SystemCapability.Multimedia.AVSession.Core
6624
6625**Parameters**
6626
6627| Name  | Type                                                        | Mandatory| Description                                                        |
6628| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6629| type     | string                                                       | Yes  | Event type. The event **'metadataChange'** is triggered when the session metadata changes.|
6630| 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.|
6631| callback | (data: [AVMetadata](#avmetadata10)) => void                    | Yes  | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.                        |
6632
6633**Error codes**
6634
6635For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6636
6637| ID| Error Message|
6638| -------- | ------------------------------ |
6639| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6640| 6600101  | Session service exception. |
6641| 6600103  | The session controller does not exist. |
6642
6643**Example**
6644
6645```ts
6646avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
6647  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6648});
6649
6650avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
6651  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6652});
6653
6654```
6655
6656### off('metadataChange')<sup>10+</sup>
6657
6658off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
6659
6660Unsubscribes from metadata change events. This API is called by the controller.
6661
6662**Atomic service API**: This API can be used in atomic services since API version 12.
6663
6664**System capability**: SystemCapability.Multimedia.AVSession.Core
6665
6666**Parameters**
6667
6668| Name  | Type                                              | Mandatory| Description                                                   |
6669| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
6670| type     | string                                           | Yes  | Event type, which is **'metadataChange'** in this case.        |
6671| 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.                        |
6672
6673**Error codes**
6674
6675For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6676
6677| ID| Error Message|
6678| -------- | ---------------- |
6679| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6680| 6600101  | Session service exception. |
6681| 6600103  | The session controller does not exist. |
6682
6683**Example**
6684
6685```ts
6686avsessionController.off('metadataChange');
6687```
6688
6689### on('playbackStateChange')<sup>10+</sup>
6690
6691on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
6692
6693Subscribes to playback state change events.
6694
6695**Atomic service API**: This API can be used in atomic services since API version 12.
6696
6697**System capability**: SystemCapability.Multimedia.AVSession.Core
6698
6699**Parameters**
6700
6701| Name  | Type      | Mandatory| Description     |
6702| --------| -----------|-----|------------|
6703| type     | string    | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
6704| 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.|
6705| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.|
6706
6707**Error codes**
6708
6709For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6710
6711| ID| Error Message|
6712| -------- | ------------------------------ |
6713| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6714| 6600101  | Session service exception. |
6715| 6600103  | The session controller does not exist. |
6716
6717**Example**
6718
6719```ts
6720avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
6721  console.info(`on playbackStateChange state : ${playbackState.state}`);
6722});
6723
6724avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
6725  console.info(`on playbackStateChange state : ${playbackState.state}`);
6726});
6727```
6728
6729### off('playbackStateChange')<sup>10+</sup>
6730
6731off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
6732
6733Unsubscribes from playback state change events. This API is called by the controller.
6734
6735**Atomic service API**: This API can be used in atomic services since API version 12.
6736
6737**System capability**: SystemCapability.Multimedia.AVSession.Core
6738
6739**Parameters**
6740
6741| Name  | Type                                                        | Mandatory| Description                                                    |
6742| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
6743| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
6744| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | No  | Callback used for unsubscription. The **state** parameter in the callback indicates the changed 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.                     |
6745
6746**Error codes**
6747
6748For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6749
6750| ID| Error Message|
6751| -------- | ---------------- |
6752| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6753| 6600101  | Session service exception. |
6754| 6600103  | The session controller does not exist. |
6755
6756**Example**
6757
6758```ts
6759avsessionController.off('playbackStateChange');
6760```
6761
6762### on('callMetadataChange')<sup>11+</sup>
6763
6764on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void;
6765
6766Subscribes to call metadata change events.
6767
6768**Atomic service API**: This API can be used in atomic services since API version 12.
6769
6770**System capability**: SystemCapability.Multimedia.AVSession.Core
6771
6772**Parameters**
6773
6774| Name  | Type      | Mandatory| Description     |
6775| --------| -----------|-----|------------|
6776| type     | string    | Yes  | Event type. The event **'callMetadataChange'** is triggered when the call metadata changes.|
6777| 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.|
6778| callback | Callback<[CallMetadata](#callmetadata11)\>\>   | Yes  | Callback used for subscription. The **callmetadata** parameter in the callback indicates the changed call metadata.|
6779
6780**Error codes**
6781
6782For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6783
6784| ID| Error Message|
6785| -------- | ------------------------------ |
6786| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6787| 6600101  | Session service exception. |
6788| 6600103  | The session controller does not exist. |
6789
6790**Example**
6791
6792```ts
6793avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
6794  console.info(`on callMetadataChange state : ${callmetadata.name}`);
6795});
6796
6797avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
6798  console.info(`on callMetadataChange state : ${callmetadata.name}`);
6799});
6800```
6801
6802### off('callMetadataChange')<sup>11+</sup>
6803
6804off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void;
6805
6806Unsubscribes from call metadata change events.
6807
6808**Atomic service API**: This API can be used in atomic services since API version 12.
6809
6810**System capability**: SystemCapability.Multimedia.AVSession.Core
6811
6812**Parameters**
6813
6814| Name  | Type                                                        | Mandatory| Description                                                    |
6815| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
6816| type     | string                                                       | Yes  | Event type, which is **'callMetadataChange'** in this case.   |
6817| 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.     |
6818
6819**Error codes**
6820
6821For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6822
6823| ID| Error Message|
6824| -------- | ---------------- |
6825| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6826| 6600101  | Session service exception. |
6827| 6600103  | The session controller does not exist. |
6828
6829**Example**
6830
6831```ts
6832avsessionController.off('callMetadataChange');
6833```
6834
6835### on('callStateChange')<sup>11+</sup>
6836
6837on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void;
6838
6839Subscribes to call state change events.
6840
6841**Atomic service API**: This API can be used in atomic services since API version 12.
6842
6843**System capability**: SystemCapability.Multimedia.AVSession.Core
6844
6845**Parameters**
6846
6847| Name  | Type      | Mandatory| Description     |
6848| --------| -----------|-----|------------|
6849| type     | string    | Yes  | Event type. The event **'callStateChange'** is triggered when the call state changes.|
6850| 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.|
6851| callback | Callback<[AVCallState](#avcallstate11)\>       | Yes  | Callback used for subscription. The **callstate** parameter in the callback indicates the changed call state.|
6852
6853**Error codes**
6854
6855For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6856
6857| ID| Error Message|
6858| -------- | ------------------------------ |
6859| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6860| 6600101  | Session service exception. |
6861| 6600103  | The session controller does not exist. |
6862
6863**Example**
6864
6865```ts
6866avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
6867  console.info(`on callStateChange state : ${callstate.state}`);
6868});
6869
6870avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
6871  console.info(`on callStateChange state : ${callstate.state}`);
6872});
6873```
6874
6875### off('callStateChange')<sup>11+</sup>
6876
6877off(type: 'callStateChange', callback?: Callback\<AVCallState>): void;
6878
6879Unsubscribes from call state change events.
6880
6881**Atomic service API**: This API can be used in atomic services since API version 12.
6882
6883**System capability**: SystemCapability.Multimedia.AVSession.Core
6884
6885**Parameters**
6886
6887| Name  | Type                                                        | Mandatory| Description                                                    |
6888| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
6889| type     | string                                                       | Yes  | Event type, which is **'callStateChange'** in this case.   |
6890| callback | Callback<[AVCallState](#avcallstate11)\>           | No  | Callback used for unsubscription. The **callstate** 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.     |
6891
6892**Error codes**
6893
6894For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6895
6896| ID| Error Message|
6897| -------- | ---------------- |
6898| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6899| 6600101  | Session service exception. |
6900| 6600103  | The session controller does not exist. |
6901
6902**Example**
6903
6904```ts
6905avsessionController.off('callMetadataChange');
6906```
6907
6908### on('sessionDestroy')<sup>10+</sup>
6909
6910on(type: 'sessionDestroy', callback: () => void)
6911
6912Subscribes to session destruction events.
6913
6914**Atomic service API**: This API can be used in atomic services since API version 12.
6915
6916**System capability**: SystemCapability.Multimedia.AVSession.Core
6917
6918**Parameters**
6919
6920| Name  | Type      | Mandatory| Description                                                        |
6921| -------- | ---------- | ---- | ------------------------------------------------------------ |
6922| type     | string     | Yes  | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.|
6923| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                 |
6924
6925**Error codes**
6926
6927For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6928
6929| ID| Error Message|
6930| -------- | ------------------------------ |
6931| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6932| 6600101  | Session service exception. |
6933| 6600103  | The session controller does not exist. |
6934
6935**Example**
6936
6937```ts
6938avsessionController.on('sessionDestroy', () => {
6939  console.info('on sessionDestroy : SUCCESS ');
6940});
6941```
6942
6943### off('sessionDestroy')<sup>10+</sup>
6944
6945off(type: 'sessionDestroy', callback?: () => void)
6946
6947Unsubscribes from session destruction events. This API is called by the controller.
6948
6949**Atomic service API**: This API can be used in atomic services since API version 12.
6950
6951**System capability**: SystemCapability.Multimedia.AVSession.Core
6952
6953**Parameters**
6954
6955| Name  | Type      | Mandatory| Description                                                     |
6956| -------- | ---------- | ---- | ----------------------------------------------------- |
6957| type     | string     | Yes  | Event type, which is **'sessionDestroy'** in this case.        |
6958| 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.                                              |
6959
6960**Error codes**
6961
6962For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6963
6964| ID| Error Message|
6965| -------- | ---------------- |
6966| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6967| 6600101  | Session service exception. |
6968| 6600103  | The session controller does not exist. |
6969
6970**Example**
6971
6972```ts
6973avsessionController.off('sessionDestroy');
6974```
6975
6976### on('activeStateChange')<sup>10+</sup>
6977
6978on(type: 'activeStateChange', callback: (isActive: boolean) => void)
6979
6980Subscribes to session activation state change events.
6981
6982**Atomic service API**: This API can be used in atomic services since API version 12.
6983
6984**System capability**: SystemCapability.Multimedia.AVSession.Core
6985
6986**Parameters**
6987
6988| Name  | Type                       | Mandatory| Description                                                        |
6989| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
6990| type     | string                      | Yes  | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes.|
6991| 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.                  |
6992
6993**Error codes**
6994
6995For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
6996
6997| ID| Error Message|
6998| -------- | ----------------------------- |
6999| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7000| 6600101  | Session service exception. |
7001| 6600103  |The session controller does not exist. |
7002
7003**Example**
7004
7005```ts
7006avsessionController.on('activeStateChange', (isActive: boolean) => {
7007  console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
7008});
7009```
7010
7011### off('activeStateChange')<sup>10+</sup>
7012
7013off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
7014
7015Unsubscribes from session activation state change events. This API is called by the controller.
7016
7017**Atomic service API**: This API can be used in atomic services since API version 12.
7018
7019**System capability**: SystemCapability.Multimedia.AVSession.Core
7020
7021**Parameters**
7022
7023| Name  | Type                       | Mandatory| Description                                                     |
7024| -------- | --------------------------- | ---- | ----------------------------------------------------- |
7025| type     | string                      | Yes  | Event type, which is **'activeStateChange'** in this case.     |
7026| 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.                  |
7027
7028**Error codes**
7029
7030For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7031
7032| ID| Error Message|
7033| -------- | ---------------- |
7034| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7035| 6600101  | Session service exception. |
7036| 6600103  | The session controller does not exist. |
7037
7038**Example**
7039
7040```ts
7041avsessionController.off('activeStateChange');
7042```
7043
7044### on('validCommandChange')<sup>10+</sup>
7045
7046on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
7047
7048Subscribes to valid command change events.
7049
7050**Atomic service API**: This API can be used in atomic services since API version 12.
7051
7052**System capability**: SystemCapability.Multimedia.AVSession.Core
7053
7054**Parameters**
7055
7056| Name  | Type                                                        | Mandatory| Description                                                        |
7057| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7058| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
7059| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
7060
7061**Error codes**
7062
7063For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7064
7065| ID| Error Message|
7066| -------- | ------------------------------ |
7067| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7068| 6600101  | Session service exception. |
7069| 6600103  | The session controller does not exist. |
7070
7071**Example**
7072
7073```ts
7074avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
7075  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
7076  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
7077});
7078```
7079
7080### off('validCommandChange')<sup>10+</sup>
7081
7082off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
7083
7084Unsubscribes from valid command change events. This API is called by the controller.
7085
7086**Atomic service API**: This API can be used in atomic services since API version 12.
7087
7088**System capability**: SystemCapability.Multimedia.AVSession.Core
7089
7090**Parameters**
7091
7092| Name  | Type                                                        | Mandatory| Description                                                       |
7093| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
7094| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
7095| 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.         |
7096
7097**Error codes**
7098
7099For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7100
7101| ID| Error Message          |
7102| -------- | ---------------- |
7103| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7104| 6600101  | Session service exception. |
7105| 6600103  | The session controller does not exist. |
7106
7107**Example**
7108
7109```ts
7110avsessionController.off('validCommandChange');
7111```
7112
7113### on('outputDeviceChange')<sup>10+</sup>
7114
7115on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7116
7117Subscribes to output device change events.
7118
7119**Atomic service API**: This API can be used in atomic services since API version 12.
7120
7121**System capability**: SystemCapability.Multimedia.AVSession.Core
7122
7123**Parameters**
7124
7125| Name  | Type                                                   | Mandatory| Description                                                        |
7126| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
7127| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
7128| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.                        |
7129
7130**Error codes**
7131
7132For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7133
7134| ID| Error Message|
7135| -------- | ----------------------- |
7136| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7137| 6600101  | Session service exception. |
7138| 6600103  | The session controller does not exist. |
7139
7140**Example**
7141
7142```ts
7143avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
7144  console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
7145});
7146```
7147
7148### off('outputDeviceChange')<sup>10+</sup>
7149
7150off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7151
7152Unsubscribes from output device change events. This API is called by the controller.
7153
7154**Atomic service API**: This API can be used in atomic services since API version 12.
7155
7156**System capability**: SystemCapability.Multimedia.AVSession.Core
7157
7158**Parameters**
7159
7160| Name  | Type                                                   | Mandatory| Description                                                     |
7161| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
7162| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.     |
7163| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | No  | Callback used for unsubscription. The **device** parameter in the callback indicates 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.                        |
7164
7165**Error codes**
7166
7167For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7168
7169| ID | Error Message         |
7170| -------- | ---------------- |
7171| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7172| 6600101  | Session service exception. |
7173| 6600103  | The session controller does not exist. |
7174
7175**Example**
7176
7177```ts
7178avsessionController.off('outputDeviceChange');
7179```
7180
7181### on('sessionEvent')<sup>10+</sup>
7182
7183on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7184
7185Subscribes to session event change events. This API is called by the controller.
7186
7187**Atomic service API**: This API can be used in atomic services since API version 12.
7188
7189**System capability**: SystemCapability.Multimedia.AVSession.Core
7190
7191**Parameters**
7192
7193| Name  | Type                                                        | Mandatory| Description                                                        |
7194| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7195| type     | string                                                       | Yes  | Event type. The event **'sessionEvent'** is triggered when the session event changes.|
7196| 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.         |
7197
7198**Error codes**
7199
7200For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7201
7202| ID| Error Message|
7203| -------- | ------------------------------ |
7204| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7205| 6600101  | Session service exception. |
7206| 6600103  | The session controller does not exist. |
7207
7208**Example**
7209
7210```ts
7211import { BusinessError } from '@kit.BasicServicesKit';
7212
7213let avSessionController: avSession.AVSessionController | undefined = undefined;
7214let currentAVSession: avSession.AVSession | undefined = undefined;
7215let tag = "createNewSession";
7216let context: Context = getContext(this);
7217
7218avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
7219  if (err) {
7220    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
7221  } else {
7222    currentAVSession = data;
7223  }
7224});
7225if (currentAVSession !== undefined) {
7226  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
7227    avSessionController = controller;
7228  }).catch((err: BusinessError) => {
7229    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
7230  });
7231}
7232
7233if (avSessionController !== undefined) {
7234  (avSessionController as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => {
7235    console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
7236  });
7237}
7238```
7239
7240### off('sessionEvent')<sup>10+</sup>
7241
7242off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7243
7244Unsubscribes from session event change events. This API is called by the controller.
7245
7246**Atomic service API**: This API can be used in atomic services since API version 12.
7247
7248**System capability**: SystemCapability.Multimedia.AVSession.Core
7249
7250**Parameters**
7251
7252| Name  | Type                                                        | Mandatory| Description                                                    |
7253| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7254| type     | string                                                       | Yes  | Event type, which is **'sessionEvent'** in this case.   |
7255| 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.                     |
7256
7257**Error codes**
7258
7259For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7260
7261| ID| Error Message|
7262| -------- | ---------------- |
7263| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7264| 6600101  | Session service exception. |
7265| 6600103  | The session controller does not exist. |
7266
7267**Example**
7268
7269```ts
7270avsessionController.off('sessionEvent');
7271```
7272
7273### on('queueItemsChange')<sup>10+</sup>
7274
7275on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7276
7277Subscribes to playlist item change events. This API is called by the controller.
7278
7279**Atomic service API**: This API can be used in atomic services since API version 12.
7280
7281**System capability**: SystemCapability.Multimedia.AVSession.Core
7282
7283**Parameters**
7284
7285| Name  | Type                                                  | Mandatory| Description                                                                        |
7286| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
7287| type     | string                                                | Yes  | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.|
7288| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void  | Yes  | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist.                           |
7289
7290**Error codes**
7291
7292For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7293
7294| ID| Error Message|
7295| -------- | ------------------------------ |
7296| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7297| 6600101  | Session service exception. |
7298| 6600103  | The session controller does not exist. |
7299
7300**Example**
7301
7302```ts
7303avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
7304  console.info(`OnQueueItemsChange, items length is ${items.length}`);
7305});
7306```
7307
7308### off('queueItemsChange')<sup>10+</sup>
7309
7310off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7311
7312Unsubscribes from playback item change events. This API is called by the controller.
7313
7314**Atomic service API**: This API can be used in atomic services since API version 12.
7315
7316**System capability**: SystemCapability.Multimedia.AVSession.Core
7317
7318**Parameters**
7319
7320| Name   | Type                                                | Mandatory| Description                                                                                               |
7321| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- |
7322| type     | string                                               | Yes  | Event type, which is **'queueItemsChange'** in this case.                                                    |
7323| 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.|
7324
7325**Error codes**
7326
7327For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7328
7329| ID| Error Message|
7330| -------- | ---------------- |
7331| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7332| 6600101  | Session service exception. |
7333| 6600103  | The session controller does not exist. |
7334
7335**Example**
7336
7337```ts
7338avsessionController.off('queueItemsChange');
7339```
7340
7341### on('queueTitleChange')<sup>10+</sup>
7342
7343on(type: 'queueTitleChange', callback: (title: string) => void): void
7344
7345Subscribes to playlist name change events. This API is called by the controller.
7346
7347**Atomic service API**: This API can be used in atomic services since API version 12.
7348
7349**System capability**: SystemCapability.Multimedia.AVSession.Core
7350
7351**Parameters**
7352
7353| Name  | Type                    | Mandatory| Description                                                                            |
7354| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- |
7355| type     | string                  | Yes  | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.|
7356| callback | (title: string) => void | Yes  | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name.                               |
7357
7358**Error codes**
7359
7360For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7361
7362| ID| Error Message|
7363| -------- | ------------------------------ |
7364| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7365| 6600101  | Session service exception. |
7366| 6600103  | The session controller does not exist. |
7367
7368**Example**
7369
7370```ts
7371avsessionController.on('queueTitleChange', (title: string) => {
7372  console.info(`queueTitleChange, title is ${title}`);
7373});
7374```
7375
7376### off('queueTitleChange')<sup>10+</sup>
7377
7378off(type: 'queueTitleChange', callback?: (title: string) => void): void
7379
7380Unsubscribes from playlist name change events. This API is called by the controller.
7381
7382**Atomic service API**: This API can be used in atomic services since API version 12.
7383
7384**System capability**: SystemCapability.Multimedia.AVSession.Core
7385
7386**Parameters**
7387
7388| Name   | Type                   | Mandatory| Description                                                                                                   |
7389| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7390| type     | string                  | Yes  | Event type, which is **'queueTitleChange'** in this case.                                                        |
7391| 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.|
7392
7393**Error codes**
7394
7395For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7396
7397| ID| Error Message|
7398| -------- | ---------------- |
7399| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7400| 6600101  | Session service exception. |
7401| 6600103  | The session controller does not exist. |
7402
7403**Example**
7404
7405```ts
7406avsessionController.off('queueTitleChange');
7407```
7408
7409### on('extrasChange')<sup>10+</sup>
7410
7411on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void
7412
7413Subscribes to custom media packet change events. This API is called by the controller.
7414
7415**Atomic service API**: This API can be used in atomic services since API version 12.
7416
7417**System capability**: SystemCapability.Multimedia.AVSession.Core
7418
7419**Parameters**
7420
7421| Name  | Type                                                        | Mandatory| Description                                                        |
7422| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7423| type     | string                                                       | Yes  | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.|
7424| 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**.         |
7425
7426**Error codes**
7427
7428For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7429
7430| ID| Error Message|
7431| -------- | ------------------------------ |
7432| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7433| 6600101  | Session service exception. |
7434| 6600103  | The session controller does not exist. |
7435
7436**Example**
7437
7438```ts
7439import { BusinessError } from '@kit.BasicServicesKit';
7440
7441let avSessionController: avSession.AVSessionController | undefined = undefined;
7442let currentAVSession: avSession.AVSession | undefined = undefined;
7443let tag = "createNewSession";
7444let context: Context = getContext(this);
7445
7446avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
7447  if (err) {
7448    console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
7449  } else {
7450    currentAVSession = data;
7451  }
7452});
7453if (currentAVSession !== undefined) {
7454  avSession.createController((currentAVSession as avSession.AVSession).sessionId).then((controller: avSession.AVSessionController) => {
7455    avSessionController = controller;
7456  }).catch((err: BusinessError) => {
7457    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
7458  });
7459}
7460
7461if (avSessionController !== undefined) {
7462  (avSessionController as avSession.AVSessionController).on('extrasChange', (extras) => {
7463    console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
7464  });
7465}
7466```
7467
7468### off('extrasChange')<sup>10+</sup>
7469
7470off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void
7471
7472Unsubscribes from custom media packet change events. This API is called by the controller.
7473
7474**Atomic service API**: This API can be used in atomic services since API version 12.
7475
7476**System capability**: SystemCapability.Multimedia.AVSession.Core
7477
7478**Parameters**
7479
7480| Name   | Type                   | Mandatory| Description                                                                                                   |
7481| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7482| type     | string                  | Yes  | Event type, which is **'extrasChange'** in this case.                                                        |
7483| 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.|
7484
7485**Error codes**
7486
7487For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7488
7489| ID| Error Message|
7490| -------- | ----------------                       |
7491| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7492| 6600101  | Session service exception.             |
7493| 6600103  | The session controller does not exist. |
7494
7495**Example**
7496
7497```ts
7498avsessionController.off('extrasChange');
7499```
7500
7501### getAVPlaybackStateSync<sup>10+</sup>
7502
7503getAVPlaybackStateSync(): AVPlaybackState;
7504
7505Obtains the playback state of this session. This API returns the result synchronously.
7506
7507**Atomic service API**: This API can be used in atomic services since API version 12.
7508
7509**System capability**: SystemCapability.Multimedia.AVSession.Core
7510
7511**Return value**
7512
7513| Type                                                       | Description                                                        |
7514| --------- | ------------------------------------------------------------ |
7515| [AVPlaybackState](#avplaybackstate10)  | Playback state of the session.|
7516
7517**Error codes**
7518
7519For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7520
7521| ID| Error Message|
7522| -------- | ---------------------------------------- |
7523| 6600101  | Session service exception. |
7524| 6600102  | The session does not exist. |
7525| 6600103  | The session controller does not exist. |
7526
7527**Example**
7528
7529```ts
7530import { BusinessError } from '@kit.BasicServicesKit';
7531
7532try {
7533  let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync();
7534} catch (err) {
7535  let error = err as BusinessError;
7536  console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`);
7537}
7538```
7539
7540### getAVMetadataSync<sup>10+</sup>
7541
7542getAVMetadataSync(): AVMetadata
7543
7544Obtains the session metadata. This API returns the result synchronously.
7545
7546**Atomic service API**: This API can be used in atomic services since API version 12.
7547
7548**System capability**: SystemCapability.Multimedia.AVSession.Core
7549
7550**Return value**
7551
7552| Type                               | Description                         |
7553| ----------------------------------- | ----------------------------- |
7554| [AVMetadata](#avmetadata10) | Session metadata.|
7555
7556**Error codes**
7557
7558For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7559
7560| ID| Error Message|
7561| -------- | ---------------------------------------- |
7562| 6600101  | Session service exception. |
7563| 6600102  | The session does not exist. |
7564| 6600103  | The session controller does not exist. |
7565
7566**Example**
7567```ts
7568import { BusinessError } from '@kit.BasicServicesKit';
7569
7570try {
7571  let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync();
7572} catch (err) {
7573  let error = err as BusinessError;
7574  console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`);
7575}
7576```
7577
7578### getAVCallState<sup>11+</sup>
7579
7580getAVCallState(): Promise\<AVCallState>
7581
7582Obtains the call state. This API uses a promise to return the result.
7583
7584**System capability**: SystemCapability.Multimedia.AVSession.Core
7585
7586**Return value**
7587
7588| Type                               | Description                         |
7589| ----------------------------------- | ----------------------------- |
7590| Promise<[AVCallState](#avcallstate11)\> | Promise used to return the call state obtained.|
7591
7592**Error codes**
7593
7594For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7595
7596| ID| Error Message|
7597| -------- | ---------------------------------------- |
7598| 6600101  | Session service exception. |
7599| 6600102  | The session does not exist. |
7600| 6600103  | The session controller does not exist. |
7601
7602**Example**
7603
7604```ts
7605import { BusinessError } from '@kit.BasicServicesKit';
7606
7607avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => {
7608  console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7609}).catch((err: BusinessError) => {
7610  console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7611});
7612```
7613
7614### getAVCallState<sup>11+</sup>
7615
7616getAVCallState(callback: AsyncCallback\<AVCallState>): void
7617
7618Obtains the call state. This API uses an asynchronous callback to return the result.
7619
7620**System capability**: SystemCapability.Multimedia.AVSession.Core
7621
7622**Parameters**
7623
7624| Name  | Type                                     | Mandatory| Description                      |
7625| -------- | ----------------------------------------- | ---- | -------------------------- |
7626| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | Yes  | Callback used to return the call state obtained.|
7627
7628**Error codes**
7629
7630For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7631
7632| ID| Error Message|
7633| -------- | ---------------------------------------- |
7634| 6600101  | Session service exception. |
7635| 6600102  | The session does not exist. |
7636| 6600103  | The session controller does not exist. |
7637
7638**Example**
7639
7640```ts
7641import { BusinessError } from '@kit.BasicServicesKit';
7642
7643avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
7644  if (err) {
7645    console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7646  } else {
7647    console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7648  }
7649});
7650```
7651
7652### getCallMetadata<sup>11+</sup>
7653
7654getCallMetadata(): Promise\<CallMetadata>
7655
7656Obtains the call metadata. This API uses a promise to return the result.
7657
7658**System capability**: SystemCapability.Multimedia.AVSession.Core
7659
7660**Return value**
7661
7662| Type                               | Description                         |
7663| ----------------------------------- | ----------------------------- |
7664| Promise<[CallMetadata](#callmetadata11)\> | Promise used to return the metadata obtained.|
7665
7666**Error codes**
7667
7668For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7669
7670| ID| Error Message|
7671| -------- | ---------------------------------------- |
7672| 6600101  | Session service exception. |
7673| 6600102  | The session does not exist. |
7674| 6600103  | The session controller does not exist. |
7675
7676**Example**
7677
7678```ts
7679import { BusinessError } from '@kit.BasicServicesKit';
7680
7681avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => {
7682  console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
7683}).catch((err: BusinessError) => {
7684  console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
7685});
7686```
7687
7688### getCallMetadata<sup>11+</sup>
7689
7690getCallMetadata(callback: AsyncCallback\<CallMetadata>): void
7691
7692Obtains the call metadata. This API uses an asynchronous callback to return the result.
7693
7694**System capability**: SystemCapability.Multimedia.AVSession.Core
7695
7696**Parameters**
7697
7698| Name  | Type                                     | Mandatory| Description                      |
7699| -------- | ----------------------------------------- | ---- | -------------------------- |
7700| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | Yes  | Callback used to return the metadata obtained.|
7701
7702**Error codes**
7703
7704For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7705
7706| ID| Error Message|
7707| -------- | ---------------------------------------- |
7708| 6600101  | Session service exception. |
7709| 6600102  | The session does not exist. |
7710| 6600103  | The session controller does not exist. |
7711
7712**Example**
7713
7714```ts
7715import { BusinessError } from '@kit.BasicServicesKit';
7716
7717avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
7718  if (err) {
7719    console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
7720  } else {
7721    console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
7722  }
7723});
7724```
7725
7726### getAVQueueTitleSync<sup>10+</sup>
7727
7728getAVQueueTitleSync(): string
7729
7730Obtains the name of the playlist of this session. This API returns the result synchronously.
7731
7732**Atomic service API**: This API can be used in atomic services since API version 12.
7733
7734**System capability**: SystemCapability.Multimedia.AVSession.Core
7735
7736**Return value**
7737
7738| Type            | Description                          |
7739| ---------------- | ----------------------------- |
7740| string | Playlist name.|
7741
7742**Error codes**
7743
7744For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7745
7746| ID| Error Message|
7747| -------- | ---------------------------------------- |
7748| 6600101  | Session service exception. |
7749| 6600102  | The session does not exist. |
7750| 6600103  | The session controller does not exist. |
7751
7752**Example**
7753
7754```ts
7755import { BusinessError } from '@kit.BasicServicesKit';
7756
7757try {
7758  let currentQueueTitle: string = avsessionController.getAVQueueTitleSync();
7759} catch (err) {
7760  let error = err as BusinessError;
7761  console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`);
7762}
7763```
7764
7765### getAVQueueItemsSync<sup>10+</sup>
7766
7767getAVQueueItemsSync(): Array\<AVQueueItem\>
7768
7769Obtains the information related to the items in the playlist of this session. This API returns the result synchronously.
7770
7771**Atomic service API**: This API can be used in atomic services since API version 12.
7772
7773**System capability**: SystemCapability.Multimedia.AVSession.Core
7774
7775**Return value**
7776
7777| Type                                         | Description                          |
7778| --------------------------------------------- | ----------------------------- |
7779| Array<[AVQueueItem](#avqueueitem10)\> | Items in the queue.|
7780
7781**Error codes**
7782
7783For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7784
7785| ID| Error Message|
7786| -------- | ---------------------------------------- |
7787| 6600101  | Session service exception. |
7788| 6600102  | The session does not exist. |
7789| 6600103  | The session controller does not exist. |
7790
7791**Example**
7792
7793```ts
7794import { BusinessError } from '@kit.BasicServicesKit';
7795
7796try {
7797  let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync();
7798} catch (err) {
7799  let error = err as BusinessError;
7800  console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`);
7801}
7802```
7803
7804### getOutputDeviceSync<sup>10+</sup>
7805
7806getOutputDeviceSync(): OutputDeviceInfo
7807
7808Obtains the output device information. This API returns the result synchronously.
7809
7810**Atomic service API**: This API can be used in atomic services since API version 12.
7811
7812**System capability**: SystemCapability.Multimedia.AVSession.Core
7813
7814**Return value**
7815
7816| Type                                           | Description                             |
7817| ----------------------------------------------- | --------------------------------- |
7818| [OutputDeviceInfo](#outputdeviceinfo10) | Information about the output device.|
7819
7820**Error codes**
7821
7822For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7823
7824| ID| Error Message|
7825| -------- | ---------------------------------------- |
7826| 6600101  | Session service exception. |
7827| 6600103  | The session controller does not exist. |
7828
7829**Example**
7830
7831```ts
7832import { BusinessError } from '@kit.BasicServicesKit';
7833
7834try {
7835  let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync();
7836} catch (err) {
7837  let error = err as BusinessError;
7838  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
7839}
7840```
7841
7842### isActiveSync<sup>10+</sup>
7843
7844isActiveSync(): boolean
7845
7846Checks whether the session is activated. This API returns the result synchronously.
7847
7848**Atomic service API**: This API can be used in atomic services since API version 12.
7849
7850**System capability**: SystemCapability.Multimedia.AVSession.Core
7851
7852**Return value**
7853
7854| Type             | Description                                                        |
7855| ----------------- | ------------------------------------------------------------ |
7856| boolean | Returns **true** is returned if the session is activated; returns **false** otherwise.|
7857
7858**Error codes**
7859
7860For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7861
7862| ID| Error Message|
7863| -------- | ---------------------------------------- |
7864| 6600101  | Session service exception. |
7865| 6600102  | The session does not exist. |
7866| 6600103  | The session controller does not exist. |
7867
7868**Example**
7869
7870```ts
7871import { BusinessError } from '@kit.BasicServicesKit';
7872
7873try {
7874  let isActive: boolean = avsessionController.isActiveSync();
7875} catch (err) {
7876  let error = err as BusinessError;
7877  console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`);
7878}
7879```
7880
7881### getValidCommandsSync<sup>10+</sup>
7882
7883getValidCommandsSync(): Array\<AVControlCommandType\>
7884
7885Obtains valid commands supported by the session. This API returns the result synchronously.
7886
7887**Atomic service API**: This API can be used in atomic services since API version 12.
7888
7889**System capability**: SystemCapability.Multimedia.AVSession.Core
7890
7891**Return value**
7892
7893| Type                                                        | Description                             |
7894| ------------------------------------------------------------ | --------------------------------- |
7895| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | A set of valid commands.|
7896
7897**Error codes**
7898
7899For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
7900
7901| ID| Error Message|
7902| -------- | ---------------------------------------- |
7903| 6600101  | Session service exception. |
7904| 6600102  | The session does not exist. |
7905| 6600103  | The session controller does not exist. |
7906
7907**Example**
7908
7909```ts
7910import { BusinessError } from '@kit.BasicServicesKit';
7911
7912try {
7913  let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync();
7914} catch (err) {
7915  let error = err as BusinessError;
7916  console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`);
7917}
7918```
7919
7920## AVControlCommandType<sup>10+</sup>
7921
7922type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
7923  'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute'
7924
7925Enumerates the commands that can be sent to a session.
7926
7927You can use the union of the strings listed in the following table.
7928
7929**Atomic service API**: This API can be used in atomic services since API version 12.
7930
7931**System capability**: SystemCapability.Multimedia.AVSession.Core
7932
7933| Type            | Description        |
7934| ---------------- | ------------ |
7935| 'play'           | Play the media.        |
7936| 'pause'          | Pause the playback.        |
7937| 'stop'           | Stop the playback.        |
7938| 'playNext'       | Play the next media asset.      |
7939| 'playPrevious'   | Play the previous media asset.      |
7940| 'fastForward'    | Fast-forward.        |
7941| 'rewind'         | Rewind.        |
7942| 'seek'           | Seek to a playback position.|
7943| 'setSpeed'       | Set the playback speed.|
7944| 'setLoopMode'    | Set the loop mode.|
7945| 'toggleFavorite' | Favorite the media asset.    |
7946| 'playFromAssetId'| Play the media asset with the specified asset ID.|
7947|'answer'          | Answer a call.       |
7948| 'hangUp'         | The call is disconnecting.       |
7949|'toggleCallMute'  | Set the mute status for a call.|
7950
7951## AVControlCommand<sup>10+</sup>
7952
7953Describes the command that can be sent to the session.
7954
7955**Atomic service API**: This API can be used in atomic services since API version 12.
7956
7957**System capability**: SystemCapability.Multimedia.AVSession.Core
7958
7959| Name     | Type                                             | Mandatory| Description          |
7960| --------- | ------------------------------------------------- | ---- | -------------- |
7961| command   | [AVControlCommandType](#avcontrolcommandtype10)     | Yes  | Command.          |
7962| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | No  | Parameters carried in the command.|
7963
7964## AVSessionErrorCode<sup>10+</sup>
7965
7966Enumerates the error codes used in the media session.
7967
7968| Name                                  | Value     | Description                            |
7969| -------------------------------------- | ------- | ------------------------------- |
7970| 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|
7971| 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|
7972| 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|
7973| 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|
7974| 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|
7975| 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|
7976| 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|
7977| 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|
7978| 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|
7979| 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|
7980| 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|
7981| 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|
7982| 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|
7983| 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|
7984| 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|
7985| 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|
7986| 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|
7987| 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|
7988| 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|
7989| 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|
7990| 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|
7991| 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|
7992| 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|
7993| 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|
7994| 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|
7995| 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|
7996| 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|
7997| 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|
7998| 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|
7999| 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|
8000| 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|
8001| 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|
8002| 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|
8003| 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|
8004| 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|
8005| 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|
8006| 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|
8007| 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|
8008| 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|
8009| 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|
8010| 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|
8011| 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|
8012| 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|
8013| 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|
8014| 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|
8015| 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|
8016| 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|
8017| 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|
8018| 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|
8019| 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|
8020| 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|
8021| 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|
8022| 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|
8023| 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|
8024| 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|
8025| 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|
8026| 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|
8027| 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|
8028| 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|
8029| 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|
8030| 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|
8031| 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|
8032| 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|
8033| 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|
8034
8035## SkipIntervals<sup>11+</sup>
8036
8037Enumerates the fast-forward or rewind intervals supported by the media session.
8038
8039**System capability**: SystemCapability.Multimedia.AVSession.Core
8040
8041| Name                  | Value| Description                    |
8042| ---------------------- | -- | ----------------------- |
8043| SECONDS_10             | 10 | The time is 10 seconds.            |
8044| SECONDS_15             | 15 | The time is 15 seconds.            |
8045| SECONDS_30             | 30 | The time is 30 seconds.            |
8046