• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AVCastController)
2<!--Kit: AVSession Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @ccfriend; @liao_qian-->
5<!--SE: @ccfriend-->
6<!--TSE: @chenmingxi1_huawei-->
7
8> **NOTE**
9>
10> - 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.
11> - The initial APIs of this interface are supported since API version 10.
12
13After a casting connection is set up, you can call [avSession.getAVCastController](arkts-apis-avsession-AVSession.md#getavcastcontroller10) to obtain the cast controller. Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
14
15## Modules to Import
16
17```ts
18import { avSession } from '@kit.AVSessionKit';
19```
20
21## getAVPlaybackState<sup>10+</sup>
22
23getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
24
25Obtains the remote playback state. This API uses an asynchronous callback to return the result.
26
27**System capability**: SystemCapability.Multimedia.AVSession.AVCast
28
29**Parameters**
30
31| Name   | Type                                                       | Mandatory| Description                                                        |
32| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
33| callback  | AsyncCallback<[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
34
35**Error codes**
36
37For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
38
39| ID| Error Message|
40| -------- | ---------------------------------------- |
41| 6600101  | Session service exception. |
42
43**Example**
44
45```ts
46import { BusinessError } from '@kit.BasicServicesKit';
47
48aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
49  if (err) {
50    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
51  } else {
52    console.info('getAVPlaybackState : SUCCESS');
53  }
54});
55```
56
57## getAVPlaybackState<sup>10+</sup>
58
59getAVPlaybackState(): Promise\<AVPlaybackState>
60
61Obtains the remote playback state. This API uses a promise to return the result.
62
63**Atomic service API**: This API can be used in atomic services since API version 12.
64
65**System capability**: SystemCapability.Multimedia.AVSession.AVCast
66
67**Return value**
68
69| Type                                                       | Description                                                        |
70| --------- | ------------------------------------------------------------ |
71| Promise<[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\>  | Promise used to return the remote playback state.|
72
73**Error codes**
74
75For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
76
77| ID| Error Message|
78| -------- | ---------------------------------------- |
79| 6600101  | Session service exception. |
80
81**Example**
82
83```ts
84import { BusinessError } from '@kit.BasicServicesKit';
85
86aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
87  console.info('getAVPlaybackState : SUCCESS');
88}).catch((err: BusinessError) => {
89  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
90});
91```
92
93## getSupportedDecoders<sup>19+</sup>
94
95getSupportedDecoders(): Promise\<Array\<DecoderType>>
96
97Obtains the decoding modes supported by the current remote device. This API uses a promise to return the result.
98
99**Atomic service API**: This API can be used in atomic services since API version 19.
100
101**System capability**: SystemCapability.Multimedia.AVSession.AVCast
102
103**Return value**
104
105| Type                                                       | Description                                                        |
106| --------- | ------------------------------------------------------------ |
107| Promise\<Array\<[DecoderType](arkts-apis-avsession-e.md#decodertype19)\>\> | Promise return an array of decoding modes supported by the remote device.|
108
109**Error codes**
110
111For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
112
113| ID| Error Message|
114| -------- | ---------------------------------------- |
115| 6600101  | Session service exception. |
116
117**Example**
118
119```ts
120import { BusinessError } from '@kit.BasicServicesKit';
121
122aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => {
123  console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`);
124  if (decoderTypes.length > 0 ) {
125    console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`);
126  }
127}).catch((err: BusinessError) => {
128  console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`);
129});
130```
131
132## getRecommendedResolutionLevel<sup>19+</sup>
133
134getRecommendedResolutionLevel(decoderType: DecoderType): Promise\<ResolutionLevel>
135
136Obtains the recommended resolution level based on the passed decoding mode. This API uses a promise to return the result.
137
138**Atomic service API**: This API can be used in atomic services since API version 19.
139
140**System capability**: SystemCapability.Multimedia.AVSession.AVCast
141
142**Parameters**
143
144| Name  | Type                                     | Mandatory| Description                      |
145| -------- | ----------------------------------------- | ---- | -------------------------- |
146| decoderType | [DecoderType](arkts-apis-avsession-e.md#decodertype19) | Yes| Decoding format supported by the device.<br>The following decoding formats are supported by the device:<br>**'OH_AVCODEC_MIMETYPE_VIDEO_AVC'**: VIDEO AVC.<br>**'OH_AVCODEC_MIMETYPE_VIDEO_HEVC'**: VIDEO HEVC.<br>**'OH_AVCODEC_MIMETYPE_AUDIO_VIVID'**: AUDIO AV3A.|
147
148**Return value**
149
150| Type                                                       | Description                                                        |
151| --------- | ------------------------------------------------------------ |
152| Promise\<[ResolutionLevel](arkts-apis-avsession-e.md#resolutionlevel19)\> | Promise return the recommended resolution level of the remote device.|
153
154**Error codes**
155
156For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
157
158| ID| Error Message|
159| -------- | ---------------------------------------- |
160| 6600101  | Session service exception. |
161
162**Example**
163
164```ts
165import { BusinessError } from '@kit.BasicServicesKit';
166
167let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC;
168let resolutionLeve = avSession.ResolutionLevel;
169aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLeve) => {
170  console.info('getRecommendedResolutionLevel successfully');
171}).catch((err: BusinessError) => {
172  console.error(`getRecommendedResolutionLevel BusinessError: code: ${err.code}, message: ${err.message}`);
173});
174```
175
176## getSupportedHdrCapabilities<sup>19+</sup>
177
178getSupportedHdrCapabilities(): Promise\<Array\<hdrCapability.HDRFormat>>
179
180Obtains the HDR capabilities supported by the current remote device. This API uses a promise to return the result.
181
182**Atomic service API**: This API can be used in atomic services since API version 19.
183
184**System capability**: SystemCapability.Multimedia.AVSession.AVCast
185
186**Return value**
187
188| Type                                                       | Description                                                        |
189| --------- | ------------------------------------------------------------ |
190| Promise\<Array\<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md#hdrformat)\>\> | Promise used to return an array of HDR capabilities supported by the remote device.|
191
192**Error codes**
193
194For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
195
196| ID| Error Message|
197| -------- | ---------------------------------------- |
198| 6600101  | Session service exception. |
199
200**Example**
201
202```ts
203import { BusinessError } from '@kit.BasicServicesKit';
204import type hdrCapability from './@ohos.graphics.hdrCapability';
205
206aVCastController.getSupportedHdrCapabilities().then((hdrFormats: hdrCapability.HDRFormat[]) => {
207  console.info(`getSupportedHdrCapabilities : SUCCESS : hdrFormats.length : ${hdrFormats.length}`);
208  if (hdrFormats.length > 0 ) {
209    console.info(`getSupportedHdrCapabilities : SUCCESS : descriptors[0] : ${hdrFormats[0]}`);
210  }
211}).catch((err: BusinessError) => {
212  console.error(`getSupportedHdrCapabilities BusinessError: code: ${err.code}, message: ${err.message}`);
213});
214```
215
216## getSupportedPlaySpeeds<sup>19+</sup>
217
218getSupportedPlaySpeeds(): Promise\<Array\<number>>
219
220Obtains the playback speeds supported by the current remote device. This API uses a promise to return the result.
221
222**Atomic service API**: This API can be used in atomic services since API version 19.
223
224**System capability**: SystemCapability.Multimedia.AVSession.AVCast
225
226**Return value**
227
228| Type                                                       | Description                                                        |
229| --------- | ------------------------------------------------------------ |
230| Promise\<Array\<number\>\> | Promise used to return an array of playback speeds supported by the remote device.|
231
232**Error codes**
233
234For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
235
236| ID| Error Message|
237| -------- | ---------------------------------------- |
238| 6600101  | Session service exception. |
239
240**Example**
241
242```ts
243import { BusinessError } from '@kit.BasicServicesKit';
244
245aVCastController.getSupportedPlaySpeeds().then((nums: number[]) => {
246  console.info(`getSupportedPlaySpeeds : SUCCESS : hdrFormats.length : ${nums.length}`);
247  if (nums.length > 0 ) {
248    console.info(`getSupportedPlaySpeeds : SUCCESS : descriptors[0] : ${nums[0]}`);
249  }
250}).catch((err: BusinessError) => {
251  console.error(`getSupportedPlaySpeeds BusinessError: code: ${err.code}, message: ${err.message}`);
252});
253```
254
255## sendControlCommand<sup>10+</sup>
256
257sendControlCommand(command: AVCastControlCommand): Promise\<void>
258
259Sends a control command to the session through the controller. This API uses a promise to return the result.
260
261
262**Atomic service API**: This API can be used in atomic services since API version 12.
263
264**System capability**: SystemCapability.Multimedia.AVSession.AVCast
265
266**Parameters**
267
268| Name   | Type                                 | Mandatory| Description                          |
269| ------- | ------------------------------------- | ---- | ------------------------------ |
270| command | [AVCastControlCommand](arkts-apis-avsession-i.md#avcastcontrolcommand10) | Yes  | Command to send.|
271
272**Return value**
273
274| Type          | Description                         |
275| -------------- | ----------------------------- |
276| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
277
278**Error codes**
279
280For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
281
282| ID| Error Message|
283| -------- | ---------------------------------------- |
284| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
285| 6600101  | Session service exception. |
286| 6600105  | Invalid session command. |
287| 6600109  | The remote connection is not established. |
288
289**Example**
290
291```ts
292import { BusinessError } from '@kit.BasicServicesKit';
293
294let avCommand: avSession.AVCastControlCommand = {command:'play'};
295aVCastController.sendControlCommand(avCommand).then(() => {
296  console.info('SendControlCommand successfully');
297}).catch((err: BusinessError) => {
298  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
299});
300```
301
302## sendControlCommand<sup>10+</sup>
303
304sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
305
306Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
307
308**System capability**: SystemCapability.Multimedia.AVSession.AVCast
309
310**Parameters**
311
312| Name  | Type                                 | Mandatory| Description                          |
313| -------- | ------------------------------------- | ---- | ------------------------------ |
314| command  | [AVCastControlCommand](arkts-apis-avsession-i.md#avcastcontrolcommand10) | Yes  | Command to send.|
315| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
316
317**Error codes**
318
319For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
320
321| ID| Error Message|
322| -------- | ------------------------------- |
323| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
324| 6600101  | Session service exception. |
325| 6600105  | Invalid session command. |
326| 6600109  | The remote connection is not established. |
327
328**Example**
329
330```ts
331import { BusinessError } from '@kit.BasicServicesKit';
332
333let avCommand: avSession.AVCastControlCommand = {command:'play'};
334aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
335  if (err) {
336    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
337  } else {
338    console.info('SendControlCommand successfully');
339  }
340});
341```
342
343## sendCustomData<sup>20+</sup>
344
345sendCustomData(data: Record\<string, Object>): Promise\<void>
346
347Sends custom data to the remote device. This API uses a promise to return the result.
348
349**Atomic service API**: This API can be used in atomic services since API version 20.
350
351**System capability**: SystemCapability.Multimedia.AVSession.AVCast
352
353**Parameters**
354
355| Name| Type                  | Mandatory| Description                                                        |
356| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
357| data   | Record\<string, Object> | Yes  | Custom data filled by the application. Only objects with the key **'customData'** and of the type string are parsed on the server.|
358
359**Return value**
360
361| Type          | Description                         |
362| -------------- | ----------------------------- |
363| Promise\<void> | Promise that returns no value.|
364
365**Error codes**
366
367For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
368
369| ID| Error Message                                                    |
370| -------- | ------------------------------------------------------------ |
371| 6600101  | Session service exception. |
372
373**Example**
374
375```ts
376import { BusinessError } from '@kit.BasicServicesKit';
377
378aVCastController.sendCustomData({customData : "This is custom data"});
379```
380
381## prepare<sup>10+</sup>
382
383prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
384
385Prepares 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.
386
387**System capability**: SystemCapability.Multimedia.AVSession.AVCast
388
389**Parameters**
390
391| Name   | Type                                 | Mandatory| Description                          |
392| ------- | ------------------------------------- | ---- | ------------------------------ |
393| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | Yes  | Properties of an item in the playlist.|
394| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
395
396**Error codes**
397
398For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
399
400| ID| Error Message|
401| -------- | ---------------------------------------- |
402| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
403| 6600101  | Session service exception. |
404| 6600109  | The remote connection is not established. |
405
406**Example**
407
408```ts
409import { BusinessError } from '@kit.BasicServicesKit';
410
411// Set playback parameters.
412let playItem: avSession.AVQueueItem = {
413  itemId: 0,
414  description: {
415    assetId: '12345',
416    mediaType: 'AUDIO',
417    mediaUri: 'http://resource1_address',
418    mediaSize: 12345,
419    startPosition: 0,
420    duration: 0,
421    artist: 'mysong',
422    albumTitle: 'song1_title',
423    albumCoverUri: "http://resource1_album_address",
424    lyricUri: "http://resource1_lyric_address",
425    appName: 'MyMusic'
426  }
427};
428// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
429aVCastController.prepare(playItem, (err: BusinessError) => {
430  if (err) {
431    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
432  } else {
433    console.info('prepare successfully');
434  }
435});
436```
437
438## prepare<sup>10+</sup>
439
440prepare(item: AVQueueItem): Promise\<void>
441
442Prepares for the playback of a media asset, that is, loads and buffers a media asset. This API uses a promise to return the result.
443
444
445**Atomic service API**: This API can be used in atomic services since API version 12.
446
447**System capability**: SystemCapability.Multimedia.AVSession.AVCast
448
449**Parameters**
450
451| Name   | Type                                 | Mandatory| Description                          |
452| ------- | ------------------------------------- | ---- | ------------------------------ |
453| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | Yes  | Properties of an item in the playlist.|
454
455**Return value**
456
457| Type          | Description                         |
458| -------------- | ----------------------------- |
459| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
460
461**Error codes**
462
463For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
464
465| ID| Error Message|
466| -------- | ---------------------------------------- |
467| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
468| 6600101  | Session service exception. |
469| 6600109  | The remote connection is not established. |
470
471**Example**
472
473```ts
474import { BusinessError } from '@kit.BasicServicesKit';
475
476// Set playback parameters.
477let playItem: avSession.AVQueueItem = {
478  itemId: 0,
479  description: {
480    assetId: '12345',
481    mediaType: 'AUDIO',
482    mediaUri: 'http://resource1_address',
483    mediaSize: 12345,
484    startPosition: 0,
485    duration: 0,
486    artist: 'mysong',
487    albumTitle: 'song1_title',
488    albumCoverUri: "http://resource1_album_address",
489    lyricUri: "http://resource1_lyric_address",
490    appName: 'MyMusic'
491  }
492};
493// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
494aVCastController.prepare(playItem).then(() => {
495  console.info('prepare successfully');
496}).catch((err: BusinessError) => {
497  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
498});
499```
500
501## start<sup>10+</sup>
502
503start(item: AVQueueItem, callback: AsyncCallback\<void>): void
504
505Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
506
507**System capability**: SystemCapability.Multimedia.AVSession.AVCast
508
509**Parameters**
510
511| Name   | Type                                 | Mandatory| Description                          |
512| ------- | ------------------------------------- | ---- | ------------------------------ |
513| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | Yes  | Properties of an item in the playlist.|
514| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
515
516**Error codes**
517
518For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
519
520| ID| Error Message|
521| -------- | ---------------------------------------- |
522| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
523| 6600101  | Session service exception. |
524| 6600109  | The remote connection is not established. |
525
526**Example**
527
528```ts
529import { BusinessError } from '@kit.BasicServicesKit';
530
531// Set playback parameters.
532let playItem: avSession.AVQueueItem = {
533  itemId: 0,
534  description: {
535    assetId: '12345',
536    mediaType: 'AUDIO',
537    mediaUri: 'http://resource1_address',
538    mediaSize: 12345,
539    startPosition: 0,
540    duration: 0,
541    artist: 'mysong',
542    albumTitle: 'song1_title',
543    albumCoverUri: "http://resource1_album_address",
544    lyricUri: "http://resource1_lyric_address",
545    appName: 'MyMusic'
546  }
547};
548
549// Start playback.
550aVCastController.start(playItem, (err: BusinessError) => {
551  if (err) {
552    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
553  } else {
554    console.info('start successfully');
555  }
556});
557```
558
559## start<sup>10+</sup>
560
561start(item: AVQueueItem): Promise\<void>
562
563Prepares for the playback of a media asset. This API uses a promise to return the result.
564
565**Atomic service API**: This API can be used in atomic services since API version 12.
566
567**System capability**: SystemCapability.Multimedia.AVSession.AVCast
568
569**Parameters**
570
571| Name   | Type                                 | Mandatory| Description                          |
572| ------- | ------------------------------------- | ---- | ------------------------------ |
573| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | Yes  | Properties of an item in the playlist.|
574
575**Return value**
576
577| Type          | Description                         |
578| -------------- | ----------------------------- |
579| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
580
581**Error codes**
582
583For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
584
585| ID| Error Message|
586| -------- | ---------------------------------------- |
587| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
588| 6600101  | Session service exception. |
589| 6600109  | The remote connection is not established. |
590
591**Example**
592
593```ts
594import { BusinessError } from '@kit.BasicServicesKit';
595
596// Set playback parameters.
597let playItem: avSession.AVQueueItem = {
598  itemId: 0,
599  description: {
600    assetId: '12345',
601    mediaType: 'AUDIO',
602    mediaUri: 'http://resource1_address',
603    mediaSize: 12345,
604    startPosition: 0,
605    duration: 0,
606    artist: 'mysong',
607    albumTitle: 'song1_title',
608    albumCoverUri: "http://resource1_album_address",
609    lyricUri: "http://resource1_lyric_address",
610    appName: 'MyMusic'
611  }
612};
613// Start playback.
614aVCastController.start(playItem).then(() => {
615  console.info('start successfully');
616}).catch((err: BusinessError) => {
617  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
618});
619```
620
621## getCurrentItem<sup>10+</sup>
622
623getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
624
625Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result.
626
627**System capability**: SystemCapability.Multimedia.AVSession.AVCast
628
629**Parameters**
630
631| Name  | Type                                 | Mandatory| Description                                 |
632| -------- | ------------------------------------- | ---- | ------------------------------------- |
633| callback | AsyncCallback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
634
635**Error codes**
636
637For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
638
639| ID| Error Message|
640| -------- | ---------------------------------------- |
641| 6600101  | Session service exception. |
642
643**Example**
644
645```ts
646import { BusinessError } from '@kit.BasicServicesKit';
647
648aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
649  if (err) {
650    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
651  } else {
652    console.info('getCurrentItem successfully');
653  }
654});
655```
656
657## getCurrentItem<sup>10+</sup>
658
659getCurrentItem(): Promise\<AVQueueItem>
660
661Obtains the information about the media asset that is being played. This API uses a promise to return the result.
662
663**Atomic service API**: This API can be used in atomic services since API version 12.
664
665**System capability**: SystemCapability.Multimedia.AVSession.AVCast
666
667**Return value**
668
669| Type          | Description                         |
670| -------------- | ----------------------------- |
671| Promise\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.|
672
673**Error codes**
674
675For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
676
677| ID| Error Message|
678| -------- | ---------------------------------------- |
679| 6600101  | Session service exception. |
680
681**Example**
682
683```ts
684import { BusinessError } from '@kit.BasicServicesKit';
685
686aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
687  console.info('getCurrentItem successfully');
688}).catch((err: BusinessError) => {
689  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
690});
691```
692
693## getValidCommands<sup>11+</sup>
694
695getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void
696
697Obtains the supported commands. This API uses an asynchronous callback to return the result.
698
699**System capability**: SystemCapability.Multimedia.AVSession.AVCast
700
701**Parameters**
702
703| Name| Type| Mandatory| Description|
704| -------- | ------------------------------------- | ---- | ------------------------------------- |
705| callback | AsyncCallback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)>> | Yes| Callback return the supported commands.|
706
707**Error codes**
708
709For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
710
711| ID| Error Message|
712| -------- | ---------------------------------------- |
713| 6600101  | Session service exception. |
714
715**Example**
716
717```ts
718import { BusinessError } from '@kit.BasicServicesKit';
719
720aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType[]) => {
721  if (err) {
722    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
723  } else {
724    console.info('getValidCommands successfully');
725  }
726});
727```
728
729## getValidCommands<sup>11+</sup>
730
731getValidCommands(): Promise<Array\<AVCastControlCommandType>>
732
733Obtains the supported commands. This API uses a promise to return the result.
734
735**System capability**: SystemCapability.Multimedia.AVSession.AVCast
736
737**Return value**
738
739| Type| Description|
740| -------------- | ----------------------------- |
741| Promise<Array\<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)>> | Promise used to return the supported commands.|
742
743**Error codes**
744
745For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
746
747| ID| Error Message|
748| -------- | ---------------------------------------- |
749| 6600101  | Session service exception. |
750
751**Example**
752
753```ts
754import { BusinessError } from '@kit.BasicServicesKit';
755
756aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType[]) => {
757  console.info('getValidCommands successfully');
758}).catch((err: BusinessError) => {
759  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
760});
761```
762
763## processMediaKeyResponse<sup>12+</sup>
764
765processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void>
766
767Processes the response to a media key request during online DRM resource projection. This API uses a promise to return the result.
768
769**Atomic service API**: This API can be used in atomic services since API version 12.
770
771**System capability**: SystemCapability.Multimedia.AVSession.AVCast
772
773**Parameters**
774
775| Name  | Type                                 | Mandatory| Description                                 |
776| -------- | ------------------------------------- | ---- | ------------------------------------- |
777| assetId | string                  | Yes  | Media asset ID.|
778| response | Uint8Array             | Yes  | Response to the media key request.|
779
780**Return value**
781
782| Type          | Description                         |
783| -------------- | ----------------------------- |
784| Promise\<void> | Promise used to return the result. If the response is processed successfully, no result is returned. Otherwise, an error object is returned.|
785
786**Error codes**
787
788For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
789
790| ID| Error Message|
791| -------- | ---------------------------------------- |
792| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
793| 6600101  | Session service exception. |
794
795**Example**
796
797```ts
798let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
799  // Obtain the DRM URL based on the asset ID.
800  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
801  // Obtain a media key from the server. Assign a value based on service requirements.
802  let licenseResponseData: Uint8Array = new Uint8Array();
803  console.info(`Succeeded in get license by ${drmUrl}.`);
804  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
805}
806```
807
808## release<sup>11+</sup>
809
810release(callback: AsyncCallback\<void>): void
811
812Releases this cast controller. This API uses an asynchronous callback to return the result.
813
814**System capability**: SystemCapability.Multimedia.AVSession.AVCast
815
816**Parameters**
817
818| Name  | Type                      | Mandatory| Description                                                        |
819| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
820| callback | AsyncCallback\<void>       | Yes  | Callback used to return the result. If the controller is released, **err** is **undefined**; otherwise, **err** is an error object.|
821
822**Error codes**
823
824For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
825
826| ID| Error Message|
827| -------- | -------------------------- |
828| 6600101  | Session service exception. |
829
830**Example**
831
832```ts
833import { BusinessError } from '@kit.BasicServicesKit';
834
835aVCastController.release((err: BusinessError) => {
836  if (err) {
837    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
838  } else {
839    console.info('release successfully');
840  }
841});
842```
843
844## release<sup>11+</sup>
845
846release(): Promise\<void>
847
848Releases this cast controller. This API uses a promise to return the result.
849
850**Atomic service API**: This API can be used in atomic services since API version 12.
851
852**System capability**: SystemCapability.Multimedia.AVSession.AVCast
853
854**Return value**
855
856| Type          | Description                         |
857| -------------- | ----------------------------- |
858| Promise\<void> | Promise used to return the result. If the controller is released, no value is returned; otherwise, an error object is returned.|
859
860**Error codes**
861
862For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
863
864| ID| Error Message|
865| -------- | ------------------------------ |
866| 6600101  | Session service exception. |
867
868**Example**
869
870```ts
871import { BusinessError } from '@kit.BasicServicesKit';
872
873aVCastController.release().then(() => {
874  console.info('release successfully');
875}).catch((err: BusinessError) => {
876  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
877});
878
879```
880
881## on('playbackStateChange')<sup>10+</sup>
882
883on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
884
885Subscribes to playback state change events.
886
887Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
888
889**Atomic service API**: This API can be used in atomic services since API version 12.
890
891**System capability**: SystemCapability.Multimedia.AVSession.AVCast
892
893**Parameters**
894
895| Name  | Type                                                        | Mandatory| Description                                                        |
896| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
897| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
898| filter   | Array\<keyof&nbsp;[AVPlaybackState](arkts-apis-avsession-i.md#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](arkts-apis-avsession-i.md#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.|
899| callback | (state: [AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)) => void         | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.                     |
900
901**Error codes**
902
903For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
904
905| ID| Error Message|
906| -------- | ------------------------------ |
907| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
908| 6600101  | Session service exception. |
909
910**Example**
911
912```ts
913aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
914  console.info(`on playbackStateChange state : ${playbackState.state}`);
915});
916
917let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
918aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
919  console.info(`on playbackStateChange state : ${playbackState.state}`);
920});
921```
922
923## off('playbackStateChange')<sup>10+</sup>
924
925off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
926
927Unsubscribes from playback state change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
928
929**Atomic service API**: This API can be used in atomic services since API version 12.
930
931**System capability**: SystemCapability.Multimedia.AVSession.AVCast
932
933**Parameters**
934
935| Name  | Type                                                        | Mandatory| Description                                                    |
936| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
937| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
938| callback | (state: [AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)) => void         | No  | Callback function, where the **state** parameter indicates the new playback state.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
939
940**Error codes**
941
942For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
943
944| ID| Error Message|
945| -------- | ---------------- |
946| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
947| 6600101  | Session service exception. |
948
949**Example**
950
951```ts
952aVCastController.off('playbackStateChange');
953```
954
955## on('mediaItemChange')<sup>10+</sup>
956
957on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
958
959Subscribes to media asset change events.
960
961Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
962
963**Atomic service API**: This API can be used in atomic services since API version 12.
964
965**System capability**: SystemCapability.Multimedia.AVSession.AVCast
966
967**Parameters**
968
969| Name  | Type                                                        | Mandatory| Description                                                        |
970| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
971| type     | string                                                       | Yes  | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.|
972| callback | Callback<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>         | Yes  | Callback used for subscription. **AVQueueItem** is the media asset that is being played.                     |
973
974**Error codes**
975
976For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
977
978| ID| Error Message|
979| -------- | ------------------------------ |
980| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
981| 6600101  | Session service exception. |
982
983**Example**
984
985```ts
986aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
987  console.info(`on mediaItemChange state : ${item.itemId}`);
988});
989```
990
991## off('mediaItemChange')<sup>10+</sup>
992
993off(type: 'mediaItemChange'): void
994
995Unsubscribes from media asset change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
996
997**Atomic service API**: This API can be used in atomic services since API version 12.
998
999**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1000
1001**Parameters**
1002
1003| Name  | Type                                                        | Mandatory| Description                                                    |
1004| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1005| type     | string                                                       | Yes  | Event type, which is **'mediaItemChange'** in this case.   |
1006
1007**Error codes**
1008
1009For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1010
1011| ID| Error Message|
1012| -------- | ---------------- |
1013| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1014| 6600101  | Session service exception. |
1015
1016**Example**
1017
1018```ts
1019aVCastController.off('mediaItemChange');
1020```
1021
1022## on('playNext')<sup>10+</sup>
1023
1024on(type: 'playNext', callback: Callback\<void>): void
1025
1026Subscribes to playNext command events.
1027
1028Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1029
1030**Atomic service API**: This API can be used in atomic services since API version 12.
1031
1032**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1033
1034**Parameters**
1035
1036| Name  | Type                                                        | Mandatory| Description                                                        |
1037| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1038| type     | string                                                       | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.|
1039| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
1040
1041**Error codes**
1042
1043For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1044
1045| ID| Error Message|
1046| -------- | ------------------------------ |
1047| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1048| 6600101  | Session service exception. |
1049
1050**Example**
1051
1052```ts
1053aVCastController.on('playNext', () => {
1054  console.info('on playNext');
1055});
1056```
1057
1058## off('playNext')<sup>10+</sup>
1059
1060off(type: 'playNext'): void
1061
1062Unsubscribes from playNext command events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1063
1064**Atomic service API**: This API can be used in atomic services since API version 12.
1065
1066**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1067
1068**Parameters**
1069
1070| Name  | Type                                                        | Mandatory| Description                                                    |
1071| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1072| type     | string                                                       | Yes  | Event type, which is **'playNext'** in this case.   |
1073
1074**Error codes**
1075
1076For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1077
1078| ID| Error Message|
1079| -------- | ---------------- |
1080| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1081| 6600101  | Session service exception. |
1082
1083**Example**
1084
1085```ts
1086aVCastController.off('playNext');
1087```
1088
1089## on('playPrevious')<sup>10+</sup>
1090
1091on(type: 'playPrevious', callback: Callback\<void>): void
1092
1093Subscribes to playPrevious command events.
1094
1095Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1096
1097**Atomic service API**: This API can be used in atomic services since API version 12.
1098
1099**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1100
1101**Parameters**
1102
1103| Name  | Type                                                        | Mandatory| Description                                                        |
1104| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1105| type     | string                                                       | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.|
1106| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
1107
1108**Error codes**
1109
1110For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1111
1112| ID| Error Message|
1113| -------- | ------------------------------ |
1114| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1115| 6600101  | Session service exception. |
1116
1117**Example**
1118
1119```ts
1120aVCastController.on('playPrevious', () => {
1121  console.info('on playPrevious');
1122});
1123```
1124
1125## off('playPrevious')<sup>10+</sup>
1126
1127off(type: 'playPrevious'): void
1128
1129Unsubscribes from playPrevious command events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1130
1131**Atomic service API**: This API can be used in atomic services since API version 12.
1132
1133**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1134
1135**Parameters**
1136
1137| Name  | Type                                                        | Mandatory| Description                                                    |
1138| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1139| type     | string                                                       | Yes  | Event type, which is **'playPrevious'** in this case.   |
1140
1141**Error codes**
1142
1143For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1144
1145| ID| Error Message|
1146| -------- | ---------------- |
1147| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1148| 6600101  | Session service exception. |
1149
1150**Example**
1151
1152```ts
1153aVCastController.off('playPrevious');
1154```
1155
1156## on('requestPlay')<sup>11+</sup>
1157
1158on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
1159
1160Subscribes to playback request events.
1161
1162Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1163
1164**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1165
1166**Parameters**
1167
1168| Name  | Type                                                        | Mandatory| Description                                                        |
1169| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1170| type     | string                                                       | Yes  | Event type. The event **'requestPlay'** is triggered when a playback request is received.|
1171| callback | Callback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>                | Yes  | Callback function, where the **AVQueueItem** parameter specifies the media asset that is being played. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object. |
1172
1173**Error codes**
1174
1175For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1176
1177| ID| Error Message|
1178| -------- | ------------------------------ |
1179| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1180| 6600101  | Session service exception. |
1181
1182**Example**
1183
1184```ts
1185aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
1186  console.info(`on requestPlay state : ${item.itemId}`);
1187});
1188```
1189
1190## off('requestPlay')<sup>11+</sup>
1191
1192off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void
1193
1194Unsubscribes from playback request events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1195
1196**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1197
1198**Parameters**
1199
1200| Name  | Type                                                        | Mandatory| Description                                                    |
1201| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
1202| type     | string                                                      | Yes  | Event type, which is **'requestPlay'** in this case.   |
1203| callback | Callback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>             | No  | Callback function, where the **AVQueueItem** parameter specifies the media asset that is being played. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
1204
1205**Error codes**
1206
1207For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1208
1209| ID| Error Message|
1210| -------- | ---------------- |
1211| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1212| 6600101  | Session service exception. |
1213
1214**Example**
1215
1216```ts
1217aVCastController.off('requestPlay');
1218```
1219
1220## on('endOfStream')<sup>11+</sup>
1221
1222on(type: 'endOfStream', callback: Callback\<void>): void
1223
1224Subscribes to playback end events.
1225
1226Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1227
1228**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1229
1230**Parameters**
1231
1232| Name  | Type                                                        | Mandatory| Description                                                        |
1233| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ |
1234| type     | string                                                      | Yes  | Event type. The event **'endOfStream'** is triggered when the playback operation is complete.|
1235| callback | Callback\<void\>                                            | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.     |
1236
1237**Error codes**
1238
1239For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1240
1241| ID| Error Message|
1242| -------- | ------------------------------ |
1243| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1244| 6600101  | Session service exception. |
1245
1246**Example**
1247
1248```ts
1249aVCastController.on('endOfStream', () => {
1250  console.info('on endOfStream');
1251});
1252```
1253
1254## off('endOfStream')<sup>11+</sup>
1255
1256off(type: 'endOfStream', callback?: Callback\<void>): void
1257
1258Unsubscribes from the playback end events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1259
1260**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1261
1262**Parameters**
1263
1264| Name  | Type                                                        | Mandatory| Description                                                    |
1265| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
1266| type     | string                                                      | Yes  | Event type, which is **'endOfStream'** in this case.   |
1267| 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.  |
1268
1269**Error codes**
1270
1271For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1272
1273| ID| Error Message|
1274| -------- | ---------------- |
1275| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1276| 6600101  | Session service exception. |
1277
1278**Example**
1279
1280```ts
1281aVCastController.off('endOfStream');
1282```
1283
1284## on('seekDone')<sup>10+</sup>
1285
1286on(type: 'seekDone', callback: Callback\<number>): void
1287
1288Subscribes to seek done events.
1289
1290Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1291
1292**Atomic service API**: This API can be used in atomic services since API version 12.
1293
1294**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1295
1296**Parameters**
1297
1298| Name  | Type                                                        | Mandatory| Description                                                        |
1299| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1300| type     | string                                                       | Yes  | Event type. The event **'seekDone'** is triggered when the seek operation is complete.|
1301| callback | Callback\<number\>         | Yes  | Callback used to return the position after the seek operation.                     |
1302
1303**Error codes**
1304
1305For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1306
1307| ID| Error Message|
1308| -------- | ------------------------------ |
1309| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1310| 6600101  | Session service exception. |
1311
1312**Example**
1313
1314```ts
1315aVCastController.on('seekDone', (pos: number) => {
1316  console.info(`on seekDone pos: ${pos} `);
1317});
1318```
1319
1320## off('seekDone')<sup>10+</sup>
1321
1322off(type: 'seekDone'): void
1323
1324Unsubscribes from the seek done events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1325
1326**Atomic service API**: This API can be used in atomic services since API version 12.
1327
1328**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1329
1330**Parameters**
1331
1332| Name  | Type                                                        | Mandatory| Description                                                    |
1333| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1334| type     | string                                                       | Yes  | Event type, which is **'seekDone'** in this case.   |
1335
1336**Error codes**
1337
1338For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1339
1340| ID| Error Message|
1341| -------- | ---------------- |
1342| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1343| 6600101  | Session service exception. |
1344
1345**Example**
1346
1347```ts
1348aVCastController.off('seekDone');
1349```
1350
1351## on('validCommandChange')<sup>11+</sup>
1352
1353on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
1354
1355Subscribes to valid command change events.
1356
1357Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1358
1359**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1360
1361**Parameters**
1362
1363| Name  | Type                                                        | Mandatory| Description                                                        |
1364| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1365| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
1366| callback | Callback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)\>\>   | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
1367
1368**Error codes**
1369
1370For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1371
1372| ID| Error Message|
1373| -------- | ------------------------------ |
1374| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1375| 6600101  | Session service exception. |
1376| 6600103  | The session controller does not exist. |
1377
1378**Example**
1379
1380```ts
1381aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
1382  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
1383  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
1384});
1385```
1386
1387## off('validCommandChange')<sup>11+</sup>
1388
1389off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>)
1390
1391Unsubscribes from valid command change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1392
1393**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1394
1395**Parameters**
1396
1397| Name  | Type                                                        | Mandatory| Description                                                       |
1398| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
1399| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
1400| callback | Callback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#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.         |
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| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1409| 6600101  | Session service exception. |
1410| 6600103  | The session controller does not exist. |
1411
1412**Example**
1413
1414```ts
1415aVCastController.off('validCommandChange');
1416```
1417
1418## on('videoSizeChange')<sup>12+</sup>
1419on(type: 'videoSizeChange', callback: (width: number, height: number) => void): void
1420
1421Subscribes to video size change events.
1422
1423Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1424
1425**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1426
1427**Parameters**
1428
1429| Name  | Type                                                        | Mandatory| Description                                                        |
1430| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1431| type     | string                                                       | Yes  | Event type. The event **'videoSizeChange'** is triggered when the video size changes.|
1432| callback | (width: number, height: number) => void   | Yes  | Callback used to return the result.                   |
1433
1434**Error codes**
1435
1436For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1437
1438| ID| Error Message|
1439| -------- | ------------------------------ |
1440| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1441| 6600101  | Session service exception. |
1442
1443**Example**
1444
1445```ts
1446aVCastController.on('videoSizeChange', (width: number, height: number) => {
1447  console.info(`videoSizeChange : SUCCESS : size : ${width}, ${height}`);
1448});
1449```
1450
1451## off('videoSizeChange')<sup>12+</sup>
1452
1453off(type: 'videoSizeChange'): void
1454
1455Unsubscribes from video size change events. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1456
1457**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1458
1459**Parameters**
1460
1461| Name  | Type                                                        | Mandatory| Description                                                        |
1462| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1463| type     | string                                                       | Yes  | Event type. The event **'videoSizeChange'** is triggered when the video size changes.|
1464| callback | (width: number, height: number) => void   | Yes  | Callback used to return the result.                   |
1465
1466**Error codes**
1467
1468For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1469
1470| ID| Error Message|
1471| -------- | ------------------------------ |
1472| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1473
1474**Example**
1475
1476```ts
1477aVCastController.off('videoSizeChange');
1478```
1479
1480## on('error')<sup>10+</sup>
1481
1482on(type: 'error', callback: ErrorCallback): void
1483
1484Subscribes to remote player errors. This event is used only for error prompt and does not require the user to stop playback control.
1485
1486Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1487
1488**Atomic service API**: This API can be used in atomic services since API version 12.
1489
1490**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1491
1492**Parameters**
1493
1494| Name  | Type    | Mandatory| Description                                                        |
1495| -------- | -------- | ---- | ------------------------------------------------------------ |
1496| type     | string   | Yes  | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.|
1497| callback | ErrorCallback | Yes  | Callback used to return the error code ID and error message.|
1498
1499**Error codes**
1500
1501For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
1502
1503| ID| Error Message             |
1504| -------- | --------------------- |
1505| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1506| 5400101  | No memory.            |
1507| 5400102  | Operation not allowed.   |
1508| 5400103  | I/O error.             |
1509| 5400104  | Time out.      |
1510| 5400105  | Service died.         |
1511| 5400106  | Unsupport format.     |
1512| 6600101  | Session service exception. |
1513
1514**Example**
1515
1516```ts
1517import { BusinessError } from '@kit.BasicServicesKit';
1518
1519aVCastController.on('error', (error: BusinessError) => {
1520  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
1521})
1522```
1523
1524## off('error')<sup>10+</sup>
1525
1526off(type: 'error'): void
1527
1528Unsubscribes from remote player errors. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1529
1530**Atomic service API**: This API can be used in atomic services since API version 12.
1531
1532**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1533
1534**Parameters**
1535
1536| Name| Type  | Mandatory| Description                                     |
1537| ------ | ------ | ---- | ----------------------------------------- |
1538| type   | string | Yes  | Event type, which is **'error'** in this case.|
1539
1540**Error codes**
1541
1542For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
1543
1544| ID| Error Message             |
1545| -------- | --------------------- |
1546| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1547| 5400101  | No memory.            |
1548| 5400102  | Operation not allowed.   |
1549| 5400103  | I/O error.             |
1550| 5400104  | Time out.      |
1551| 5400105  | Service died.         |
1552| 5400106  | Unsupport format.     |
1553| 6600101  | Session service exception. |
1554
1555**Example**
1556
1557```ts
1558aVCastController.off('error')
1559```
1560
1561## on('keyRequest')<sup>12+</sup>
1562
1563on(type: 'keyRequest', callback: KeyRequestCallback): void
1564
1565Subscribes to media key requests during the cast of online DRM resources.
1566
1567Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1568
1569**Atomic service API**: This API can be used in atomic services since API version 12.
1570
1571**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1572
1573**Parameters**
1574
1575| Name| Type  | Mandatory| Description                                     |
1576| ------ | ------ | ---- | ----------------------------------------- |
1577| type     | string  | Yes  | Event type. The event **'keyRequest'** is triggered when a media key request is required during the cast of online DRM resources.|
1578| callback | [KeyRequestCallback](arkts-apis-avsession-t.md#keyrequestcallback12)  | Yes  | Callback used to request the media resources and media key.|
1579
1580
1581**Error codes**
1582
1583For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1584
1585| ID| Error Message          |
1586| -------- | ---------------- |
1587| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1588| 6600101  | Session service exception. |
1589
1590**Example**
1591
1592```ts
1593let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
1594  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
1595}
1596aVCastController.on('keyRequest', keyRequestCallback);
1597```
1598
1599## off('keyRequest')<sup>12+</sup>
1600
1601off(type: 'keyRequest', callback?: KeyRequestCallback): void
1602
1603Unsubscribes from media key requests during the cast of online DRM resources. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1604
1605**Atomic service API**: This API can be used in atomic services since API version 12.
1606
1607**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1608
1609**Parameters**
1610
1611| Name| Type  | Mandatory| Description                                     |
1612| ------ | ------ | ---- | ----------------------------------------- |
1613| type     | string                                                       | Yes  | Event type, which is **'keyRequest'** in this case.|
1614| callback |  [KeyRequestCallback](arkts-apis-avsession-t.md#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.                           |
1615
1616**Error codes**
1617
1618For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
1619
1620| ID| Error Message          |
1621| -------- | ---------------- |
1622| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1623| 6600101  | Session service exception. |
1624
1625**Example**
1626
1627```ts
1628aVCastController.off('keyRequest');
1629```
1630
1631## on('castControlGenericError')<sup>13+</sup>
1632
1633on(type: 'castControlGenericError', callback: ErrorCallback): void
1634
1635Subscribes to generic error events during cast control.
1636
1637Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1638
1639**Atomic service API**: This API can be used in atomic services since API version 13.
1640
1641**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1642
1643**Parameters**
1644
1645| Name  | Type    | Mandatory| Description                                                        |
1646| -------- | -------- | ---- | ------------------------------------------------------------ |
1647| type     | string   | Yes  | Event type, which is **'castControlGenericError'** in this case.|
1648| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
1649
1650**Error codes**
1651
1652| ID| Error Message             |
1653| -------- | --------------------- |
1654| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1655| 6611000  | The error code for cast control is unspecified.      |
1656| 6611001  | An unspecified error occurs in the remote player.   |
1657| 6611002  | The playback position falls behind the live window.     |
1658| 6611003  | The process of cast control times out.    |
1659| 6611004  | The runtime check failed.      |
1660| 6611100  | Cross-device data transmission is locked.    |
1661| 6611101  | The specified seek mode is not supported.   |
1662| 6611102  | The position to seek to is out of the range of the media asset or the specified seek mode is not supported.  |
1663| 6611103  | The specified playback mode is not supported.       |
1664| 6611104  | The specified playback speed is not supported.    |
1665| 6611105  | The action failed because either the media source device or the media sink device has been revoked.   |
1666| 6611106  | The parameter is invalid, for example, the url is illegal to play.  |
1667| 6611107  | Allocation of memory failed.  |
1668| 6611108  | Operation is not allowed.    |
1669
1670**Example**
1671
1672```ts
1673aVCastController.on('castControlGenericError', (error: BusinessError) => {
1674  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
1675})
1676```
1677
1678## off('castControlGenericError')<sup>13+</sup>
1679
1680off(type: 'castControlGenericError', callback?: ErrorCallback): void
1681
1682Unsubscribes from generic error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1683
1684**Atomic service API**: This API can be used in atomic services since API version 13.
1685
1686**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1687
1688**Parameters**
1689
1690| Name  | Type    | Mandatory| Description                                                        |
1691| -------- | -------- | ---- | ------------------------------------------------------------ |
1692| type     | string   | Yes  | 	Event type, which is **'castControlGenericError'** in this case.|
1693| 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.|
1694
1695**Error codes**
1696
1697| ID| Error Message             |
1698| -------- | --------------------- |
1699| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1700
1701**Example**
1702
1703```ts
1704aVCastController.off('castControlGenericError');
1705```
1706
1707## on('castControlIoError')<sup>13+</sup>
1708
1709on(type: 'castControlIoError', callback: ErrorCallback): void
1710
1711Subscribes to input/output error events during cast control.
1712
1713Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1714
1715**Atomic service API**: This API can be used in atomic services since API version 13.
1716
1717**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1718
1719**Parameters**
1720
1721| Name  | Type    | Mandatory| Description                                                        |
1722| -------- | -------- | ---- | ------------------------------------------------------------ |
1723| type     | string   | Yes  | Event type, which is **'castControlIoError'** in this case.|
1724| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
1725
1726**Error codes**
1727
1728| ID| Error Message             |
1729| -------- | --------------------- |
1730| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1731| 6612000  | An unspecified input/output error occurs.     |
1732| 6612001  | Network connection failure.   |
1733| 6612002  | Network timeout.     |
1734| 6612003  | Invalid "Content-Type" HTTP header.    |
1735| 6612004  | The HTTP server returns an unexpected HTTP response status code.      |
1736| 6612005  | The file does not exist.    |
1737| 6612006  | No permission is granted to perform the IO operation.   |
1738| 6612007  | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. |
1739| 6612008  | Reading data out of the data bound.    |
1740| 6612100  | The media does not contain any contents that can be played.   |
1741| 6612101  | The media cannot be read, for example, because of dust or scratches.   |
1742| 6612102  | This resource is already in use. |
1743| 6612103  | The content using the validity interval has expired.  |
1744| 6612104  | Using the requested content to play is not allowed.    |
1745| 6612105  | The use of the allowed content cannot be verified.  |
1746| 6612106  | The number of times this content has been used as requested has reached the maximum allowed number of uses.  |
1747| 6612107  | An error occurs when sending packet from source device to sink device.    |
1748
1749**Example**
1750
1751```ts
1752aVCastController.on('castControlIoError', (error: BusinessError) => {
1753  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
1754})
1755```
1756
1757## off('castControlIoError')<sup>13+</sup>
1758
1759off(type: 'castControlIoError', callback?: ErrorCallback): void
1760
1761Unsubscribes from input/output error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1762
1763**Atomic service API**: This API can be used in atomic services since API version 13.
1764
1765**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1766
1767**Parameters**
1768
1769| Name  | Type    | Mandatory| Description                                                        |
1770| -------- | -------- | ---- | ------------------------------------------------------------ |
1771| type     | string   | Yes  | Event type, which is **'castControlIoError'** in this case.|
1772| 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.|
1773
1774**Error codes**
1775
1776| ID| Error Message             |
1777| -------- | --------------------- |
1778| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1779
1780**Example**
1781
1782```ts
1783aVCastController.off('castControlIoError');
1784```
1785
1786## on('castControlParsingError')<sup>13+</sup>
1787
1788on(type: 'castControlParsingError', callback: ErrorCallback): void
1789
1790Subscribes to parsing error events during cast control.
1791
1792Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1793
1794**Atomic service API**: This API can be used in atomic services since API version 13.
1795
1796**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1797
1798**Parameters**
1799
1800| Name  | Type    | Mandatory| Description                                                        |
1801| -------- | -------- | ---- | ------------------------------------------------------------ |
1802| type     | string   | Yes  | Event type, which is **'castControlParsingError'** in this case.|
1803| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
1804
1805**Error codes**
1806
1807| ID | Error Message             |
1808| -------- | --------------------- |
1809| 401      |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1810| 6613000  | Unspecified error related to content parsing.     |
1811| 6613001  | Parsing error associated with media container format bit streams.   |
1812| 6613002  | Parsing error associated with the media manifest.     |
1813| 6613003  | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.    |
1814| 6613004  | Unsupported feature in the media manifest.    |
1815
1816**Example**
1817
1818```ts
1819aVCastController.on('castControlParsingError', (error: BusinessError) => {
1820  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
1821})
1822```
1823
1824## off('castControlParsingError')<sup>13+</sup>
1825
1826off(type: 'castControlParsingError', callback?: ErrorCallback): void
1827
1828Unsubscribes from parsing error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1829
1830**Atomic service API**: This API can be used in atomic services since API version 13.
1831
1832**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1833
1834**Parameters**
1835
1836| Name  | Type    | Mandatory| Description                                                        |
1837| -------- | -------- | ---- | ------------------------------------------------------------ |
1838| type     | string   | Yes  | 	Event type, which is **'castControlParsingError'** in this case.|
1839| 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.|
1840
1841**Error codes**
1842
1843| ID| Error Message             |
1844| -------- | --------------------- |
1845| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1846
1847**Example**
1848
1849```ts
1850aVCastController.off('castControlParsingError');
1851```
1852
1853## on('castControlDecodingError')<sup>13+</sup>
1854
1855on(type: 'castControlDecodingError', callback: ErrorCallback): void
1856
1857Subscribes to decoding error events during cast control.
1858
1859Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1860
1861**Atomic service API**: This API can be used in atomic services since API version 13.
1862
1863**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1864
1865**Parameters**
1866
1867| Name  | Type    | Mandatory| Description                                                        |
1868| -------- | -------- | ---- | ------------------------------------------------------------ |
1869| type     | string   | Yes  | Event type, which is **'castControlDecodingError'** in this case.|
1870| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
1871
1872**Error codes**
1873
1874| ID| Error Message             |
1875| -------- | --------------------- |
1876| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1877| 6614000  | Unspecified decoding error.     |
1878| 6614001  | Decoder initialization failed.   |
1879| 6614002  | Decoder query failed.     |
1880| 6614003  | Decoding the media samples failed.    |
1881| 6614004  | The format of the content to decode exceeds the capabilities of the device.    |
1882| 6614005  | The format of the content to decode is not supported.    |
1883
1884**Example**
1885
1886```ts
1887aVCastController.on('castControlDecodingError', (error: BusinessError) => {
1888  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
1889})
1890```
1891
1892## off('castControlDecodingError')<sup>13+</sup>
1893
1894off(type: 'castControlDecodingError', callback?: ErrorCallback): void
1895
1896Unsubscribes from decoding error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1897
1898**Atomic service API**: This API can be used in atomic services since API version 13.
1899
1900**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1901
1902**Parameters**
1903
1904| Name  | Type    | Mandatory| Description                                                        |
1905| -------- | -------- | ---- | ------------------------------------------------------------ |
1906| type     | string   | Yes  | 	Event type, which is **'castControlDecodingError'** in this case.|
1907| 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.|
1908
1909**Error codes**
1910
1911| ID| Error Message             |
1912| -------- | --------------------- |
1913| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1914
1915**Example**
1916
1917```ts
1918aVCastController.off('castControlDecodingError');
1919```
1920
1921## on('castControlAudioRendererError')<sup>13+</sup>
1922
1923on(type: 'castControlAudioRendererError', callback: ErrorCallback): void
1924
1925Subscribes to audio renderer error events during cast control.
1926
1927Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1928
1929**Atomic service API**: This API can be used in atomic services since API version 13.
1930
1931**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1932
1933**Parameters**
1934
1935| Name  | Type    | Mandatory| Description                                                        |
1936| -------- | -------- | ---- | ------------------------------------------------------------ |
1937| type     | string   | Yes  | Event type, which is **'castControlAudioRendererError'** in this case.|
1938| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
1939
1940**Error codes**
1941
1942For details about the error codes, see [Media Error Codes](../apis-media-kit/errorcode-media.md) and [AVSession Management Error Codes](errorcode-avsession.md).
1943
1944| ID| Error Message             |
1945| -------- | --------------------- |
1946| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1947| 6615000  | Unspecified errors related to the audio renderer.     |
1948| 6615001  | Initializing the audio renderer failed.   |
1949| 6615002  | The audio renderer fails to write data.     |
1950
1951**Example**
1952
1953```ts
1954aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
1955  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
1956})
1957```
1958
1959## off('castControlAudioRendererError')<sup>13+</sup>
1960
1961off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void
1962
1963Unsubscribes from audio renderer error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
1964
1965**Atomic service API**: This API can be used in atomic services since API version 13.
1966
1967**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1968
1969**Parameters**
1970
1971| Name  | Type    | Mandatory| Description                                                        |
1972| -------- | -------- | ---- | ------------------------------------------------------------ |
1973| type     | string   | Yes  | Event type, which is **'castControlAudioRendererError'** in this case.|
1974| 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.|
1975
1976**Error codes**
1977
1978| ID| Error Message             |
1979| -------- | --------------------- |
1980| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
1981
1982**Example**
1983
1984```ts
1985aVCastController.off('castControlAudioRendererError');
1986```
1987
1988## on('castControlDrmError')<sup>13+</sup>
1989
1990on(type: 'castControlDrmError', callback: ErrorCallback): void
1991
1992Subscribes to DRM error events during cast control.
1993
1994Multiple callbacks can be registered for this event. To ensure only the latest callback executes, unregister previous listeners first. Otherwise, all registered callbacks will fire on state changes.
1995
1996**Atomic service API**: This API can be used in atomic services since API version 13.
1997
1998**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1999
2000**Parameters**
2001
2002| Name  | Type    | Mandatory| Description                                                        |
2003| -------- | -------- | ---- | ------------------------------------------------------------ |
2004| type     | string   | Yes  | Event type, which is **'castControlDrmError'** in this case.|
2005| callback | ErrorCallback | Yes  | Callback invoked when the event is triggered.|
2006
2007**Error codes**
2008
2009| ID| Error Message             |
2010| -------- | --------------------- |
2011| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2012| 6616000  | Unspecified error related to DRM.     |
2013| 6616001  | The chosen DRM protection scheme is not supported by the device.  |
2014| 6616002  | Device provisioning failed.    |
2015| 6616003  | The DRM-protected content to play is incompatible.     |
2016| 6616004  | Failed to obtain a license.   |
2017| 6616005  | The operation is disallowed by the license policy.     |
2018| 6616006  | An error occurs in the DRM system.     |
2019| 6616007  | The device has revoked DRM privileges.   |
2020| 6616008  | The DRM license being loaded into the open DRM session has expired.      |
2021| 6616100  | An error occurs when the DRM processes the key response.     |
2022
2023**Example**
2024
2025```ts
2026aVCastController.on('castControlDrmError', (error: BusinessError) => {
2027  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
2028})
2029```
2030
2031## off('castControlDrmError')<sup>13+</sup>
2032
2033off(type: 'castControlDrmError', callback?: ErrorCallback): void
2034
2035Unsubscribes from DRM error events during cast control. If a callback is specified, the corresponding listener is unregistered. If no callback is specified, all listeners for the specified event are unregistered.
2036
2037**Atomic service API**: This API can be used in atomic services since API version 13.
2038
2039**System capability**: SystemCapability.Multimedia.AVSession.AVCast
2040
2041**Parameters**
2042
2043| Name  | Type    | Mandatory| Description                                                        |
2044| -------- | -------- | ---- | ------------------------------------------------------------ |
2045| type     | string   | Yes  | Event type, which is **'castControlDrmError'** in this case.|
2046| 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.|
2047
2048**Error codes**
2049
2050| ID| Error Message             |
2051| -------- | --------------------- |
2052| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2053
2054**Example**
2055
2056```ts
2057aVCastController.off('castControlDrmError');
2058```
2059
2060## on('customDataChange')<sup>20+</sup>
2061
2062on(type: 'customDataChange', callback: Callback\<Record\<string, Object>>): void
2063
2064Subscribes to events indicating that custom data is sent to a remote device.
2065
2066**Atomic service API**: This API can be used in atomic services since API version 20.
2067
2068**System capability**: SystemCapability.Multimedia.AVSession.AVCast
2069
2070**Parameters**
2071
2072| Name  | Type                            | Mandatory| Description                                                        |
2073| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
2074| type | string | Yes| Event type. The event **'customDataChange'** is triggered when the provider sends custom data.|
2075| callback | Callback\<Record\<string, Object>> | Yes  | Callback used to receive the custom data.                              |
2076
2077**Error codes**
2078
2079For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2080
2081| ID| Error Message                                                    |
2082| -------- | ------------------------------------------------------------ |
2083| 6600101  | Session service exception. |
2084
2085**Example**
2086
2087```ts
2088aVCastController.on('customDataChange', (callback) => {
2089    console.info(`Caught customDataChange event,the new callback is: ${JSON.stringify(callback)}`);
2090});
2091```
2092
2093## off('customDataChange')<sup>20+</sup>
2094
2095off(type: 'customDataChange', callback?: Callback\<Record\<string, Object>>): void
2096
2097Unsubscribes from events indicating that custom data is sent to a remote device.
2098
2099**Atomic service API**: This API can be used in atomic services since API version 20.
2100
2101**System capability**: SystemCapability.Multimedia.AVSession.AVCast
2102
2103**Parameters**
2104
2105| Name  | Type                            | Mandatory| Description                                                        |
2106| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
2107| type     | string                           | Yes  | Event type, which is **'customDataChange'** in this case.        |
2108| callback | Callback\<Record\<string, Object>> | No  | Callback used for unsubscription. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
2109
2110**Error codes**
2111
2112For details about the error codes, see [AVSession Management Error Codes](errorcode-avsession.md).
2113
2114| ID| Error Message                                                    |
2115| -------- | ------------------------------------------------------------ |
2116| 6600101  | Session service exception. |
2117
2118**Example**
2119
2120```ts
2121aVCastController.off('customDataChange');
2122```
2123