• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AVCastController)
2<!--Kit: AVSession Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @ccfriend; @liao_qian-->
5<!--Designer: @ccfriend-->
6<!--Tester: @chenmingxi1_huawei-->
7<!--Adviser: @zengyawen-->
8
9> **说明:**
10>
11> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
12> - 本Interface首批接口从API version 10开始支持。
13
14在投播建立后,调用[avSession.getAVCastController](arkts-apis-avsession-AVSession.md#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。
15
16## 导入模块
17
18```ts
19import { avSession } from '@kit.AVSessionKit';
20```
21
22## getAVPlaybackState<sup>10+</sup>
23
24getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
25
26获取当前的远端播放状态。结果通过callback异步回调方式返回。
27
28**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
29
30**参数:**
31
32| 参数名    | 类型                                                        | 必填 | 说明                                                         |
33| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
34| callback  | AsyncCallback<[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\> | 是   | 回调函数,返回远端播放状态。 |
35
36**错误码:**
37
38以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
39
40| 错误码ID | 错误信息 |
41| -------- | ---------------------------------------- |
42| 6600101  | Session service exception. |
43
44**示例:**
45
46```ts
47import { BusinessError } from '@kit.BasicServicesKit';
48
49aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
50  if (err) {
51    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
52  } else {
53    console.info('getAVPlaybackState : SUCCESS');
54  }
55});
56```
57
58## getAVPlaybackState<sup>10+</sup>
59
60getAVPlaybackState(): Promise\<AVPlaybackState>
61
62获取当前的远端播放状态。结果通过Promise异步回调方式返回。
63
64**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
65
66**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
67
68**返回值:**
69
70| 类型                                                        | 说明                                                         |
71| --------- | ------------------------------------------------------------ |
72| Promise<[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\>  | Promise对象。返回远端播放状态。 |
73
74**错误码:**
75
76以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
77
78| 错误码ID | 错误信息 |
79| -------- | ---------------------------------------- |
80| 6600101  | Session service exception. |
81
82**示例:**
83
84```ts
85import { BusinessError } from '@kit.BasicServicesKit';
86
87aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
88  console.info('getAVPlaybackState : SUCCESS');
89}).catch((err: BusinessError) => {
90  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
91});
92```
93
94## getSupportedDecoders<sup>19+</sup>
95
96getSupportedDecoders(): Promise\<Array\<DecoderType>>
97
98获取当前远端设备的解码方式。使用Promise异步回调。
99
100**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
101
102**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
103
104**返回值:**
105
106| 类型                                                        | 说明                                                         |
107| --------- | ------------------------------------------------------------ |
108| Promise\<Array\<[DecoderType](arkts-apis-avsession-e.md#decodertype19)\>\> | Promise对象。返回远端设备所支持的解码能力列表。 |
109
110**错误码:**
111
112以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
113
114| 错误码ID | 错误信息 |
115| -------- | ---------------------------------------- |
116| 6600101  | Session service exception. |
117
118**示例:**
119
120```ts
121import { BusinessError } from '@kit.BasicServicesKit';
122
123aVCastController.getSupportedDecoders().then((decoderTypes: avSession.DecoderType[]) => {
124  console.info(`getSupportedDecoders : SUCCESS : decoderTypes.length : ${decoderTypes.length}`);
125  if (decoderTypes.length > 0 ) {
126    console.info(`getSupportedDecoders : SUCCESS : decoderTypes[0] : ${decoderTypes[0]}`);
127  }
128}).catch((err: BusinessError) => {
129  console.error(`getSupportedDecoders BusinessError: code: ${err.code}, message: ${err.message}`);
130});
131```
132
133## getRecommendedResolutionLevel<sup>19+</sup>
134
135getRecommendedResolutionLevel(decoderType: DecoderType): Promise\<ResolutionLevel>
136
137通过传递解码方式,获取推荐的分辨率。使用Promise异步回调。
138
139**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
140
141**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
142
143**参数:**
144
145| 参数名   | 类型                                      | 必填 | 说明                       |
146| -------- | ----------------------------------------- | ---- | -------------------------- |
147| decoderType | [DecoderType](arkts-apis-avsession-e.md#decodertype19) | 是 | 设备所支持的解码格式。<br>设备所支持的解码格式包括:<br>'OH_AVCODEC_MIMETYPE_VIDEO_AVC':VIDEO AVC,<br>'OH_AVCODEC_MIMETYPE_VIDEO_HEVC':VIDEO HEVC,<br>'OH_AVCODEC_MIMETYPE_AUDIO_VIVID':AUDIO AV3A。 |
148
149**返回值:**
150
151| 类型                                                        | 说明                                                         |
152| --------- | ------------------------------------------------------------ |
153| Promise\<[ResolutionLevel](arkts-apis-avsession-e.md#resolutionlevel19)\> | Promise对象。返回远端设备推荐的分辨率。 |
154
155**错误码:**
156
157以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
158
159| 错误码ID | 错误信息 |
160| -------- | ---------------------------------------- |
161| 6600101  | Session service exception. |
162
163**示例:**
164
165```ts
166import { BusinessError } from '@kit.BasicServicesKit';
167
168let decoderType = avSession.DecoderType.OH_AVCODEC_MIMETYPE_VIDEO_AVC;
169aVCastController.getRecommendedResolutionLevel(decoderType).then((resolutionLevel: avSession.ResolutionLevel) => {
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
180获取当前的远端设备所支持的HDR能力。使用Promise异步回调。
181
182**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
183
184**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
185
186**返回值:**
187
188| 类型                                                        | 说明                                                         |
189| --------- | ------------------------------------------------------------ |
190| Promise\<Array\<[hdrCapability.HDRFormat](../apis-arkgraphics2d/js-apis-hdrCapability.md#hdrformat)\>\> | Promise对象。返回远端设备所支持的HDR能力。 |
191
192**错误码:**
193
194以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
195
196| 错误码ID | 错误信息 |
197| -------- | ---------------------------------------- |
198| 6600101  | Session service exception. |
199
200**示例:**
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
220获取当前的远端设备所支持倍速播放列表。使用Promise异步回调。
221
222**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。
223
224**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
225
226**返回值:**
227
228| 类型                                                        | 说明                                                         |
229| --------- | ------------------------------------------------------------ |
230| Promise\<Array\<number\>\> | Promise对象。返回远端设备所支持的倍速播放列表。 |
231
232**错误码:**
233
234以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
235
236| 错误码ID | 错误信息 |
237| -------- | ---------------------------------------- |
238| 6600101  | Session service exception. |
239
240**示例:**
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
259通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。
260
261
262**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
263
264**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
265
266**参数:**
267
268| 参数名    | 类型                                  | 必填 | 说明                           |
269| ------- | ------------------------------------- | ---- | ------------------------------ |
270| command | [AVCastControlCommand](arkts-apis-avsession-i.md#avcastcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
271
272**返回值:**
273
274| 类型           | 说明                          |
275| -------------- | ----------------------------- |
276| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
277
278**错误码:**
279
280以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
281
282| 错误码ID | 错误信息 |
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**示例:**
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
306通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。
307
308**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
309
310**参数:**
311
312| 参数名   | 类型                                  | 必填 | 说明                           |
313| -------- | ------------------------------------- | ---- | ------------------------------ |
314| command  | [AVCastControlCommand](arkts-apis-avsession-i.md#avcastcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
315| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。                     |
316
317**错误码:**
318
319以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
320
321| 错误码ID | 错误信息 |
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**示例:**
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
347发送私有数据到远端设备。使用Promise异步回调。
348
349**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
350
351**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
352
353**参数:**
354
355| 参数名 | 类型                   | 必填 | 说明                                                         |
356| ------ | ---------------------- | ---- | ------------------------------------------------------------ |
357| data   | Record\<string, Object> | 是   | 应用程序填充的自定义数据。服务端仅解析key为'customData',且Object为string类型的对象。 |
358
359**返回值:**
360
361| 类型           | 说明                          |
362| -------------- | ----------------------------- |
363| Promise\<void> | Promise对象,无返回结果。 |
364
365**错误码:**
366
367以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
368
369| 错误码ID | 错误信息                                                     |
370| -------- | ------------------------------------------------------------ |
371| 6600101  | Session service exception. |
372
373**示例:**
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
385准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过callback异步回调方式返回。
386
387**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
388
389**参数:**
390
391| 参数名    | 类型                                  | 必填 | 说明                           |
392| ------- | ------------------------------------- | ---- | ------------------------------ |
393| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
394| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
395
396**错误码:**
397
398以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
399
400| 错误码ID | 错误信息 |
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**示例:**
407
408```ts
409import { BusinessError } from '@kit.BasicServicesKit';
410
411// 设置播放参数,开始播放。
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// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
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
442准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过Promise异步回调方式返回。
443
444
445**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
446
447**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
448
449**参数:**
450
451| 参数名    | 类型                                  | 必填 | 说明                           |
452| ------- | ------------------------------------- | ---- | ------------------------------ |
453| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
454
455**返回值:**
456
457| 类型           | 说明                          |
458| -------------- | ----------------------------- |
459| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
460
461**错误码:**
462
463以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
464
465| 错误码ID | 错误信息 |
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**示例:**
472
473```ts
474import { BusinessError } from '@kit.BasicServicesKit';
475
476// 设置播放参数,开始播放。
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// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
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
505启动播放某个媒体资源。结果通过callback异步回调方式返回。
506
507**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
508
509**参数:**
510
511| 参数名    | 类型                                  | 必填 | 说明                           |
512| ------- | ------------------------------------- | ---- | ------------------------------ |
513| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
514| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
515
516**错误码:**
517
518以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
519
520| 错误码ID | 错误信息 |
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**示例:**
527
528```ts
529import { BusinessError } from '@kit.BasicServicesKit';
530
531// 设置播放参数,开始播放。
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// 启动播放。
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
563启动播放某个媒体资源。结果通过Promise异步回调方式返回。
564
565**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
566
567**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
568
569**参数:**
570
571| 参数名    | 类型                                  | 必填 | 说明                           |
572| ------- | ------------------------------------- | ---- | ------------------------------ |
573| item | [AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
574
575**返回值:**
576
577| 类型           | 说明                          |
578| -------------- | ----------------------------- |
579| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
580
581**错误码:**
582
583以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
584
585| 错误码ID | 错误信息 |
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**示例:**
592
593```ts
594import { BusinessError } from '@kit.BasicServicesKit';
595
596// 设置播放参数,开始播放。
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// 启动播放。
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
625获取当前投播的资源信息。结果通过callback异步回调方式返回。
626
627**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
628
629**参数:**
630
631| 参数名   | 类型                                  | 必填 | 说明                                  |
632| -------- | ------------------------------------- | ---- | ------------------------------------- |
633| callback | AsyncCallback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
634
635**错误码:**
636
637以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
638
639| 错误码ID | 错误信息 |
640| -------- | ---------------------------------------- |
641| 6600101  | Session service exception. |
642
643**示例:**
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
661获取当前投播的资源信息。结果通过Promise异步回调方式返回。
662
663**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
664
665**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
666
667**返回值:**
668
669| 类型           | 说明                          |
670| -------------- | ----------------------------- |
671| Promise\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 |
672
673**错误码:**
674
675以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
676
677| 错误码ID | 错误信息 |
678| -------- | ---------------------------------------- |
679| 6600101  | Session service exception. |
680
681**示例:**
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
697获取当前支持的命令。结果通过callback异步回调方式返回。
698
699**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
700
701**参数:**
702
703| 参数名 | 类型 | 必填 | 说明 |
704| -------- | ------------------------------------- | ---- | ------------------------------------- |
705| callback | AsyncCallback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)>> | 是 | 回调函数。返回当前支持的命令。 |
706
707**错误码:**
708
709以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
710
711| 错误码ID | 错误信息 |
712| -------- | ---------------------------------------- |
713| 6600101  | Session service exception. |
714
715**示例:**
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
733获取当前支持的命令。结果通过Promise异步回调方式返回。
734
735**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
736
737**返回值:**
738
739| 类型 | 说明 |
740| -------------- | ----------------------------- |
741| Promise<Array\<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)>> | Promise对象,返回当前支持的命令。 |
742
743**错误码:**
744
745以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
746
747| 错误码ID | 错误信息 |
748| -------- | ---------------------------------------- |
749| 6600101  | Session service exception. |
750
751**示例:**
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
767在线DRM资源投播时,处理许可证响应。结果通过Promise异步回调方式返回。
768
769**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
770
771**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
772
773**参数:**
774
775| 参数名   | 类型                                  | 必填 | 说明                                  |
776| -------- | ------------------------------------- | ---- | ------------------------------------- |
777| assetId | string                  | 是   | 媒体ID。 |
778| response | Uint8Array             | 是   | 许可证响应。 |
779
780**返回值:**
781
782| 类型           | 说明                          |
783| -------------- | ----------------------------- |
784| Promise\<void> | Promise对象,当处理许可证响应成功,无返回结果,否则返回错误对象。 |
785
786**错误码:**
787
788以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
789
790| 错误码ID | 错误信息 |
791| -------- | ---------------------------------------- |
792| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
793| 6600101  | Session service exception. |
794
795**示例:**
796
797```ts
798let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
799  // 根据assetId获取对应的DRM url。
800  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
801  // 从服务器获取许可证,需要开发者根据实际情况进行赋值。
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
812销毁当前controller,结果通过callback异步回调方式返回。
813
814**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
815
816**参数:**
817
818| 参数名   | 类型                       | 必填 | 说明                                                         |
819| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
820| callback | AsyncCallback\<void>       | 是   | 回调函数。当命令执行成功,err为undefined,否则返回错误对象。 |
821
822**错误码:**
823
824以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
825
826| 错误码ID | 错误信息 |
827| -------- | -------------------------- |
828| 6600101  | Session service exception. |
829
830**示例:**
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
848销毁当前controller。结果通过Promise异步回调方式返回。
849
850**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
851
852**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
853
854**返回值:**
855
856| 类型           | 说明                          |
857| -------------- | ----------------------------- |
858| Promise\<void> | Promise对象,controller销毁成功,无结果返回,否则返回错误对象。 |
859
860**错误码:**
861
862以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
863
864| 错误码ID | 错误信息 |
865| -------- | ------------------------------ |
866| 6600101  | Session service exception. |
867
868**示例:**
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
885设置播放状态变化的监听事件。
886
887每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
888
889**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
890
891**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
892
893**参数:**
894
895| 参数名   | 类型                                                         | 必填 | 说明                                                         |
896| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
897| type     | string                                                       | 是   | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 |
898| filter   | Array\<keyof&nbsp;[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注播放状态所有字段变化;Array<keyof&nbsp;[AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)\> 表示关注Array中的字段变化。 |
899| callback | (state: [AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)) => void         | 是   | 回调函数,参数state是变化后的播放状态。                      |
900
901**错误码:**
902
903以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
904
905| 错误码ID | 错误信息 |
906| -------- | ------------------------------ |
907| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
908| 6600101  | Session service exception. |
909
910**示例:**
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
927取消播放状态变化事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
928
929**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
930
931**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
932
933**参数:**
934
935| 参数名   | 类型                                                         | 必填 | 说明                                                     |
936| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
937| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playbackStateChange'`。    |
938| callback | (state: [AVPlaybackState](arkts-apis-avsession-i.md#avplaybackstate10)) => void         | 否   | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                      |
939
940**错误码:**
941
942以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
943
944| 错误码ID | 错误信息 |
945| -------- | ---------------- |
946| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
947| 6600101  | Session service exception. |
948
949**示例:**
950
951```ts
952aVCastController.off('playbackStateChange');
953```
954
955## on('mediaItemChange')<sup>10+</sup>
956
957on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
958
959设置投播当前播放媒体内容的监听事件。
960
961每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
962
963**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
964
965**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
966
967**参数:**
968
969| 参数名   | 类型                                                         | 必填 | 说明                                                         |
970| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
971| type     | string                                                       | 是   | 事件回调类型,支持事件`'mediaItemChange'`:当播放的媒体内容变化时,触发该事件。 |
972| callback | Callback<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>         | 是   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。                      |
973
974**错误码:**
975
976以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
977
978| 错误码ID | 错误信息 |
979| -------- | ------------------------------ |
980| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
981| 6600101  | Session service exception. |
982
983**示例:**
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
995取消设置投播当前播放媒体内容事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
996
997**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
998
999**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1000
1001**参数:**
1002
1003| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1004| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1005| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'mediaItemChange'`。    |
1006
1007**错误码:**
1008
1009以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1010
1011| 错误码ID | 错误信息 |
1012| -------- | ---------------- |
1013| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1014| 6600101  | Session service exception. |
1015
1016**示例:**
1017
1018```ts
1019aVCastController.off('mediaItemChange');
1020```
1021
1022## on('playNext')<sup>10+</sup>
1023
1024on(type: 'playNext', callback: Callback\<void>): void
1025
1026设置播放下一首资源的监听事件。
1027
1028每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1029
1030**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1031
1032**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1033
1034**参数:**
1035
1036| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1037| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1038| type     | string                                                       | 是   | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 |
1039| callback | Callback\<void\>         | 是   | 回调函数。                      |
1040
1041**错误码:**
1042
1043以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1044
1045| 错误码ID | 错误信息 |
1046| -------- | ------------------------------ |
1047| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1048| 6600101  | Session service exception. |
1049
1050**示例:**
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
1062取消设置播放下一首资源事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1063
1064**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1065
1066**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1067
1068**参数:**
1069
1070| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1071| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1072| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playNext'`。    |
1073
1074**错误码:**
1075
1076以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1077
1078| 错误码ID | 错误信息 |
1079| -------- | ---------------- |
1080| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1081| 6600101  | Session service exception. |
1082
1083**示例:**
1084
1085```ts
1086aVCastController.off('playNext');
1087```
1088
1089## on('playPrevious')<sup>10+</sup>
1090
1091on(type: 'playPrevious', callback: Callback\<void>): void
1092
1093设置播放上一首资源的监听事件。
1094
1095每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1096
1097**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1098
1099**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1100
1101**参数:**
1102
1103| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1104| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1105| type     | string                                                       | 是   | 事件回调类型,支持事件`'playPrevious'`:当播放上一首状态变化时,触发该事件。 |
1106| callback | Callback\<void\>         | 是   | 回调函数。                      |
1107
1108**错误码:**
1109
1110以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1111
1112| 错误码ID | 错误信息 |
1113| -------- | ------------------------------ |
1114| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1115| 6600101  | Session service exception. |
1116
1117**示例:**
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
1129取消设置播放上一首资源事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1130
1131**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1132
1133**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1134
1135**参数:**
1136
1137| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1138| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1139| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playPrevious'`。    |
1140
1141**错误码:**
1142
1143以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1144
1145| 错误码ID | 错误信息 |
1146| -------- | ---------------- |
1147| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1148| 6600101  | Session service exception. |
1149
1150**示例:**
1151
1152```ts
1153aVCastController.off('playPrevious');
1154```
1155
1156## on('requestPlay')<sup>11+</sup>
1157
1158on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
1159
1160设置请求播放的监听事件。
1161
1162每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1163
1164**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1165
1166**参数:**
1167
1168| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1169| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1170| type     | string                                                       | 是   | 事件回调类型,支持事件`'requestPlay'`:当请求播放状态变化时,触发该事件。 |
1171| callback | Callback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>                | 是   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件注册成功,err为undefined,否则返回错误对象。  |
1172
1173**错误码:**
1174
1175以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1176
1177| 错误码ID | 错误信息 |
1178| -------- | ------------------------------ |
1179| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1180| 6600101  | Session service exception. |
1181
1182**示例:**
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
1194取消设置请求播放事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1195
1196**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1197
1198**参数:**
1199
1200| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1201| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
1202| type     | string                                                      | 是   | 取消对应的监听事件,支持事件`'requestPlay'`。    |
1203| callback | Callback\<[AVQueueItem](arkts-apis-avsession-i.md#avqueueitem10)>             | 否   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。|
1204
1205**错误码:**
1206
1207以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1208
1209| 错误码ID | 错误信息 |
1210| -------- | ---------------- |
1211| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1212| 6600101  | Session service exception. |
1213
1214**示例:**
1215
1216```ts
1217aVCastController.off('requestPlay');
1218```
1219
1220## on('endOfStream')<sup>11+</sup>
1221
1222on(type: 'endOfStream', callback: Callback\<void>): void
1223
1224设置播放结束的监听事件。
1225
1226每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1227
1228**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1229
1230**参数:**
1231
1232| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1233| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ |
1234| type     | string                                                      | 是   | 事件回调类型,支持事件`'endOfStream'`:当资源播放结束时,触发该事件。 |
1235| callback | Callback\<void\>                                            | 是   | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。      |
1236
1237**错误码:**
1238
1239以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1240
1241| 错误码ID | 错误信息 |
1242| -------- | ------------------------------ |
1243| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1244| 6600101  | Session service exception. |
1245
1246**示例:**
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
1258取消设置播放结束事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1259
1260**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1261
1262**参数:**
1263
1264| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1265| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
1266| type     | string                                                      | 是   | 取消对应的监听事件,支持事件`'endOfStream'`。    |
1267| callback | Callback\<void\>                                            | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。   |
1268
1269**错误码:**
1270
1271以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1272
1273| 错误码ID | 错误信息 |
1274| -------- | ---------------- |
1275| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1276| 6600101  | Session service exception. |
1277
1278**示例:**
1279
1280```ts
1281aVCastController.off('endOfStream');
1282```
1283
1284## on('seekDone')<sup>10+</sup>
1285
1286on(type: 'seekDone', callback: Callback\<number>): void
1287
1288设置seek结束的监听事件。
1289
1290每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1291
1292**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1293
1294**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1295
1296**参数:**
1297
1298| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1299| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1300| type     | string                                                       | 是   | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 |
1301| callback | Callback\<number\>         | 是   | 回调函数,返回seek后播放的位置。                      |
1302
1303**错误码:**
1304
1305以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1306
1307| 错误码ID | 错误信息 |
1308| -------- | ------------------------------ |
1309| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1310| 6600101  | Session service exception. |
1311
1312**示例:**
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
1324取消设置seek结束事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1325
1326**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1327
1328**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1329
1330**参数:**
1331
1332| 参数名   | 类型                                                         | 必填 | 说明                                                     |
1333| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
1334| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'seekDone'`。    |
1335
1336**错误码:**
1337
1338以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1339
1340| 错误码ID | 错误信息 |
1341| -------- | ---------------- |
1342| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1343| 6600101  | Session service exception. |
1344
1345**示例:**
1346
1347```ts
1348aVCastController.off('seekDone');
1349```
1350
1351## on('validCommandChange')<sup>11+</sup>
1352
1353on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
1354
1355会话支持的有效命令变化监听事件。
1356
1357每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1358
1359**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1360
1361**参数:**
1362
1363| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1364| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1365| type     | string                                                       | 是   | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 |
1366| callback | Callback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)\>\>   | 是   | 回调函数。参数commands是有效命令的集合。                     |
1367
1368**错误码:**
1369
1370以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1371
1372| 错误码ID | 错误信息 |
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**示例:**
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
1391取消会话有效命令变化事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1392
1393**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1394
1395**参数:**
1396
1397| 参数名   | 类型                                                         | 必填 | 说明                                                        |
1398| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
1399| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'validCommandChange'`。         |
1400| callback | Callback<Array<[AVCastControlCommandType](arkts-apis-avsession-t.md#avcastcontrolcommandtype10)\>\> | 否   | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。          |
1401
1402**错误码:**
1403
1404以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1405
1406| 错误码ID | 错误信息           |
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**示例:**
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
1421媒体控制器监听视频尺寸变化变化的事件。
1422
1423每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1424
1425系统能力: SystemCapability.Multimedia.AVSession.AVCast
1426
1427**参数:**
1428
1429| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1430| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1431| type     | string                                                       | 是   | 事件回调类型,支持事件`'videoSizeChange'`:当检测到会话的合法命令发生改变时,触发该事件。 |
1432| callback | (width: number, height: number) => void   | 是   | 回调函数。                    |
1433
1434**错误码:**
1435
1436以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1437
1438| 错误码ID | 错误信息 |
1439| -------- | ------------------------------ |
1440| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1441| 6600101  | Session service exception. |
1442
1443**示例:**
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
1455取消视频尺寸事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1456
1457系统能力: SystemCapability.Multimedia.AVSession.AVCast
1458
1459**参数:**
1460
1461| 参数名   | 类型                                                         | 必填 | 说明                                                         |
1462| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1463| type     | string                                                       | 是   | 事件回调类型,支持事件`'videoSizeChange'`:当检测到会话的合法命令发生改变时,触发该事件。 |
1464
1465**错误码:**
1466
1467以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1468
1469| 错误码ID | 错误信息 |
1470| -------- | ------------------------------ |
1471| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1472| 6600101  | Session service exception. |
1473
1474**示例:**
1475
1476```ts
1477aVCastController.off('videoSizeChange');
1478```
1479
1480## on('error')<sup>10+</sup>
1481
1482on(type: 'error', callback: ErrorCallback): void
1483
1484监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。
1485
1486每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1487
1488**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1489
1490**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1491
1492**参数:**
1493
1494| 参数名   | 类型     | 必填 | 说明                                                         |
1495| -------- | -------- | ---- | ------------------------------------------------------------ |
1496| type     | string   | 是   | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 |
1497| callback | ErrorCallback | 是   | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 |
1498
1499**错误码:**
1500
1501以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)、[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
1502
1503| 错误码ID | 错误信息              |
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**示例:**
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
1528取消播放的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1529
1530**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1531
1532**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1533
1534**参数:**
1535
1536| 参数名 | 类型   | 必填 | 说明                                      |
1537| ------ | ------ | ---- | ----------------------------------------- |
1538| type   | string | 是   | 错误事件回调类型,取消注册的事件:'error'。 |
1539
1540**错误码:**
1541
1542以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)、[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
1543
1544| 错误码ID | 错误信息              |
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**示例:**
1556
1557```ts
1558aVCastController.off('error')
1559```
1560
1561## on('keyRequest')<sup>12+</sup>
1562
1563on(type: 'keyRequest', callback: KeyRequestCallback): void
1564
1565在线DRM资源投播时,设置许可证请求的事件监听。
1566
1567每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1568
1569**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1570
1571**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1572
1573**参数:**
1574
1575| 参数名 | 类型   | 必填 | 说明                                      |
1576| ------ | ------ | ---- | ----------------------------------------- |
1577| type     | string  | 是   | 事件回调类型,支持事件`'keyRequest'`:当DRM资源播放需要许可证时,触发该事件。 |
1578| callback | [KeyRequestCallback](arkts-apis-avsession-t.md#keyrequestcallback12)  | 是   | 回调函数,媒体资源及许可证请求数据。|
1579
1580
1581**错误码:**
1582
1583以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1584
1585| 错误码ID | 错误信息           |
1586| -------- | ---------------- |
1587| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1588| 6600101  | Session service exception. |
1589
1590**示例:**
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
1603取消许可证请求事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1604
1605**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1606
1607**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1608
1609**参数:**
1610
1611| 参数名 | 类型   | 必填 | 说明                                      |
1612| ------ | ------ | ---- | ----------------------------------------- |
1613| type     | string                                                       | 是   | 取消对应的监听事件,支持的事件是`'keyRequest'`。 |
1614| callback |  [KeyRequestCallback](arkts-apis-avsession-t.md#keyrequestcallback12)  | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
1615
1616**错误码:**
1617
1618以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1619
1620| 错误码ID | 错误信息           |
1621| -------- | ---------------- |
1622| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1623| 6600101  | Session service exception. |
1624
1625**示例:**
1626
1627```ts
1628aVCastController.off('keyRequest');
1629```
1630
1631## on('castControlGenericError')<sup>13+</sup>
1632
1633on(type: 'castControlGenericError', callback: ErrorCallback): void
1634
1635监听投播通用错误事件。
1636
1637每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1638
1639**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1640
1641**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1642
1643**参数:**
1644
1645| 参数名   | 类型     | 必填 | 说明                                                         |
1646| -------- | -------- | ---- | ------------------------------------------------------------ |
1647| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlGenericError'。 |
1648| callback | ErrorCallback | 是   | 投播通用错误事件回调方法。 |
1649
1650**错误码:**
1651
1652以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1653
1654| 错误码ID | 错误信息              |
1655| -------- | --------------------- |
1656| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1657| 6611000  | The error code for cast control is unspecified.      |
1658| 6611001  | An unspecified error occurs in the remote player.   |
1659| 6611002  | The playback position falls behind the live window.     |
1660| 6611003  | The process of cast control times out.    |
1661| 6611004  | The runtime check failed.      |
1662| 6611100  | Cross-device data transmission is locked.    |
1663| 6611101  | The specified seek mode is not supported.   |
1664| 6611102  | The position to seek to is out of the range of the media asset or the specified seek mode is not supported.  |
1665| 6611103  | The specified playback mode is not supported.       |
1666| 6611104  | The specified playback speed is not supported.    |
1667| 6611105  | The action failed because either the media source device or the media sink device has been revoked.   |
1668| 6611106  | The parameter is invalid, for example, the url is illegal to play.  |
1669| 6611107  | Allocation of memory failed.  |
1670| 6611108  | Operation is not allowed.    |
1671
1672**示例:**
1673
1674```ts
1675aVCastController.on('castControlGenericError', (error: BusinessError) => {
1676  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
1677})
1678```
1679
1680## off('castControlGenericError')<sup>13+</sup>
1681
1682off(type: 'castControlGenericError', callback?: ErrorCallback): void
1683
1684取消投播通用的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1685
1686**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1687
1688**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1689
1690**参数:**
1691
1692| 参数名   | 类型     | 必填 | 说明                                                         |
1693| -------- | -------- | ---- | ------------------------------------------------------------ |
1694| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlGenericError'。 |
1695| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
1696
1697**错误码:**
1698
1699以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1700
1701| 错误码ID | 错误信息              |
1702| -------- | --------------------- |
1703| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1704
1705**示例:**
1706
1707```ts
1708aVCastController.off('castControlGenericError');
1709```
1710
1711## on('castControlIoError')<sup>13+</sup>
1712
1713on(type: 'castControlIoError', callback: ErrorCallback): void
1714
1715监听投播输入/输出的错误事件。
1716
1717每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1718
1719**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1720
1721**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1722
1723**参数:**
1724
1725| 参数名   | 类型     | 必填 | 说明                                                         |
1726| -------- | -------- | ---- | ------------------------------------------------------------ |
1727| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlIoError'。 |
1728| callback | ErrorCallback | 是   | 投播输入/输出的错误事件回调方法。 |
1729
1730**错误码:**
1731
1732以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1733
1734| 错误码ID | 错误信息              |
1735| -------- | --------------------- |
1736| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1737| 6612000  | An unspecified input/output error occurs.     |
1738| 6612001  | Network connection failure.   |
1739| 6612002  | Network timeout.     |
1740| 6612003  | Invalid "Content-Type" HTTP header.    |
1741| 6612004  | The HTTP server returns an unexpected HTTP response status code.      |
1742| 6612005  | The file does not exist.    |
1743| 6612006  | No permission is granted to perform the IO operation.   |
1744| 6612007  | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. |
1745| 6612008  | Reading data out of the data bound.    |
1746| 6612100  | The media does not contain any contents that can be played.   |
1747| 6612101  | The media cannot be read, for example, because of dust or scratches.   |
1748| 6612102  | This resource is already in use. |
1749| 6612103  | The content using the validity interval has expired.  |
1750| 6612104  | Using the requested content to play is not allowed.    |
1751| 6612105  | The use of the allowed content cannot be verified.  |
1752| 6612106  | The number of times this content has been used as requested has reached the maximum allowed number of uses.  |
1753| 6612107  | An error occurs when sending packet from source device to sink device.    |
1754
1755**示例:**
1756
1757```ts
1758aVCastController.on('castControlIoError', (error: BusinessError) => {
1759  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
1760})
1761```
1762
1763## off('castControlIoError')<sup>13+</sup>
1764
1765off(type: 'castControlIoError', callback?: ErrorCallback): void
1766
1767取消投播输入/输出的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1768
1769**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1770
1771**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1772
1773**参数:**
1774
1775| 参数名   | 类型     | 必填 | 说明                                                         |
1776| -------- | -------- | ---- | ------------------------------------------------------------ |
1777| type     | string   | 是   | 取消对应的监听事件,支持的事件是'castControlIoError'。 |
1778| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
1779
1780**错误码:**
1781
1782以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1783
1784| 错误码ID | 错误信息              |
1785| -------- | --------------------- |
1786| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1787
1788**示例:**
1789
1790```ts
1791aVCastController.off('castControlIoError');
1792```
1793
1794## on('castControlParsingError')<sup>13+</sup>
1795
1796on(type: 'castControlParsingError', callback: ErrorCallback): void
1797
1798监听投播解析的错误事件。
1799
1800每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1801
1802**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1803
1804**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1805
1806**参数:**
1807
1808| 参数名   | 类型     | 必填 | 说明                                                         |
1809| -------- | -------- | ---- | ------------------------------------------------------------ |
1810| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlParsingError'。 |
1811| callback | ErrorCallback | 是   | 投播解析的错误事件回调方法。 |
1812
1813**错误码:**
1814
1815以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1816
1817| 错误码ID  | 错误信息              |
1818| -------- | --------------------- |
1819| 401      |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1820| 6613000  | Unspecified error related to content parsing.     |
1821| 6613001  | Parsing error associated with media container format bit streams.   |
1822| 6613002  | Parsing error associated with the media manifest.     |
1823| 6613003  | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.    |
1824| 6613004  | Unsupported feature in the media manifest.    |
1825
1826**示例:**
1827
1828```ts
1829aVCastController.on('castControlParsingError', (error: BusinessError) => {
1830  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
1831})
1832```
1833
1834## off('castControlParsingError')<sup>13+</sup>
1835
1836off(type: 'castControlParsingError', callback?: ErrorCallback): void
1837
1838取消投播解析的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1839
1840**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1841
1842**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1843
1844**参数:**
1845
1846| 参数名   | 类型     | 必填 | 说明                                                         |
1847| -------- | -------- | ---- | ------------------------------------------------------------ |
1848| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlParsingError'。 |
1849| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
1850
1851**错误码:**
1852
1853以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1854
1855| 错误码ID | 错误信息              |
1856| -------- | --------------------- |
1857| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1858
1859**示例:**
1860
1861```ts
1862aVCastController.off('castControlParsingError');
1863```
1864
1865## on('castControlDecodingError')<sup>13+</sup>
1866
1867on(type: 'castControlDecodingError', callback: ErrorCallback): void
1868
1869监听投播解码的错误事件。
1870
1871每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1872
1873**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1874
1875**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1876
1877**参数:**
1878
1879| 参数名   | 类型     | 必填 | 说明                                                         |
1880| -------- | -------- | ---- | ------------------------------------------------------------ |
1881| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlDecodingError'。 |
1882| callback | ErrorCallback | 是   | 投播解码的错误事件回调方法。 |
1883
1884**错误码:**
1885
1886以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
1887
1888| 错误码ID | 错误信息              |
1889| -------- | --------------------- |
1890| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1891| 6614000  | Unspecified decoding error.     |
1892| 6614001  | Decoder initialization failed.   |
1893| 6614002  | Decoder query failed.     |
1894| 6614003  | Decoding the media samples failed.    |
1895| 6614004  | The format of the content to decode exceeds the capabilities of the device.    |
1896| 6614005  | The format of the content to decode is not supported.    |
1897
1898**示例:**
1899
1900```ts
1901aVCastController.on('castControlDecodingError', (error: BusinessError) => {
1902  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
1903})
1904```
1905
1906## off('castControlDecodingError')<sup>13+</sup>
1907
1908off(type: 'castControlDecodingError', callback?: ErrorCallback): void
1909
1910取消投播解码的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1911
1912**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1913
1914**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1915
1916**参数:**
1917
1918| 参数名   | 类型     | 必填 | 说明                                                         |
1919| -------- | -------- | ---- | ------------------------------------------------------------ |
1920| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlDecodingError'。 |
1921| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
1922
1923**错误码:**
1924
1925以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1926
1927| 错误码ID | 错误信息              |
1928| -------- | --------------------- |
1929| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1930
1931**示例:**
1932
1933```ts
1934aVCastController.off('castControlDecodingError');
1935```
1936
1937## on('castControlAudioRendererError')<sup>13+</sup>
1938
1939on(type: 'castControlAudioRendererError', callback: ErrorCallback): void
1940
1941监听投播音频渲染器的错误事件。
1942
1943每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
1944
1945**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1946
1947**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1948
1949**参数:**
1950
1951| 参数名   | 类型     | 必填 | 说明                                                         |
1952| -------- | -------- | ---- | ------------------------------------------------------------ |
1953| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlAudioRendererError'。 |
1954| callback | ErrorCallback | 是   | 投播音频渲染器的错误事件回调方法。 |
1955
1956**错误码:**
1957
1958以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)、[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
1959
1960| 错误码ID | 错误信息              |
1961| -------- | --------------------- |
1962| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
1963| 6615000  | Unspecified errors related to the audio renderer.     |
1964| 6615001  | Initializing the audio renderer failed.   |
1965| 6615002  | The audio renderer fails to write data.     |
1966
1967**示例:**
1968
1969```ts
1970aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
1971  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
1972})
1973```
1974
1975## off('castControlAudioRendererError')<sup>13+</sup>
1976
1977off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void
1978
1979取消投播音频渲染器的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
1980
1981**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
1982
1983**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1984
1985**参数:**
1986
1987| 参数名   | 类型     | 必填 | 说明                                                         |
1988| -------- | -------- | ---- | ------------------------------------------------------------ |
1989| type     | string   | 是   | 取消对应的监听事件,支持的事件是'castControlAudioRendererError'。 |
1990| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
1991
1992**错误码:**
1993
1994以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
1995
1996| 错误码ID | 错误信息              |
1997| -------- | --------------------- |
1998| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
1999
2000**示例:**
2001
2002```ts
2003aVCastController.off('castControlAudioRendererError');
2004```
2005
2006## on('castControlDrmError')<sup>13+</sup>
2007
2008on(type: 'castControlDrmError', callback: ErrorCallback): void
2009
2010监听投播drm的错误事件。
2011
2012每个指令支持注册多个回调,如果需要只执行最新监听,需要先注销旧的监听,否则新旧监听都会触发回调。
2013
2014**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
2015
2016**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2017
2018**参数:**
2019
2020| 参数名   | 类型     | 必填 | 说明                                                         |
2021| -------- | -------- | ---- | ------------------------------------------------------------ |
2022| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlDrmError'。 |
2023| callback | ErrorCallback | 是   | 投播drm的错误事件回调方法。 |
2024
2025**错误码:**
2026
2027以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
2028
2029| 错误码ID | 错误信息              |
2030| -------- | --------------------- |
2031| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2032| 6616000  | Unspecified error related to DRM.     |
2033| 6616001  | The chosen DRM protection scheme is not supported by the device.  |
2034| 6616002  | Device provisioning failed.    |
2035| 6616003  | The DRM-protected content to play is incompatible.     |
2036| 6616004  | Failed to obtain a license.   |
2037| 6616005  | The operation is disallowed by the license policy.     |
2038| 6616006  | An error occurs in the DRM system.     |
2039| 6616007  | The device has revoked DRM privileges.   |
2040| 6616008  | The DRM license being loaded into the open DRM session has expired.      |
2041| 6616100  | An error occurs when the DRM processes the key response.     |
2042
2043**示例:**
2044
2045```ts
2046aVCastController.on('castControlDrmError', (error: BusinessError) => {
2047  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
2048})
2049```
2050
2051## off('castControlDrmError')<sup>13+</sup>
2052
2053off(type: 'castControlDrmError', callback?: ErrorCallback): void
2054
2055取消投播drm的错误事件监听。指定callback,可取消对应监听;未指定callback,取消所有事件监听。
2056
2057**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
2058
2059**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2060
2061**参数:**
2062
2063| 参数名   | 类型     | 必填 | 说明                                                         |
2064| -------- | -------- | ---- | ------------------------------------------------------------ |
2065| type     | string   | 是   | 取消对应的监听事件,支持的事件是'castControlDrmError'。 |
2066| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
2067
2068**错误码:**
2069
2070以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)。
2071
2072| 错误码ID | 错误信息              |
2073| -------- | --------------------- |
2074| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
2075
2076**示例:**
2077
2078```ts
2079aVCastController.off('castControlDrmError');
2080```
2081
2082## on('customDataChange')<sup>20+</sup>
2083
2084on(type: 'customDataChange', callback: Callback\<Record\<string, Object>>): void
2085
2086注册从远端设备发送的自定义数据的监听器。
2087
2088**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
2089
2090**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2091
2092**参数:**
2093
2094| 参数名   | 类型                             | 必填 | 说明                                                         |
2095| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
2096| type | string | 是 | 事件回调类型,支持'customDataChange'事件。媒体提供方发送自定义数据时触发。 |
2097| callback | Callback\<Record\<string, Object>> | 是   | 回调函数,用于接收自定义数据。                               |
2098
2099**错误码:**
2100
2101以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2102
2103| 错误码ID | 错误信息                                                     |
2104| -------- | ------------------------------------------------------------ |
2105| 6600101  | Session service exception. |
2106
2107**示例:**
2108
2109```ts
2110aVCastController.on('customDataChange', (callback) => {
2111    console.info(`Caught customDataChange event,the new callback is: ${JSON.stringify(callback)}`);
2112});
2113```
2114
2115## off('customDataChange')<sup>20+</sup>
2116
2117off(type: 'customDataChange', callback?: Callback\<Record\<string, Object>>): void
2118
2119取消对自定义数据的监听。
2120
2121**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
2122
2123**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2124
2125**参数:**
2126
2127| 参数名   | 类型                             | 必填 | 说明                                                         |
2128| -------- | -------------------------------- | ---- | ------------------------------------------------------------ |
2129| type     | string                           | 是   | 取消对应的监听事件,支持的事件是'customDataChange'。         |
2130| callback | Callback\<Record\<string, Object>> | 否   | 注册监听事件时的回调函数。该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 |
2131
2132**错误码:**
2133
2134以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2135
2136| 错误码ID | 错误信息                                                     |
2137| -------- | ------------------------------------------------------------ |
2138| 6600101  | Session service exception. |
2139
2140**示例:**
2141
2142```ts
2143aVCastController.off('customDataChange');
2144```
2145