• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.avsession (媒体会话管理)
2
3媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。
4
5该模块提供以下媒体会话相关的常用功能:
6
7- [AVSession](#avsession10) : 会话,可用于设置元数据、播放状态信息等操作。
8- [AVSessionController](#avsessioncontroller10): 会话控制器,可用于查看会话ID,完成对会话发送命令及事件,获取会话元数据、播放状态信息等操作。
9- [AVCastController](#avcastcontroller10): 投播控制器,可用于投播场景下,完成播放控制、远端播放状态监听、远端播放状态信息获取等操作。
10
11> **说明:**
12>
13> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14
15## 导入模块
16
17```ts
18import { avSession } from '@kit.AVSessionKit';
19```
20
21## avSession.createAVSession<sup>10+</sup>
22
23createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession>
24
25创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过Promise异步回调方式返回。
26
27**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
28
29**系统能力:** SystemCapability.Multimedia.AVSession.Core
30
31**参数:**
32
33| 参数名 | 类型                            | 必填 | 说明                           |
34| ------ | ------------------------------- | ---- | ------------------------------ |
35| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | 是| 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。 |
36| tag    | string                          | 是   | 会话的自定义名称。             |
37| type   | [AVSessionType](#avsessiontype10) | 是   | 会话类型。 |
38
39**返回值:**
40
41| 类型                              | 说明                                                         |
42| --------------------------------- | ------------------------------------------------------------ |
43| Promise<[AVSession](#avsession10)\> | Promise对象。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。|
44
45**错误码:**
46
47以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
48
49| 错误码ID | 错误信息 |
50| -------- | ---------------------------------------- |
51| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
52| 6600101  | Session service exception. |
53
54**示例:**
55
56```ts
57import { BusinessError } from '@kit.BasicServicesKit';
58import { avSession } from '@kit.AVSessionKit';
59@Entry
60@Component
61struct Index {
62  @State message: string = 'hello world';
63
64  build() {
65    Column() {
66        Text(this.message)
67          .onClick(()=>{
68            let currentAVSession: avSession.AVSession;
69            let tag = "createNewSession";
70            let context: Context = this.getUIContext().getHostContext() as Context;
71            let sessionId: string;  // 供后续函数入参使用。
72
73            avSession.createAVSession(context, tag, "audio").then((data: avSession.AVSession) => {
74            currentAVSession = data;
75            sessionId = currentAVSession.sessionId;
76            console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
77            }).catch((err: BusinessError) => {
78            console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
79            });
80          })
81      }
82    .width('100%')
83    .height('100%')
84  }
85}
86```
87
88## avSession.createAVSession<sup>10+</sup>
89
90createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void
91
92创建会话对象,一个Ability只能存在一个会话,重复创建会失败,结果通过callback异步回调方式返回。
93
94**系统能力:** SystemCapability.Multimedia.AVSession.Core
95
96**参数:**
97
98| 参数名   | 类型                                    | 必填 | 说明                                                         |
99| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
100| context| [Context](../apis-ability-kit/js-apis-inner-app-context.md) | 是| 需要使用UIAbilityContext,用于系统获取应用组件的相关信息。     |
101| tag      | string                                  | 是   | 会话的自定义名称。                                           |
102| type     | [AVSessionType](#avsessiontype10)         | 是   | 会话类型。                               |
103| callback | AsyncCallback<[AVSession](#avsession10)\> | 是   | 回调函数。回调返回会话实例对象,可用于获取会话ID,以及设置元数据、播放状态,发送按键事件等操作。 |
104
105**错误码:**
106
107以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
108
109| 错误码ID | 错误信息 |
110| -------- | ---------------------------------------- |
111| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
112| 6600101  | Session service exception. |
113
114**示例:**
115
116```ts
117import { BusinessError } from '@kit.BasicServicesKit';
118import { avSession } from '@kit.AVSessionKit';
119@Entry
120@Component
121struct Index {
122  @State message: string = 'hello world';
123
124  build() {
125    Column() {
126        Text(this.message)
127          .onClick(()=>{
128            let currentAVSession: avSession.AVSession;
129            let tag = "createNewSession";
130            let context: Context = this.getUIContext().getHostContext() as Context;
131            let sessionId: string;  // 供后续函数入参使用。
132
133            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
134            if (err) {
135                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
136            } else {
137                currentAVSession = data;
138                sessionId = currentAVSession.sessionId;
139                console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
140            }
141            });
142          })
143      }
144    .width('100%')
145    .height('100%')
146  }
147}
148```
149
150## ProtocolType<sup>11+</sup>
151
152远端设备支持的协议类型的枚举。
153
154**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
155
156**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
157
158| 名称                        | 值   | 说明         |
159| --------------------------- | ---- | ----------- |
160| TYPE_LOCAL<sup>11+</sup>      | 0    | 本地设备,包括设备本身的内置扬声器或音频插孔、A2DP 设备。 |
161| TYPE_CAST_PLUS_STREAM<sup>11+</sup>      | 2    | Cast+的Stream模式。表示媒体正在其他设备上展示。 |
162| TYPE_DLNA<sup>12+</sup>      | 4    | DLNA协议。表示媒体正在其他设备上展示。 |
163
164## AVSessionType<sup>10+<sup>
165
166type AVSessionType = 'audio' | 'video' | 'voice_call' | 'video_call'
167
168当前会话支持的会话类型。
169
170该类型可取的值为下表字符串。
171
172**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
173
174**系统能力:** SystemCapability.Multimedia.AVSession.Core
175
176| 类型  | 说明 |
177| -----  | ---- |
178| 'audio' | 音频 |
179| 'video' | 视频 |
180| 'voice_call'<sup>11+<sup> | 音频通话。 |
181| 'video_call'<sup>12+<sup> | 视频通话。 |
182
183## AVSession<sup>10+</sup>
184
185调用[avSession.createAVSession](#avsessioncreateavsession10)后,返回会话的实例,可以获得会话ID,完成设置元数据,播放状态信息等操作。
186
187### 属性
188
189**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
190
191**系统能力:** SystemCapability.Multimedia.AVSession.Core
192
193| 名称      | 类型   | 可读 | 可写 | 说明                          |
194| :-------- | :----- | :--- | :--- | :---------------------------- |
195| sessionId | string | 是   | 否   | AVSession对象唯一的会话标识。 |
196| sessionType| [AVSessionType](#avsessiontype10) | 是   | 否   | AVSession会话类型。 |
197
198**示例:**
199
200```ts
201let sessionId: string = currentAVSession.sessionId;
202let sessionType: avSession.AVSessionType = currentAVSession.sessionType;
203```
204
205### setAVMetadata<sup>10+</sup>
206
207setAVMetadata(data: AVMetadata): Promise\<void>
208
209设置会话元数据。结果通过Promise异步回调方式返回。
210
211**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
212
213**系统能力:** SystemCapability.Multimedia.AVSession.Core
214
215**参数:**
216
217| 参数名 | 类型                      | 必填 | 说明         |
218| ------ | ------------------------- | ---- | ------------ |
219| data   | [AVMetadata](#avmetadata10) | 是   | 会话元数据。 |
220
221**返回值:**
222
223| 类型           | 说明                          |
224| -------------- | ----------------------------- |
225| Promise\<void> | Promise对象。当元数据设置成功,无返回结果,否则返回错误对象。 |
226
227**错误码:**
228
229以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
230
231| 错误码ID | 错误信息 |
232| -------- | ---------------------------------------- |
233| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
234| 6600101  | Session service exception. |
235| 6600102  | The session does not exist. |
236
237**示例:**
238
239```ts
240import { BusinessError } from '@kit.BasicServicesKit';
241
242let metadata: avSession.AVMetadata = {
243  assetId: "121278",
244  title: "lose yourself",
245  artist: "Eminem",
246  author: "ST",
247  album: "Slim shady",
248  writer: "ST",
249  composer: "ST",
250  duration: 2222,
251  mediaImage: "https://www.example.com/example.jpg",
252  subtitle: "8 Mile",
253  description: "Rap",
254  // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。
255  // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n
256  lyric: "lrc格式歌词内容",
257  // singleLyricText字段存储单条歌词文本,不包含时间戳。
258  // 例如:"单条歌词内容"。
259  singleLyricText: "单条歌词内容",
260  previousAssetId: "121277",
261  nextAssetId: "121279"
262};
263currentAVSession.setAVMetadata(metadata).then(() => {
264  console.info('SetAVMetadata successfully');
265}).catch((err: BusinessError) => {
266  console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
267});
268```
269
270### setAVMetadata<sup>10+</sup>
271
272setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
273
274设置会话元数据。结果通过callback异步回调方式返回。
275
276**系统能力:** SystemCapability.Multimedia.AVSession.Core
277
278**参数:**
279
280| 参数名   | 类型                      | 必填 | 说明                                  |
281| -------- | ------------------------- | ---- | ------------------------------------- |
282| data     | [AVMetadata](#avmetadata10) | 是   | 会话元数据。                          |
283| callback | AsyncCallback\<void>      | 是   | 回调函数。当元数据设置成功,err为undefined,否则返回错误对象。 |
284
285**错误码:**
286
287以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
288
289| 错误码ID | 错误信息 |
290| -------- | ---------------------------------------- |
291| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
292| 6600101  | Session service exception. |
293| 6600102  | The session does not exist. |
294
295**示例:**
296
297```ts
298import { BusinessError } from '@kit.BasicServicesKit';
299
300let metadata: avSession.AVMetadata = {
301  assetId: "121278",
302  title: "lose yourself",
303  artist: "Eminem",
304  author: "ST",
305  album: "Slim shady",
306  writer: "ST",
307  composer: "ST",
308  duration: 2222,
309  mediaImage: "https://www.example.com/example.jpg",
310  subtitle: "8 Mile",
311  description: "Rap",
312  // LRC中有两类元素:一种是时间标签+歌词,一种是ID标签。
313  // 例如:[00:25.44]xxx\r\n[00:26.44]xxx\r\n
314  lyric: "lrc格式歌词内容",
315  // singleLyricText字段存储单条歌词文本,不包含时间戳。
316  // 例如:"单条歌词内容"。
317  singleLyricText: "单条歌词内容",
318  previousAssetId: "121277",
319  nextAssetId: "121279"
320};
321currentAVSession.setAVMetadata(metadata, (err: BusinessError) => {
322  if (err) {
323    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
324  } else {
325    console.info('SetAVMetadata successfully');
326  }
327});
328```
329
330### setCallMetadata<sup>11+</sup>
331
332setCallMetadata(data: CallMetadata): Promise\<void>
333
334设置通话会话元数据。结果通过Promise异步回调方式返回。
335
336**系统能力:** SystemCapability.Multimedia.AVSession.Core
337
338**参数:**
339
340| 参数名 | 类型                      | 必填 | 说明         |
341| ------ | ------------------------- | ---- | ------------ |
342| data   | [CallMetadata](#callmetadata11) | 是   | 通话会话元数据。 |
343
344**返回值:**
345
346| 类型           | 说明                          |
347| -------------- | ----------------------------- |
348| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 |
349
350**错误码:**
351
352以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
353
354| 错误码ID | 错误信息 |
355| -------- | ---------------------------------------- |
356| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
357| 6600101  | Session service exception. |
358| 6600102  | The session does not exist. |
359
360**示例:**
361
362```ts
363import { image } from '@kit.ImageKit';
364import { resourceManager } from '@kit.LocalizationKit';
365import { BusinessError } from '@kit.BasicServicesKit';
366
367let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
368    let imageSource = await image.createImageSource(value.buffer);
369    let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
370    let calldata: avSession.CallMetadata = {
371      name: "xiaoming",
372      phoneNumber: "111xxxxxxxx",
373      avatar: imagePixel
374    };
375currentAVSession.setCallMetadata(calldata).then(() => {
376  console.info('setCallMetadata successfully');
377}).catch((err: BusinessError) => {
378  console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
379});
380```
381
382### setCallMetadata<sup>11+</sup>
383
384setCallMetadata(data: CallMetadata, callback: AsyncCallback\<void>): void
385
386设置通话会话元数据。结果通过callback异步回调方式返回。
387
388**系统能力:** SystemCapability.Multimedia.AVSession.Core
389
390**参数:**
391
392| 参数名   | 类型                      | 必填 | 说明                                  |
393| -------- | ------------------------- | ---- | ------------------------------------- |
394| data     | [CallMetadata](#callmetadata11) | 是   | 通话会话元数据。                          |
395| callback | AsyncCallback\<void>      | 是   | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 |
396
397**错误码:**
398
399以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
400
401| 错误码ID | 错误信息 |
402| -------- | ---------------------------------------- |
403| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
404| 6600101  | Session service exception. |
405| 6600102  | The session does not exist. |
406
407**示例:**
408
409```ts
410import { image } from '@kit.ImageKit';
411import { resourceManager } from '@kit.LocalizationKit';
412import { BusinessError } from '@kit.BasicServicesKit';
413
414async function setCallMetadata() {
415  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
416  let imageSource = await image.createImageSource(value.buffer);
417  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
418  let calldata: avSession.CallMetadata = {
419    name: "xiaoming",
420    phoneNumber: "111xxxxxxxx",
421    avatar: imagePixel
422  };
423  currentAVSession.setCallMetadata(calldata, (err: BusinessError) => {
424    if (err) {
425      console.error(`setCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
426    } else {
427      console.info('setCallMetadata successfully');
428    }
429  });
430}
431```
432
433### setAVCallState<sup>11+</sup>
434
435setAVCallState(state: AVCallState): Promise\<void>
436
437设置通话状态。结果通过Promise异步回调方式返回。
438
439**系统能力:** SystemCapability.Multimedia.AVSession.Core
440
441**参数:**
442
443| 参数名 | 类型                      | 必填 | 说明         |
444| ------ | ------------------------- | ---- | ------------ |
445| state   | [AVCallState](#avcallstate11) | 是   | 通话状态。 |
446
447**返回值:**
448
449| 类型           | 说明                          |
450| -------------- | ----------------------------- |
451| Promise\<void> | Promise对象。当通话元数据设置成功,无返回结果,否则返回错误对象。 |
452
453**错误码:**
454
455以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
456
457| 错误码ID | 错误信息 |
458| -------- | ---------------------------------------- |
459| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
460| 6600101  | Session service exception. |
461| 6600102  | The session does not exist. |
462
463**示例:**
464
465```ts
466import { BusinessError } from '@kit.BasicServicesKit';
467
468let calldata: avSession.AVCallState = {
469  state: avSession.CallState.CALL_STATE_ACTIVE,
470  muted: false
471};
472currentAVSession.setAVCallState(calldata).then(() => {
473  console.info('setAVCallState successfully');
474}).catch((err: BusinessError) => {
475  console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
476});
477```
478
479### setAVCallState<sup>11+</sup>
480
481setAVCallState(state: AVCallState, callback: AsyncCallback\<void>): void
482
483设置通话状态。结果通过callback异步回调方式返回。
484
485**系统能力:** SystemCapability.Multimedia.AVSession.Core
486
487**参数:**
488
489| 参数名   | 类型                      | 必填 | 说明                                  |
490| -------- | ------------------------- | ---- | ------------------------------------- |
491| state     | [AVCallState](#avcallstate11) | 是   | 通话状态。                          |
492| callback | AsyncCallback\<void>      | 是   | 回调函数。当通话元数据设置成功,err为undefined,否则返回错误对象。 |
493
494**错误码:**
495
496以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
497
498| 错误码ID | 错误信息 |
499| -------- | ---------------------------------------- |
500| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
501| 6600101  | Session service exception. |
502| 6600102  | The session does not exist. |
503
504**示例:**
505
506```ts
507import { BusinessError } from '@kit.BasicServicesKit';
508
509let avcalldata: avSession.AVCallState = {
510  state: avSession.CallState.CALL_STATE_ACTIVE,
511  muted: false
512};
513currentAVSession.setAVCallState(avcalldata, (err: BusinessError) => {
514  if (err) {
515    console.error(`setAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
516  } else {
517    console.info('setAVCallState successfully');
518  }
519});
520```
521
522### setAVPlaybackState<sup>10+</sup>
523
524setAVPlaybackState(state: AVPlaybackState): Promise\<void>
525
526设置会话播放状态。结果通过Promise异步回调方式返回。
527
528**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
529
530**系统能力:** SystemCapability.Multimedia.AVSession.Core
531
532**参数:**
533
534| 参数名 | 类型                                | 必填 | 说明                                           |
535| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
536| state   | [AVPlaybackState](#avplaybackstate10) | 是   | 会话播放状态,包括状态、倍数、循环模式等信息。 |
537
538**返回值:**
539
540| 类型           | 说明                          |
541| -------------- | ----------------------------- |
542| Promise\<void> | Promise对象。当播放状态设置成功,无返回结果,否则返回错误对象。 |
543
544**错误码:**
545
546以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
547
548| 错误码ID | 错误信息 |
549| -------- | ---------------------------------------- |
550| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
551| 6600101  | Session service exception. |
552| 6600102  | The session does not exist. |
553
554**示例:**
555
556```ts
557import { BusinessError } from '@kit.BasicServicesKit';
558
559let playbackState: avSession.AVPlaybackState = {
560  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
561  speed: 1.0,
562  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
563  bufferedTime:1000,
564  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
565  isFavorite:true
566};
567currentAVSession.setAVPlaybackState(playbackState).then(() => {
568  console.info('SetAVPlaybackState successfully');
569}).catch((err: BusinessError) => {
570  console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
571});
572```
573
574### setAVPlaybackState<sup>10+</sup>
575
576setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
577
578设置会话播放状态。结果通过callback异步回调方式返回。
579
580**系统能力:** SystemCapability.Multimedia.AVSession.Core
581
582**参数:**
583
584| 参数名   | 类型                                | 必填 | 说明                                           |
585| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
586| state     | [AVPlaybackState](#avplaybackstate10) | 是   | 会话播放状态,包括状态、倍数、循环模式等信息。 |
587| callback | AsyncCallback\<void>                | 是   | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。          |
588
589**错误码:**
590
591以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
592
593| 错误码ID | 错误信息 |
594| -------- | ---------------------------------------- |
595| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
596| 6600101  | Session service exception. |
597| 6600102  | The session does not exist. |
598
599**示例:**
600
601```ts
602import { BusinessError } from '@kit.BasicServicesKit';
603
604let PlaybackState: avSession.AVPlaybackState = {
605  state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
606  speed: 1.0,
607  position:{elapsedTime:10, updateTime:(new Date()).getTime()},
608  bufferedTime:1000,
609  loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
610  isFavorite:true
611};
612currentAVSession.setAVPlaybackState(PlaybackState, (err: BusinessError) => {
613  if (err) {
614    console.error(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
615  } else {
616    console.info('SetAVPlaybackState successfully');
617  }
618});
619```
620
621### setLaunchAbility<sup>10+</sup>
622
623setLaunchAbility(ability: WantAgent): Promise\<void>
624
625设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。
626
627**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
628
629**系统能力:** SystemCapability.Multimedia.AVSession.Core
630
631**参数:**
632
633| 参数名  | 类型                                          | 必填 | 说明                                                        |
634| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
635| ability | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是   | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 |
636
637**返回值:**
638
639| 类型           | 说明                          |
640| -------------- | ----------------------------- |
641| Promise\<void> | Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。 |
642
643**错误码:**
644
645以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
646
647| 错误码ID | 错误信息 |
648| -------- | ---------------------------------------- |
649| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
650| 6600101  | Session service exception. |
651| 6600102  | The session does not exist. |
652
653**示例:**
654
655```ts
656import { wantAgent } from '@kit.AbilityKit';
657import { BusinessError } from '@kit.BasicServicesKit';
658
659// WantAgentInfo对象。
660let wantAgentInfo: wantAgent.WantAgentInfo = {
661  wants: [
662    {
663      deviceId: "deviceId",
664      bundleName: "com.example.myapplication",
665      abilityName: "EntryAbility",
666      action: "action1",
667      entities: ["entity1"],
668      type: "MIMETYPE",
669      uri: "key = {true,true,false}",
670      parameters:
671        {
672          mykey0: 2222,
673          mykey1: [1, 2, 3],
674          mykey2: "[1, 2, 3]",
675          mykey3: "ssssssssssssssssssssssssss",
676          mykey4: [false, true, false],
677          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
678          mykey6: true
679        }
680    }
681  ],
682  operationType: wantAgent.OperationType.START_ABILITIES,
683  requestCode: 0,
684  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
685}
686
687wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
688  currentAVSession.setLaunchAbility(agent).then(() => {
689    console.info('SetLaunchAbility successfully');
690  }).catch((err: BusinessError) => {
691    console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
692  });
693});
694```
695
696### setLaunchAbility<sup>10+</sup>
697
698setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
699
700设置一个WantAgent用于拉起会话的Ability。结果通过callback异步回调方式返回。
701
702**系统能力:** SystemCapability.Multimedia.AVSession.Core
703
704**参数:**
705
706| 参数名   | 类型                                          | 必填 | 说明                                                         |
707| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
708| ability  | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | 是   | 应用的相关属性信息,如bundleName,abilityName,deviceId等。  |
709| callback | AsyncCallback\<void>                          | 是   | 回调函数。当Ability设置成功,err为undefined,否则返回错误对象。 |
710
711**错误码:**
712
713以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
714
715| 错误码ID | 错误信息 |
716| -------- | ---------------------------------------- |
717| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
718| 6600101  | Session service exception. |
719| 6600102  | The session does not exist. |
720
721**示例:**
722
723```ts
724import { wantAgent } from '@kit.AbilityKit';
725import { BusinessError } from '@kit.BasicServicesKit';
726
727// WantAgentInfo对象。
728let wantAgentInfo: wantAgent.WantAgentInfo = {
729  wants: [
730    {
731      deviceId: "deviceId",
732      bundleName: "com.example.myapplication",
733      abilityName: "EntryAbility",
734      action: "action1",
735      entities: ["entity1"],
736      type: "MIMETYPE",
737      uri: "key = {true,true,false}",
738      parameters:
739        {
740          mykey0: 2222,
741          mykey1: [1, 2, 3],
742          mykey2: "[1, 2, 3]",
743          mykey3: "ssssssssssssssssssssssssss",
744          mykey4: [false, true, false],
745          mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
746          mykey6: true
747        }
748    }
749  ],
750  operationType: wantAgent.OperationType.START_ABILITIES,
751  requestCode: 0,
752  wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
753}
754
755wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
756  currentAVSession.setLaunchAbility(agent, (err: BusinessError) => {
757    if (err) {
758      console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
759    } else {
760      console.info('SetLaunchAbility successfully');
761    }
762  });
763});
764```
765
766### dispatchSessionEvent<sup>10+</sup>
767
768dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void>
769
770媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容,结果通过Promise异步回调方式返回。
771
772**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
773
774**系统能力:** SystemCapability.Multimedia.AVSession.Core
775
776**参数:**
777
778| 参数名  | 类型                                          | 必填 | 说明                                                        |
779| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
780| event | string | 是   | 需要设置的会话事件的名称。 |
781| args | {[key: string]: Object} | 是   | 需要传递的会话事件内容。 |
782
783> **说明:**
784> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
785
786**返回值:**
787
788| 类型           | 说明                          |
789| -------------- | ----------------------------- |
790| Promise\<void> | Promise对象。当事件设置成功,无返回结果,否则返回错误对象。 |
791
792**错误码:**
793
794以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
795
796| 错误码ID | 错误信息 |
797| -------- | ---------------------------------------- |
798| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
799| 6600101  | Session service exception. |
800| 6600102  | The session does not exist. |
801
802**示例:**
803
804```ts
805import { BusinessError } from '@kit.BasicServicesKit';
806import { avSession } from '@kit.AVSessionKit';
807@Entry
808@Component
809struct Index {
810  @State message: string = 'hello world';
811
812  build() {
813    Column() {
814        Text(this.message)
815          .onClick(()=>{
816            let currentAVSession: avSession.AVSession | undefined = undefined;
817            let tag = "createNewSession";
818            let context: Context = this.getUIContext().getHostContext() as Context;
819
820            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
821            if (err) {
822                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
823            } else {
824                currentAVSession = data;
825            }
826            });
827            let eventName = "dynamic_lyric";
828            if (currentAVSession !== undefined) {
829            (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}).then(() => {
830                console.info('dispatchSessionEvent successfully');
831            }).catch((err: BusinessError) => {
832                console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
833            })
834            }
835          })
836      }
837    .width('100%')
838    .height('100%')
839  }
840}
841```
842
843### dispatchSessionEvent<sup>10+</sup>
844
845dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
846
847媒体提供方设置一个会话内自定义事件,包括事件名和键值对形式的事件内容,结果通过callback异步回调方式返回。
848
849**系统能力:** SystemCapability.Multimedia.AVSession.Core
850
851**参数:**
852
853| 参数名  | 类型                                          | 必填 | 说明                                                        |
854| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
855| event | string | 是   | 需要设置的会话事件的名称。 |
856| args | {[key: string]: Object} | 是   | 需要传递的会话事件内容。 |
857| callback | AsyncCallback\<void>                          | 是   | 回调函数。当会话事件设置成功,err为undefined,否则返回错误对象。 |
858
859> **说明:**
860
861> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
862
863**错误码:**
864
865以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
866
867| 错误码ID | 错误信息 |
868| -------- | ---------------------------------------- |
869| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
870| 6600101  | Session service exception. |
871| 6600102  | The session does not exist. |
872
873**示例:**
874
875```ts
876import { BusinessError } from '@kit.BasicServicesKit';
877import { avSession } from '@kit.AVSessionKit';
878@Entry
879@Component
880struct Index {
881  @State message: string = 'hello world';
882
883  build() {
884    Column() {
885        Text(this.message)
886          .onClick(()=>{
887            let currentAVSession: avSession.AVSession | undefined = undefined;
888            let tag = "createNewSession";
889            let context: Context = this.getUIContext().getHostContext() as Context;
890
891            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
892            if (err) {
893                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
894            } else {
895                currentAVSession = data;
896            }
897            });
898            let eventName: string = "dynamic_lyric";
899            if (currentAVSession !== undefined) {
900            (currentAVSession as avSession.AVSession).dispatchSessionEvent(eventName, {lyric : "This is lyric"}, (err: BusinessError) => {
901                if (err) {
902                console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
903                }
904            })
905            }
906          })
907      }
908    .width('100%')
909    .height('100%')
910  }
911}
912```
913
914### setAVQueueItems<sup>10+</sup>
915
916setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>
917
918设置媒体播放列表。结果通过Promise异步回调方式返回。
919
920**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
921
922**系统能力:** SystemCapability.Multimedia.AVSession.Core
923
924**参数:**
925
926| 参数名  | 类型                                 | 必填 | 说明                               |
927| ------ | ------------------------------------ | ---- | ---------------------------------- |
928| items  | Array<[AVQueueItem](#avqueueitem10)\> | 是   | 播放列表单项的队列,用以表示播放列表。 |
929
930**返回值:**
931
932| 类型           | 说明                          |
933| -------------- | ----------------------------- |
934| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 |
935
936**错误码:**
937
938以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
939
940| 错误码ID | 错误信息 |
941| -------- | ---------------------------------------- |
942| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
943| 6600101  | Session service exception. |
944| 6600102  | The session does not exist. |
945
946**示例:**
947
948```ts
949import { image } from '@kit.ImageKit';
950import { resourceManager } from '@kit.LocalizationKit';
951import { BusinessError } from '@kit.BasicServicesKit';
952
953async function setAVQueueItems() {
954  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
955  let imageSource = await image.createImageSource(value.buffer);
956  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
957  let queueItemDescription_1: avSession.AVMediaDescription = {
958    assetId: '001',
959    title: 'music_name',
960    subtitle: 'music_sub_name',
961    description: 'music_description',
962    mediaImage : imagePixel,
963    extras: {extras:'any'}
964  };
965  let queueItem_1: avSession.AVQueueItem = {
966    itemId: 1,
967    description: queueItemDescription_1
968  };
969  let queueItemDescription_2: avSession.AVMediaDescription = {
970    assetId: '002',
971    title: 'music_name',
972    subtitle: 'music_sub_name',
973    description: 'music_description',
974    mediaImage: imagePixel,
975    extras: {extras:'any'}
976  };
977  let queueItem_2: avSession.AVQueueItem = {
978    itemId: 2,
979    description: queueItemDescription_2
980  };
981  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
982  currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
983    console.info('SetAVQueueItems successfully');
984  }).catch((err: BusinessError) => {
985    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
986  });
987}
988```
989
990### setAVQueueItems<sup>10+</sup>
991
992setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void
993
994设置媒体播放列表。结果通过callback异步回调方式返回。
995
996**系统能力:** SystemCapability.Multimedia.AVSession.Core
997
998**参数:**
999
1000| 参数名   | 类型                                  | 必填 | 说明                                                         |
1001| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- |
1002| items    | Array<[AVQueueItem](#avqueueitem10)\> | 是   | 播放列表单项的队列,用以表示播放列表。                          |
1003| callback | AsyncCallback\<void>                 | 是   | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 |
1004
1005**错误码:**
1006
1007以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1008
1009| 错误码ID | 错误信息 |
1010| -------- | ---------------------------------------- |
1011| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1012| 6600101  | Session service exception. |
1013| 6600102  | The session does not exist. |
1014
1015**示例:**
1016
1017```ts
1018import { image } from '@kit.ImageKit';
1019import { resourceManager } from '@kit.LocalizationKit';
1020import { BusinessError } from '@kit.BasicServicesKit';
1021
1022async function setAVQueueItems() {
1023  let value = await resourceManager.getSystemResourceManager().getRawFileContent('IMAGE_URI');
1024  let imageSource = await image.createImageSource(value.buffer);
1025  let imagePixel = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
1026  let queueItemDescription_1: avSession.AVMediaDescription = {
1027    assetId: '001',
1028    title: 'music_name',
1029    subtitle: 'music_sub_name',
1030    description: 'music_description',
1031    mediaImage : imagePixel,
1032    extras: {extras:'any'}
1033  };
1034  let queueItem_1: avSession.AVQueueItem = {
1035    itemId: 1,
1036    description: queueItemDescription_1
1037  };
1038  let queueItemDescription_2: avSession.AVMediaDescription = {
1039    assetId: '002',
1040    title: 'music_name',
1041    subtitle: 'music_sub_name',
1042    description: 'music_description',
1043    mediaImage: imagePixel,
1044    extras: {extras:'any'}
1045  };
1046  let queueItem_2: avSession.AVQueueItem = {
1047    itemId: 2,
1048    description: queueItemDescription_2
1049  };
1050  let queueItemsArray: avSession.AVQueueItem[] = [queueItem_1, queueItem_2];
1051  currentAVSession.setAVQueueItems(queueItemsArray, (err: BusinessError) => {
1052    if (err) {
1053      console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
1054    } else {
1055      console.info('SetAVQueueItems successfully');
1056    }
1057  });
1058}
1059```
1060
1061### setAVQueueTitle<sup>10+</sup>
1062
1063setAVQueueTitle(title: string): Promise\<void>
1064
1065设置媒体播放列表名称。结果通过Promise异步回调方式返回。
1066
1067**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1068
1069**系统能力:** SystemCapability.Multimedia.AVSession.Core
1070
1071**参数:**
1072
1073| 参数名  | 类型   | 必填 | 说明           |
1074| ------ | ------ | ---- | -------------- |
1075| title  | string | 是   | 播放列表的名称。 |
1076
1077**返回值:**
1078
1079| 类型           | 说明                          |
1080| -------------- | ----------------------------- |
1081| Promise\<void> | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 |
1082
1083**错误码:**
1084
1085以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1086
1087| 错误码ID | 错误信息 |
1088| -------- | ---------------------------------------- |
1089| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1090| 6600101  | Session service exception. |
1091| 6600102  | The session does not exist. |
1092
1093**示例:**
1094
1095```ts
1096import { BusinessError } from '@kit.BasicServicesKit';
1097
1098let queueTitle = 'QUEUE_TITLE';
1099currentAVSession.setAVQueueTitle(queueTitle).then(() => {
1100  console.info('SetAVQueueTitle successfully');
1101}).catch((err: BusinessError) => {
1102  console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1103});
1104```
1105
1106### setAVQueueTitle<sup>10+</sup>
1107
1108setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void
1109
1110设置媒体播放列表名称。结果通过callback异步回调方式返回。
1111
1112**系统能力:** SystemCapability.Multimedia.AVSession.Core
1113
1114**参数:**
1115
1116| 参数名   | 类型                                  | 必填 | 说明                                                         |
1117| -------- | --------------------- | ---- | ----------------------------------------------------------- |
1118| title    | string                | 是   | 播放列表名称字段。                          |
1119| callback | AsyncCallback\<void>  | 是   | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 |
1120
1121**错误码:**
1122
1123以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1124
1125| 错误码ID | 错误信息 |
1126| -------- | ---------------------------------------- |
1127| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1128| 6600101  | Session service exception. |
1129| 6600102  | The session does not exist. |
1130
1131**示例:**
1132
1133```ts
1134import { BusinessError } from '@kit.BasicServicesKit';
1135
1136let queueTitle = 'QUEUE_TITLE';
1137currentAVSession.setAVQueueTitle(queueTitle, (err: BusinessError) => {
1138  if (err) {
1139    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
1140  } else {
1141    console.info('SetAVQueueTitle successfully');
1142  }
1143});
1144```
1145
1146### setExtras<sup>10+</sup>
1147
1148setExtras(extras: {[key: string]: Object}): Promise\<void>
1149
1150媒体提供方设置键值对形式的自定义媒体数据包,结果通过Promise异步回调方式返回。
1151
1152**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1153
1154**系统能力:** SystemCapability.Multimedia.AVSession.Core
1155
1156**参数:**
1157
1158| 参数名  | 类型                                          | 必填 | 说明                                                        |
1159| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1160| extras | {[key: string]: Object} | 是   | 需要传递的自定义媒体数据包键值对。 |
1161
1162> **说明:**
1163
1164> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
1165
1166**返回值:**
1167
1168| 类型           | 说明                          |
1169| -------------- | ----------------------------- |
1170| Promise\<void> | Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。 |
1171
1172**错误码:**
1173
1174以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1175
1176| 错误码ID | 错误信息 |
1177| -------- | ---------------------------------------- |
1178| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1179| 6600101  | Session service exception. |
1180| 6600102  | The session does not exist. |
1181
1182**示例:**
1183
1184```ts
1185import { BusinessError } from '@kit.BasicServicesKit';
1186import { avSession } from '@kit.AVSessionKit';
1187@Entry
1188@Component
1189struct Index {
1190  @State message: string = 'hello world';
1191
1192  build() {
1193    Column() {
1194        Text(this.message)
1195          .onClick(()=>{
1196            let currentAVSession: avSession.AVSession | undefined = undefined;
1197            let tag = "createNewSession";
1198            let context: Context = this.getUIContext().getHostContext() as Context;
1199
1200            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1201            if (err) {
1202                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1203            } else {
1204                currentAVSession = data;
1205            }
1206            });
1207            if (currentAVSession !== undefined) {
1208            (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}).then(() => {
1209                console.info('setExtras successfully');
1210            }).catch((err: BusinessError) => {
1211                console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1212            })
1213            }
1214          })
1215      }
1216    .width('100%')
1217    .height('100%')
1218  }
1219}
1220```
1221
1222### setExtras<sup>10+</sup>
1223
1224setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void
1225
1226媒体提供方设置键值对形式的自定义媒体数据包,结果通过callback异步回调方式返回。
1227
1228**系统能力:** SystemCapability.Multimedia.AVSession.Core
1229
1230**参数:**
1231
1232| 参数名  | 类型                                          | 必填 | 说明                                                        |
1233| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1234| extras | {[key: string]: Object} | 是   | 需要传递的自定义媒体数据包键值对。 |
1235| callback | AsyncCallback\<void>                          | 是   | 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。 |
1236
1237> **说明:**
1238
1239> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
1240
1241**错误码:**
1242
1243以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1244
1245| 错误码ID | 错误信息 |
1246| -------- | ---------------------------------------- |
1247| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1248| 6600101  | Session service exception. |
1249| 6600102  | The session does not exist. |
1250
1251**示例:**
1252
1253```ts
1254import { BusinessError } from '@kit.BasicServicesKit';
1255import { avSession } from '@kit.AVSessionKit';
1256@Entry
1257@Component
1258struct Index {
1259  @State message: string = 'hello world';
1260
1261  build() {
1262    Column() {
1263        Text(this.message)
1264          .onClick(()=>{
1265            let currentAVSession: avSession.AVSession | undefined = undefined;
1266            let tag = "createNewSession";
1267            let context: Context = this.getUIContext().getHostContext() as Context;
1268
1269            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
1270            if (err) {
1271                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
1272            } else {
1273                currentAVSession = data;
1274            }
1275            });
1276            if (currentAVSession !== undefined) {
1277            (currentAVSession as avSession.AVSession).setExtras({extras : "This is custom media packet"}, (err: BusinessError) => {
1278                if (err) {
1279                console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
1280                }
1281            })
1282            }
1283          })
1284      }
1285    .width('100%')
1286    .height('100%')
1287  }
1288}
1289```
1290
1291### getController<sup>10+</sup>
1292
1293getController(): Promise\<AVSessionController>
1294
1295获取本会话对应的控制器。结果通过Promise异步回调方式返回。
1296
1297**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1298
1299**系统能力:** SystemCapability.Multimedia.AVSession.Core
1300
1301**返回值:**
1302
1303| 类型                                                 | 说明                          |
1304| ---------------------------------------------------- | ----------------------------- |
1305| Promise<[AVSessionController](#avsessioncontroller10)> | Promise对象。返回会话控制器。 |
1306
1307**错误码:**
1308
1309以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1310
1311| 错误码ID | 错误信息 |
1312| -------- | ---------------------------------------- |
1313| 6600101  | Session service exception. |
1314| 6600102  | The session does not exist. |
1315
1316**示例:**
1317
1318```ts
1319import { BusinessError } from '@kit.BasicServicesKit';
1320
1321let avsessionController: avSession.AVSessionController;
1322currentAVSession.getController().then((avcontroller: avSession.AVSessionController) => {
1323  avsessionController = avcontroller;
1324  console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1325}).catch((err: BusinessError) => {
1326  console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1327});
1328```
1329
1330### getController<sup>10+</sup>
1331
1332getController(callback: AsyncCallback\<AVSessionController>): void
1333
1334获取本会话相应的控制器。结果通过callback异步回调方式返回。
1335
1336**系统能力:** SystemCapability.Multimedia.AVSession.Core
1337
1338**参数:**
1339
1340| 参数名   | 类型                                                        | 必填 | 说明                       |
1341| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
1342| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 是   | 回调函数。返回会话控制器。 |
1343
1344**错误码:**
1345
1346以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1347
1348| 错误码ID | 错误信息 |
1349| -------- | ---------------------------------------- |
1350| 6600101  | Session service exception. |
1351| 6600102  | The session does not exist. |
1352
1353**示例:**
1354
1355```ts
1356import { BusinessError } from '@kit.BasicServicesKit';
1357
1358let avsessionController: avSession.AVSessionController;
1359currentAVSession.getController((err: BusinessError, avcontroller: avSession.AVSessionController) => {
1360  if (err) {
1361    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1362  } else {
1363    avsessionController = avcontroller;
1364    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
1365  }
1366});
1367```
1368
1369### getAVCastController<sup>10+</sup>
1370
1371getAVCastController(): Promise\<AVCastController>
1372
1373设备建立连接后,获取投播控制器。结果通过Promise异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。
1374
1375**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1376
1377**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1378
1379**返回值:**
1380
1381| 类型                                                        | 说明                                                         |
1382| --------- | ------------------------------------------------------------ |
1383| Promise<[AVCastController](#avcastcontroller10)\>  | Promise对象。返回投播控制器实例。 |
1384
1385**错误码:**
1386
1387以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1388
1389| 错误码ID | 错误信息 |
1390| -------- | --------------------------------------- |
1391| 6600102| The session does not exist.           |
1392| 6600109| The remote connection is not established. |
1393
1394**示例:**
1395
1396```ts
1397import { BusinessError } from '@kit.BasicServicesKit';
1398
1399let aVCastController: avSession.AVCastController;
1400currentAVSession.getAVCastController().then((avcontroller: avSession.AVCastController) => {
1401  aVCastController = avcontroller;
1402  console.info('getAVCastController : SUCCESS');
1403}).catch((err: BusinessError) => {
1404  console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1405});
1406```
1407
1408### getAVCastController<sup>10+</sup>
1409
1410getAVCastController(callback: AsyncCallback\<AVCastController>): void
1411
1412设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。如果 avsession 未处于投播状态,则控制器将返回 null。
1413
1414**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1415
1416**参数:**
1417
1418| 参数名    | 类型                                                        | 必填 | 说明                                                         |
1419| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1420| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是   | 回调函数,返回投播控制器实例。 |
1421
1422**错误码:**
1423
1424以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1425
1426| 错误码ID | 错误信息                                  |
1427| -------- |---------------------------------------|
1428| 6600102| The session does not exist.           |
1429| 6600109| The remote connection is not established. |
1430
1431**示例:**
1432
1433```ts
1434import { BusinessError } from '@kit.BasicServicesKit';
1435
1436let aVCastController: avSession.AVCastController;
1437currentAVSession.getAVCastController((err: BusinessError, avcontroller: avSession.AVCastController) => {
1438  if (err) {
1439    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1440  } else {
1441    aVCastController = avcontroller;
1442    console.info('getAVCastController : SUCCESS');
1443  }
1444});
1445```
1446
1447### getOutputDevice<sup>10+</sup>
1448
1449getOutputDevice(): Promise\<OutputDeviceInfo>
1450
1451通过会话获取播放设备信息。结果通过Promise异步回调方式返回。
1452
1453**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1454
1455**系统能力:** SystemCapability.Multimedia.AVSession.Core
1456
1457**返回值:**
1458
1459| 类型                                           | 说明                              |
1460| ---------------------------------------------- | --------------------------------- |
1461| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise对象。返回播放设备信息。 |
1462
1463**错误码:**
1464
1465以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1466
1467| 错误码ID | 错误信息 |
1468| -------- | ---------------------------------------- |
1469| 6600101  | Session service exception. |
1470| 6600102  | The session does not exist. |
1471
1472**示例:**
1473
1474```ts
1475import { BusinessError } from '@kit.BasicServicesKit';
1476
1477currentAVSession.getOutputDevice().then((outputDeviceInfo: avSession.OutputDeviceInfo) => {
1478  console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1479}).catch((err: BusinessError) => {
1480  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1481})
1482```
1483
1484### getOutputDevice<sup>10+</sup>
1485
1486getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
1487
1488通过会话获取播放设备相关信息。结果通过callback异步回调方式返回。
1489
1490**系统能力:** SystemCapability.Multimedia.AVSession.Core
1491
1492**参数:**
1493
1494| 参数名   | 类型                                                  | 必填 | 说明                           |
1495| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1496| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是   | 回调函数,返回播放设备信息。 |
1497
1498**错误码:**
1499
1500以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1501
1502| 错误码ID | 错误信息 |
1503| -------- | ---------------------------------------- |
1504| 6600101  | Session service exception. |
1505| 6600102  | The session does not exist. |
1506
1507**示例:**
1508
1509```ts
1510import { BusinessError } from '@kit.BasicServicesKit';
1511
1512currentAVSession.getOutputDevice((err: BusinessError, outputDeviceInfo: avSession.OutputDeviceInfo) => {
1513  if (err) {
1514    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1515  } else {
1516    console.info(`GetOutputDevice : SUCCESS : devices length : ${outputDeviceInfo.devices.length}`);
1517  }
1518});
1519```
1520
1521### activate<sup>10+</sup>
1522
1523activate(): Promise\<void>
1524
1525激活会话,激活后可正常使用会话。结果通过Promise异步回调方式返回。
1526
1527**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1528
1529**系统能力:** SystemCapability.Multimedia.AVSession.Core
1530
1531**返回值:**
1532
1533| 类型           | 说明                          |
1534| -------------- | ----------------------------- |
1535| Promise\<void> | Promise对象。当会话激活成功,无返回结果,否则返回错误对象。 |
1536
1537**错误码:**
1538
1539以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1540
1541| 错误码ID | 错误信息 |
1542| -------- | ---------------------------------------- |
1543| 6600101  | Session service exception. |
1544| 6600102  | The session does not exist. |
1545
1546**示例:**
1547
1548```ts
1549import { BusinessError } from '@kit.BasicServicesKit';
1550
1551currentAVSession.activate().then(() => {
1552  console.info('Activate : SUCCESS ');
1553}).catch((err: BusinessError) => {
1554  console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1555});
1556```
1557
1558### activate<sup>10+</sup>
1559
1560activate(callback: AsyncCallback\<void>): void
1561
1562激活会话,激活后可正常使用会话。结果通过callback异步回调方式返回。
1563
1564**系统能力:** SystemCapability.Multimedia.AVSession.Core
1565
1566**参数:**
1567
1568| 参数名   | 类型                 | 必填 | 说明       |
1569| -------- | -------------------- | ---- | ---------- |
1570| callback | AsyncCallback\<void> | 是   | 回调函数。当会话激活成功,err为undefined,否则返回错误对象。 |
1571
1572**错误码:**
1573
1574以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1575
1576| 错误码ID | 错误信息 |
1577| -------- | ---------------------------------------- |
1578| 6600101  | Session service exception. |
1579| 6600102  | The session does not exist. |
1580
1581**示例:**
1582
1583```ts
1584import { BusinessError } from '@kit.BasicServicesKit';
1585
1586currentAVSession.activate((err: BusinessError) => {
1587  if (err) {
1588    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1589  } else {
1590    console.info('Activate : SUCCESS ');
1591  }
1592});
1593```
1594
1595### deactivate<sup>10+</sup>
1596
1597deactivate(): Promise\<void>
1598
1599禁用当前会话的功能,可通过[activate](#activate10)恢复。结果通过Promise异步回调方式返回。
1600
1601**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1602
1603**系统能力:** SystemCapability.Multimedia.AVSession.Core
1604
1605**返回值:**
1606
1607| 类型           | 说明                          |
1608| -------------- | ----------------------------- |
1609| Promise\<void> | Promise对象。当禁用会话成功,无返回结果,否则返回错误对象。|
1610
1611**错误码:**
1612
1613以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1614
1615| 错误码ID | 错误信息 |
1616| -------- | ---------------------------------------- |
1617| 6600101  | Session service exception. |
1618| 6600102  | The session does not exist. |
1619
1620**示例:**
1621
1622```ts
1623import { BusinessError } from '@kit.BasicServicesKit';
1624
1625currentAVSession.deactivate().then(() => {
1626  console.info('Deactivate : SUCCESS ');
1627}).catch((err: BusinessError) => {
1628  console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1629});
1630```
1631
1632### deactivate<sup>10+</sup>
1633
1634deactivate(callback: AsyncCallback\<void>): void
1635
1636禁用当前会话。结果通过callback异步回调方式返回。
1637
1638禁用当前会话的功能,可通过[activate](#activate10)恢复。
1639
1640**系统能力:** SystemCapability.Multimedia.AVSession.Core
1641
1642**参数:**
1643
1644| 参数名   | 类型                 | 必填 | 说明       |
1645| -------- | -------------------- | ---- | ---------- |
1646| callback | AsyncCallback\<void> | 是   | 回调函数。当禁用会话成功,err为undefined,否则返回错误对象。|
1647
1648**错误码:**
1649
1650以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1651
1652| 错误码ID | 错误信息 |
1653| -------- | ---------------------------------------- |
1654| 6600101  | Session service exception. |
1655| 6600102  | The session does not exist. |
1656
1657**示例:**
1658
1659```ts
1660import { BusinessError } from '@kit.BasicServicesKit';
1661
1662currentAVSession.deactivate((err: BusinessError) => {
1663  if (err) {
1664    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1665  } else {
1666    console.info('Deactivate : SUCCESS ');
1667  }
1668});
1669```
1670
1671### destroy<sup>10+</sup>
1672
1673destroy(): Promise\<void>
1674
1675销毁当前会话,使当前会话完全失效。结果通过Promise异步回调方式返回。
1676
1677**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1678
1679**系统能力:** SystemCapability.Multimedia.AVSession.Core
1680
1681**返回值:**
1682
1683| 类型           | 说明                          |
1684| -------------- | ----------------------------- |
1685| Promise\<void> | Promise对象。当会话销毁成功,无返回结果,否则返回错误对象。 |
1686
1687**错误码:**
1688
1689以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1690
1691| 错误码ID | 错误信息 |
1692| -------- | ---------------------------------------- |
1693| 6600101  | Session service exception. |
1694| 6600102  | The session does not exist. |
1695
1696**示例:**
1697
1698```ts
1699import { BusinessError } from '@kit.BasicServicesKit';
1700
1701currentAVSession.destroy().then(() => {
1702  console.info('Destroy : SUCCESS ');
1703}).catch((err: BusinessError) => {
1704  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1705});
1706```
1707
1708### destroy<sup>10+</sup>
1709
1710destroy(callback: AsyncCallback\<void>): void
1711
1712销毁当前会话,使当前会话完全失效。结果通过callback异步回调方式返回。
1713
1714**系统能力:** SystemCapability.Multimedia.AVSession.Core
1715
1716**参数:**
1717
1718| 参数名   | 类型                 | 必填 | 说明       |
1719| -------- | -------------------- | ---- | ---------- |
1720| callback | AsyncCallback\<void> | 是   | 回调函数。当会话销毁成功,err为undefined,否则返回错误对象。 |
1721
1722**错误码:**
1723
1724以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1725
1726| 错误码ID | 错误信息 |
1727| -------- | ---------------------------------------- |
1728| 6600101  | Session service exception. |
1729| 6600102  | The session does not exist. |
1730
1731**示例:**
1732
1733```ts
1734import { BusinessError } from '@kit.BasicServicesKit';
1735
1736currentAVSession.destroy((err: BusinessError) => {
1737  if (err) {
1738    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1739  } else {
1740    console.info('Destroy : SUCCESS ');
1741  }
1742});
1743```
1744
1745### on('play')<sup>10+</sup>
1746
1747on(type: 'play', callback: () => void): void
1748
1749设置播放命令监听事件。注册该监听,说明应用支持播放指令。
1750
1751每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1752
1753**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1754
1755**系统能力:** SystemCapability.Multimedia.AVSession.Core
1756
1757**参数:**
1758
1759| 参数名   | 类型                 | 必填 | 说明                                                         |
1760| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1761| type     | string               | 是   | 事件回调类型,支持的事件为`'play'`,当播放命令被发送到会话时,触发该事件回调。 |
1762| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。                                        |
1763
1764**错误码:**
1765
1766以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1767
1768| 错误码ID | 错误信息 |
1769| -------- | ---------------------------------------- |
1770| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1771| 6600101  | Session service exception. |
1772| 6600102  | The session does not exist. |
1773
1774**示例:**
1775
1776```ts
1777currentAVSession.on('play', () => {
1778  console.info('on play entry');
1779});
1780```
1781
1782### on('pause')<sup>10+</sup>
1783
1784on(type: 'pause', callback: () => void): void
1785
1786设置暂停命令监听事件。注册该监听,说明应用支持暂停指令。
1787
1788每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1789
1790**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1791
1792**系统能力:** SystemCapability.Multimedia.AVSession.Core
1793
1794**参数:**
1795
1796| 参数名   | 类型                 | 必填 | 说明                                                         |
1797| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1798| type     | string               | 是   | 事件回调类型,支持的事件为`'pause'`,当暂停命令被发送到会话时,触发该事件回调。 |
1799| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。     |
1800
1801**错误码:**
1802
1803以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1804
1805| 错误码ID | 错误信息 |
1806| -------- | ---------------------------------------- |
1807| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1808| 6600101  | Session service exception. |
1809| 6600102  | The session does not exist. |
1810
1811**示例:**
1812
1813```ts
1814currentAVSession.on('pause', () => {
1815  console.info('on pause entry');
1816});
1817```
1818
1819### on('stop')<sup>10+</sup>
1820
1821on(type:'stop', callback: () => void): void
1822
1823设置停止命令监听事件。注册该监听,说明应用支持停止指令。
1824
1825每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1826
1827**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1828
1829**系统能力:** SystemCapability.Multimedia.AVSession.Core
1830
1831**参数:**
1832
1833| 参数名   | 类型                 | 必填 | 说明                                                         |
1834| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1835| type     | string               | 是   | 事件回调类型,支持的事件是`'stop'`,当停止命令被发送到会话时,触发该事件回调。 |
1836| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。          |
1837
1838**错误码:**
1839
1840以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1841
1842| 错误码ID | 错误信息 |
1843| -------- | ---------------------------------------- |
1844| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1845| 6600101  | Session service exception. |
1846| 6600102  | The session does not exist. |
1847
1848**示例:**
1849
1850```ts
1851currentAVSession.on('stop', () => {
1852  console.info('on stop entry');
1853});
1854```
1855
1856### on('playNext')<sup>10+</sup>
1857
1858on(type:'playNext', callback: () => void): void
1859
1860设置播放下一首命令监听事件。注册该监听,说明应用支持下一首指令。
1861
1862每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1863
1864**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1865
1866**系统能力:** SystemCapability.Multimedia.AVSession.Core
1867
1868**参数:**
1869
1870| 参数名   | 类型                 | 必填 | 说明                                                         |
1871| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1872| type     | string               | 是   | 事件回调类型,支持的事件是`'playNext'`,当播放下一首命令被发送到会话时,触发该事件回调。 |
1873| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。     |
1874
1875**错误码:**
1876
1877以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1878
1879| 错误码ID | 错误信息 |
1880| -------- | ---------------------------------------- |
1881| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1882| 6600101  | Session service exception. |
1883| 6600102  | The session does not exist. |
1884
1885**示例:**
1886
1887```ts
1888currentAVSession.on('playNext', () => {
1889  console.info('on playNext entry');
1890});
1891```
1892
1893### on('playPrevious')<sup>10+</sup>
1894
1895on(type:'playPrevious', callback: () => void): void
1896
1897设置播放上一首命令监听事件。注册该监听,说明应用支持上一首指令。
1898
1899每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1900
1901**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1902
1903**系统能力:** SystemCapability.Multimedia.AVSession.Core
1904
1905**参数:**
1906
1907| 参数名   | 类型                 | 必填 | 说明                                                         |
1908| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1909| type     | string               | 是   | 事件回调类型,支持的事件是`'playPrevious'`,当播放上一首命令被发送到会话时,触发该事件回调。 |
1910| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。       |
1911
1912**错误码:**
1913
1914以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1915
1916| 错误码ID | 错误信息 |
1917| -------- | ---------------------------------------- |
1918| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1919| 6600101  | Session service exception. |
1920| 6600102  | The session does not exist. |
1921
1922**示例:**
1923
1924```ts
1925currentAVSession.on('playPrevious', () => {
1926  console.info('on playPrevious entry');
1927});
1928```
1929
1930### on('fastForward')<sup>10+</sup>
1931
1932on(type: 'fastForward', callback: (time?: number) => void): void
1933
1934设置快进命令监听事件。注册该监听,说明应用支持快进指令。
1935
1936每个播放命令仅支持注册一个回调,如果注册新的回调,将替换前一个回调。
1937
1938**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1939
1940**系统能力:** SystemCapability.Multimedia.AVSession.Core
1941
1942**参数:**
1943
1944| 参数名   | 类型                 | 必填 | 说明                                                         |
1945| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1946| type     | string               | 是   | 事件回调类型,支持的事件是 `'fastForward'`,当快进命令被发送到会话时,触发该事件回调。 |
1947| callback | (time?: number) => void | 是   | 回调函数。参数time是时间节点,单位为秒。    |
1948
1949**错误码:**
1950
1951以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1952
1953| 错误码ID | 错误信息 |
1954| -------- | ---------------------------------------- |
1955| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1956| 6600101  | Session service exception. |
1957| 6600102  | The session does not exist. |
1958
1959**示例:**
1960
1961```ts
1962currentAVSession.on('fastForward', (time?: number) => {
1963  console.info('on fastForward entry');
1964});
1965```
1966
1967### on('rewind')<sup>10+</sup>
1968
1969on(type:'rewind', callback: (time?: number) => void): void
1970
1971设置快退命令监听事件。
1972
1973**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1974
1975**系统能力:** SystemCapability.Multimedia.AVSession.Core
1976
1977**参数:**
1978
1979| 参数名   | 类型                 | 必填 | 说明                                                         |
1980| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1981| type     | string               | 是   | 事件回调类型,支持的事件是`'rewind'`,当快退命令被发送到会话时,触发该事件回调。 |
1982| callback | (time?: number) => void | 是   | 回调函数。参数time是时间节点,单位为秒。      |
1983
1984**错误码:**
1985
1986以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1987
1988| 错误码ID | 错误信息 |
1989| -------- | ---------------------------------------- |
1990| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1991| 6600101  | Session service exception. |
1992| 6600102  | The session does not exist. |
1993
1994**示例:**
1995
1996```ts
1997currentAVSession.on('rewind', (time?: number) => {
1998  console.info('on rewind entry');
1999});
2000```
2001
2002### on('playFromAssetId')<sup>11+</sup>
2003
2004on(type:'playFromAssetId', callback: (assetId: number) => void): void
2005
2006设置媒体id播放监听事件。
2007
2008**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2009
2010**系统能力:** SystemCapability.Multimedia.AVSession.Core
2011
2012**参数:**
2013
2014| 参数名   | 类型                 | 必填 | 说明                                                         |
2015| -------- | -------------------- | ---- | ------------------------------------------------------------ |
2016| type     | string               | 是   | 事件回调类型,支持的事件是`'playFromAssetId'`,当媒体id播放时,触发该事件回调。 |
2017| callback | callback: (assetId: number) => void | 是   | 回调函数。参数assetId是媒体id。      |
2018
2019**错误码:**
2020
2021以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2022
2023| 错误码ID | 错误信息 |
2024| -------- | ---------------------------------------- |
2025| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2026| 6600101  | Session service exception. |
2027| 6600102  | The session does not exist. |
2028
2029**示例:**
2030
2031```ts
2032currentAVSession.on('playFromAssetId', (assetId: number) => {
2033  console.info('on playFromAssetId entry');
2034});
2035```
2036
2037### off('playFromAssetId')<sup>11+</sup>
2038
2039off(type: 'playFromAssetId', callback?: (assetId: number) => void): void
2040
2041取消媒体id播放事件监听,关闭后,不再进行该事件回调。
2042
2043**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2044
2045**系统能力:** SystemCapability.Multimedia.AVSession.Core
2046
2047**参数:**
2048
2049| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2050| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2051| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'playFromAssetId'`。 |
2052| callback | callback: (assetId: number) => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。参数assetId是媒体id。                            |
2053
2054**错误码:**
2055
2056以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2057
2058| 错误码ID | 错误信息 |
2059| -------- | ---------------------------------------- |
2060| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2061| 6600101  | Session service exception. |
2062| 6600102  | The session does not exist. |
2063
2064**示例:**
2065
2066```ts
2067currentAVSession.off('playFromAssetId');
2068```
2069
2070### on('seek')<sup>10+</sup>
2071
2072on(type: 'seek', callback: (time: number) => void): void
2073
2074设置跳转节点监听事件。
2075
2076**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2077
2078**系统能力:** SystemCapability.Multimedia.AVSession.Core
2079
2080**参数:**
2081
2082| 参数名   | 类型                   | 必填 | 说明                                                         |
2083| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
2084| type     | string                 | 是   | 事件回调类型,支持事件`'seek'`:当跳转节点命令被发送到会话时,触发该事件。 |
2085| callback | (time: number) => void | 是   | 回调函数。参数time是时间节点,单位为毫秒。                   |
2086
2087**错误码:**
2088
2089以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2090
2091| 错误码ID | 错误信息 |
2092| -------- | ---------------------------------------- |
2093| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2094| 6600101  | Session service exception. |
2095| 6600102  | The session does not exist. |
2096
2097**示例:**
2098
2099```ts
2100currentAVSession.on('seek', (time: number) => {
2101  console.info(`on seek entry time : ${time}`);
2102});
2103```
2104
2105### on('setSpeed')<sup>10+</sup>
2106
2107on(type: 'setSpeed', callback: (speed: number) => void): void
2108
2109设置播放速率的监听事件。
2110
2111**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2112
2113**系统能力:** SystemCapability.Multimedia.AVSession.Core
2114
2115**参数:**
2116
2117| 参数名   | 类型                    | 必填 | 说明                                                         |
2118| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
2119| type     | string                  | 是   | 事件回调类型,支持事件`'setSpeed'`:当设置播放速率的命令被发送到会话时,触发该事件。 |
2120| callback | (speed: number) => void | 是   | 回调函数。参数speed是播放倍速。                              |
2121
2122**错误码:**
2123
2124以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2125
2126| 错误码ID | 错误信息 |
2127| -------- | ---------------------------------------- |
2128| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2129| 6600101  | Session service exception. |
2130| 6600102  | The session does not exist. |
2131
2132**示例:**
2133
2134```ts
2135currentAVSession.on('setSpeed', (speed: number) => {
2136  console.info(`on setSpeed speed : ${speed}`);
2137});
2138```
2139
2140### on('setLoopMode')<sup>10+</sup>
2141
2142on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
2143
2144设置循环模式的监听事件。
2145
2146**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2147
2148**系统能力:** SystemCapability.Multimedia.AVSession.Core
2149
2150**参数:**
2151
2152| 参数名    | 类型                                   | 必填 | 说明  |
2153| -------- | ------------------------------------- | ---- | ---- |
2154| type     | string                                | 是   | 事件回调类型,支持事件`'setLoopMode'`:当设置循环模式的命令被发送到会话时,触发该事件。 |
2155| callback | (mode: [LoopMode](#loopmode10)) => void | 是   | 回调函数。参数mode是循环模式。                               |
2156
2157**错误码:**
2158
2159以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2160
2161| 错误码ID | 错误信息 |
2162| -------- | ---------------------------------------- |
2163| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2164| 6600101  | Session service exception. |
2165| 6600102  | The session does not exist. |
2166
2167**示例:**
2168
2169```ts
2170currentAVSession.on('setLoopMode', (mode: avSession.LoopMode) => {
2171  console.info(`on setLoopMode mode : ${mode}`);
2172});
2173```
2174
2175### on('setTargetLoopMode')<sup>18+</sup>
2176
2177on(type: 'setTargetLoopMode', callback: Callback\<LoopMode>): void
2178
2179设置目标循环模式的监听事件。
2180
2181**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
2182
2183**系统能力:** SystemCapability.Multimedia.AVSession.Core
2184
2185**参数:**
2186
2187| 参数名    | 类型                                   | 必填 | 说明  |
2188| -------- | ------------------------------------- | ---- | ---- |
2189| type     | string                                | 是   | 事件回调类型,支持事件`'setTargetLoopMode'`。<br>- `'setTargetLoopMode'`:当设置目标循环模式的命令被发送到会话时,触发该事件。 |
2190| callback | Callback<[LoopMode](#loopmode10)> | 是   | 回调函数。参数表示目标循环模式。                               |
2191
2192**错误码:**
2193
2194以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
2195
2196| 错误码ID | 错误信息 |
2197| -------- | ---------------------------------------- |
2198| 6600101  | Session service exception. |
2199| 6600102  | The session does not exist. |
2200
2201**示例:**
2202
2203```ts
2204currentAVSession.on('setTargetLoopMode', (mode: avSession.LoopMode) => {
2205  console.info(`on setTargetLoopMode mode : ${mode}`);
2206});
2207```
2208
2209### on('toggleFavorite')<sup>10+</sup>
2210
2211on(type: 'toggleFavorite', callback: (assetId: string) => void): void
2212
2213设置是否收藏的监听事件
2214
2215**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2216
2217**系统能力:** SystemCapability.Multimedia.AVSession.Core
2218
2219**参数:**
2220
2221| 参数名   | 类型                      | 必填 | 说明                                                         |
2222| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
2223| type     | string                    | 是   | 事件回调类型,支持事件`'toggleFavorite'`:当是否收藏的命令被发送到会话时,触发该事件。 |
2224| callback | (assetId: string) => void | 是   | 回调函数。参数assetId是媒体ID。                              |
2225
2226**错误码:**
2227
2228以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2229
2230| 错误码ID | 错误信息 |
2231| -------- | ---------------------------------------- |
2232| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2233| 6600101  | Session service exception. |
2234| 6600102  | The session does not exist. |
2235
2236**示例:**
2237
2238```ts
2239currentAVSession.on('toggleFavorite', (assetId: string) => {
2240  console.info(`on toggleFavorite mode : ${assetId}`);
2241});
2242```
2243
2244### on('skipToQueueItem')<sup>10+</sup>
2245
2246on(type: 'skipToQueueItem', callback: (itemId: number) => void): void
2247
2248设置播放列表其中某项被选中的监听事件,session端可以选择对这个单项歌曲进行播放。
2249
2250**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2251
2252**系统能力:** SystemCapability.Multimedia.AVSession.Core
2253
2254**参数:**
2255
2256| 参数名   | 类型                      | 必填 | 说明                                                                                      |
2257| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- |
2258| type     | string                   | 是   | 事件回调类型,支持事件`'skipToQueueItem'`:当播放列表选中单项的命令被发送到会话时,触发该事件。 |
2259| callback | (itemId: number) => void | 是   | 回调函数。参数itemId是选中的播放列表项的ID。                                                |
2260
2261**错误码:**
2262
2263以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2264
2265| 错误码ID | 错误信息 |
2266| -------- | ---------------------------------------- |
2267| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2268| 6600101  | Session service exception. |
2269| 6600102  | The session does not exist. |
2270
2271**示例:**
2272
2273```ts
2274currentAVSession.on('skipToQueueItem', (itemId: number) => {
2275  console.info(`on skipToQueueItem id : ${itemId}`);
2276});
2277```
2278
2279### on('handleKeyEvent')<sup>10+</sup>
2280
2281on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
2282
2283设置蓝牙/有线等外设接入的按键输入事件的监听,监听多媒体按键事件中播放、暂停、上下一首、快进、快退的指令。
2284
2285**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2286
2287**系统能力:** SystemCapability.Multimedia.AVSession.Core
2288
2289**参数:**
2290
2291| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2292| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2293| type     | string                                                       | 是   | 事件回调类型,支持事件`'handleKeyEvent'`:当按键事件被发送到会话时,触发该事件。 |
2294| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 是   | 回调函数。参数event是按键事件。                              |
2295
2296**错误码:**
2297
2298以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2299
2300| 错误码ID | 错误信息 |
2301| -------- | ---------------------------------------- |
2302| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2303| 6600101  | Session service exception. |
2304| 6600102  | The session does not exist. |
2305
2306**示例:**
2307
2308```ts
2309import { KeyEvent } from '@kit.InputKit';
2310
2311currentAVSession.on('handleKeyEvent', (event: KeyEvent) => {
2312  console.info(`on handleKeyEvent event : ${event}`);
2313});
2314
2315```
2316
2317### on('outputDeviceChange')<sup>10+</sup>
2318
2319on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2320
2321设置播放设备变化的监听事件。应用接入[系统投播组件](ohos-multimedia-avcastpicker.md),当用户通过组件切换设备时,会收到设备切换的回调。
2322
2323**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2324
2325**系统能力:** SystemCapability.Multimedia.AVSession.Core
2326
2327**参数:**
2328
2329| 参数名   | 类型                                                    | 必填 | 说明                                                         |
2330| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2331| type     | string                                                  | 是   | 事件回调类型,支持事件`'outputDeviceChange'`:当播放设备变化时,触发该事件。 |
2332| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是   | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                         |
2333
2334**错误码:**
2335
2336以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2337
2338| 错误码ID | 错误信息 |
2339| -------- | ---------------------------------------- |
2340| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2341| 6600101  | Session service exception. |
2342| 6600102  | The session does not exist. |
2343
2344**示例:**
2345
2346```ts
2347currentAVSession.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
2348  console.info(`on outputDeviceChange device : ${device}`);
2349});
2350```
2351
2352### on('commonCommand')<sup>10+</sup>
2353
2354on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void
2355
2356设置自定义控制命令变化的监听器。
2357
2358**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2359
2360**系统能力:** SystemCapability.Multimedia.AVSession.Core
2361
2362**参数:**
2363
2364| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2365| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2366| type     | string                                                       | 是   | 事件回调类型,支持事件`'commonCommand'`:当自定义控制命令变化时,触发该事件。 |
2367| callback | (command: string, args: {[key:string]: Object}) => void         | 是   | 回调函数,command为变化的自定义控制命令名,args为自定义控制命令的参数,参数内容与[sendCommonCommand](#sendcommoncommand10)方法设置的参数内容完全一致。          |
2368
2369**错误码:**
2370
2371以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2372
2373| 错误码ID | 错误信息 |
2374| -------- | ------------------------------ |
2375| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2376| 6600101  | Session service exception. |
2377| 6600102  | The session does not exist. |
2378
2379**示例:**
2380
2381```ts
2382import { BusinessError } from '@kit.BasicServicesKit';
2383import { avSession } from '@kit.AVSessionKit';
2384@Entry
2385@Component
2386struct Index {
2387  @State message: string = 'hello world';
2388
2389  build() {
2390    Column() {
2391        Text(this.message)
2392          .onClick(()=>{
2393            let currentAVSession: avSession.AVSession | undefined = undefined;
2394            let tag = "createNewSession";
2395            let context: Context = this.getUIContext().getHostContext() as Context;
2396
2397            avSession.createAVSession(context, tag, "audio", (err: BusinessError, data: avSession.AVSession) => {
2398            if (err) {
2399                console.error(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
2400            } else {
2401                currentAVSession = data;
2402            }
2403            });
2404            if (currentAVSession !== undefined) {
2405            (currentAVSession as avSession.AVSession).on('commonCommand', (commonCommand, args) => {
2406                console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
2407            });
2408            }
2409          })
2410      }
2411    .width('100%')
2412    .height('100%')
2413  }
2414}
2415```
2416
2417### off('play')<sup>10+</sup>
2418
2419off(type: 'play', callback?: () => void): void
2420
2421取消会话播放事件监听,关闭后,不再进行该事件回调。
2422
2423取消回调时,需要更新支持的命令列表。
2424
2425**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2426
2427**系统能力:** SystemCapability.Multimedia.AVSession.Core
2428
2429**参数:**
2430
2431| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2432| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2433| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'play'`。|
2434| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2435
2436**错误码:**
2437
2438以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2439
2440| 错误码ID | 错误信息 |
2441| -------- | ---------------------------------------- |
2442| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2443| 6600101  | Session service exception. |
2444| 6600102  | The session does not exist. |
2445
2446**示例:**
2447
2448```ts
2449currentAVSession.off('play');
2450```
2451
2452### off('pause')<sup>10+</sup>
2453
2454off(type: 'pause', callback?: () => void): void
2455
2456取消会话暂停事件监听,关闭后,不再进行该事件回调。
2457
2458取消回调时,需要更新支持的命令列表。
2459
2460**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2461
2462**系统能力:** SystemCapability.Multimedia.AVSession.Core
2463
2464**参数:**
2465
2466| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2467| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2468| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'pause'`。 |
2469| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
2470
2471**错误码:**
2472
2473以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2474
2475| 错误码ID | 错误信息 |
2476| -------- | ---------------------------------------- |
2477| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2478| 6600101  | Session service exception. |
2479| 6600102  | The session does not exist. |
2480
2481**示例:**
2482
2483```ts
2484currentAVSession.off('pause');
2485```
2486
2487### off('stop')<sup>10+</sup>
2488
2489off(type: 'stop', callback?: () => void): void
2490
2491取消会话停止事件监听,关闭后,不再进行该事件回调。
2492
2493取消回调时,需要更新支持的命令列表。
2494
2495**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2496
2497**系统能力:** SystemCapability.Multimedia.AVSession.Core
2498
2499**参数:**
2500
2501| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2502| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2503| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'stop'`。 |
2504| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2505
2506**错误码:**
2507
2508以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2509
2510| 错误码ID | 错误信息 |
2511| -------- | ---------------------------------------- |
2512| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2513| 6600101  | Session service exception. |
2514| 6600102  | The session does not exist. |
2515
2516**示例:**
2517
2518```ts
2519currentAVSession.off('stop');
2520```
2521
2522### off('playNext')<sup>10+</sup>
2523
2524off(type: 'playNext', callback?: () => void): void
2525
2526取消会话播放下一首事件监听,关闭后,不再进行该事件回调。
2527
2528取消回调时,需要更新支持的命令列表。
2529
2530**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2531
2532**系统能力:** SystemCapability.Multimedia.AVSession.Core
2533
2534**参数:**
2535
2536| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2537| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2538| type     | string               | 是   | 关闭对应的监听事件,支持的事件是 `'playNext'`。 |
2539| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2540
2541**错误码:**
2542
2543以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2544
2545| 错误码ID | 错误信息 |
2546| -------- | ---------------------------------------- |
2547| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2548| 6600101  | Session service exception. |
2549| 6600102  | The session does not exist. |
2550
2551**示例:**
2552
2553```ts
2554currentAVSession.off('playNext');
2555```
2556
2557### off('playPrevious')<sup>10+</sup>
2558
2559off(type: 'playPrevious', callback?: () => void): void
2560
2561取消会话播放上一首事件监听,关闭后,不再进行该事件回调。
2562
2563取消回调时,需要更新支持的命令列表。
2564
2565**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2566
2567**系统能力:** SystemCapability.Multimedia.AVSession.Core
2568
2569**参数:**
2570
2571| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2572| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2573| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'playPrevious'`。 |
2574| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2575
2576**错误码:**
2577
2578以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2579
2580| 错误码ID | 错误信息 |
2581| -------- | ---------------------------------------- |
2582| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2583| 6600101  | Session service exception. |
2584| 6600102  | The session does not exist. |
2585
2586**示例:**
2587
2588```ts
2589currentAVSession.off('playPrevious');
2590```
2591
2592### off('fastForward')<sup>10+</sup>
2593
2594off(type: 'fastForward', callback?: () => void): void
2595
2596取消会话快进事件监听,关闭后,不再进行该事件回调。
2597
2598取消回调时,需要更新支持的命令列表。
2599
2600**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2601
2602**系统能力:** SystemCapability.Multimedia.AVSession.Core
2603
2604**参数:**
2605
2606| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2607| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2608| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'fastForward'`。 |
2609| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2610
2611**错误码:**
2612
2613以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2614
2615| 错误码ID | 错误信息 |
2616| -------- | ---------------------------------------- |
2617| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2618| 6600101  | Session service exception. |
2619| 6600102  | The session does not exist. |
2620
2621**示例:**
2622
2623```ts
2624currentAVSession.off('fastForward');
2625```
2626
2627### off('rewind')<sup>10+</sup>
2628
2629off(type: 'rewind', callback?: () => void): void
2630
2631取消会话快退事件监听,关闭后,不再进行该事件回调。
2632
2633**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2634
2635**系统能力:** SystemCapability.Multimedia.AVSession.Core
2636
2637**参数:**
2638
2639| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
2640| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
2641| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'rewind'`。 |
2642| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
2643
2644**错误码:**
2645
2646以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2647
2648| 错误码ID | 错误信息 |
2649| -------- | ---------------------------------------- |
2650| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2651| 6600101  | Session service exception. |
2652| 6600102  | The session does not exist. |
2653
2654**示例:**
2655
2656```ts
2657currentAVSession.off('rewind');
2658```
2659
2660### off('seek')<sup>10+</sup>
2661
2662off(type: 'seek', callback?: (time: number) => void): void
2663
2664取消监听跳转节点事件。
2665
2666**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2667
2668**系统能力:** SystemCapability.Multimedia.AVSession.Core
2669
2670**参数:**
2671
2672| 参数名   | 类型                   | 必填 | 说明                                          |
2673| -------- | ---------------------- | ---- | ----------------------------------------- |
2674| type     | string                 | 是   | 关闭对应的监听事件,支持关闭事件`'seek'`。       |
2675| callback | (time: number) => void | 否   | 回调函数,参数time是时间节点,单位为毫秒。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。        |
2676
2677**错误码:**
2678
2679以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2680
2681| 错误码ID | 错误信息 |
2682| -------- | ---------------------------------------- |
2683| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2684| 6600101  | Session service exception. |
2685| 6600102  | The session does not exist. |
2686
2687**示例:**
2688
2689```ts
2690currentAVSession.off('seek');
2691```
2692
2693### off('setSpeed')<sup>10+</sup>
2694
2695off(type: 'setSpeed', callback?: (speed: number) => void): void
2696
2697取消监听播放速率变化事件。
2698
2699**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2700
2701**系统能力:** SystemCapability.Multimedia.AVSession.Core
2702
2703**参数:**
2704
2705| 参数名   | 类型                    | 必填 | 说明                                           |
2706| -------- | ----------------------- | ---- | -------------------------------------------|
2707| type     | string                  | 是   | 关闭对应的监听事件,支持关闭事件`'setSpeed'`。    |
2708| callback | (speed: number) => void | 否   | 回调函数,参数speed是播放倍速。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                 |
2709
2710**错误码:**
2711
2712以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2713
2714| 错误码ID | 错误信息 |
2715| -------- | ---------------------------------------- |
2716| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2717| 6600101  | Session service exception. |
2718| 6600102  | The session does not exist. |
2719
2720**示例:**
2721
2722```ts
2723currentAVSession.off('setSpeed');
2724```
2725
2726### off('setLoopMode')<sup>10+</sup>
2727
2728off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
2729
2730取消监听循环模式变化事件。
2731
2732**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2733
2734**系统能力:** SystemCapability.Multimedia.AVSession.Core
2735
2736**参数:**
2737
2738| 参数名   | 类型                                  | 必填 | 说明     |
2739| -------- | ------------------------------------- | ---- | ----- |
2740| type     | string | 是   | 关闭对应的监听事件,支持关闭事件`'setLoopMode'`。|
2741| callback | (mode: [LoopMode](#loopmode10)) => void | 否   | 回调函数,参数mode是循环模式。<br>- 当监听事件取消成功,err为undefined,否则返回错误对象。<br>- 该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
2742
2743**错误码:**
2744
2745以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2746
2747| 错误码ID | 错误信息 |
2748| -------- | ---------------------------------------- |
2749| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2750| 6600101  | Session service exception. |
2751| 6600102  | The session does not exist. |
2752
2753**示例:**
2754
2755```ts
2756currentAVSession.off('setLoopMode');
2757```
2758
2759### off('setTargetLoopMode')<sup>18+</sup>
2760
2761off(type: 'setTargetLoopMode', callback?: Callback\<LoopMode>): void
2762
2763取消监听目标循环模式变化事件。
2764
2765**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
2766
2767**系统能力:** SystemCapability.Multimedia.AVSession.Core
2768
2769**参数:**
2770
2771| 参数名   | 类型                                  | 必填 | 说明     |
2772| -------- | ------------------------------------- | ---- | ----- |
2773| type     | string | 是   | 关闭对应的监听事件,支持关闭事件`'setTargetLoopMode'`。|
2774| callback | Callback<[LoopMode](#loopmode10)> | 否   | 回调函数,参数表示目标循环模式。<br>- 当监听事件取消成功,err为undefined,否则返回错误对象。<br>- 该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
2775
2776**错误码:**
2777
2778以下错误码的详细介绍请参见[通用错误码说明文档](../errorcode-universal.md)和[媒体会话管理错误码](errorcode-avsession.md)。
2779
2780| 错误码ID | 错误信息 |
2781| -------- | ---------------------------------------- |
2782| 6600101  | Session service exception. |
2783| 6600102  | The session does not exist. |
2784
2785**示例:**
2786
2787```ts
2788currentAVSession.off('setTargetLoopMode');
2789```
2790
2791### off('toggleFavorite')<sup>10+</sup>
2792
2793off(type: 'toggleFavorite', callback?: (assetId: string) => void): void
2794
2795取消监听是否收藏的事件
2796
2797**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2798
2799**系统能力:** SystemCapability.Multimedia.AVSession.Core
2800
2801**参数:**
2802
2803| 参数名   | 类型                      | 必填 | 说明                                                         |
2804| -------- | ------------------------- | ---- | -------------------------------------------------------- |
2805| type     | string                    | 是   | 关闭对应的监听事件,支持关闭事件`'toggleFavorite'`。            |
2806| callback | (assetId: string) => void | 否   | 回调函数,参数assetId是媒体ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                               |
2807
2808**错误码:**
2809
2810以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2811
2812| 错误码ID | 错误信息 |
2813| -------- | ---------------------------------------- |
2814| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2815| 6600101  | Session service exception. |
2816| 6600102  | The session does not exist. |
2817
2818**示例:**
2819
2820```ts
2821currentAVSession.off('toggleFavorite');
2822```
2823
2824### off('skipToQueueItem')<sup>10+</sup>
2825
2826off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
2827
2828取消监听播放列表单项选中的事件
2829
2830**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2831
2832**系统能力:** SystemCapability.Multimedia.AVSession.Core
2833
2834**参数:**
2835
2836| 参数名   | 类型                      | 必填 | 说明                                                                                                                                                        |
2837| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
2838| type     | string                   | 是   | 关闭对应的监听事件,支持关闭事件`'skipToQueueItem'`。                                                                                                          |
2839| callback | (itemId: number) => void | 否   | 回调函数,参数itemId是播放列表单项ID。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
2840
2841**错误码:**
2842
2843以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2844
2845| 错误码ID | 错误信息 |
2846| -------- | ---------------------------------------- |
2847| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2848| 6600101  | Session service exception. |
2849| 6600102  | The session does not exist. |
2850
2851**示例:**
2852
2853```ts
2854currentAVSession.off('skipToQueueItem');
2855```
2856
2857### off('handleKeyEvent')<sup>10+</sup>
2858
2859off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
2860
2861取消监听按键事件。
2862
2863**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2864
2865**系统能力:** SystemCapability.Multimedia.AVSession.Core
2866
2867**参数:**
2868
2869| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2870| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2871| type     | string                                                       | 是   | 关闭对应的监听事件,支持关闭事件`'handleKeyEvent'`。             |
2872| callback | (event: [KeyEvent](../apis-input-kit/js-apis-keyevent.md)) => void | 否   | 回调函数,参数event是按键事件。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                              |
2873
2874**错误码:**
2875
2876以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2877
2878| 错误码ID | 错误信息 |
2879| -------- | ---------------------------------------- |
2880| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2881| 6600101  | Session service exception. |
2882| 6600102  | The session does not exist. |
2883
2884**示例:**
2885
2886```ts
2887currentAVSession.off('handleKeyEvent');
2888```
2889
2890### off('outputDeviceChange')<sup>10+</sup>
2891
2892off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
2893
2894取消监听播放设备变化的事件。
2895
2896**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2897
2898**系统能力:** SystemCapability.Multimedia.AVSession.Core
2899
2900**参数:**
2901
2902| 参数名   | 类型                                                    | 必填 | 说明                                                      |
2903| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
2904| type     | string                                                  | 是   | 关闭对应的监听事件,支持关闭事件`'outputDeviceChange'`。     |
2905| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否   | 回调函数,参数device是设备相关信息。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                        |
2906
2907**错误码:**
2908
2909以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2910
2911| 错误码ID | 错误信息 |
2912| -------- | ---------------------------------------- |
2913| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2914| 6600101  | Session service exception. |
2915| 6600102  | The session does not exist. |
2916
2917**示例:**
2918
2919```ts
2920currentAVSession.off('outputDeviceChange');
2921```
2922
2923
2924### off('commonCommand')<sup>10+</sup>
2925
2926off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void
2927
2928取消监听自定义控制命令的变化。
2929
2930**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2931
2932**系统能力:** SystemCapability.Multimedia.AVSession.Core
2933
2934**参数:**
2935
2936| 参数名   | 类型                                                         | 必填 | 说明                                                     |
2937| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2938| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'commonCommand'`。    |
2939| callback | (command: string, args: {[key:string]: Object}) => void         | 否   | 回调函数,参数command是变化的自定义控制命令名,args为自定义控制命令的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对command事件的监听。                      |
2940
2941**错误码:**
2942
2943以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2944
2945| 错误码ID | 错误信息 |
2946| -------- | ---------------- |
2947| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2948| 6600101  | Session service exception. |
2949| 6600102  | The session does not exist. |
2950
2951**示例:**
2952
2953```ts
2954currentAVSession.off('commonCommand');
2955```
2956
2957### on('answer')<sup>11+</sup>
2958
2959on(type: 'answer', callback: Callback\<void>): void
2960
2961设置通话接听的监听事件。
2962
2963**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2964
2965**系统能力:** SystemCapability.Multimedia.AVSession.Core
2966
2967**参数:**
2968
2969| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2970| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2971| type     | string                                                       | 是   | 事件回调类型,支持事件`'answer'`:当通话接听时,触发该事件。 |
2972| callback | Callback\<void>                                               | 是   | 回调函数。                      |
2973
2974**错误码:**
2975
2976以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2977
2978| 错误码ID | 错误信息 |
2979| -------- | ------------------------------ |
2980| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2981| 6600101  | Session service exception. |
2982| 6600102  | The session does not exist. |
2983
2984**示例:**
2985
2986```ts
2987currentAVSession.on('answer', () => {
2988  console.info('on call answer');
2989});
2990```
2991
2992### off('answer')<sup>11+</sup>
2993
2994off(type: 'answer', callback?: Callback\<void>): void
2995
2996取消通话接听事件的监听。
2997
2998**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
2999
3000**系统能力:** SystemCapability.Multimedia.AVSession.Core
3001
3002**参数:**
3003
3004| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
3005| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3006| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'answer'`。 |
3007| callback | Callback\<void>     | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。    |
3008
3009**错误码:**
3010
3011以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3012
3013| 错误码ID | 错误信息 |
3014| -------- | ---------------------------------------- |
3015| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3016| 6600101  | Session service exception. |
3017| 6600102  | The session does not exist. |
3018
3019**示例:**
3020
3021```ts
3022currentAVSession.off('answer');
3023```
3024
3025### on('hangUp')<sup>11+</sup>
3026
3027on(type: 'hangUp', callback: Callback\<void>): void
3028
3029设置通话挂断的监听事件。
3030
3031**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3032
3033**系统能力:** SystemCapability.Multimedia.AVSession.Core
3034
3035**参数:**
3036
3037| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3038| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3039| type     | string                                                       | 是   | 事件回调类型,支持事件`'hangUp'`:当通话挂断时,触发该事件。 |
3040| callback | Callback\<void>                                               | 是   | 回调函数。                                             |
3041
3042**错误码:**
3043
3044以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3045
3046| 错误码ID | 错误信息 |
3047| -------- | ------------------------------ |
3048| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3049| 6600101  | Session service exception. |
3050| 6600102  | The session does not exist. |
3051
3052**示例:**
3053
3054```ts
3055currentAVSession.on('hangUp', () => {
3056  console.info('on call hangUp');
3057});
3058```
3059
3060### off('hangUp')<sup>11+</sup>
3061
3062off(type: 'hangUp', callback?: Callback\<void>): void
3063
3064取消通话挂断事件的监听。
3065
3066**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3067
3068**系统能力:** SystemCapability.Multimedia.AVSession.Core
3069
3070**参数:**
3071
3072| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
3073| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3074| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'hangUp'`。 |
3075| callback | Callback\<void>      | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
3076
3077**错误码:**
3078
3079以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3080
3081| 错误码ID | 错误信息 |
3082| -------- | ---------------------------------------- |
3083| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3084| 6600101  | Session service exception. |
3085| 6600102  | The session does not exist. |
3086
3087**示例:**
3088
3089```ts
3090currentAVSession.off('hangUp');
3091```
3092
3093### on('toggleCallMute')<sup>11+</sup>
3094
3095on(type: 'toggleCallMute', callback: Callback\<void>): void
3096
3097设置通话静音的监听事件。
3098
3099**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3100
3101**系统能力:** SystemCapability.Multimedia.AVSession.Core
3102
3103**参数:**
3104
3105| 参数名   | 类型                                                         | 必填 | 说明                                                         |
3106| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
3107| type     | string                                                       | 是   | 事件回调类型,支持事件`'toggleCallMute'`:当通话静音或解除静音时,触发该事件。 |
3108| callback | Callback\<void>                                               | 是   | 回调函数。                                             |
3109
3110**错误码:**
3111
3112以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3113
3114| 错误码ID | 错误信息 |
3115| -------- | ------------------------------ |
3116| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3117| 6600101  | Session service exception. |
3118| 6600102  | The session does not exist. |
3119
3120**示例:**
3121
3122```ts
3123currentAVSession.on('toggleCallMute', () => {
3124  console.info('on call toggleCallMute');
3125});
3126```
3127
3128### off('toggleCallMute')<sup>11+</sup>
3129
3130off(type: 'toggleCallMute', callback?: Callback\<void>): void
3131
3132取消通话静音事件的监听。
3133
3134**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3135
3136**系统能力:** SystemCapability.Multimedia.AVSession.Core
3137
3138**参数:**
3139
3140| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
3141| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3142| type     | string               | 是   | 关闭对应的监听事件,支持的事件是`'toggleCallMute'`。 |
3143| callback | Callback\<void>    | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
3144
3145**错误码:**
3146
3147以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3148
3149| 错误码ID | 错误信息 |
3150| -------- | ---------------------------------------- |
3151| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3152| 6600101  | Session service exception. |
3153| 6600102  | The session does not exist. |
3154
3155**示例:**
3156
3157```ts
3158currentAVSession.off('toggleCallMute');
3159```
3160
3161### on('castDisplayChange')<sup>12+</sup>
3162
3163on(type: 'castDisplayChange', callback: Callback\<CastDisplayInfo>): void
3164
3165设置扩展屏投播显示设备变化的监听事件。
3166
3167**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3168
3169**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3170
3171**参数:**
3172
3173| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
3174| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3175| type     | string                                                       | 是   | 事件回调类型,支持事件`'castDisplayChange'`:当扩展屏投播显示设备变化时触发事件。 |
3176| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | 是   | 回调函数。参数是扩展屏投播显示设备信息。                            |
3177
3178**错误码:**
3179
3180以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3181
3182| 错误码ID | 错误信息 |
3183| -------- | ---------------------------------------- |
3184| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3185| 6600101  | Session service exception. |
3186| 6600102  | The session does not exist. |
3187
3188**示例:**
3189
3190```ts
3191let castDisplay: avSession.CastDisplayInfo;
3192currentAVSession.on('castDisplayChange', (display: avSession.CastDisplayInfo) => {
3193    if (display.state === avSession.CastDisplayState.STATE_ON) {
3194        castDisplay = display;
3195        console.info(`Succeeded in castDisplayChange display : ${display.id} ON`);
3196    } else if (display.state === avSession.CastDisplayState.STATE_OFF){
3197        console.info(`Succeeded in castDisplayChange display : ${display.id} OFF`);
3198    }
3199});
3200```
3201### off('castDisplayChange')<sup>12+</sup>
3202
3203 off(type: 'castDisplayChange', callback?: Callback\<CastDisplayInfo>): void
3204
3205取消扩展屏投播显示设备变化事件监听,关闭后,不再进行该事件回调。
3206
3207**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3208
3209**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3210
3211**参数:**
3212
3213| 参数名    | 类型                  | 必填 | 说明                                                                                                                         |
3214| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
3215| type     | string                                                       | 是   | 关闭对应的监听事件,支持的事件是`'castDisplayChange'`。 |
3216| callback | Callback<[CastDisplayInfo](#castdisplayinfo12)>   | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
3217
3218**错误码:**
3219
3220以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3221
3222| 错误码ID | 错误信息 |
3223| -------- | ---------------------------------------- |
3224| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
3225| 6600101  | Session service exception. |
3226| 6600102  | The session does not exist. |
3227
3228**示例:**
3229
3230```ts
3231currentAVSession.off('castDisplayChange');
3232```
3233
3234### stopCasting<sup>10+</sup>
3235
3236stopCasting(callback: AsyncCallback\<void>): void
3237
3238结束投播。结果通过callback异步回调方式返回。
3239
3240**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3241
3242**参数:**
3243
3244| 参数名   | 类型                                  | 必填 | 说明                                  |
3245| -------- | ------------------------------------- | ---- | ------------------------------------- |
3246| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
3247
3248**错误码:**
3249
3250以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3251
3252| 错误码ID | 错误信息 |
3253| -------- | ---------------------------------------- |
3254| 6600109  | The remote connection is not established. |
3255
3256**示例:**
3257
3258```ts
3259import { BusinessError } from '@kit.BasicServicesKit';
3260
3261currentAVSession.stopCasting((err: BusinessError) => {
3262  if (err) {
3263    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3264  } else {
3265    console.info('stopCasting successfully');
3266  }
3267});
3268```
3269
3270### stopCasting<sup>10+</sup>
3271
3272stopCasting(): Promise\<void>
3273
3274结束投播。结果通过Promise异步回调方式返回。
3275
3276**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3277
3278**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3279
3280**返回值:**
3281
3282| 类型           | 说明                          |
3283| -------------- | ----------------------------- |
3284| Promise\<void> | Promise对象。当成功结束投播,无返回结果,否则返回错误对象。 |
3285
3286**错误码:**
3287
3288以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3289
3290| 错误码ID | 错误信息 |
3291| -------- | ---------------------------------------- |
3292| 6600109  | The remote connection is not established. |
3293
3294**示例:**
3295
3296```ts
3297import { BusinessError } from '@kit.BasicServicesKit';
3298
3299currentAVSession.stopCasting().then(() => {
3300  console.info('stopCasting successfully');
3301}).catch((err: BusinessError) => {
3302  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
3303});
3304```
3305
3306### getOutputDeviceSync<sup>10+</sup>
3307
3308getOutputDeviceSync(): OutputDeviceInfo
3309
3310使用同步方法获取当前输出设备信息。
3311
3312**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3313
3314**系统能力:** SystemCapability.Multimedia.AVSession.Core
3315
3316**返回值:**
3317
3318| 类型                                            | 说明                              |
3319| ----------------------------------------------- | --------------------------------- |
3320| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 |
3321
3322**错误码:**
3323
3324以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3325
3326| 错误码ID   | 错误信息 |
3327|---------| --------------------------------------- |
3328| 6600101 | Session service exception. |
3329| 6600102 | The session does not exist. |
3330
3331**示例:**
3332
3333```ts
3334import { BusinessError } from '@kit.BasicServicesKit';
3335
3336try {
3337  let currentOutputDevice: avSession.OutputDeviceInfo = currentAVSession.getOutputDeviceSync();
3338} catch (err) {
3339  let error = err as BusinessError;
3340  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
3341}
3342```
3343### getAllCastDisplays<sup>12+</sup>
3344
3345getAllCastDisplays(): Promise<Array\<CastDisplayInfo>>
3346
3347获取当前系统中所有支持扩展屏投播的显示设备。通过Promise异步回调方式返回。
3348
3349**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3350
3351**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
3352
3353**返回值:**
3354
3355| 类型                                            | 说明                              |
3356| ----------------------------------------------- | --------------------------------- |
3357| Promise<Array<[CastDisplayInfo](#castdisplayinfo12)>>| Promise对象,返回当前系统中所有支持扩展屏投播的显示设备。 |
3358
3359**错误码:**
3360
3361以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3362
3363| 错误码ID   | 错误信息 |
3364|---------| --------------------------------------- |
3365| 6600101 | Session service exception. |
3366| 6600102 | The session does not exist. |
3367
3368**示例:**
3369
3370```ts
3371import { BusinessError } from '@kit.BasicServicesKit';
3372
3373let castDisplay: avSession.CastDisplayInfo;
3374currentAVSession.getAllCastDisplays().then((data: Array< avSession.CastDisplayInfo >) => {
3375    if (data.length >= 1) {
3376       castDisplay = data[0];
3377     }
3378   }).catch((err: BusinessError) => {
3379     console.error(`Failed to getAllCastDisplay. Code: ${err.code}, message: ${err.message}`);
3380   });
3381```
3382
3383## AVCastControlCommandType<sup>10+</sup>
3384
3385type AVCastControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
3386  'seek' | 'setVolume' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'toggleMute'
3387
3388投播控制器可传递的命令。
3389
3390**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3391
3392**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3393
3394| 类型             | 说明         |
3395| ---------------- | ------------ |
3396| 'play'           | 播放。         |
3397| 'pause'          | 暂停。        |
3398| 'stop'           | 停止。         |
3399| 'playNext'       | 下一首。       |
3400| 'playPrevious'   | 上一首。       |
3401| 'fastForward'    | 快进。         |
3402| 'rewind'         | 快退。         |
3403| 'seek'           | 跳转某一节点。 |
3404| 'setVolume'      | 设置音量。     |
3405| 'setSpeed'       | 设置播放倍速。 |
3406| 'setLoopMode'    | 设置循环模式。 |
3407| 'toggleFavorite' | 是否收藏。     |
3408| 'toggleMute'     | 设置静音状态。 |
3409
3410## AVCastControlCommand<sup>10+</sup>
3411
3412投播控制器接受的命令的对象描述。
3413
3414**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3415
3416**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3417
3418| 名称      | 类型                                              | 必填 | 说明           |
3419| --------- | ------------------------------------------------- | ---- | -------------- |
3420| command   | [AVCastControlCommandType](#avcastcontrolcommandtype10)     | 是   | 命令。           |
3421| parameter | [media.PlaybackSpeed](../apis-media-kit/js-apis-media.md#playbackspeed8) &#124; number &#124; string &#124; [LoopMode](#loopmode10) | 否   | 命令对应的参数。 |
3422
3423## AVCastController<sup>10+</sup>
3424
3425在投播建立后,调用[avSession.getAVCastController](#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。
3426
3427### getAVPlaybackState<sup>10+</sup>
3428
3429getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
3430
3431获取当前的远端播放状态。结果通过callback异步回调方式返回。
3432
3433**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3434
3435**参数:**
3436
3437| 参数名    | 类型                                                        | 必填 | 说明                                                         |
3438| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
3439| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是   | 回调函数,返回远端播放状态。 |
3440
3441**错误码:**
3442
3443以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3444
3445| 错误码ID | 错误信息 |
3446| -------- | ---------------------------------------- |
3447| 6600101  | Session service exception |
3448
3449**示例:**
3450
3451```ts
3452import { BusinessError } from '@kit.BasicServicesKit';
3453
3454aVCastController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
3455  if (err) {
3456    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3457  } else {
3458    console.info('getAVPlaybackState : SUCCESS');
3459  }
3460});
3461```
3462
3463### getAVPlaybackState<sup>10+</sup>
3464
3465getAVPlaybackState(): Promise\<AVPlaybackState>
3466
3467获取当前的远端播放状态。结果通过Promise异步回调方式返回。
3468
3469**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3470
3471**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3472
3473**返回值:**
3474
3475| 类型                                                        | 说明                                                         |
3476| --------- | ------------------------------------------------------------ |
3477| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise对象。返回远端播放状态。 |
3478
3479**错误码:**
3480
3481以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3482
3483| 错误码ID | 错误信息 |
3484| -------- | ---------------------------------------- |
3485| 6600101  | Session service exception |
3486
3487**示例:**
3488
3489```ts
3490import { BusinessError } from '@kit.BasicServicesKit';
3491
3492aVCastController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
3493  console.info('getAVPlaybackState : SUCCESS');
3494}).catch((err: BusinessError) => {
3495  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
3496});
3497```
3498
3499### sendControlCommand<sup>10+</sup>
3500
3501sendControlCommand(command: AVCastControlCommand): Promise\<void>
3502
3503通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。
3504
3505
3506**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3507
3508**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3509
3510**参数:**
3511
3512| 参数名    | 类型                                  | 必填 | 说明                           |
3513| ------- | ------------------------------------- | ---- | ------------------------------ |
3514| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
3515
3516**返回值:**
3517
3518| 类型           | 说明                          |
3519| -------------- | ----------------------------- |
3520| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
3521
3522**错误码:**
3523
3524以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3525
3526| 错误码ID | 错误信息 |
3527| -------- | ---------------------------------------- |
3528| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3529| 6600101  | Session service exception. |
3530| 6600105  | Invalid session command. |
3531| 6600109  | The remote connection is not established. |
3532
3533**示例:**
3534
3535```ts
3536import { BusinessError } from '@kit.BasicServicesKit';
3537
3538let avCommand: avSession.AVCastControlCommand = {command:'play'};
3539aVCastController.sendControlCommand(avCommand).then(() => {
3540  console.info('SendControlCommand successfully');
3541}).catch((err: BusinessError) => {
3542  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3543});
3544```
3545
3546### sendControlCommand<sup>10+</sup>
3547
3548sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
3549
3550通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。
3551
3552
3553**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3554
3555**参数:**
3556
3557| 参数名   | 类型                                  | 必填 | 说明                           |
3558| -------- | ------------------------------------- | ---- | ------------------------------ |
3559| command  | [AVCastControlCommand](#avcastcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
3560| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。                     |
3561
3562**错误码:**
3563
3564以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3565
3566| 错误码ID | 错误信息 |
3567| -------- | ------------------------------- |
3568| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3569| 6600101  | Session service exception. |
3570| 6600105  | Invalid session command. |
3571| 6600109  | The remote connection is not established. |
3572
3573**示例:**
3574
3575```ts
3576import { BusinessError } from '@kit.BasicServicesKit';
3577
3578let avCommand: avSession.AVCastControlCommand = {command:'play'};
3579aVCastController.sendControlCommand(avCommand, (err: BusinessError) => {
3580  if (err) {
3581    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
3582  } else {
3583    console.info('SendControlCommand successfully');
3584  }
3585});
3586```
3587
3588### prepare<sup>10+</sup>
3589
3590prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
3591
3592准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过callback异步回调方式返回。
3593
3594**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3595
3596**参数:**
3597
3598| 参数名    | 类型                                  | 必填 | 说明                           |
3599| ------- | ------------------------------------- | ---- | ------------------------------ |
3600| item | [AVQueueItem](#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
3601| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
3602
3603**错误码:**
3604
3605以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3606
3607| 错误码ID | 错误信息 |
3608| -------- | ---------------------------------------- |
3609| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3610| 6600101  | Session service exception. |
3611| 6600109  | The remote connection is not established. |
3612
3613**示例:**
3614
3615```ts
3616import { BusinessError } from '@kit.BasicServicesKit';
3617
3618// 设置播放参数,开始播放。
3619let playItem: avSession.AVQueueItem = {
3620  itemId: 0,
3621  description: {
3622    assetId: '12345',
3623    mediaType: 'AUDIO',
3624    mediaUri: 'http://resource1_address',
3625    mediaSize: 12345,
3626    startPosition: 0,
3627    duration: 0,
3628    artist: 'mysong',
3629    albumTitle: 'song1_title',
3630    albumCoverUri: "http://resource1_album_address",
3631    lyricUri: "http://resource1_lyric_address",
3632    appName: 'MyMusic'
3633  }
3634};
3635// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
3636aVCastController.prepare(playItem, (err: BusinessError) => {
3637  if (err) {
3638    console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3639  } else {
3640    console.info('prepare successfully');
3641  }
3642});
3643```
3644
3645
3646### prepare<sup>10+</sup>
3647
3648prepare(item: AVQueueItem): Promise\<void>
3649
3650准备播放媒体资源,即进行播放资源的加载和缓冲。结果通过Promise异步回调方式返回。
3651
3652
3653**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3654
3655**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3656
3657**参数:**
3658
3659| 参数名    | 类型                                  | 必填 | 说明                           |
3660| ------- | ------------------------------------- | ---- | ------------------------------ |
3661| item | [AVQueueItem](#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
3662
3663**返回值:**
3664
3665| 类型           | 说明                          |
3666| -------------- | ----------------------------- |
3667| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
3668
3669**错误码:**
3670
3671以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3672
3673| 错误码ID | 错误信息 |
3674| -------- | ---------------------------------------- |
3675| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3676| 6600101  | Session service exception. |
3677| 6600109  | The remote connection is not established. |
3678
3679
3680**示例:**
3681
3682```ts
3683import { BusinessError } from '@kit.BasicServicesKit';
3684
3685// 设置播放参数,开始播放。
3686let playItem: avSession.AVQueueItem = {
3687  itemId: 0,
3688  description: {
3689    assetId: '12345',
3690    mediaType: 'AUDIO',
3691    mediaUri: 'http://resource1_address',
3692    mediaSize: 12345,
3693    startPosition: 0,
3694    duration: 0,
3695    artist: 'mysong',
3696    albumTitle: 'song1_title',
3697    albumCoverUri: "http://resource1_album_address",
3698    lyricUri: "http://resource1_lyric_address",
3699    appName: 'MyMusic'
3700  }
3701};
3702// 准备播放,这个不会触发真正的播放,会进行加载和缓冲。
3703aVCastController.prepare(playItem).then(() => {
3704  console.info('prepare successfully');
3705}).catch((err: BusinessError) => {
3706  console.error(`prepare BusinessError: code: ${err.code}, message: ${err.message}`);
3707});
3708```
3709
3710### start<sup>10+</sup>
3711
3712start(item: AVQueueItem, callback: AsyncCallback\<void>): void
3713
3714启动播放某个媒体资源。结果通过callback异步回调方式返回。
3715
3716**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3717
3718**参数:**
3719
3720| 参数名    | 类型                                  | 必填 | 说明                           |
3721| ------- | ------------------------------------- | ---- | ------------------------------ |
3722| item | [AVQueueItem](#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
3723| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
3724
3725**错误码:**
3726
3727以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3728
3729| 错误码ID | 错误信息 |
3730| -------- | ---------------------------------------- |
3731| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3732| 6600101  | Session service exception. |
3733| 6600109  | The remote connection is not established. |
3734
3735**示例:**
3736
3737```ts
3738import { BusinessError } from '@kit.BasicServicesKit';
3739
3740// 设置播放参数,开始播放。
3741let playItem: avSession.AVQueueItem = {
3742  itemId: 0,
3743  description: {
3744    assetId: '12345',
3745    mediaType: 'AUDIO',
3746    mediaUri: 'http://resource1_address',
3747    mediaSize: 12345,
3748    startPosition: 0,
3749    duration: 0,
3750    artist: 'mysong',
3751    albumTitle: 'song1_title',
3752    albumCoverUri: "http://resource1_album_address",
3753    lyricUri: "http://resource1_lyric_address",
3754    appName: 'MyMusic'
3755  }
3756};
3757
3758// 启动播放。
3759aVCastController.start(playItem, (err: BusinessError) => {
3760  if (err) {
3761    console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3762  } else {
3763    console.info('start successfully');
3764  }
3765});
3766```
3767
3768### start<sup>10+</sup>
3769
3770start(item: AVQueueItem): Promise\<void>
3771
3772启动播放某个媒体资源。结果通过Promise异步回调方式返回。
3773
3774
3775**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3776
3777**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3778
3779**参数:**
3780
3781| 参数名    | 类型                                  | 必填 | 说明                           |
3782| ------- | ------------------------------------- | ---- | ------------------------------ |
3783| item | [AVQueueItem](#avqueueitem10) | 是   | 播放列表中单项的相关属性。 |
3784
3785**返回值:**
3786
3787| 类型           | 说明                          |
3788| -------------- | ----------------------------- |
3789| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
3790
3791**错误码:**
3792
3793以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3794
3795| 错误码ID | 错误信息 |
3796| -------- | ---------------------------------------- |
3797| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
3798| 6600101  | Session service exception. |
3799| 6600109  | The remote connection is not established. |
3800
3801
3802**示例:**
3803
3804```ts
3805import { BusinessError } from '@kit.BasicServicesKit';
3806
3807// 设置播放参数,开始播放。
3808let playItem: avSession.AVQueueItem = {
3809  itemId: 0,
3810  description: {
3811    assetId: '12345',
3812    mediaType: 'AUDIO',
3813    mediaUri: 'http://resource1_address',
3814    mediaSize: 12345,
3815    startPosition: 0,
3816    duration: 0,
3817    artist: 'mysong',
3818    albumTitle: 'song1_title',
3819    albumCoverUri: "http://resource1_album_address",
3820    lyricUri: "http://resource1_lyric_address",
3821    appName: 'MyMusic'
3822  }
3823};
3824// 启动播放。
3825aVCastController.start(playItem).then(() => {
3826  console.info('start successfully');
3827}).catch((err: BusinessError) => {
3828  console.error(`start BusinessError: code: ${err.code}, message: ${err.message}`);
3829});
3830```
3831
3832### getCurrentItem<sup>10+</sup>
3833
3834getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
3835
3836获取当前投播的资源信息。结果通过callback异步回调方式返回。
3837
3838**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3839
3840**参数:**
3841
3842| 参数名   | 类型                                  | 必填 | 说明                                  |
3843| -------- | ------------------------------------- | ---- | ------------------------------------- |
3844| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
3845
3846**错误码:**
3847
3848以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3849
3850| 错误码ID | 错误信息 |
3851| -------- | ---------------------------------------- |
3852| 6600101  | Session service exception. |
3853
3854**示例:**
3855
3856```ts
3857import { BusinessError } from '@kit.BasicServicesKit';
3858
3859aVCastController.getCurrentItem((err: BusinessError, value: avSession.AVQueueItem) => {
3860  if (err) {
3861    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3862  } else {
3863    console.info('getCurrentItem successfully');
3864  }
3865});
3866```
3867
3868### getCurrentItem<sup>10+</sup>
3869
3870getCurrentItem(): Promise\<AVQueueItem>
3871
3872获取当前投播的资源信息。结果通过Promise异步回调方式返回。
3873
3874**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3875
3876**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3877
3878**返回值:**
3879
3880| 类型           | 说明                          |
3881| -------------- | ----------------------------- |
3882| Promise\<[AVQueueItem](#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 |
3883
3884**错误码:**
3885
3886以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3887
3888| 错误码ID | 错误信息 |
3889| -------- | ---------------------------------------- |
3890| 6600101  | Session service exception. |
3891
3892**示例:**
3893
3894```ts
3895import { BusinessError } from '@kit.BasicServicesKit';
3896
3897aVCastController.getCurrentItem().then((value: avSession.AVQueueItem) => {
3898  console.info('getCurrentItem successfully');
3899}).catch((err: BusinessError) => {
3900  console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
3901});
3902```
3903
3904### getValidCommands<sup>11+</sup>
3905
3906getValidCommands(callback: AsyncCallback<Array\<AVCastControlCommandType>>): void
3907
3908获取当前支持的命令。结果通过callback异步回调方式返回。
3909
3910**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3911
3912**参数:**
3913
3914| 参数名 | 类型 | 必填 | 说明 |
3915| -------- | ------------------------------------- | ---- | ------------------------------------- |
3916| callback | Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)> | 是 | 回调函数。返回当前支持的命令。 |
3917
3918**错误码:**
3919
3920以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3921
3922| 错误码ID | 错误信息 |
3923| -------- | ---------------------------------------- |
3924| 6600101  | Session service exception. |
3925
3926**示例:**
3927
3928```ts
3929import { BusinessError } from '@kit.BasicServicesKit';
3930
3931aVCastController.getValidCommands((err: BusinessError, state: avSession.AVCastControlCommandType) => {
3932  if (err) {
3933    console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3934  } else {
3935    console.info('getValidCommands successfully');
3936  }
3937});
3938```
3939
3940### getValidCommands<sup>11+</sup>
3941
3942getValidCommands(): Promise<Array\<AVCastControlCommandType>>
3943
3944获取当前支持的命令。结果通过Promise异步回调方式返回。
3945
3946**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3947
3948**返回值:**
3949
3950| 类型 | 说明 |
3951| -------------- | ----------------------------- |
3952| Promise<Array\<[AVCastControlCommandType](#avcastcontrolcommandtype10)>> | Promise对象,返回当前支持的命令。 |
3953
3954**错误码:**
3955
3956以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
3957
3958| 错误码ID | 错误信息 |
3959| -------- | ---------------------------------------- |
3960| 6600101  | Session service exception. |
3961
3962**示例:**
3963
3964```ts
3965import { BusinessError } from '@kit.BasicServicesKit';
3966
3967aVCastController.getValidCommands().then((state: avSession.AVCastControlCommandType) => {
3968  console.info('getValidCommands successfully');
3969}).catch((err: BusinessError) => {
3970  console.error(`getValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
3971});
3972```
3973
3974### processMediaKeyResponse<sup>12+</sup>
3975
3976processMediaKeyResponse(assetId: string, response: Uint8Array): Promise\<void>
3977
3978在线DRM资源投播时,处理许可证响应。结果通过Promise异步回调方式返回。
3979
3980**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
3981
3982**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
3983
3984**参数:**
3985
3986| 参数名   | 类型                                  | 必填 | 说明                                  |
3987| -------- | ------------------------------------- | ---- | ------------------------------------- |
3988| assetId | string                  | 是   | 媒体ID。 |
3989| response | Uint8Array             | 是   | 许可证响应。 |
3990
3991**返回值:**
3992
3993| 类型           | 说明                          |
3994| -------------- | ----------------------------- |
3995| Promise\<void> | Promise对象,当处理许可证响应成功,无返回结果,否则返回错误对象。 |
3996
3997**错误码:**
3998
3999以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4000
4001| 错误码ID | 错误信息 |
4002| -------- | ---------------------------------------- |
4003| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
4004| 6600101  | Session service exception. |
4005
4006**示例:**
4007
4008```ts
4009let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4010  // 根据assetId获取对应的DRM url。
4011  let drmUrl = 'http://license.xxx.xxx.com:8080/drmproxy/getLicense';
4012  // 从服务器获取许可证,需要开发者根据实际情况进行赋值。
4013  let licenseResponseData: Uint8Array = new Uint8Array();
4014  console.info(`Succeeded in get license by ${drmUrl}.`);
4015  aVCastController.processMediaKeyResponse(assetId, licenseResponseData);
4016}
4017```
4018
4019### release<sup>11+</sup>
4020
4021release(callback: AsyncCallback\<void>): void
4022
4023销毁当前controller,结果通过callback异步回调方式返回。
4024
4025**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4026
4027**参数:**
4028
4029| 参数名   | 类型                       | 必填 | 说明                                                         |
4030| -------- | -------------------------- | ---- | ------------------------------------------------------------ |
4031| callback | AsyncCallback\<void>       | 是   | 回调函数。当命令执行成功,err为undefined,否则返回错误对象。 |
4032
4033**错误码:**
4034
4035以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4036
4037| 错误码ID | 错误信息 |
4038| -------- | -------------------------- |
4039| 6600101  | Session service exception. |
4040
4041**示例:**
4042
4043```ts
4044import { BusinessError } from '@kit.BasicServicesKit';
4045
4046aVCastController.release((err: BusinessError) => {
4047  if (err) {
4048    console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
4049  } else {
4050    console.info('release successfully');
4051  }
4052});
4053```
4054
4055### release<sup>11+</sup>
4056
4057release(): Promise\<void>
4058
4059销毁当前controller。结果通过Promise异步回调方式返回。
4060
4061**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4062
4063**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4064
4065**返回值:**
4066
4067| 类型           | 说明                          |
4068| -------------- | ----------------------------- |
4069| Promise\<void> | Promise对象,controller销毁成功,无结果返回,否则返回错误对象。 |
4070
4071**错误码:**
4072
4073以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4074
4075| 错误码ID | 错误信息 |
4076| -------- | ------------------------------ |
4077| 6600101  | Session service exception. |
4078
4079**示例:**
4080
4081```ts
4082import { BusinessError } from '@kit.BasicServicesKit';
4083
4084aVCastController.release().then(() => {
4085  console.info('release successfully');
4086}).catch((err: BusinessError) => {
4087  console.error(`release BusinessError: code: ${err.code}, message: ${err.message}`);
4088});
4089
4090```
4091
4092### on('playbackStateChange')<sup>10+</sup>
4093
4094on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
4095
4096设置播放状态变化的监听事件。
4097
4098**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4099
4100**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4101
4102**参数:**
4103
4104| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4105| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4106| type     | string                                                       | 是   | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 |
4107| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注播放状态所有字段变化;Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 |
4108| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | 是   | 回调函数,参数state是变化后的播放状态。                      |
4109
4110**错误码:**
4111
4112以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4113
4114| 错误码ID | 错误信息 |
4115| -------- | ------------------------------ |
4116| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4117| 6600101  | Session service exception. |
4118
4119**示例:**
4120
4121```ts
4122aVCastController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
4123  console.info(`on playbackStateChange state : ${playbackState.state}`);
4124});
4125
4126let playbackFilter: Array<keyof avSession.AVPlaybackState> = ['state', 'speed', 'loopMode'];
4127aVCastController.on('playbackStateChange', playbackFilter, (playbackState: avSession.AVPlaybackState) => {
4128  console.info(`on playbackStateChange state : ${playbackState.state}`);
4129});
4130```
4131
4132### off('playbackStateChange')<sup>10+</sup>
4133
4134off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
4135
4136媒体控制器取消监听播放状态变化的事件。
4137
4138**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4139
4140**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4141
4142**参数:**
4143
4144| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4145| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4146| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playbackStateChange'`。    |
4147| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | 否   | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                      |
4148
4149**错误码:**
4150
4151以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4152
4153| 错误码ID | 错误信息 |
4154| -------- | ---------------- |
4155| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4156| 6600101  | Session service exception. |
4157
4158**示例:**
4159
4160```ts
4161aVCastController.off('playbackStateChange');
4162```
4163
4164### on('mediaItemChange')<sup>10+</sup>
4165
4166on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
4167
4168设置投播当前播放媒体内容的监听事件。
4169
4170**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4171
4172**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4173
4174**参数:**
4175
4176| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4177| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4178| type     | string                                                       | 是   | 事件回调类型,支持事件`'mediaItemChange'`:当播放的媒体内容变化时,触发该事件。 |
4179| callback | (callback: [AVQueueItem](#avqueueitem10)) => void         | 是   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。                      |
4180
4181**错误码:**
4182
4183以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4184
4185| 错误码ID | 错误信息 |
4186| -------- | ------------------------------ |
4187| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4188| 6600101  | Session service exception. |
4189
4190**示例:**
4191
4192```ts
4193aVCastController.on('mediaItemChange', (item: avSession.AVQueueItem) => {
4194  console.info(`on mediaItemChange state : ${item.itemId}`);
4195});
4196```
4197
4198### off('mediaItemChange')<sup>10+</sup>
4199
4200off(type: 'mediaItemChange'): void
4201
4202取消设置投播当前播放媒体内容的监听事件。
4203
4204**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4205
4206**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4207
4208**参数:**
4209
4210| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4211| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4212| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'mediaItemChange'`。    |
4213
4214**错误码:**
4215
4216以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4217
4218| 错误码ID | 错误信息 |
4219| -------- | ---------------- |
4220| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4221| 6600101  | Session service exception. |
4222
4223**示例:**
4224
4225```ts
4226aVCastController.off('mediaItemChange');
4227```
4228
4229### on('playNext')<sup>10+</sup>
4230
4231on(type: 'playNext', callback: Callback\<void>): void
4232
4233设置播放下一首资源的监听事件。
4234
4235**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4236
4237**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4238
4239**参数:**
4240
4241| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4242| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4243| type     | string                                                       | 是   | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 |
4244| callback | Callback\<void\>         | 是   | 回调函数。                      |
4245
4246**错误码:**
4247
4248以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4249
4250| 错误码ID | 错误信息 |
4251| -------- | ------------------------------ |
4252| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4253| 6600101  | Session service exception. |
4254
4255**示例:**
4256
4257```ts
4258aVCastController.on('playNext', () => {
4259  console.info('on playNext');
4260});
4261```
4262
4263### off('playNext')<sup>10+</sup>
4264
4265off(type: 'playNext'): void
4266
4267取消设置播放下一首资源的监听事件。
4268
4269**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4270
4271**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4272
4273**参数:**
4274
4275| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4276| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4277| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playNext'`。    |
4278
4279**错误码:**
4280
4281以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4282
4283| 错误码ID | 错误信息 |
4284| -------- | ---------------- |
4285| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4286| 6600101  | Session service exception. |
4287
4288**示例:**
4289
4290```ts
4291aVCastController.off('playNext');
4292```
4293
4294### on('playPrevious')<sup>10+</sup>
4295
4296on(type: 'playPrevious', callback: Callback\<void>): void
4297
4298设置播放上一首资源的监听事件。
4299
4300**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4301
4302**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4303
4304**参数:**
4305
4306| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4307| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4308| type     | string                                                       | 是   | 事件回调类型,支持事件`'playPrevious'`:当播放上一首状态变化时,触发该事件。 |
4309| callback | Callback\<void\>         | 是   | 回调函数。                      |
4310
4311**错误码:**
4312
4313以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4314
4315| 错误码ID | 错误信息 |
4316| -------- | ------------------------------ |
4317| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4318| 6600101  | Session service exception. |
4319
4320**示例:**
4321
4322```ts
4323aVCastController.on('playPrevious', () => {
4324  console.info('on playPrevious');
4325});
4326```
4327
4328### off('playPrevious')<sup>10+</sup>
4329
4330off(type: 'playPrevious'): void
4331
4332取消设置播放上一首资源的监听事件。
4333
4334**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4335
4336**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4337
4338**参数:**
4339
4340| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4341| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4342| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playPrevious'`。    |
4343
4344**错误码:**
4345
4346以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4347
4348| 错误码ID | 错误信息 |
4349| -------- | ---------------- |
4350| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4351| 6600101  | Session service exception. |
4352
4353**示例:**
4354
4355```ts
4356aVCastController.off('playPrevious');
4357```
4358
4359### on('requestPlay')<sup>11+</sup>
4360
4361on(type: 'requestPlay', callback: Callback\<AVQueueItem>): void
4362
4363设置请求播放的监听事件。
4364
4365**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4366
4367**参数:**
4368
4369| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4370| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4371| type     | string                                                       | 是   | 事件回调类型,支持事件`'requestPlay'`:当请求播放状态变化时,触发该事件。 |
4372| callback | (state: [AVQueueItem](#avqueueitem10)) => void               | 是   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件注册成功,err为undefined,否则返回错误对象。  |
4373
4374**错误码:**
4375
4376以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4377
4378| 错误码ID | 错误信息 |
4379| -------- | ------------------------------ |
4380| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4381| 6600101  | Session service exception. |
4382
4383**示例:**
4384
4385```ts
4386aVCastController.on('requestPlay', (item: avSession.AVQueueItem) => {
4387  console.info(`on requestPlay state : ${item.itemId}`);
4388});
4389```
4390
4391### off('requestPlay')<sup>11+</sup>
4392
4393off(type: 'requestPlay', callback?: Callback\<AVQueueItem>): void
4394
4395取消设置请求播放的监听事件。
4396
4397**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4398
4399**参数:**
4400
4401| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4402| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4403| type     | string                                                      | 是   | 取消对应的监听事件,支持事件`'requestPlay'`。    |
4404| callback | (state: [AVQueueItem](#avqueueitem10)) => void              | 否   | 回调函数,参数AVQueueItem是当前正在播放的媒体内容。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。|
4405
4406**错误码:**
4407
4408以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4409
4410| 错误码ID | 错误信息 |
4411| -------- | ---------------- |
4412| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4413| 6600101  | Session service exception. |
4414
4415**示例:**
4416
4417```ts
4418aVCastController.off('requestPlay');
4419```
4420
4421### on('endOfStream')<sup>11+</sup>
4422
4423on(type: 'endOfStream', callback: Callback\<void>): void
4424
4425设置播放结束的监听事件。
4426
4427**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4428
4429**参数:**
4430
4431| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4432| -------- | ------------------------------------------------------------| ---- | ------------------------------------------------------------ |
4433| type     | string                                                      | 是   | 事件回调类型,支持事件`'endOfStream'`:当资源播放结束时,触发该事件。 |
4434| callback | Callback\<void\>                                            | 是   | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。      |
4435
4436**错误码:**
4437
4438以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4439
4440| 错误码ID | 错误信息 |
4441| -------- | ------------------------------ |
4442| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4443| 6600101  | Session service exception. |
4444
4445**示例:**
4446
4447```ts
4448aVCastController.on('endOfStream', () => {
4449  console.info('on endOfStream');
4450});
4451```
4452
4453### off('endOfStream')<sup>11+</sup>
4454
4455off(type: 'endOfStream', callback?: Callback\<void>): void
4456
4457取消设置播放结束的监听事件。
4458
4459**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4460
4461**参数:**
4462
4463| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4464| -------- | ------------------------------------------------------------| ---- | ----------------------------------------------------- |
4465| type     | string                                                      | 是   | 取消对应的监听事件,支持事件`'endOfStream'`。    |
4466| callback | Callback\<void\>                                            | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。   |
4467
4468**错误码:**
4469
4470以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4471
4472| 错误码ID | 错误信息 |
4473| -------- | ---------------- |
4474| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4475| 6600101  | Session service exception. |
4476
4477**示例:**
4478
4479```ts
4480aVCastController.off('endOfStream');
4481```
4482
4483### on('seekDone')<sup>10+</sup>
4484
4485on(type: 'seekDone', callback: Callback\<number>): void
4486
4487设置seek结束的监听事件。
4488
4489**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4490
4491**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4492
4493**参数:**
4494
4495| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4496| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4497| type     | string                                                       | 是   | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 |
4498| callback | Callback\<number\>         | 是   | 回调函数,返回seek后播放的位置。                      |
4499
4500**错误码:**
4501
4502以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4503
4504| 错误码ID | 错误信息 |
4505| -------- | ------------------------------ |
4506| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4507| 6600101  | Session service exception. |
4508
4509**示例:**
4510
4511```ts
4512aVCastController.on('seekDone', (pos: number) => {
4513  console.info(`on seekDone pos:${pos} `);
4514});
4515```
4516
4517### off('seekDone')<sup>10+</sup>
4518
4519off(type: 'seekDone'): void
4520
4521取消设置seek结束的监听事件。
4522
4523**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4524
4525**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4526
4527**参数:**
4528
4529| 参数名   | 类型                                                         | 必填 | 说明                                                     |
4530| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
4531| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'seekDone'`。    |
4532
4533**错误码:**
4534
4535以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4536
4537| 错误码ID | 错误信息 |
4538| -------- | ---------------- |
4539| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4540| 6600101  | Session service exception. |
4541
4542**示例:**
4543
4544```ts
4545aVCastController.off('seekDone');
4546```
4547
4548### on('validCommandChange')<sup>11+</sup>
4549
4550on(type: 'validCommandChange', callback: Callback\<Array\<AVCastControlCommandType>>)
4551
4552会话支持的有效命令变化监听事件。
4553
4554**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4555
4556**参数:**
4557
4558| 参数名   | 类型                                                         | 必填 | 说明                                                         |
4559| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
4560| type     | string                                                       | 是   | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 |
4561| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\>   | 是   | 回调函数。参数commands是有效命令的集合。                     |
4562
4563**错误码:**
4564
4565以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4566
4567| 错误码ID | 错误信息 |
4568| -------- | ------------------------------ |
4569| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4570| 6600101  | Session service exception. |
4571| 6600103  | The session controller does not exist. |
4572
4573**示例:**
4574
4575```ts
4576aVCastController.on('validCommandChange', (validCommands: avSession.AVCastControlCommandType[]) => {
4577  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
4578  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
4579});
4580```
4581
4582### off('validCommandChange')<sup>11+</sup>
4583
4584off(type: 'validCommandChange', callback?: Callback\<Array\<AVCastControlCommandType>>)
4585
4586媒体控制器取消监听会话有效命令变化的事件。
4587
4588**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4589
4590**参数:**
4591
4592| 参数名   | 类型                                                         | 必填 | 说明                                                        |
4593| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
4594| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'validCommandChange'`。         |
4595| callback | Callback<Array<[AVCastControlCommandType](#avcastcontrolcommandtype10)\>\> | 否   | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。          |
4596
4597**错误码:**
4598
4599以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4600
4601| 错误码ID | 错误信息           |
4602| -------- | ---------------- |
4603| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4604| 6600101  | Session service exception. |
4605| 6600103  | The session controller does not exist. |
4606
4607**示例:**
4608
4609```ts
4610aVCastController.off('validCommandChange');
4611```
4612
4613### on('error')<sup>10+</sup>
4614
4615on(type: 'error', callback: ErrorCallback): void
4616
4617监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。
4618
4619**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4620
4621**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4622
4623**参数:**
4624
4625| 参数名   | 类型     | 必填 | 说明                                                         |
4626| -------- | -------- | ---- | ------------------------------------------------------------ |
4627| type     | string   | 是   | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 |
4628| callback | ErrorCallback | 是   | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 |
4629
4630**错误码:**
4631
4632以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
4633
4634| 错误码ID | 错误信息              |
4635| -------- | --------------------- |
4636| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4637| 5400101  | No memory.            |
4638| 5400102  | Operation not allowed.   |
4639| 5400103  | I/O error.             |
4640| 5400104  | Time out.      |
4641| 5400105  | Service died.         |
4642| 5400106  | Unsupport format.     |
4643| 6600101  | Session service exception.     |
4644
4645**示例:**
4646
4647```ts
4648import { BusinessError } from '@kit.BasicServicesKit';
4649
4650aVCastController.on('error', (error: BusinessError) => {
4651  console.info(`error happened, error code: ${error.code}, error message : ${error.message}.`)
4652})
4653```
4654
4655### off('error')<sup>10+</sup>
4656
4657off(type: 'error'): void
4658
4659取消监听播放的错误事件。
4660
4661**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4662
4663**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4664
4665**参数:**
4666
4667| 参数名 | 类型   | 必填 | 说明                                      |
4668| ------ | ------ | ---- | ----------------------------------------- |
4669| type   | string | 是   | 错误事件回调类型,取消注册的事件:'error'。 |
4670
4671**错误码:**
4672
4673以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
4674
4675| 错误码ID | 错误信息              |
4676| -------- | --------------------- |
4677| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4678| 5400101  | No memory.            |
4679| 5400102  | Operation not allowed.   |
4680| 5400103  | I/O error.             |
4681| 5400104  | Time out.      |
4682| 5400105  | Service died.         |
4683| 5400106  | Unsupport format.     |
4684| 6600101  | Session service exception.     |
4685
4686**示例:**
4687
4688```ts
4689aVCastController.off('error')
4690```
4691
4692### on('keyRequest')<sup>12+</sup>
4693
4694on(type: 'keyRequest', callback: KeyRequestCallback): void
4695
4696在线DRM资源投播时,设置许可证请求的事件监听。
4697
4698**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4699
4700**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4701
4702**参数:**
4703
4704| 参数名 | 类型   | 必填 | 说明                                      |
4705| ------ | ------ | ---- | ----------------------------------------- |
4706| type     | string  | 是   | 事件回调类型,支持事件`'keyRequest'`:当DRM资源播放需要许可证时,触发该事件。 |
4707| callback | [KeyRequestCallback](#keyrequestcallback12)  | 是   | 回调函数,媒体资源及许可证请求数据。|
4708
4709
4710**错误码:**
4711
4712以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4713
4714| 错误码ID | 错误信息           |
4715| -------- | ---------------- |
4716| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4717| 6600101  | Session service exception. |
4718
4719**示例:**
4720
4721```ts
4722let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
4723  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
4724}
4725aVCastController.on('keyRequest', keyRequestCallback);
4726```
4727### off('keyRequest')<sup>12+</sup>
4728
4729off(type: 'keyRequest', callback?: KeyRequestCallback): void
4730
4731取消监听许可证请求的事件。
4732
4733**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
4734
4735**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4736
4737**参数:**
4738
4739| 参数名 | 类型   | 必填 | 说明                                      |
4740| ------ | ------ | ---- | ----------------------------------------- |
4741| type     | string                                                       | 是   | 取消对应的监听事件,支持的事件是`'keyRequest'`。 |
4742| callback |  [KeyRequestCallback](#keyrequestcallback12)  | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                            |
4743
4744**错误码:**
4745
4746以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
4747
4748| 错误码ID | 错误信息           |
4749| -------- | ---------------- |
4750| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
4751| 6600101  | Session service exception. |
4752
4753**示例:**
4754
4755```ts
4756aVCastController.off('keyRequest');
4757```
4758
4759### on('castControlGenericError')<sup>13+</sup>
4760
4761on(type: 'castControlGenericError', callback: ErrorCallback): void
4762
4763监听投播通用错误事件。
4764
4765**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4766
4767**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4768
4769**参数:**
4770
4771| 参数名   | 类型     | 必填 | 说明                                                         |
4772| -------- | -------- | ---- | ------------------------------------------------------------ |
4773| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlGenericError'。 |
4774| callback | ErrorCallback | 是   | 投播通用错误事件回调方法。 |
4775
4776**错误码:**
4777
4778| 错误码ID | 错误信息              |
4779| -------- | --------------------- |
4780| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4781| 6611000  | The error code for cast control is unspecified.      |
4782| 6611001  | An unspecified error occurs in the remote player.   |
4783| 6611002  | The playback position falls behind the live window.     |
4784| 6611003  | The process of cast control times out.    |
4785| 6611004  | The runtime check failed.      |
4786| 6611100  | Cross-device data transmission is locked.    |
4787| 6611101  | The specified seek mode is not supported.   |
4788| 6611102  | The position to seek to is out of the range of the media asset or the specified seek mode is not supported.  |
4789| 6611103  | The specified playback mode is not supported.       |
4790| 6611104  | The specified playback speed is not supported.    |
4791| 6611105  | The action failed because either the media source device or the media sink device has been revoked.   |
4792| 6611106  | The parameter is invalid, for example, the url is illegal to play.  |
4793| 6611107  | Allocation of memory failed.  |
4794| 6611108  | Operation is not allowed.    |
4795
4796**示例:**
4797
4798```ts
4799aVCastController.on('castControlGenericError', (error: BusinessError) => {
4800  console.info(`castControlGenericError happened, error code: ${error.code}, error message : ${error.message}.`)
4801})
4802```
4803
4804### off('castControlGenericError')<sup>13+</sup>
4805
4806off(type: 'castControlGenericError', callback?: ErrorCallback): void
4807
4808取消监听投播通用的错误事件。
4809
4810**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4811
4812**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4813
4814**参数:**
4815
4816| 参数名   | 类型     | 必填 | 说明                                                         |
4817| -------- | -------- | ---- | ------------------------------------------------------------ |
4818| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlGenericError'。 |
4819| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
4820
4821**错误码:**
4822
4823| 错误码ID | 错误信息              |
4824| -------- | --------------------- |
4825| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4826
4827**示例:**
4828
4829```ts
4830aVCastController.off('castControlGenericError');
4831```
4832
4833### on('castControlIoError')<sup>13+</sup>
4834
4835on(type: 'castControlIoError', callback: ErrorCallback): void
4836
4837监听投播输入/输出的错误事件。
4838
4839**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4840
4841**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4842
4843**参数:**
4844
4845| 参数名   | 类型     | 必填 | 说明                                                         |
4846| -------- | -------- | ---- | ------------------------------------------------------------ |
4847| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlIoError'。 |
4848| callback | ErrorCallback | 是   | 投播输入/输出的错误事件回调方法。 |
4849
4850**错误码:**
4851
4852| 错误码ID | 错误信息              |
4853| -------- | --------------------- |
4854| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4855| 6612000  | An unspecified input/output error occurs.     |
4856| 6612001  | Network connection failure.   |
4857| 6612002  | Network timeout.     |
4858| 6612003  | Invalid "Content-Type" HTTP header.    |
4859| 6612004  | The HTTP server returns an unexpected HTTP response status code.      |
4860| 6612005  | The file does not exist.    |
4861| 6612006  | No permission is granted to perform the IO operation.   |
4862| 6612007  | Access to cleartext HTTP traffic is not allowed by the app's network security configuration. |
4863| 6612008  | Reading data out of the data bound.    |
4864| 6612100  | The media does not contain any contents that can be played.   |
4865| 6612101  | The media cannot be read, for example, because of dust or scratches.   |
4866| 6612102  | This resource is already in use. |
4867| 6612103  | The content using the validity interval has expired.  |
4868| 6612104  | Using the requested content to play is not allowed.    |
4869| 6612105  | The use of the allowed content cannot be verified.  |
4870| 6612106  | The number of times this content has been used as requested has reached the maximum allowed number of uses.  |
4871| 6612107  | An error occurs when sending packet from source device to sink device.    |
4872
4873**示例:**
4874
4875```ts
4876aVCastController.on('castControlIoError', (error: BusinessError) => {
4877  console.info(`castControlIoError happened, error code: ${error.code}, error message : ${error.message}.`)
4878})
4879```
4880
4881### off('castControlIoError')<sup>13+</sup>
4882
4883off(type: 'castControlIoError', callback?: ErrorCallback): void
4884
4885取消监听投播输入/输出的错误事件。
4886
4887**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4888
4889**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4890
4891**参数:**
4892
4893| 参数名   | 类型     | 必填 | 说明                                                         |
4894| -------- | -------- | ---- | ------------------------------------------------------------ |
4895| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlIoError'。 |
4896| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
4897
4898**错误码:**
4899
4900| 错误码ID | 错误信息              |
4901| -------- | --------------------- |
4902| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4903
4904**示例:**
4905
4906```ts
4907aVCastController.off('castControlIoError');
4908```
4909
4910### on('castControlParsingError')<sup>13+</sup>
4911
4912on(type: 'castControlParsingError', callback: ErrorCallback): void
4913
4914监听投播解析的错误事件。
4915
4916**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4917
4918**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4919
4920**参数:**
4921
4922| 参数名   | 类型     | 必填 | 说明                                                         |
4923| -------- | -------- | ---- | ------------------------------------------------------------ |
4924| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlParsingError'。 |
4925| callback | ErrorCallback | 是   | 投播解析的错误事件回调方法。 |
4926
4927**错误码:**
4928
4929| 错误码ID  | 错误信息              |
4930| -------- | --------------------- |
4931| 401      |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4932| 6613000  | Unspecified error related to content parsing.     |
4933| 6613001  | Parsing error associated with media container format bit streams.   |
4934| 6613002  | Parsing error associated with the media manifest.     |
4935| 6613003  | An error occurs when attempting to extract a file with an unsupported media container format or an unsupported media container feature.    |
4936| 6613004  | Unsupported feature in the media manifest.    |
4937
4938**示例:**
4939
4940```ts
4941aVCastController.on('castControlParsingError', (error: BusinessError) => {
4942  console.info(`castControlParsingError happened, error code: ${error.code}, error message : ${error.message}.`)
4943})
4944```
4945
4946### off('castControlParsingError')<sup>13+</sup>
4947
4948off(type: 'castControlParsingError', callback?: ErrorCallback): void
4949
4950取消监听投播解析的错误事件。
4951
4952**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4953
4954**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4955
4956**参数:**
4957
4958| 参数名   | 类型     | 必填 | 说明                                                         |
4959| -------- | -------- | ---- | ------------------------------------------------------------ |
4960| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlParsingError'。 |
4961| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
4962
4963**错误码:**
4964
4965| 错误码ID | 错误信息              |
4966| -------- | --------------------- |
4967| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4968
4969**示例:**
4970
4971```ts
4972aVCastController.off('castControlParsingError');
4973```
4974
4975### on('castControlDecodingError')<sup>13+</sup>
4976
4977on(type: 'castControlDecodingError', callback: ErrorCallback): void
4978
4979监听投播解码的错误事件。
4980
4981**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
4982
4983**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
4984
4985**参数:**
4986
4987| 参数名   | 类型     | 必填 | 说明                                                         |
4988| -------- | -------- | ---- | ------------------------------------------------------------ |
4989| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlDecodingError'。 |
4990| callback | ErrorCallback | 是   | 投播解码的错误事件回调方法。 |
4991
4992**错误码:**
4993
4994| 错误码ID | 错误信息              |
4995| -------- | --------------------- |
4996| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
4997| 6614000  | Unspecified decoding error.     |
4998| 6614001  | Decoder initialization failed.   |
4999| 6614002  | Decoder query failed.     |
5000| 6614003  | Decoding the media samples failed.    |
5001| 6614004  | The format of the content to decode exceeds the capabilities of the device.    |
5002| 6614005  | The format of the content to decode is not supported.    |
5003
5004**示例:**
5005
5006```ts
5007aVCastController.on('castControlDecodingError', (error: BusinessError) => {
5008  console.info(`castControlDecodingError happened, error code: ${error.code}, error message : ${error.message}.`)
5009})
5010```
5011### off('castControlDecodingError')<sup>13+</sup>
5012
5013off(type: 'castControlDecodingError', callback?: ErrorCallback): void
5014
5015取消监听投播解码的错误事件。
5016
5017**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5018
5019**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5020
5021**参数:**
5022
5023| 参数名   | 类型     | 必填 | 说明                                                         |
5024| -------- | -------- | ---- | ------------------------------------------------------------ |
5025| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlDecodingError'。 |
5026| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
5027
5028**错误码:**
5029
5030| 错误码ID | 错误信息              |
5031| -------- | --------------------- |
5032| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5033
5034**示例:**
5035
5036```ts
5037aVCastController.off('castControlDecodingError');
5038```
5039
5040### on('castControlAudioRendererError')<sup>13+</sup>
5041
5042on(type: 'castControlAudioRendererError', callback: ErrorCallback): void
5043
5044监听投播音频渲染器的错误事件。
5045
5046**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5047
5048**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5049
5050**参数:**
5051
5052| 参数名   | 类型     | 必填 | 说明                                                         |
5053| -------- | -------- | ---- | ------------------------------------------------------------ |
5054| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlAudioRendererError'。 |
5055| callback | ErrorCallback | 是   | 投播音频渲染器的错误事件回调方法。 |
5056
5057**错误码:**
5058
5059以下错误码的详细介绍请参见[媒体服务错误码](../apis-media-kit/errorcode-media.md)以及[媒体会话管理错误码](errorcode-avsession.md)。
5060
5061| 错误码ID | 错误信息              |
5062| -------- | --------------------- |
5063| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5064| 6615000  | Unspecified errors related to the audio renderer.     |
5065| 6615001  | Initializing the audio renderer failed.   |
5066| 6615002  | The audio renderer fails to write data.     |
5067
5068**示例:**
5069
5070```ts
5071aVCastController.on('castControlAudioRendererError', (error: BusinessError) => {
5072  console.info(`castControlAudioRendererError happened, error code: ${error.code}, error message : ${error.message}.`)
5073})
5074```
5075### off('castControlAudioRendererError')<sup>13+</sup>
5076
5077off(type: 'castControlAudioRendererError', callback?: ErrorCallback): void
5078
5079取消监听投播音频渲染器的错误事件。
5080
5081**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5082
5083**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5084
5085**参数:**
5086
5087| 参数名   | 类型     | 必填 | 说明                                                         |
5088| -------- | -------- | ---- | ------------------------------------------------------------ |
5089| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlAudioRendererError'。 |
5090| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
5091
5092**错误码:**
5093
5094| 错误码ID | 错误信息              |
5095| -------- | --------------------- |
5096| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
5097
5098**示例:**
5099
5100```ts
5101aVCastController.off('castControlAudioRendererError');
5102```
5103
5104### on('castControlDrmError')<sup>13+</sup>
5105
5106on(type: 'castControlDrmError', callback: ErrorCallback): void
5107
5108监听投播drm的错误事件。
5109
5110**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5111
5112**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5113
5114**参数:**
5115
5116| 参数名   | 类型     | 必填 | 说明                                                         |
5117| -------- | -------- | ---- | ------------------------------------------------------------ |
5118| type     | string   | 是   | 错误事件回调类型,支持的事件:'castControlDrmError'。 |
5119| callback | ErrorCallback | 是   | 投播drm的错误事件回调方法。 |
5120
5121**错误码:**
5122
5123| 错误码ID | 错误信息              |
5124| -------- | --------------------- |
5125| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5126| 6616000  | Unspecified error related to DRM.     |
5127| 6616001  | The chosen DRM protection scheme is not supported by the device.  |
5128| 6616002  | Device provisioning failed.    |
5129| 6616003  | The DRM-protected content to play is incompatible.     |
5130| 6616004  | Failed to obtain a license.   |
5131| 6616005  | The operation is disallowed by the license policy.     |
5132| 6616006  | An error occurs in the DRM system.     |
5133| 6616007  | The device has revoked DRM privileges.   |
5134| 6616008  | The DRM license being loaded into the open DRM session has expired.      |
5135| 6616100  | An error occurs when the DRM processes the key response.     |
5136
5137**示例:**
5138
5139```ts
5140aVCastController.on('castControlDrmError', (error: BusinessError) => {
5141  console.info(`castControlDrmError happened, error code: ${error.code}, error message : ${error.message}.`)
5142})
5143```
5144
5145### off('castControlDrmError')<sup>13+</sup>
5146
5147off(type: 'castControlDrmError', callback?: ErrorCallback): void
5148
5149取消监听投播drm的错误事件。
5150
5151**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。
5152
5153**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5154
5155**参数:**
5156
5157| 参数名   | 类型     | 必填 | 说明                                                         |
5158| -------- | -------- | ---- | ------------------------------------------------------------ |
5159| type     | string   | 是   | 	取消对应的监听事件,支持的事件是'castControlDrmError'。 |
5160| callback | ErrorCallback | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
5161
5162**错误码:**
5163
5164| 错误码ID | 错误信息              |
5165| -------- | --------------------- |
5166| 401 |  Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
5167
5168**示例:**
5169
5170```ts
5171aVCastController.off('castControlDrmError');
5172```
5173
5174## ExtraInfo<sup>18+</sup>
5175type ExtraInfo = { [key: string]: Object; }
5176
5177媒体提供方设置的自定义媒体数据包对象。
5178
5179**系统能力:** SystemCapability.Multimedia.AVSession.Core
5180
5181| 类型                                | 说明                          |
5182| ----------------------------------- | ----------------------------- |
5183| [key: string]: Object   | key为远端分布式事件类型。当前支持的事件类型包括:<br>'AUDIO_GET_VOLUME':获取远端设备音量。<br>'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备。<br>'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。<br>媒体提供方根据不同的远端分布式事件类型,返回对应的媒体数据包Object对象。 |
5184
5185## KeyRequestCallback<sup>12+</sup>
5186type KeyRequestCallback = (assetId: string, requestData: Uint8Array) => void
5187
5188许可证请求事件的回调函数。
5189
5190**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5191
5192**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5193
5194**参数:**
5195
5196| 参数名 | 类型   | 必填 | 说明                                      |
5197| ------ | ------ | ---- | ----------------------------------------- |
5198| assetId     | string  | 是   | 媒体ID。 |
5199| requestData |  Uint8Array  | 是   | 媒体许可证请求数据。                            |
5200
5201**示例:**
5202<!--code_no_check-->
5203```ts
5204let keyRequestCallback: avSession.KeyRequestCallback = async(assetId: string, requestData: Uint8Array) => {
5205  console.info(`Succeeded in keyRequestCallback. assetId: ${assetId}, requestData: ${requestData}`);
5206}
5207```
5208
5209## CastDisplayState<sup>12+</sup>
5210
5211投播显示设备状态的枚举。
5212
5213**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5214
5215**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5216
5217| 名称                        | 值   | 说明         |
5218| --------------------------- | ---- | ----------- |
5219| STATE_OFF      | 1    | 设备断开,扩展屏不再显示内容。    |
5220| STATE_ON      | 2    | 设备连接成功,扩展屏可用。 |
5221
5222
5223## CastDisplayInfo<sup>12+</sup>
5224
5225扩展屏投播显示设备相关属性。
5226
5227**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5228
5229**系统能力:** SystemCapability.Multimedia.AVSession.ExtendedDisplayCast
5230
5231| 名称            | 类型                      | 只读 | 可选 | 说明                                                                  |
5232| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------|
5233| id            | number                  | 否    | 否    | 投播显示设备的ID,该参数应为整数。  |
5234| name     | string                  | 否    | 否    | 投播显示设备的名称。           |
5235| state          | [CastDisplayState](#castdisplaystate12)          | 否    | 否    |投播显示设备状态。            |
5236| width          | number          | 否    | 否    | 投播显示设备的屏幕宽度,单位为px,该参数应为整数。          |
5237| height          | number          | 否    | 否    | 投播显示设备的屏幕高度,单位为px,该参数应为整数。            |
5238
5239## ConnectionState<sup>10+</sup>
5240
5241连接状态枚举。
5242
5243**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5244
5245**系统能力:** SystemCapability.Multimedia.AVSession.Core
5246
5247| 名称                        | 值   | 说明         |
5248| --------------------------- | ---- | ----------- |
5249| STATE_CONNECTING      | 0    | 设备连接中。    |
5250| STATE_CONNECTED      | 1    | 设备连接成功。 |
5251| STATE_DISCONNECTED      | 6    | 设备断开连接。 |
5252
5253## AVMetadata<sup>10+</sup>
5254
5255媒体元数据的相关属性。
5256
5257**系统能力:** SystemCapability.Multimedia.AVSession.Core
5258
5259| 名称            | 类型                      | 只读 | 可选 | 说明                                                                  |
5260| --------------- |-------------------------| ---- | ---- |---------------------------------------------------------------------|
5261| assetId         | string                  | 否   | 否   | 媒体ID。歌曲的唯一标识,由应用自定义。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                     |
5262| title           | string                  | 否   | 是   | 标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                 |
5263| artist          | string                  | 否   | 是   | 艺术家。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                |
5264| author          | string                  | 否   | 是   | 专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                               |
5265| avQueueName<sup>12+</sup>       | string                  | 否   | 是   | 歌单(歌曲列表)名称。                                                               |
5266| avQueueId<sup>11+</sup>       | string                  | 否   | 是   | 歌单(歌曲列表)唯一标识Id。                                                               |
5267| avQueueImage<sup>11+</sup>    | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | 否   | 是   | 歌单(歌曲列表)封面图。<br>图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。<br>- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。<br>- 设置为url图片路径,获取的为url图片路径。  |
5268| album           | string                  | 否   | 是   | 专辑名称。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                               |
5269| writer          | string                  | 否   | 是   | 词作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                |
5270| composer        | string                  | 否   | 是   | 作曲者。                                                                |
5271| duration        | number                  | 否   | 是   | 媒体时长,单位毫秒(ms)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                  |
5272| mediaImage      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) &#124; string | 否   | 是   | 图片的像素数据或者图片路径地址(本地路径或网络路径)。应用通过setAVMetadata设置图片数据。<br>- 设置的数据类型为PixelMap时,通过getAVMetadata获取的将为PixelMap。<br>- 设置为url图片路径,获取的为url图片路径。  <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                             |
5273| bundleIcon<sup>18+</sup>      | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | 是   | 是   | 应用图标图片的像素数据。只读类型,不从应用侧设置。|
5274| publishDate     | Date                    | 否   | 是   | 发行日期。                                                             |
5275| subtitle        | string                  | 否   | 是   | 子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                                |
5276| description     | string                  | 否   | 是   | 媒体描述。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                               |
5277| lyric           | string                  | 否   | 是   | 媒体歌词内容。应用需将歌词内容拼接为一个字符串传入。<br>字符串长度需<40960字节。<br>**说明:** 系统支持简单版的LRC格式(Simple LRC format)的歌词文本内容。当传入的歌词内容不规范(例如:出现重复的时间戳等),将导致解析失败,并在系统中显示异常。 |
5278| singleLyricText<sup>17+</sup> | string    | 否   | 是   | 单条媒体歌词内容。应用需将歌词内容拼接为一个字符串传入(不包含时间戳)。<br>字符串长度<40960字节。<br>**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。|
5279| previousAssetId | string                  | 否   | 是   | 上一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                            |
5280| nextAssetId     | string                  | 否   | 是   | 下一首媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                                                            |
5281| filter<sup>11+</sup>        | number         | 否   | 是   | 当前session支持的协议,默认为TYPE_CAST_PLUS_STREAM。具体取值参考[ProtocolType](#protocoltype11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。                   |
5282| drmSchemes<sup>12+</sup>        | Array\<string>         | 否   | 是   | 当前session支持的DRM方案,取值为DRM方案uuid。|
5283| skipIntervals<sup>11+</sup>  | [SkipIntervals](#skipintervals11)        | 否   | 是   | 快进快退支持的时间间隔。默认为SECONDS_15,即15秒。                            |
5284|displayTags<sup>11+</sup>     | number                           | 否   | 是   | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。                                                          |
5285
5286## AVMediaDescription<sup>10+</sup>
5287
5288播放列表媒体元数据的相关属性。
5289
5290**系统能力:** SystemCapability.Multimedia.AVSession.Core
5291
5292| 名称         | 类型                    | 必填  | 说明                     |
5293| ------------ | ----------------------- | ---- | ----------------------- |
5294| assetId      | string                  | 是   | 播放列表媒体ID。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。          |
5295| title        | string                  | 否   | 播放列表媒体标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。        |
5296| subtitle     | string                  | 否   | 播放列表媒体子标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。      |
5297| description  | string                  | 否   | 播放列表媒体描述的文本。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。   |
5298| mediaImage | image.PixelMap \| string   | 否   | 播放列表媒体图片像素数据。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5299| extras       | {[key: string]: Object}    | 否   | 播放列表媒体额外字段。     |
5300| mediaUri     | string                  | 否   | 播放列表媒体URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5301| mediaType     | string                  | 否   | 播放列表媒体类型。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5302| mediaSize     | number                  | 否   | 播放列表媒体的大小。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5303| albumTitle     | string                  | 否   | 播放列表媒体专辑标题。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5304| albumCoverUri     | string                  | 否   | 播放列表媒体专辑标题URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。    |
5305| lyricContent     | string                  | 否   | 播放列表媒体歌词内容。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5306| lyricUri     | string                  | 否   | 播放列表媒体歌词URI。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5307| artist     | string                  | 否   | 播放列表媒体专辑作者。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5308| fdSrc     | media.AVFileDescriptor        | 否   | 播放列表媒体本地文件的句柄。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5309| dataSrc<sup>12+</sup>     | media.AVDataSrcDescriptor        | 否   | 播放列表数据源描述。         |
5310| drmScheme<sup>12+</sup>     | string        | 否   | 播放列表媒体支持的DRM方案,由uuid表示。       |
5311| duration     | number                  | 否   | 播放列表媒体播放时长。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5312| startPosition     | number                  | 否   | 播放列表媒体起始播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5313| creditsPosition     | number                  | 否   | 播放列表媒体的片尾播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5314| appName     | string                  | 否   | 播放列表提供的应用的名字。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。         |
5315|displayTags<sup>11+</sup>     | number | 否   | 媒体资源的金标类型,取值参考[DisplayTag](#displaytag11)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。        |
5316
5317## AVQueueItem<sup>10+</sup>
5318
5319播放列表中单项的相关属性。
5320
5321**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5322
5323**系统能力:** SystemCapability.Multimedia.AVSession.Core
5324
5325| 名称         | 类型                                        | 必填 | 说明                        |
5326| ------------ | ------------------------------------------ | ---- | --------------------------- |
5327| itemId       | number                                     | 是   | 播放列表中单项的ID。          |
5328| description  | [AVMediaDescription](#avmediadescription10)  | 否   | 播放列表中单项的媒体元数据。   |
5329
5330## AVPlaybackState<sup>10+</sup>
5331
5332媒体播放状态的相关属性。
5333
5334**系统能力:** SystemCapability.Multimedia.AVSession.Core
5335
5336| 名称         | 类型                                  | 必填 | 说明     |
5337| ------------ | ------------------------------------- | ---- | ------- |
5338| state        | [PlaybackState](#playbackstate10)       | 否   | 播放状态。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5339| speed        | number                                | 否   | 播放倍速。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5340| position     | [PlaybackPosition](#playbackposition10) | 否   | 播放位置。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5341| bufferedTime | number                                | 否   | 缓冲时间。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5342| loopMode     | [LoopMode](#loopmode10)                 | 否   | 循环模式。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5343| isFavorite   | boolean                               | 否   | 是否收藏,true表示收藏。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5344| activeItemId<sup>10+</sup> | number                  | 否   | 正在播放的媒体Id。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5345| volume<sup>10+</sup> | number                  | 否   | 正在播放的媒体音量。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5346| maxVolume<sup>11+</sup> | number                    | 否   | 最大音量。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5347| muted<sup>11+</sup>     | boolean                   | 否   | 当前静音状态,true表示静音。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5348| duration<sup>11+</sup>     | number                   | 否   | 当前媒体资源的时长。 |
5349| videoWidth<sup>11+</sup>  | number                  | 否   | 媒体资源的视频宽度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5350| videoHeight<sup>11+</sup> |  number                 | 否   | 媒体资源的视频高度,单位为像素(px)。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5351| extras<sup>10+</sup> | {[key: string]: Object}       | 否   | 自定义媒体数据。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5352
5353## PlaybackPosition<sup>10+</sup>
5354
5355媒体播放位置的相关属性。
5356
5357**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5358
5359**系统能力:** SystemCapability.Multimedia.AVSession.Core
5360
5361| 名称        | 类型   | 必填 | 说明               |
5362| ----------- | ------ | ---- | ------------------ |
5363| elapsedTime | number | 是   | 已用时间,单位毫秒(ms)。 |
5364| updateTime  | number | 是   | 更新时间,单位毫秒(ms)。 |
5365
5366## CallMetadata<sup>11+</sup>
5367
5368通话会话元数据相关属性。
5369
5370**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5371
5372**系统能力:** SystemCapability.Multimedia.AVSession.Core
5373
5374| 名称            | 类型                      | 必填 | 说明                                                                  |
5375| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
5376| name            | string                  | 否    | 来电人姓名(别名)。    |
5377| phoneNumber     | string                  | 否    | 来电电话号码。            |
5378| avatar          | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)          | 否    | 来电人头像。            |
5379
5380## AVCallState<sup>11+</sup>
5381
5382通话状态相关属性。
5383
5384**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5385
5386**系统能力:** SystemCapability.Multimedia.AVSession.Core
5387
5388| 名称            | 类型                      | 必填 | 说明                                                                  |
5389| --------------- |-------------------------  | ---- |---------------------------------------------------------------------|
5390| state           | [CallState](#callstate11)                 | 是    | 当前通话状态。      |
5391| muted           | boolean                   | 是    | 通话mic是否静音。 <br>true:静音。 <br>false:不是静音。|
5392
5393## CallState<sup>11+</sup>
5394
5395表示通话状态的枚举。
5396
5397**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5398
5399**系统能力:** SystemCapability.Multimedia.AVSession.Core
5400
5401| 名称                        | 值   | 说明      |
5402| --------------------------  | ---- | -------- |
5403| CALL_STATE_IDLE             | 0    | 空闲状态。   |
5404| CALL_STATE_INCOMING         | 1    | 来电。     |
5405| CALL_STATE_ACTIVE           | 2    | 接通。     |
5406| CALL_STATE_DIALING          | 3    | 响铃。     |
5407| CALL_STATE_WAITING          | 4    | 等待接通。  |
5408| CALL_STATE_HOLDING          | 5    | 保持。     |
5409| CALL_STATE_DISCONNECTING    | 6    | 挂断。     |
5410
5411## DisplayTag<sup>11+</sup>
5412
5413枚举,表示当前媒体资源的金标,即应用媒体音源的特殊类型标识。
5414
5415**系统能力:** SystemCapability.Multimedia.AVSession.Core
5416
5417| 名称                        | 值   | 说明           |
5418| --------------------------  | ---- | ------------ |
5419| TAG_AUDIO_VIVID             | 1    | AUDIO VIVID  |
5420
5421## AVCastCategory<sup>10+</sup>
5422
5423投播的类别枚举。
5424
5425**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5426
5427**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
5428
5429| 名称                        | 值   | 说明         |
5430| --------------------------- | ---- | ----------- |
5431| CATEGORY_LOCAL      | 0    | 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。     |
5432| CATEGORY_REMOTE      | 1    | 远端播放,远端播放设备,声音从其他设备发出声音或者画面。  |
5433
5434## DeviceType<sup>10+</sup>
5435
5436播放设备的类型枚举。
5437
5438**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5439
5440| 名称                        | 值   | 说明         |
5441| --------------------------- | ---- | ----------- |
5442| DEVICE_TYPE_LOCAL      | 0    | 本地播放类型。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core|
5443| DEVICE_TYPE_BLUETOOTH      | 10   | 蓝牙设备。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core |
5444| DEVICE_TYPE_TV      | 2    | 电视。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast |
5445| DEVICE_TYPE_SMART_SPEAKER      | 3   | 音箱设备。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast |
5446
5447## DeviceInfo<sup>10+</sup>
5448
5449播放设备的相关信息。
5450
5451| 名称       | 类型           | 必填 | 说明                   |
5452| ---------- | -------------- | ---- | ---------------------- |
5453| castCategory   | AVCastCategory        | 是   | 投播的类别。  <br> **系统能力:** SystemCapability.Multimedia.AVSession.Core  <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
5454| deviceId   | string | 是   | 播放设备的ID。<br> **系统能力:** SystemCapability.Multimedia.AVSession.Core  <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
5455| deviceName | string | 是   | 播放设备的名称。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
5456| deviceType | DeviceType | 是   | 播放设备的类型。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。|
5457| supportedProtocols<sup>11+</sup> | number | 否   | 播放设备支持的协议。默认为TYPE_LOCAL。具体取值参考[ProtocolType](#protocoltype11)。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast   <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5458| supportedDrmCapabilities<sup>12+</sup> | Array\<string> | 否   | 播放设备支持的DRM能力。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast   <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
5459| manufacturer<sup>13+</sup> | string | 否   | 播放设备生产厂家。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast  <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。|
5460| modelName<sup>13+</sup> | string | 否   | 播放设备型号名称。 <br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast  <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。|
5461
5462## OutputDeviceInfo<sup>10+</sup>
5463
5464播放设备的相关信息。
5465
5466**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5467
5468**系统能力:** SystemCapability.Multimedia.AVSession.Core
5469
5470| 名称       | 类型           | 必填 | 说明                   |
5471| ---------- | -------------- | ---- | ---------------------- |
5472| devices | Array\<DeviceInfo\> | 是   | 播放设备的集合。    |
5473
5474## LoopMode<sup>10+</sup>
5475
5476表示媒体播放循环模式的枚举。
5477
5478**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5479
5480**系统能力:** SystemCapability.Multimedia.AVSession.Core
5481
5482| 名称               | 值   | 说明     |
5483| ------------------ | ---- | -------- |
5484| LOOP_MODE_SEQUENCE | 0    | 顺序播放。 |
5485| LOOP_MODE_SINGLE   | 1    | 单曲循环。 |
5486| LOOP_MODE_LIST     | 2    | 表单循环。 |
5487| LOOP_MODE_SHUFFLE  | 3    | 随机播放。 |
5488| LOOP_MODE_CUSTOM<sup>11+</sup>   | 4    | 自定义播放。  |
5489
5490## PlaybackState<sup>10+</sup>
5491
5492表示媒体播放状态的枚举。
5493
5494**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5495
5496**系统能力:** SystemCapability.Multimedia.AVSession.Core
5497
5498| 名称                        | 值   | 说明         |
5499| --------------------------- | ---- | ----------- |
5500| PLAYBACK_STATE_INITIAL      | 0    | 初始状态。     |
5501| PLAYBACK_STATE_PREPARE      | 1    | 播放准备状态。  |
5502| PLAYBACK_STATE_PLAY         | 2    | 正在播放。     |
5503| PLAYBACK_STATE_PAUSE        | 3    | 暂停。         |
5504| PLAYBACK_STATE_FAST_FORWARD | 4    | 快进。         |
5505| PLAYBACK_STATE_REWIND       | 5    | 快退。         |
5506| PLAYBACK_STATE_STOP         | 6    | 停止。         |
5507| PLAYBACK_STATE_COMPLETED    | 7    | 播放完成。     |
5508| PLAYBACK_STATE_RELEASED     | 8    | 释放。         |
5509| PLAYBACK_STATE_ERROR        | 9    | 错误。         |
5510| PLAYBACK_STATE_IDLE<sup>11+</sup>        | 10    | 空闲。     |
5511| PLAYBACK_STATE_BUFFERING<sup>11+</sup>         | 11    | 缓冲。   |
5512
5513## AVSessionController<sup>10+</sup>
5514
5515AVSessionController控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。
5516
5517### 属性
5518
5519**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5520
5521**系统能力:** SystemCapability.Multimedia.AVSession.Core
5522
5523| 名称      | 类型   | 可读 | 可写 | 说明                                    |
5524| :-------- | :----- | :--- | :--- | :-------------------------------------- |
5525| sessionId | string | 是   | 否   | AVSessionController对象唯一的会话标识。 |
5526
5527
5528**示例:**
5529
5530```ts
5531import { BusinessError } from '@kit.BasicServicesKit';
5532import { avSession } from '@kit.AVSessionKit';
5533@Entry
5534@Component
5535struct Index {
5536  @State message: string = 'hello world';
5537
5538  build() {
5539    Column() {
5540      Text(this.message)
5541        .onClick(()=>{
5542          let currentAVSession: avSession.AVSession | undefined = undefined;
5543          let tag: string = "createNewSession";
5544          let context: Context = this.getUIContext().getHostContext() as Context;
5545          let sessionId: string = "";
5546          let AVSessionController: avSession.AVSessionController;
5547          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
5548            currentAVSession = data;
5549            sessionId = currentAVSession.sessionId;
5550            AVSessionController = await currentAVSession.getController();
5551            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
5552          }).catch((err: BusinessError) => {
5553            console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
5554          });
5555        })
5556    }
5557    .width('100%')
5558    .height('100%')
5559  }
5560}
5561```
5562
5563### getAVPlaybackState<sup>10+</sup>
5564
5565getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
5566
5567获取当前的远端播放状态。结果通过callback异步回调方式返回。
5568
5569**系统能力:** SystemCapability.Multimedia.AVSession.Core
5570
5571**参数:**
5572
5573| 参数名    | 类型                                                        | 必填 | 说明                                                         |
5574| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
5575| callback  | AsyncCallback<[AVPlaybackState](#avplaybackstate10)\> | 是   | 回调函数,返回远端播放状态。 |
5576
5577**错误码:**
5578
5579以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5580
5581| 错误码ID | 错误信息 |
5582| -------- | ---------------------------------------- |
5583| 6600101  | Session service exception. |
5584| 6600102  | The session does not exist. |
5585| 6600103  | The session controller does not exist. |
5586
5587**示例:**
5588
5589```ts
5590import { BusinessError } from '@kit.BasicServicesKit';
5591
5592avsessionController.getAVPlaybackState((err: BusinessError, state: avSession.AVPlaybackState) => {
5593  if (err) {
5594    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5595  } else {
5596    console.info('getAVPlaybackState : SUCCESS');
5597  }
5598});
5599```
5600
5601### getAVPlaybackState<sup>10+</sup>
5602
5603getAVPlaybackState(): Promise\<AVPlaybackState>
5604
5605获取当前的远端播放状态。结果通过Promise异步回调方式返回。
5606
5607**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5608
5609**系统能力:** SystemCapability.Multimedia.AVSession.Core
5610
5611**返回值:**
5612
5613| 类型                                                        | 说明                                                         |
5614| --------- | ------------------------------------------------------------ |
5615| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise对象。返回远端播放状态。  |
5616
5617**错误码:**
5618
5619以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5620
5621| 错误码ID | 错误信息 |
5622| -------- | ---------------------------------------- |
5623| 6600101  | Session service exception. |
5624| 6600102  | The session does not exist. |
5625| 6600103  | The session controller does not exist. |
5626
5627**示例:**
5628
5629```ts
5630import { BusinessError } from '@kit.BasicServicesKit';
5631
5632avsessionController.getAVPlaybackState().then((state: avSession.AVPlaybackState) => {
5633  console.info('getAVPlaybackState : SUCCESS');
5634}).catch((err: BusinessError) => {
5635  console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5636});
5637```
5638
5639### getAVMetadata<sup>10+</sup>
5640
5641getAVMetadata(): Promise\<AVMetadata>
5642
5643获取会话元数据。结果通过Promise异步回调方式返回。
5644
5645**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5646
5647**系统能力:** SystemCapability.Multimedia.AVSession.Core
5648
5649**返回值:**
5650
5651| 类型                                | 说明                          |
5652| ----------------------------------- | ----------------------------- |
5653| Promise<[AVMetadata](#avmetadata10)\> | Promise对象,返回会话元数据。 |
5654
5655**错误码:**
5656
5657以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5658
5659| 错误码ID | 错误信息 |
5660| -------- | ---------------------------------------- |
5661| 6600101  | Session service exception. |
5662| 6600102  | The session does not exist. |
5663| 6600103  | The session controller does not exist. |
5664
5665**示例:**
5666
5667```ts
5668import { BusinessError } from '@kit.BasicServicesKit';
5669
5670avsessionController.getAVMetadata().then((metadata: avSession.AVMetadata) => {
5671  console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5672}).catch((err: BusinessError) => {
5673  console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5674});
5675```
5676
5677### getAVMetadata<sup>10+</sup>
5678
5679getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
5680
5681获取会话元数据。结果通过callback异步回调方式返回。
5682
5683**系统能力:** SystemCapability.Multimedia.AVSession.Core
5684
5685**参数:**
5686
5687| 参数名   | 类型                                      | 必填 | 说明                       |
5688| -------- | ----------------------------------------- | ---- | -------------------------- |
5689| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | 是   | 回调函数,返回会话元数据。 |
5690
5691**错误码:**
5692
5693以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5694
5695| 错误码ID | 错误信息 |
5696| -------- | ---------------------------------------- |
5697| 6600101  | Session service exception. |
5698| 6600102  | The session does not exist. |
5699| 6600103  | The session controller does not exist. |
5700
5701**示例:**
5702
5703```ts
5704import { BusinessError } from '@kit.BasicServicesKit';
5705
5706avsessionController.getAVMetadata((err: BusinessError, metadata: avSession.AVMetadata) => {
5707  if (err) {
5708    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5709  } else {
5710    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5711  }
5712});
5713```
5714
5715### getAVQueueTitle<sup>10+</sup>
5716
5717getAVQueueTitle(): Promise\<string>
5718
5719获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。
5720
5721**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5722
5723**系统能力:** SystemCapability.Multimedia.AVSession.Core
5724
5725**返回值:**
5726
5727| 类型             | 说明                           |
5728| ---------------- | ----------------------------- |
5729| Promise<string\> | Promise对象。返回播放列表名称。 |
5730
5731**错误码:**
5732
5733以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5734
5735| 错误码ID | 错误信息 |
5736| -------- | ---------------------------------------- |
5737| 6600101  | Session service exception. |
5738| 6600102  | The session does not exist. |
5739| 6600103  | The session controller does not exist. |
5740
5741**示例:**
5742
5743```ts
5744import { BusinessError } from '@kit.BasicServicesKit';
5745
5746avsessionController.getAVQueueTitle().then((title: string) => {
5747  console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5748}).catch((err: BusinessError) => {
5749  console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5750});
5751```
5752
5753### getAVQueueTitle<sup>10+</sup>
5754
5755getAVQueueTitle(callback: AsyncCallback\<string>): void
5756
5757获取当前播放列表的名称。结果通过callback异步回调方式返回。
5758
5759**系统能力:** SystemCapability.Multimedia.AVSession.Core
5760
5761**参数:**
5762
5763| 参数名   | 类型                    | 必填 | 说明                      |
5764| -------- | ---------------------- | ---- | ------------------------- |
5765| callback | AsyncCallback<string\> | 是   | 回调函数,返回播放列表名称。 |
5766
5767**错误码:**
5768
5769以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5770
5771| 错误码ID | 错误信息 |
5772| -------- | ---------------------------------------- |
5773| 6600101  | Session service exception. |
5774| 6600102  | The session does not exist. |
5775| 6600103  | The session controller does not exist. |
5776
5777**示例:**
5778
5779```ts
5780import { BusinessError } from '@kit.BasicServicesKit';
5781
5782avsessionController.getAVQueueTitle((err: BusinessError, title: string) => {
5783  if (err) {
5784    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
5785  } else {
5786    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
5787  }
5788});
5789```
5790
5791### getAVQueueItems<sup>10+</sup>
5792
5793getAVQueueItems(): Promise\<Array\<AVQueueItem>>
5794
5795获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。
5796
5797**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5798
5799**系统能力:** SystemCapability.Multimedia.AVSession.Core
5800
5801**返回值:**
5802
5803| 类型                                          | 说明                           |
5804| --------------------------------------------- | ----------------------------- |
5805| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise对象。返回播放列表队列。 |
5806
5807**错误码:**
5808
5809以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5810
5811| 错误码ID | 错误信息 |
5812| -------- | ---------------------------------------- |
5813| 6600101  | Session service exception. |
5814| 6600102  | The session does not exist. |
5815| 6600103  | The session controller does not exist. |
5816
5817**示例:**
5818
5819```ts
5820import { BusinessError } from '@kit.BasicServicesKit';
5821
5822avsessionController.getAVQueueItems().then((items: avSession.AVQueueItem[]) => {
5823  console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5824}).catch((err: BusinessError) => {
5825  console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5826});
5827```
5828
5829### getAVQueueItems<sup>10+</sup>
5830
5831getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
5832
5833获取当前播放列表相关信息。结果通过callback异步回调方式返回。
5834
5835**系统能力:** SystemCapability.Multimedia.AVSession.Core
5836
5837**参数:**
5838
5839| 参数名   | 类型                                                 | 必填 | 说明                      |
5840| -------- | --------------------------------------------------- | ---- | ------------------------- |
5841| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | 是   | 回调函数,返回播放列表队列。 |
5842
5843**错误码:**
5844
5845以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5846
5847| 错误码ID | 错误信息 |
5848| -------- | ---------------------------------------- |
5849| 6600101  | Session service exception. |
5850| 6600102  | The session does not exist. |
5851| 6600103  | The session controller does not exist. |
5852
5853**示例:**
5854
5855```ts
5856import { BusinessError } from '@kit.BasicServicesKit';
5857
5858avsessionController.getAVQueueItems((err: BusinessError, items: avSession.AVQueueItem[]) => {
5859  if (err) {
5860    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
5861  } else {
5862    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
5863  }
5864});
5865```
5866
5867### skipToQueueItem<sup>10+</sup>
5868
5869skipToQueueItem(itemId: number): Promise\<void>
5870
5871设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。
5872
5873**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5874
5875**系统能力:** SystemCapability.Multimedia.AVSession.Core
5876
5877**参数:**
5878
5879| 参数名  | 类型    | 必填 | 说明                                        |
5880| ------ | ------- | ---- | ------------------------------------------- |
5881| itemId | number  | 是   | 播放列表单项的ID值,用以表示选中的播放列表单项。 |
5882
5883**返回值:**
5884
5885| 类型           | 说明                                                             |
5886| -------------- | --------------------------------------------------------------- |
5887| Promise\<void> | Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。 |
5888
5889**错误码:**
5890
5891以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5892
5893| 错误码ID | 错误信息 |
5894| -------- | ---------------------------------------- |
5895| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5896| 6600101  | Session service exception. |
5897| 6600102  | The session does not exist. |
5898| 6600103  | The session controller does not exist. |
5899
5900**示例:**
5901
5902```ts
5903import { BusinessError } from '@kit.BasicServicesKit';
5904
5905let queueItemId = 0;
5906avsessionController.skipToQueueItem(queueItemId).then(() => {
5907  console.info('SkipToQueueItem successfully');
5908}).catch((err: BusinessError) => {
5909  console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5910});
5911```
5912
5913### skipToQueueItem<sup>10+</sup>
5914
5915skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
5916
5917设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。
5918
5919**系统能力:** SystemCapability.Multimedia.AVSession.Core
5920
5921**参数:**
5922
5923| 参数名    | 类型                  | 必填 | 说明                                                        |
5924| -------- | --------------------- | ---- | ----------------------------------------------------------- |
5925| itemId   | number                | 是   | 播放列表单项的ID值,用以表示选中的播放列表单项。                |
5926| callback | AsyncCallback\<void>  | 是   | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 |
5927
5928**错误码:**
5929
5930以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5931
5932| 错误码ID | 错误信息 |
5933| -------- | ---------------------------------------- |
5934| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
5935| 6600101  | Session service exception. |
5936| 6600102  | The session does not exist. |
5937| 6600103  | The session controller does not exist. |
5938
5939**示例:**
5940
5941```ts
5942import { BusinessError } from '@kit.BasicServicesKit';
5943
5944let queueItemId = 0;
5945avsessionController.skipToQueueItem(queueItemId, (err: BusinessError) => {
5946  if (err) {
5947    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5948  } else {
5949    console.info('SkipToQueueItem successfully');
5950  }
5951});
5952```
5953
5954### getOutputDevice<sup>10+</sup>
5955
5956getOutputDevice(): Promise\<OutputDeviceInfo>
5957
5958获取播放设备信息。结果通过Promise异步回调方式返回。
5959
5960**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
5961
5962**系统能力:** SystemCapability.Multimedia.AVSession.Core
5963
5964**返回值:**
5965
5966| 类型                                            | 说明                              |
5967| ----------------------------------------------- | --------------------------------- |
5968| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise对象,返回播放设备信息。 |
5969
5970**错误码:**
5971
5972以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
5973
5974| 错误码ID | 错误信息 |
5975| -------- | ---------------------------------------- |
5976| 600101  | Session service exception. |
5977| 600103  | The session controller does not exist. |
5978
5979**示例:**
5980
5981```ts
5982import { BusinessError } from '@kit.BasicServicesKit';
5983
5984avsessionController.getOutputDevice().then((deviceInfo: avSession.OutputDeviceInfo) => {
5985  console.info('GetOutputDevice : SUCCESS');
5986}).catch((err: BusinessError) => {
5987  console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5988});
5989```
5990
5991### getOutputDevice<sup>10+</sup>
5992
5993getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
5994
5995获取播放设备信息。结果通过callback异步回调方式返回。
5996
5997**系统能力:** SystemCapability.Multimedia.AVSession.Core
5998
5999**参数:**
6000
6001| 参数名   | 类型                                                  | 必填 | 说明                           |
6002| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
6003| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是   | 回调函数,返回播放设备信息。 |
6004
6005**错误码:**
6006
6007以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6008
6009| 错误码ID | 错误信息 |
6010| -------- | ---------------------------------------- |
6011| 600101  | Session service exception. |
6012| 600103  | The session controller does not exist. |
6013
6014**示例:**
6015
6016```ts
6017import { BusinessError } from '@kit.BasicServicesKit';
6018
6019avsessionController.getOutputDevice((err: BusinessError, deviceInfo: avSession.OutputDeviceInfo) => {
6020  if (err) {
6021    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
6022  } else {
6023    console.info('GetOutputDevice : SUCCESS');
6024  }
6025});
6026```
6027
6028### sendAVKeyEvent<sup>10+</sup>
6029
6030sendAVKeyEvent(event: KeyEvent): Promise\<void>
6031
6032发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。
6033
6034**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6035
6036**系统能力:** SystemCapability.Multimedia.AVSession.Core
6037
6038**参数:**
6039
6040| 参数名 | 类型                                                         | 必填 | 说明       |
6041| ------ | ------------------------------------------------------------ | ---- | ---------- |
6042| event  | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是   | 按键事件。 |
6043
6044**错误码:**
6045
6046以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6047
6048| 错误码ID | 错误信息 |
6049| -------- | ---------------------------------------- |
6050| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6051| 600101  | Session service exception. |
6052| 600102  | The session does not exist. |
6053| 600103  | The session controller does not exist. |
6054| 600105  | Invalid session command. |
6055| 600106  | The session is not activated. |
6056
6057**返回值:**
6058
6059| 类型           | 说明                          |
6060| -------------- | ----------------------------- |
6061| Promise\<void> | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 |
6062
6063**示例:**
6064
6065```ts
6066import { Key, KeyEvent } from '@kit.InputKit';
6067import { BusinessError } from '@kit.BasicServicesKit';
6068
6069let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
6070let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
6071
6072
6073avsessionController.sendAVKeyEvent(event).then(() => {
6074  console.info('SendAVKeyEvent Successfully');
6075}).catch((err: BusinessError) => {
6076  console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
6077});
6078```
6079
6080### sendAVKeyEvent<sup>10+</sup>
6081
6082sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
6083
6084发送按键事件到会话。结果通过callback异步回调方式返回。
6085
6086**系统能力:** SystemCapability.Multimedia.AVSession.Core
6087
6088**参数:**
6089
6090| 参数名   | 类型                                                         | 必填 | 说明       |
6091| -------- | ------------------------------------------------------------ | ---- | ---------- |
6092| event    | [KeyEvent](../apis-input-kit/js-apis-keyevent.md) | 是   | 按键事件。 |
6093| callback | AsyncCallback\<void>                                         | 是   | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 |
6094
6095**错误码:**
6096
6097以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6098
6099| 错误码ID | 错误信息 |
6100| -------- | ---------------------------------------- |
6101| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6102| 600101  | Session service exception. |
6103| 600102  | The session does not exist. |
6104| 600103  | The session controller does not exist. |
6105| 600105  | Invalid session command. |
6106| 600106  | The session is not activated. |
6107
6108**示例:**
6109
6110```ts
6111import { Key, KeyEvent } from '@kit.InputKit';
6112import { BusinessError } from '@kit.BasicServicesKit';
6113
6114let keyItem: Key = {code:0x49, pressedTime:2, deviceId:0};
6115let event:KeyEvent = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false};
6116avsessionController.sendAVKeyEvent(event, (err: BusinessError) => {
6117  if (err) {
6118    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
6119  } else {
6120    console.info('SendAVKeyEvent Successfully');
6121  }
6122});
6123```
6124
6125### getLaunchAbility<sup>10+</sup>
6126
6127getLaunchAbility(): Promise\<WantAgent>
6128
6129获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。
6130
6131**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6132
6133**系统能力:** SystemCapability.Multimedia.AVSession.Core
6134
6135**返回值:**
6136
6137| 类型                                                    | 说明                                                         |
6138| ------------------------------------------------------- | ------------------------------------------------------------ |
6139| Promise<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | Promise对象,返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 |
6140
6141**错误码:**
6142
6143以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6144
6145| 错误码ID | 错误信息 |
6146| -------- | ---------------------------------------- |
6147| 6600101  | Session service exception. |
6148| 6600102  | The session does not exist. |
6149| 6600103  | The session controller does not exist. |
6150
6151**示例:**
6152
6153```ts
6154import { BusinessError } from '@kit.BasicServicesKit';
6155
6156avsessionController.getLaunchAbility().then((agent: object) => {
6157  console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
6158}).catch((err: BusinessError) => {
6159  console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
6160});
6161```
6162
6163### getLaunchAbility<sup>10+</sup>
6164
6165getLaunchAbility(callback: AsyncCallback\<WantAgent>): void
6166
6167获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。
6168
6169**系统能力:** SystemCapability.Multimedia.AVSession.Core
6170
6171**参数:**
6172
6173| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6174| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6175| callback | AsyncCallback<[WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md)\> | 是   | 回调函数。返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 |
6176
6177**错误码:**
6178
6179以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6180
6181| 错误码ID | 错误信息 |
6182| -------- | ---------------------------------------- |
6183| 6600101  | Session service exception. |
6184| 6600102  | The session does not exist. |
6185| 6600103  | The session controller does not exist. |
6186
6187**示例:**
6188
6189```ts
6190import { BusinessError } from '@kit.BasicServicesKit';
6191
6192avsessionController.getLaunchAbility((err: BusinessError, agent: object) => {
6193  if (err) {
6194    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
6195  } else {
6196    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
6197  }
6198});
6199```
6200
6201### getRealPlaybackPositionSync<sup>10+</sup>
6202
6203getRealPlaybackPositionSync(): number
6204
6205获取当前播放位置。
6206
6207**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6208
6209**系统能力:** SystemCapability.Multimedia.AVSession.Core
6210
6211**返回值:**
6212
6213| 类型   | 说明               |
6214| ------ | ------------------ |
6215| number | 时间节点,毫秒数。 |
6216
6217**错误码:**
6218
6219以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6220
6221| 错误码ID | 错误信息 |
6222| -------- | ---------------------------------------- |
6223| 6600101  | Session service exception. |
6224| 6600103  | The session controller does not exist. |
6225
6226**示例:**
6227
6228```ts
6229let time: number = avsessionController.getRealPlaybackPositionSync();
6230```
6231
6232### isActive<sup>10+</sup>
6233
6234isActive(): Promise\<boolean>
6235
6236获取会话是否被激活。结果通过Promise异步回调方式返回。
6237
6238**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6239
6240**系统能力:** SystemCapability.Multimedia.AVSession.Core
6241
6242**返回值:**
6243
6244| 类型              | 说明                                                         |
6245| ----------------- | ------------------------------------------------------------ |
6246| Promise<boolean\> | Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。 |
6247
6248**错误码:**
6249
6250以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6251
6252| 错误码ID | 错误信息 |
6253| -------- | ---------------------------------------- |
6254| 6600101  | Session service exception. |
6255| 6600102  | The session does not exist. |
6256| 6600103  | The session controller does not exist. |
6257
6258**示例:**
6259
6260```ts
6261import { BusinessError } from '@kit.BasicServicesKit';
6262
6263avsessionController.isActive().then((isActive: boolean) => {
6264  console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6265}).catch((err: BusinessError) => {
6266  console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6267});
6268```
6269
6270### isActive<sup>10+</sup>
6271
6272isActive(callback: AsyncCallback\<boolean>): void
6273
6274判断会话是否被激活。结果通过callback异步回调方式返回。
6275
6276**系统能力:** SystemCapability.Multimedia.AVSession.Core
6277
6278**参数:**
6279
6280| 参数名   | 类型                    | 必填 | 说明                                                         |
6281| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
6282| callback | AsyncCallback<boolean\> | 是   | 回调函数。返回会话是否为激活状态,true表示被激活,false表示禁用。 |
6283
6284**错误码:**
6285
6286以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6287
6288| 错误码ID | 错误信息 |
6289| -------- | ---------------------------------------- |
6290| 6600101  | Session service exception. |
6291| 6600102  | The session does not exist. |
6292| 6600103  | The session controller does not exist. |
6293
6294**示例:**
6295
6296```ts
6297import { BusinessError } from '@kit.BasicServicesKit';
6298
6299avsessionController.isActive((err: BusinessError, isActive: boolean) => {
6300  if (err) {
6301    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
6302  } else {
6303    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
6304  }
6305});
6306```
6307
6308### destroy<sup>10+</sup>
6309
6310destroy(): Promise\<void>
6311
6312销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。
6313
6314**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6315
6316**系统能力:** SystemCapability.Multimedia.AVSession.Core
6317
6318**返回值:**
6319
6320| 类型           | 说明                          |
6321| -------------- | ----------------------------- |
6322| Promise\<void> | Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。 |
6323
6324**错误码:**
6325
6326以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6327
6328| 错误码ID | 错误信息 |
6329| -------- | ---------------------------------------- |
6330| 6600101  | Session service exception. |
6331| 6600103  | The session controller does not exist. |
6332
6333**示例:**
6334
6335```ts
6336import { BusinessError } from '@kit.BasicServicesKit';
6337
6338avsessionController.destroy().then(() => {
6339  console.info('Destroy : SUCCESS ');
6340}).catch((err: BusinessError) => {
6341  console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6342});
6343```
6344
6345### destroy<sup>10+</sup>
6346
6347destroy(callback: AsyncCallback\<void>): void
6348
6349销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。
6350
6351**系统能力:** SystemCapability.Multimedia.AVSession.Core
6352
6353**参数:**
6354
6355| 参数名   | 类型                 | 必填 | 说明       |
6356| -------- | -------------------- | ---- | ---------- |
6357| callback | AsyncCallback\<void> | 是   | 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。 |
6358
6359**错误码:**
6360
6361以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6362
6363| 错误码ID | 错误信息 |
6364| -------- | ---------------------------------------- |
6365| 6600101  | Session service exception. |
6366| 6600103  | The session controller does not exist. |
6367
6368**示例:**
6369
6370```ts
6371import { BusinessError } from '@kit.BasicServicesKit';
6372
6373avsessionController.destroy((err: BusinessError) => {
6374  if (err) {
6375    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
6376  } else {
6377    console.info('Destroy : SUCCESS ');
6378  }
6379});
6380```
6381
6382### getValidCommands<sup>10+</sup>
6383
6384getValidCommands(): Promise\<Array\<AVControlCommandType>>
6385
6386获取会话支持的有效命令。结果通过Promise异步回调方式返回。
6387
6388**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6389
6390**系统能力:** SystemCapability.Multimedia.AVSession.Core
6391
6392**返回值:**
6393
6394| 类型                                                         | 说明                              |
6395| ------------------------------------------------------------ | --------------------------------- |
6396| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise对象。返回有效命令的集合。 |
6397
6398**错误码:**
6399
6400以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6401
6402| 错误码ID | 错误信息 |
6403| -------- | ---------------------------------------- |
6404| 6600101  | Session service exception. |
6405| 6600102  | The session does not exist. |
6406| 6600103  | The session controller does not exist. |
6407
6408**示例:**
6409
6410```ts
6411import { BusinessError } from '@kit.BasicServicesKit';
6412
6413avsessionController.getValidCommands().then((validCommands: avSession.AVControlCommandType[]) => {
6414  console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6415}).catch((err: BusinessError) => {
6416  console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6417});
6418```
6419
6420### getValidCommands<sup>10+</sup>
6421
6422getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
6423
6424获取会话支持的有效命令。结果通过callback异步回调方式返回。
6425
6426**系统能力:** SystemCapability.Multimedia.AVSession.Core
6427
6428**参数:**
6429
6430| 参数名   | 类型                                                         | 必填 | 说明                           |
6431| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
6432| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | 是   | 回调函数,返回有效命令的集合。 |
6433
6434**错误码:**
6435
6436以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6437
6438| 错误码ID | 错误信息 |
6439| -------- | ---------------------------------------- |
6440| 6600101  | Session service exception. |
6441| 6600102  | The session does not exist. |
6442| 6600103  | The session controller does not exist. |
6443
6444**示例:**
6445
6446```ts
6447import { BusinessError } from '@kit.BasicServicesKit';
6448
6449avsessionController.getValidCommands((err: BusinessError, validCommands: avSession.AVControlCommandType[]) => {
6450  if (err) {
6451    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
6452  } else {
6453    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
6454  }
6455});
6456```
6457
6458### sendControlCommand<sup>10+</sup>
6459
6460sendControlCommand(command: AVControlCommand): Promise\<void>
6461
6462通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。
6463
6464> **说明:**
6465>
6466> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。
6467
6468**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6469
6470**系统能力:** SystemCapability.Multimedia.AVSession.Core
6471
6472**参数:**
6473
6474| 参数名    | 类型                                  | 必填 | 说明                           |
6475| ------- | ------------------------------------- | ---- | ------------------------------ |
6476| command | [AVControlCommand](#avcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
6477
6478**返回值:**
6479
6480| 类型           | 说明                          |
6481| -------------- | ----------------------------- |
6482| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
6483
6484**错误码:**
6485
6486以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6487
6488| 错误码ID | 错误信息 |
6489| -------- | ---------------------------------------- |
6490| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6491| 6600101  | Session service exception. |
6492| 6600102  | The session does not exist. |
6493| 6600103  | The session controller does not exist. |
6494| 6600105  | Invalid session command. |
6495| 6600106  | The session is not activated. |
6496| 6600107  | Too many commands or events. |
6497
6498**示例:**
6499
6500```ts
6501import { BusinessError } from '@kit.BasicServicesKit';
6502
6503let avCommand: avSession.AVControlCommand = {command:'play'};
6504avsessionController.sendControlCommand(avCommand).then(() => {
6505  console.info('SendControlCommand successfully');
6506}).catch((err: BusinessError) => {
6507  console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6508});
6509```
6510
6511### sendControlCommand<sup>10+</sup>
6512
6513sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
6514
6515通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。
6516
6517> **说明:**
6518>
6519> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。
6520
6521**系统能力:** SystemCapability.Multimedia.AVSession.Core
6522
6523**参数:**
6524
6525| 参数名   | 类型                                  | 必填 | 说明                           |
6526| -------- | ------------------------------------- | ---- | ------------------------------ |
6527| command  | [AVControlCommand](#avcontrolcommand10) | 是   | 会话的相关命令和命令相关参数。 |
6528| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。                     |
6529
6530**错误码:**
6531
6532以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6533
6534| 错误码ID | 错误信息 |
6535| -------- | ------------------------------- |
6536| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6537| 6600101  | Session service exception.                |
6538| 6600102  | The session does not exist.     |
6539| 6600103  | The session controller does not exist.   |
6540| 6600105  | Invalid session command.           |
6541| 6600106  | The session is not activated.                |
6542| 6600107  | Too many commands or events.      |
6543
6544**示例:**
6545
6546```ts
6547import { BusinessError } from '@kit.BasicServicesKit';
6548
6549let avCommand: avSession.AVControlCommand = {command:'play'};
6550avsessionController.sendControlCommand(avCommand, (err: BusinessError) => {
6551  if (err) {
6552    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6553  } else {
6554    console.info('SendControlCommand successfully');
6555  }
6556});
6557```
6558
6559### sendCommonCommand<sup>10+</sup>
6560
6561sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void>
6562
6563通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。
6564
6565**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6566
6567**系统能力:** SystemCapability.Multimedia.AVSession.Core
6568
6569**参数:**
6570
6571| 参数名    | 类型                                  | 必填 | 说明                           |
6572| ------- | ------------------------------------- | ---- | ------------------------------ |
6573| command | string | 是   | 需要设置的自定义控制命令的名称。 |
6574| args | {[key: string]: Object} | 是   | 需要传递的控制命令键值对。 |
6575
6576> **说明:**
6577> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
6578
6579**返回值:**
6580
6581| 类型           | 说明                          |
6582| -------------- | ----------------------------- |
6583| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
6584
6585**错误码:**
6586
6587以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6588
6589| 错误码ID | 错误信息 |
6590| -------- | ---------------------------------------- |
6591| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
6592| 6600101  | Session service exception. |
6593| 6600102  | The session does not exist. |
6594| 6600103  | The session controller does not exist. |
6595| 6600105  | Invalid session command. |
6596| 6600106  | The session is not activated. |
6597| 6600107  | Too many commands or events. |
6598
6599**示例:**
6600
6601```ts
6602import { BusinessError } from '@kit.BasicServicesKit';
6603import { avSession } from '@kit.AVSessionKit';
6604@Entry
6605@Component
6606struct Index {
6607  @State message: string = 'hello world';
6608
6609  build() {
6610    Column() {
6611      Text(this.message)
6612        .onClick(()=>{
6613          let currentAVSession: avSession.AVSession | undefined = undefined;
6614          let tag: string = "createNewSession";
6615          let context: Context = this.getUIContext().getHostContext() as Context;
6616          let sessionId: string = "";
6617          let controller:avSession.AVSessionController | undefined = undefined;
6618          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
6619            currentAVSession = data;
6620            sessionId = currentAVSession.sessionId;
6621            controller = await currentAVSession.getController();
6622            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
6623          }).catch((err: BusinessError) => {
6624            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
6625          });
6626          let commandName = "my_command";
6627          if (controller !== undefined) {
6628            (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}, (err: BusinessError) => {
6629              if (err) {
6630                console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6631              }
6632            })
6633          }
6634        })
6635    }
6636    .width('100%')
6637    .height('100%')
6638  }
6639}
6640```
6641
6642### sendCommonCommand<sup>10+</sup>
6643
6644sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void
6645
6646通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。
6647
6648**系统能力:** SystemCapability.Multimedia.AVSession.Core
6649
6650**参数:**
6651
6652| 参数名    | 类型                                  | 必填 | 说明                           |
6653| ------- | ------------------------------------- | ---- | ------------------------------ |
6654| command | string | 是   | 需要设置的自定义控制命令的名称。 |
6655| args | {[key: string]: Object} | 是   | 需要传递的控制命令键值对。 |
6656| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。                     |
6657
6658> **说明:**
6659> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。
6660
6661**错误码:**
6662
6663以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6664
6665| 错误码ID | 错误信息 |
6666| -------- | ------------------------------- |
6667| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed.|
6668| 6600101  | Session service exception.                |
6669| 6600102  | The session does not exist.     |
6670| 6600103  | The session controller does not exist.   |
6671| 6600105  | Invalid session command.           |
6672| 6600106  | The session is not activated.                |
6673| 6600107  | Too many commands or events.      |
6674
6675**示例:**
6676
6677```ts
6678import { BusinessError } from '@kit.BasicServicesKit';
6679import { avSession } from '@kit.AVSessionKit';
6680@Entry
6681@Component
6682struct Index {
6683  @State message: string = 'hello world';
6684
6685  build() {
6686    Column() {
6687      Text(this.message)
6688        .onClick(()=>{
6689          let currentAVSession: avSession.AVSession | undefined = undefined;
6690          let tag: string = "createNewSession";
6691          let context: Context = this.getUIContext().getHostContext() as Context;
6692          let sessionId: string = "";
6693          let controller:avSession.AVSessionController | undefined = undefined;
6694          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
6695            currentAVSession = data;
6696            sessionId = currentAVSession.sessionId;
6697            controller = await currentAVSession.getController();
6698            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
6699          }).catch((err: BusinessError) => {
6700            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
6701          });
6702          let commandName = "my_command";
6703          if (controller !== undefined) {
6704            (controller as avSession.AVSessionController).sendCommonCommand(commandName, {command : "This is my command"}).then(() => {
6705              console.info('SendCommonCommand successfully');
6706            }).catch((err: BusinessError) => {
6707              console.error(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
6708            })
6709          }
6710        })
6711    }
6712    .width('100%')
6713    .height('100%')
6714  }
6715}
6716```
6717
6718### getExtras<sup>10+</sup>
6719
6720getExtras(): Promise\<{[key: string]: Object}>
6721
6722获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。
6723
6724**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6725
6726**系统能力:** SystemCapability.Multimedia.AVSession.Core
6727
6728**返回值:**
6729
6730| 类型                                | 说明                          |
6731| ----------------------------------- | ----------------------------- |
6732| Promise<{[key: string]: Object}\>   | Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 |
6733
6734**错误码:**
6735
6736以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6737
6738| 错误码ID | 错误信息 |
6739| -------- | ---------------------------------------- |
6740| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6741| 6600101  | Session service exception. |
6742| 6600102  | The session does not exist. |
6743| 6600103  | The session controller does not exist. |
6744| 6600105  | Invalid session command. |
6745| 6600107  | Too many commands or events. |
6746
6747**示例:**
6748
6749```ts
6750import { BusinessError } from '@kit.BasicServicesKit';
6751import { avSession } from '@kit.AVSessionKit';
6752@Entry
6753@Component
6754struct Index {
6755  @State message: string = 'hello world';
6756
6757  build() {
6758    Column() {
6759      Text(this.message)
6760        .onClick(()=>{
6761          let currentAVSession: avSession.AVSession | undefined = undefined;
6762          let tag: string = "createNewSession";
6763          let context: Context = this.getUIContext().getHostContext() as Context;
6764          let sessionId: string = "";
6765          let controller:avSession.AVSessionController | undefined = undefined;
6766          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
6767            currentAVSession = data;
6768            sessionId = currentAVSession.sessionId;
6769            controller = await currentAVSession.getController();
6770            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
6771          }).catch((err: BusinessError) => {
6772            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
6773          });
6774          if (controller !== undefined) {
6775            (controller as avSession.AVSessionController).getExtras().then((extras) => {
6776              console.info(`getExtras : SUCCESS : ${extras}`);
6777            }).catch((err: BusinessError) => {
6778              console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6779            });
6780          }
6781        })
6782    }
6783    .width('100%')
6784    .height('100%')
6785  }
6786}
6787```
6788
6789### getExtras<sup>10+</sup>
6790
6791getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
6792
6793获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。
6794
6795**系统能力:** SystemCapability.Multimedia.AVSession.Core
6796
6797**参数:**
6798
6799| 参数名   | 类型                                      | 必填 | 说明                       |
6800| -------- | ----------------------------------------- | ---- | -------------------------- |
6801| callback | AsyncCallback<{[key: string]: Object}\> | 是   | 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 |
6802
6803**错误码:**
6804
6805以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6806
6807| 错误码ID | 错误信息 |
6808| -------- | ---------------------------------------- |
6809| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
6810| 6600101  | Session service exception. |
6811| 6600102  | The session does not exist. |
6812| 6600103  | The session controller does not exist. |
6813| 6600105  | Invalid session command. |
6814| 6600107  | Too many commands or events. |
6815
6816**示例:**
6817
6818```ts
6819import { BusinessError } from '@kit.BasicServicesKit';
6820import { avSession } from '@kit.AVSessionKit';
6821@Entry
6822@Component
6823struct Index {
6824  @State message: string = 'hello world';
6825
6826  build() {
6827    Column() {
6828      Text(this.message)
6829        .onClick(()=>{
6830          let currentAVSession: avSession.AVSession | undefined = undefined;
6831          let tag: string = "createNewSession";
6832          let context: Context = this.getUIContext().getHostContext() as Context;
6833          let sessionId: string = "";
6834          let controller:avSession.AVSessionController | undefined = undefined;
6835          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
6836            currentAVSession = data;
6837            sessionId = currentAVSession.sessionId;
6838            controller = await currentAVSession.getController();
6839            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
6840          }).catch((err: BusinessError) => {
6841            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
6842          });
6843          if (controller !== undefined) {
6844            (controller as avSession.AVSessionController).getExtras((err, extras) => {
6845              if (err) {
6846                console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6847              } else {
6848                console.info(`getExtras : SUCCESS : ${extras}`);
6849              }
6850            });
6851          }
6852        })
6853    }
6854    .width('100%')
6855    .height('100%')
6856  }
6857}
6858```
6859
6860### getExtrasWithEvent<sup>18+</sup>
6861
6862getExtrasWithEvent(extraEvent: string): Promise\<ExtraInfo>
6863
6864根据远端分布式事件类型,获取远端分布式媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。
6865
6866**系统能力:** SystemCapability.Multimedia.AVSession.Core
6867
6868**参数:**
6869
6870| 参数名   | 类型                                      | 必填 | 说明                       |
6871| -------- | ----------------------------------------- | ---- | -------------------------- |
6872| extraEvent | string | 是 | 远端分布式事件类型。<br>当前支持的事件类型包括:<br>'AUDIO_GET_VOLUME':获取远端设备音量,<br>'AUDIO_GET_AVAILABLE_DEVICES':获取远端所有可连接设备,<br>'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO':获取远端实际发声设备。 |
6873
6874**返回值:**
6875
6876| 类型                                | 说明                          |
6877| ----------------------------------- | ----------------------------- |
6878| Promise<[ExtraInfo](#extrainfo18)\>   | Promise对象,返回远端分布式媒体提供方设置的自定义媒体数据包。<br>参数ExtraInfo支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](../apis-ability-kit/js-apis-app-ability-want.md)。 |
6879
6880**错误码:**
6881
6882以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6883
6884| 错误码ID | 错误信息 |
6885| -------- | ---------------------------------------- |
6886| 6600101  | Session service exception. |
6887| 6600102  | The session does not exist. |
6888| 6600103  | The session controller does not exist. |
6889| 6600105  | Invalid session command. |
6890
6891**示例:**
6892
6893```ts
6894import { BusinessError } from '@kit.BasicServicesKit';
6895
6896@Entry
6897@Component
6898struct Index {
6899  @State message: string = 'hello world';
6900
6901  build() {
6902    Row() {
6903      Column() {
6904        Text(this.message)
6905          .fontSize(40)
6906          .fontWeight(FontWeight.Bold)
6907          .onClick(() => {
6908            getExtrasWithEventTest();
6909          })
6910      }
6911    }
6912  }
6913}
6914
6915async function getExtrasWithEventTest() {
6916  let controllerList: Array<avSession.AVSessionController>;
6917  let controller: avSession.AVSessionController | ESObject;
6918
6919  try {
6920    controllerList = await avSession.getDistributedSessionController(avSession.DistributedSessionType.TYPE_SESSION_REMOTE);
6921    controller = controllerList[0];
6922  } catch (err) {
6923    console.info(`getDistributedSessionController fail with err: ${err}`);
6924  }
6925
6926  const COMMON_COMMAND_STRING_1 = 'AUDIO_GET_VOLUME';
6927  const COMMON_COMMAND_STRING_2 = 'AUDIO_GET_AVAILABLE_DEVICES';
6928  const COMMON_COMMAND_STRING_3 = 'AUDIO_GET_PREFERRED_OUTPUT_DEVICE_FOR_RENDERER_INFO';
6929  if (controller !== undefined) {
6930    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_1).then((extras: avSession.ExtraInfo) => {
6931      console.info(`${extras[COMMON_COMMAND_STRING_1]}`);
6932    }).catch((err: BusinessError) => {
6933      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6934    })
6935
6936    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_2).then((extras: avSession.ExtraInfo) => {
6937      console.info(`${extras[COMMON_COMMAND_STRING_2]}`);
6938    }).catch((err: BusinessError) => {
6939      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6940    })
6941
6942    controller.getExtrasWithEvent(COMMON_COMMAND_STRING_3).then((extras: avSession.ExtraInfo) => {
6943      console.info(`${extras[COMMON_COMMAND_STRING_3]}`);
6944    }).catch((err: BusinessError) => {
6945      console.info(`getExtrasWithEvent failed with err: ${err.code}, ${err.message}`);
6946    })
6947  }
6948}
6949```
6950
6951### on('metadataChange')<sup>10+</sup>
6952
6953on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
6954
6955设置元数据变化的监听事件。
6956
6957**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6958
6959**系统能力:** SystemCapability.Multimedia.AVSession.Core
6960
6961**参数:**
6962
6963| 参数名   | 类型                                                         | 必填 | 说明                                                         |
6964| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
6965| type     | string                                                       | 是   | 事件回调类型,支持事件`'metadataChange'`:当元数据变化时,触发该事件。 |
6966| filter   | Array\<keyof&nbsp;[AVMetadata](#avmetadata10)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注元数据所有字段变化;Array<keyof&nbsp;[AVMetadata](#avmetadata10)\> 表示关注Array中的字段变化。 |
6967| callback | (data: [AVMetadata](#avmetadata10)) => void                    | 是   | 回调函数,参数data是变化后的元数据。                         |
6968
6969**错误码:**
6970
6971以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
6972
6973| 错误码ID | 错误信息 |
6974| -------- | ------------------------------ |
6975| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
6976| 6600101  | Session service exception. |
6977| 6600103  | The session controller does not exist. |
6978
6979**示例:**
6980
6981```ts
6982avsessionController.on('metadataChange', 'all', (metadata: avSession.AVMetadata) => {
6983  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6984});
6985
6986avsessionController.on('metadataChange', ['assetId', 'title', 'description'], (metadata: avSession.AVMetadata) => {
6987  console.info(`on metadataChange assetId : ${metadata.assetId}`);
6988});
6989
6990```
6991
6992### off('metadataChange')<sup>10+</sup>
6993
6994off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
6995
6996媒体控制器取消监听元数据变化的事件。
6997
6998**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
6999
7000**系统能力:** SystemCapability.Multimedia.AVSession.Core
7001
7002**参数:**
7003
7004| 参数名   | 类型                                               | 必填 | 说明                                                    |
7005| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
7006| type     | string                                           | 是   | 取消对应的监听事件,支持事件`'metadataChange'`。         |
7007| callback | (data: [AVMetadata](#avmetadata10)) => void        | 否   | 回调函数,参数data是变化后的元数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                         |
7008
7009**错误码:**
7010
7011以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7012
7013| 错误码ID | 错误信息 |
7014| -------- | ---------------- |
7015| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7016| 6600101  | Session service exception. |
7017| 6600103  | The session controller does not exist. |
7018
7019**示例:**
7020
7021```ts
7022avsessionController.off('metadataChange');
7023```
7024
7025### on('playbackStateChange')<sup>10+</sup>
7026
7027on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
7028
7029设置播放状态变化的监听事件。
7030
7031**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7032
7033**系统能力:** SystemCapability.Multimedia.AVSession.Core
7034
7035**参数:**
7036
7037| 参数名   | 类型       | 必填 | 说明      |
7038| --------| -----------|-----|------------|
7039| type     | string    | 是   | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 |
7040| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注播放状态所有字段变化;Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\> 表示关注Array中的字段变化。 |
7041| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | 是   | 回调函数,参数state是变化后的播放状态。|
7042
7043**错误码:**
7044
7045以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7046
7047| 错误码ID | 错误信息 |
7048| -------- | ------------------------------ |
7049| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7050| 6600101  | Session service exception. |
7051| 6600103  | The session controller does not exist. |
7052
7053**示例:**
7054
7055```ts
7056avsessionController.on('playbackStateChange', 'all', (playbackState: avSession.AVPlaybackState) => {
7057  console.info(`on playbackStateChange state : ${playbackState.state}`);
7058});
7059
7060avsessionController.on('playbackStateChange', ['state', 'speed', 'loopMode'], (playbackState: avSession.AVPlaybackState) => {
7061  console.info(`on playbackStateChange state : ${playbackState.state}`);
7062});
7063```
7064
7065### off('playbackStateChange')<sup>10+</sup>
7066
7067off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
7068
7069媒体控制器取消监听播放状态变化的事件。
7070
7071**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7072
7073**系统能力:** SystemCapability.Multimedia.AVSession.Core
7074
7075**参数:**
7076
7077| 参数名   | 类型                                                         | 必填 | 说明                                                     |
7078| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7079| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'playbackStateChange'`。    |
7080| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | 否   | 回调函数,参数state是变化后的播放状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                      |
7081
7082**错误码:**
7083
7084以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7085
7086| 错误码ID | 错误信息 |
7087| -------- | ---------------- |
7088| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7089| 6600101  | Session service exception. |
7090| 6600103  | The session controller does not exist. |
7091
7092**示例:**
7093
7094```ts
7095avsessionController.off('playbackStateChange');
7096```
7097
7098### on('callMetadataChange')<sup>11+</sup>
7099
7100on(type: 'callMetadataChange', filter: Array\<keyof CallMetadata> | 'all', callback: Callback\<CallMetadata>): void
7101
7102设置通话元数据变化的监听事件。
7103
7104**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7105
7106**系统能力:** SystemCapability.Multimedia.AVSession.Core
7107
7108**参数:**
7109
7110| 参数名   | 类型       | 必填 | 说明      |
7111| --------| -----------|-----|------------|
7112| type     | string    | 是   | 事件回调类型,支持事件`'callMetadataChange'`:当通话元数据变化时,触发该事件。 |
7113| filter   | Array\<keyof&nbsp;[CallMetadata](#callmetadata11)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注通话元数据所有字段变化;Array<keyof&nbsp;[CallMetadata](#callmetadata11)\> 表示关注Array中的字段变化。 |
7114| callback | Callback<[CallMetadata](#callmetadata11)\>\>   | 是   | 回调函数,参数callmetadata是变化后的通话元数据。|
7115
7116**错误码:**
7117
7118以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7119
7120| 错误码ID | 错误信息 |
7121| -------- | ------------------------------ |
7122| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7123| 6600101  | Session service exception. |
7124| 6600103  | The session controller does not exist. |
7125
7126**示例:**
7127
7128```ts
7129avsessionController.on('callMetadataChange', 'all', (callmetadata: avSession.CallMetadata) => {
7130  console.info(`on callMetadataChange state : ${callmetadata.name}`);
7131});
7132
7133avsessionController.on('callMetadataChange', ['name'], (callmetadata: avSession.CallMetadata) => {
7134  console.info(`on callMetadataChange state : ${callmetadata.name}`);
7135});
7136```
7137
7138### off('callMetadataChange')<sup>11+</sup>
7139
7140off(type: 'callMetadataChange', callback?: Callback\<CallMetadata>): void
7141
7142取消设置通话元数据变化的监听事件。
7143
7144**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7145
7146**系统能力:** SystemCapability.Multimedia.AVSession.Core
7147
7148**参数:**
7149
7150| 参数名   | 类型                                                         | 必填 | 说明                                                     |
7151| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7152| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'callMetadataChange'`。    |
7153| callback | Callback<[CallMetadata](#callmetadata11)\>       | 否   | 回调函数,参数calldata是变化后的通话原数据。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。      |
7154
7155**错误码:**
7156
7157以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7158
7159| 错误码ID | 错误信息 |
7160| -------- | ---------------- |
7161| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7162| 6600101  | Session service exception. |
7163| 6600103  | The session controller does not exist. |
7164
7165**示例:**
7166
7167```ts
7168avsessionController.off('callMetadataChange');
7169```
7170
7171### on('callStateChange')<sup>11+</sup>
7172
7173on(type: 'callStateChange', filter: Array\<keyof AVCallState> | 'all', callback: Callback\<AVCallState>): void
7174
7175设置通话状态变化的监听事件。
7176
7177**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7178
7179**系统能力:** SystemCapability.Multimedia.AVSession.Core
7180
7181**参数:**
7182
7183| 参数名   | 类型       | 必填 | 说明      |
7184| --------| -----------|-----|------------|
7185| type     | string    | 是   | 事件回调类型,支持事件`'callStateChange'`:当通话状态变化时,触发该事件。 |
7186| filter   | Array<keyof&nbsp;[AVCallState](#avcallstate11)\>&nbsp;&#124;&nbsp;'all' | 是   | 'all' 表示关注通话状态所有字段变化;Array<keyof&nbsp;[AVCallState](#avcallstate11)\> 表示关注Array中的字段变化。 |
7187| callback | Callback<[AVCallState](#avcallstate11)\>       | 是   | 回调函数,参数callstate是变化后的通话状态。|
7188
7189**错误码:**
7190
7191以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7192
7193| 错误码ID | 错误信息 |
7194| -------- | ------------------------------ |
7195| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7196| 6600101  | Session service exception. |
7197| 6600103  | The session controller does not exist. |
7198
7199**示例:**
7200
7201```ts
7202avsessionController.on('callStateChange', 'all', (callstate: avSession.AVCallState) => {
7203  console.info(`on callStateChange state : ${callstate.state}`);
7204});
7205
7206avsessionController.on('callStateChange', ['state'], (callstate: avSession.AVCallState) => {
7207  console.info(`on callStateChange state : ${callstate.state}`);
7208});
7209```
7210
7211### off('callStateChange')<sup>11+</sup>
7212
7213off(type: 'callStateChange', callback?: Callback\<AVCallState>): void
7214
7215取消设置通话状态变化的监听事件。
7216
7217**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7218
7219**系统能力:** SystemCapability.Multimedia.AVSession.Core
7220
7221**参数:**
7222
7223| 参数名   | 类型                                                         | 必填 | 说明                                                     |
7224| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7225| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'callStateChange'`。    |
7226| callback | Callback<[AVCallState](#avcallstate11)\>           | 否   | 回调函数,参数callstate是变化后的通话状态。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。      |
7227
7228**错误码:**
7229
7230以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7231
7232| 错误码ID | 错误信息 |
7233| -------- | ---------------- |
7234| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7235| 6600101  | Session service exception. |
7236| 6600103  | The session controller does not exist. |
7237
7238**示例:**
7239
7240```ts
7241avsessionController.off('callMetadataChange');
7242```
7243
7244### on('sessionDestroy')<sup>10+</sup>
7245
7246on(type: 'sessionDestroy', callback: () => void)
7247
7248会话销毁的监听事件。
7249
7250**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7251
7252**系统能力:** SystemCapability.Multimedia.AVSession.Core
7253
7254**参数:**
7255
7256| 参数名   | 类型       | 必填 | 说明                                                         |
7257| -------- | ---------- | ---- | ------------------------------------------------------------ |
7258| type     | string     | 是   | 事件回调类型,支持事件`'sessionDestroy'`:当检测到会话销毁时,触发该事件)。 |
7259| callback | () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。                  |
7260
7261**错误码:**
7262
7263以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7264
7265| 错误码ID | 错误信息 |
7266| -------- | ------------------------------ |
7267| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7268| 6600101  | Session service exception. |
7269| 6600103  | The session controller does not exist. |
7270
7271**示例:**
7272
7273```ts
7274avsessionController.on('sessionDestroy', () => {
7275  console.info('on sessionDestroy : SUCCESS ');
7276});
7277```
7278
7279### off('sessionDestroy')<sup>10+</sup>
7280
7281off(type: 'sessionDestroy', callback?: () => void)
7282
7283媒体控制器取消监听会话的销毁事件。
7284
7285**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7286
7287**系统能力:** SystemCapability.Multimedia.AVSession.Core
7288
7289**参数:**
7290
7291| 参数名   | 类型       | 必填 | 说明                                                      |
7292| -------- | ---------- | ---- | ----------------------------------------------------- |
7293| type     | string     | 是   | 取消对应的监听事件,支持事件`'sessionDestroy'`。         |
7294| callback | () => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                                               |
7295
7296**错误码:**
7297
7298以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7299
7300| 错误码ID | 错误信息 |
7301| -------- | ---------------- |
7302| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7303| 6600101  | Session service exception. |
7304| 6600103  | The session controller does not exist. |
7305
7306**示例:**
7307
7308```ts
7309avsessionController.off('sessionDestroy');
7310```
7311
7312### on('activeStateChange')<sup>10+</sup>
7313
7314on(type: 'activeStateChange', callback: (isActive: boolean) => void)
7315
7316会话的激活状态的监听事件。
7317
7318**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7319
7320**系统能力:** SystemCapability.Multimedia.AVSession.Core
7321
7322**参数:**
7323
7324| 参数名   | 类型                        | 必填 | 说明                                                         |
7325| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
7326| type     | string                      | 是   | 事件回调类型,支持事件`'activeStateChange'`:当检测到会话的激活状态发生改变时,触发该事件。 |
7327| callback | (isActive: boolean) => void | 是   | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。                   |
7328
7329**错误码:**
7330
7331以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7332
7333| 错误码ID | 错误信息 |
7334| -------- | ----------------------------- |
7335| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7336| 6600101  | Session service exception. |
7337| 6600103  |The session controller does not exist. |
7338
7339**示例:**
7340
7341```ts
7342avsessionController.on('activeStateChange', (isActive: boolean) => {
7343  console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
7344});
7345```
7346
7347### off('activeStateChange')<sup>10+</sup>
7348
7349off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
7350
7351媒体控制器取消监听会话激活状态变化的事件。
7352
7353**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7354
7355**系统能力:** SystemCapability.Multimedia.AVSession.Core
7356
7357**参数:**
7358
7359| 参数名   | 类型                        | 必填 | 说明                                                      |
7360| -------- | --------------------------- | ---- | ----------------------------------------------------- |
7361| type     | string                      | 是   | 取消对应的监听事件,支持事件`'activeStateChange'`。      |
7362| callback | (isActive: boolean) => void | 否   | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                   |
7363
7364**错误码:**
7365
7366以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7367
7368| 错误码ID | 错误信息 |
7369| -------- | ---------------- |
7370| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7371| 6600101  | Session service exception. |
7372| 6600103  | The session controller does not exist. |
7373
7374**示例:**
7375
7376```ts
7377avsessionController.off('activeStateChange');
7378```
7379
7380### on('validCommandChange')<sup>10+</sup>
7381
7382on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
7383
7384会话支持的有效命令变化监听事件。
7385
7386**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7387
7388**系统能力:** SystemCapability.Multimedia.AVSession.Core
7389
7390**参数:**
7391
7392| 参数名   | 类型                                                         | 必填 | 说明                                                         |
7393| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7394| type     | string                                                       | 是   | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 |
7395| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 是   | 回调函数。参数commands是有效命令的集合。                     |
7396
7397**错误码:**
7398
7399以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7400
7401| 错误码ID | 错误信息 |
7402| -------- | ------------------------------ |
7403| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7404| 6600101  | Session service exception. |
7405| 6600103  | The session controller does not exist. |
7406
7407**示例:**
7408
7409```ts
7410avsessionController.on('validCommandChange', (validCommands: avSession.AVControlCommandType[]) => {
7411  console.info(`validCommandChange : SUCCESS : size : ${validCommands.length}`);
7412  console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
7413});
7414```
7415
7416### off('validCommandChange')<sup>10+</sup>
7417
7418off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
7419
7420媒体控制器取消监听会话有效命令变化的事件。
7421
7422**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7423
7424**系统能力:** SystemCapability.Multimedia.AVSession.Core
7425
7426**参数:**
7427
7428| 参数名   | 类型                                                         | 必填 | 说明                                                        |
7429| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
7430| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'validCommandChange'`。         |
7431| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 否   | 回调函数。参数commands是有效命令的集合。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。          |
7432
7433**错误码:**
7434
7435以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7436
7437| 错误码ID | 错误信息           |
7438| -------- | ---------------- |
7439| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7440| 6600101  | Session service exception. |
7441| 6600103  | The session controller does not exist. |
7442
7443**示例:**
7444
7445```ts
7446avsessionController.off('validCommandChange');
7447```
7448
7449### on('outputDeviceChange')<sup>10+</sup>
7450
7451on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7452
7453设置播放设备变化的监听事件。
7454
7455**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7456
7457**系统能力:** SystemCapability.Multimedia.AVSession.Core
7458
7459**参数:**
7460
7461| 参数名   | 类型                                                    | 必填 | 说明                                                         |
7462| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
7463| type     | string                                                  | 是   | 事件回调类型,支持事件为`'outputDeviceChange'`:当播放设备变化时,触发该事件)。 |
7464| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是   | 回调函数,参数device是设备相关信息。                         |
7465
7466**错误码:**
7467
7468以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7469
7470| 错误码ID | 错误信息 |
7471| -------- | ----------------------- |
7472| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7473| 6600101  | Session service exception. |
7474| 6600103  | The session controller does not exist. |
7475
7476**示例:**
7477
7478```ts
7479avsessionController.on('outputDeviceChange', (state: avSession.ConnectionState, device: avSession.OutputDeviceInfo) => {
7480  console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
7481});
7482```
7483
7484### off('outputDeviceChange')<sup>10+</sup>
7485
7486off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
7487
7488媒体控制器取消监听分布式设备变化的事件。
7489
7490**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7491
7492**系统能力:** SystemCapability.Multimedia.AVSession.Core
7493
7494**参数:**
7495
7496| 参数名   | 类型                                                    | 必填 | 说明                                                      |
7497| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
7498| type     | string                                                  | 是   | 取消对应的监听事件,支持事件`'outputDeviceChange'`。      |
7499| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否   | 回调函数,参数device是设备相关信息。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                         |
7500
7501**错误码:**
7502
7503以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7504
7505| 错误码ID  | 错误信息          |
7506| -------- | ---------------- |
7507| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7508| 6600101  | Session service exception. |
7509| 6600103  | The session controller does not exist. |
7510
7511**示例:**
7512
7513```ts
7514avsessionController.off('outputDeviceChange');
7515```
7516
7517### on('sessionEvent')<sup>10+</sup>
7518
7519on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7520
7521媒体控制器设置会话自定义事件变化的监听器。
7522
7523**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7524
7525**系统能力:** SystemCapability.Multimedia.AVSession.Core
7526
7527**参数:**
7528
7529| 参数名   | 类型                                                         | 必填 | 说明                                                         |
7530| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7531| type     | string                                                       | 是   | 事件回调类型,支持事件`'sessionEvent'`:当会话事件变化时,触发该事件。 |
7532| callback | (sessionEvent: string, args: {[key:string]: object}) => void         | 是   | 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。          |
7533
7534**错误码:**
7535
7536以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7537
7538| 错误码ID | 错误信息 |
7539| -------- | ------------------------------ |
7540| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7541| 6600101  | Session service exception. |
7542| 6600103  | The session controller does not exist. |
7543
7544**示例:**
7545
7546```ts
7547import { BusinessError } from '@kit.BasicServicesKit';
7548import { avSession } from '@kit.AVSessionKit';
7549@Entry
7550@Component
7551struct Index {
7552  @State message: string = 'hello world';
7553
7554  build() {
7555    Column() {
7556      Text(this.message)
7557        .onClick(()=>{
7558          let currentAVSession: avSession.AVSession | undefined = undefined;
7559          let tag: string = "createNewSession";
7560          let context: Context = this.getUIContext().getHostContext() as Context;
7561          let sessionId: string = "";
7562          let controller:avSession.AVSessionController | undefined = undefined;
7563          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
7564            currentAVSession = data;
7565            sessionId = currentAVSession.sessionId;
7566            controller = await currentAVSession.getController();
7567            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
7568          }).catch((err: BusinessError) => {
7569            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
7570          });
7571          if (controller !== undefined) {
7572            (controller as avSession.AVSessionController).on('sessionEvent', (sessionEvent, args) => {
7573              console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
7574            });
7575          }
7576        })
7577    }
7578    .width('100%')
7579    .height('100%')
7580  }
7581}
7582```
7583
7584### off('sessionEvent')<sup>10+</sup>
7585
7586off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void
7587
7588媒体控制器取消监听会话事件的变化通知。
7589
7590**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7591
7592**系统能力:** SystemCapability.Multimedia.AVSession.Core
7593
7594**参数:**
7595
7596| 参数名   | 类型                                                         | 必填 | 说明                                                     |
7597| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
7598| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'sessionEvent'`。    |
7599| callback | (sessionEvent: string, args: {[key:string]: Object}) => void         | 否   | 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。<br>该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。                      |
7600
7601**错误码:**
7602
7603以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7604
7605| 错误码ID | 错误信息 |
7606| -------- | ---------------- |
7607| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7608| 6600101  | Session service exception. |
7609| 6600103  | The session controller does not exist. |
7610
7611**示例:**
7612
7613```ts
7614avsessionController.off('sessionEvent');
7615```
7616
7617### on('queueItemsChange')<sup>10+</sup>
7618
7619on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7620
7621媒体控制器设置会话自定义播放列表变化的监听器。
7622
7623**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7624
7625**系统能力:** SystemCapability.Multimedia.AVSession.Core
7626
7627**参数:**
7628
7629| 参数名   | 类型                                                   | 必填 | 说明                                                                         |
7630| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
7631| type     | string                                                | 是   | 事件回调类型,支持事件`'queueItemsChange'`:当session修改播放列表时,触发该事件。 |
7632| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void  | 是   | 回调函数,items为变化的播放列表。                            |
7633
7634**错误码:**
7635
7636以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7637
7638| 错误码ID | 错误信息 |
7639| -------- | ------------------------------ |
7640| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7641| 6600101  | Session service exception. |
7642| 6600103  | The session controller does not exist. |
7643
7644**示例:**
7645
7646```ts
7647avsessionController.on('queueItemsChange', (items: avSession.AVQueueItem[]) => {
7648  console.info(`OnQueueItemsChange, items length is ${items.length}`);
7649});
7650```
7651
7652### off('queueItemsChange')<sup>10+</sup>
7653
7654off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
7655
7656媒体控制器取消监听播放列表变化的事件。
7657
7658**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7659
7660**系统能力:** SystemCapability.Multimedia.AVSession.Core
7661
7662**参数:**
7663
7664| 参数名    | 类型                                                 | 必填 | 说明                                                                                                |
7665| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- |
7666| type     | string                                               | 是   | 取消对应的监听事件,支持事件`'queueItemsChange'`。                                                     |
7667| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 否   | 回调函数,参数items是变化的播放列表。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
7668
7669**错误码:**
7670
7671以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7672
7673| 错误码ID | 错误信息 |
7674| -------- | ---------------- |
7675| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7676| 6600101  | Session service exception. |
7677| 6600103  | The session controller does not exist. |
7678
7679**示例:**
7680
7681```ts
7682avsessionController.off('queueItemsChange');
7683```
7684
7685### on('queueTitleChange')<sup>10+</sup>
7686
7687on(type: 'queueTitleChange', callback: (title: string) => void): void
7688
7689媒体控制器设置会话自定义播放列表的名称变化的监听器。
7690
7691**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7692
7693**系统能力:** SystemCapability.Multimedia.AVSession.Core
7694
7695**参数:**
7696
7697| 参数名   | 类型                     | 必填 | 说明                                                                             |
7698| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- |
7699| type     | string                  | 是   | 事件回调类型,支持事件`'queueTitleChange'`:当session修改播放列表名称时,触发该事件。 |
7700| callback | (title: string) => void | 是   | 回调函数,title为变化的播放列表名称。                                |
7701
7702**错误码:**
7703
7704以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7705
7706| 错误码ID | 错误信息 |
7707| -------- | ------------------------------ |
7708| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7709| 6600101  | Session service exception. |
7710| 6600103  | The session controller does not exist. |
7711
7712**示例:**
7713
7714```ts
7715avsessionController.on('queueTitleChange', (title: string) => {
7716  console.info(`queueTitleChange, title is ${title}`);
7717});
7718```
7719
7720### off('queueTitleChange')<sup>10+</sup>
7721
7722off(type: 'queueTitleChange', callback?: (title: string) => void): void
7723
7724媒体控制器取消监听播放列表名称变化的事件。
7725
7726**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7727
7728**系统能力:** SystemCapability.Multimedia.AVSession.Core
7729
7730**参数:**
7731
7732| 参数名    | 类型                    | 必填 | 说明                                                                                                    |
7733| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7734| type     | string                  | 是   | 取消对应的监听事件,支持事件`'queueTitleChange'`。                                                         |
7735| callback | (title: string) => void | 否   | 回调函数,参数items是变化的播放列表名称。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
7736
7737**错误码:**
7738
7739以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7740
7741| 错误码ID | 错误信息 |
7742| -------- | ---------------- |
7743| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7744| 6600101  | Session service exception. |
7745| 6600103  | The session controller does not exist. |
7746
7747**示例:**
7748
7749```ts
7750avsessionController.off('queueTitleChange');
7751```
7752
7753### on('extrasChange')<sup>10+</sup>
7754
7755on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void
7756
7757媒体控制器设置自定义媒体数据包事件变化的监听器。
7758
7759**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7760
7761**系统能力:** SystemCapability.Multimedia.AVSession.Core
7762
7763**参数:**
7764
7765| 参数名   | 类型                                                         | 必填 | 说明                                                         |
7766| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
7767| type     | string                                                       | 是   | 事件回调类型,支持事件`'extrasChange'`:当媒体提供方设置自定义媒体数据包时,触发该事件。 |
7768| callback | (extras: {[key:string]: object}) => void         | 是   | 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。          |
7769
7770**错误码:**
7771
7772以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7773
7774| 错误码ID | 错误信息 |
7775| -------- | ------------------------------ |
7776| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7777| 6600101  | Session service exception. |
7778| 6600103  | The session controller does not exist. |
7779
7780**示例:**
7781
7782```ts
7783import { BusinessError } from '@kit.BasicServicesKit';
7784import { avSession } from '@kit.AVSessionKit';
7785@Entry
7786@Component
7787struct Index {
7788  @State message: string = 'hello world';
7789
7790  build() {
7791    Column() {
7792      Text(this.message)
7793        .onClick(()=>{
7794          let currentAVSession: avSession.AVSession | undefined = undefined;
7795          let tag: string = "createNewSession";
7796          let context: Context = this.getUIContext().getHostContext() as Context;
7797          let sessionId: string = "";
7798          let controller:avSession.AVSessionController | undefined = undefined;
7799          avSession.createAVSession(context, tag, "audio").then(async (data:avSession.AVSession)=> {
7800            currentAVSession = data;
7801            sessionId = currentAVSession.sessionId;
7802            controller = await currentAVSession.getController();
7803            console.info('CreateAVSession : SUCCESS :sessionid = ${sessionid}');
7804          }).catch((err: BusinessError) => {
7805            console.info('CreateAVSession BusinessError:code: ${err.code}, message: ${err.message}')
7806          });
7807          if (controller !== undefined) {
7808            (controller as avSession.AVSessionController).on('extrasChange', (extras) => {
7809              console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
7810            });
7811          }
7812        })
7813    }
7814    .width('100%')
7815    .height('100%')
7816  }
7817}
7818```
7819
7820### off('extrasChange')<sup>10+</sup>
7821
7822off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void
7823
7824媒体控制器取消监听自定义媒体数据包变化事件。
7825
7826**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7827
7828**系统能力:** SystemCapability.Multimedia.AVSession.Core
7829
7830**参数:**
7831
7832| 参数名    | 类型                    | 必填 | 说明                                                                                                    |
7833| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
7834| type     | string                  | 是   | 取消对应的监听事件,支持事件`'extrasChange'`。                                                         |
7835| callback | ({[key:string]: Object}) => void | 否   | 注册监听事件时的回调函数。<br>该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 |
7836
7837**错误码:**
7838
7839以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7840
7841| 错误码ID | 错误信息 |
7842| -------- | ----------------                       |
7843| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
7844| 6600101  | Session service exception.             |
7845| 6600103  | The session controller does not exist. |
7846
7847**示例:**
7848
7849```ts
7850avsessionController.off('extrasChange');
7851```
7852
7853### getAVPlaybackStateSync<sup>10+</sup>
7854
7855getAVPlaybackStateSync(): AVPlaybackState;
7856
7857使用同步方法获取当前会话的播放状态。
7858
7859**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7860
7861**系统能力:** SystemCapability.Multimedia.AVSession.Core
7862
7863**返回值:**
7864
7865| 类型                                                        | 说明                                                         |
7866| --------- | ------------------------------------------------------------ |
7867| [AVPlaybackState](#avplaybackstate10)  | 当前会话的播放状态。 |
7868
7869**错误码:**
7870
7871以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7872
7873| 错误码ID | 错误信息 |
7874| -------- | ---------------------------------------- |
7875| 6600101  | Session service exception. |
7876| 6600102  | The session does not exist. |
7877| 6600103  | The session controller does not exist. |
7878
7879**示例:**
7880
7881```ts
7882import { BusinessError } from '@kit.BasicServicesKit';
7883
7884try {
7885  let playbackState: avSession.AVPlaybackState = avsessionController.getAVPlaybackStateSync();
7886} catch (err) {
7887  let error = err as BusinessError;
7888  console.info(`getAVPlaybackStateSync error, error code: ${error.code}, error message: ${error.message}`);
7889}
7890```
7891
7892### getAVMetadataSync<sup>10+</sup>
7893
7894getAVMetadataSync(): AVMetadata
7895
7896使用同步方法获取会话元数据。
7897
7898**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
7899
7900**系统能力:** SystemCapability.Multimedia.AVSession.Core
7901
7902**返回值:**
7903
7904| 类型                                | 说明                          |
7905| ----------------------------------- | ----------------------------- |
7906| [AVMetadata](#avmetadata10) | 会话元数据。 |
7907
7908**错误码:**
7909
7910以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7911
7912| 错误码ID | 错误信息 |
7913| -------- | ---------------------------------------- |
7914| 6600101  | Session service exception. |
7915| 6600102  | The session does not exist. |
7916| 6600103  | The session controller does not exist. |
7917
7918**示例:**
7919```ts
7920import { BusinessError } from '@kit.BasicServicesKit';
7921
7922try {
7923  let metaData: avSession.AVMetadata = avsessionController.getAVMetadataSync();
7924} catch (err) {
7925  let error = err as BusinessError;
7926  console.info(`getAVMetadataSync error, error code: ${error.code}, error message: ${error.message}`);
7927}
7928```
7929
7930### getAVCallState<sup>11+</sup>
7931
7932getAVCallState(): Promise\<AVCallState>
7933
7934获取通话状态数据。结果通过Promise异步回调方式返回。
7935
7936**系统能力:** SystemCapability.Multimedia.AVSession.Core
7937
7938**返回值:**
7939
7940| 类型                                | 说明                          |
7941| ----------------------------------- | ----------------------------- |
7942| Promise<[AVCallState](#avcallstate11)\> | Promise对象,返回通话状态。 |
7943
7944**错误码:**
7945
7946以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7947
7948| 错误码ID | 错误信息 |
7949| -------- | ---------------------------------------- |
7950| 6600101  | Session service exception. |
7951| 6600102  | The session does not exist. |
7952| 6600103  | The session controller does not exist. |
7953
7954**示例:**
7955
7956```ts
7957import { BusinessError } from '@kit.BasicServicesKit';
7958
7959avsessionController.getAVCallState().then((callstate: avSession.AVCallState) => {
7960  console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
7961}).catch((err: BusinessError) => {
7962  console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7963});
7964```
7965
7966### getAVCallState<sup>11+</sup>
7967
7968getAVCallState(callback: AsyncCallback\<AVCallState>): void
7969
7970获取通话状态数据。结果通过callback异步回调方式返回。
7971
7972**系统能力:** SystemCapability.Multimedia.AVSession.Core
7973
7974**参数:**
7975
7976| 参数名   | 类型                                      | 必填 | 说明                       |
7977| -------- | ----------------------------------------- | ---- | -------------------------- |
7978| callback | AsyncCallback<[AVCallState](#avcallstate11)\> | 是   | 回调函数,返回通话状态。 |
7979
7980**错误码:**
7981
7982以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
7983
7984| 错误码ID | 错误信息 |
7985| -------- | ---------------------------------------- |
7986| 6600101  | Session service exception. |
7987| 6600102  | The session does not exist. |
7988| 6600103  | The session controller does not exist. |
7989
7990**示例:**
7991
7992```ts
7993import { BusinessError } from '@kit.BasicServicesKit';
7994
7995avsessionController.getAVCallState((err: BusinessError, callstate: avSession.AVCallState) => {
7996  if (err) {
7997    console.error(`getAVCallState BusinessError: code: ${err.code}, message: ${err.message}`);
7998  } else {
7999    console.info(`getAVCallState : SUCCESS : state : ${callstate.state}`);
8000  }
8001});
8002```
8003
8004### getCallMetadata<sup>11+</sup>
8005
8006getCallMetadata(): Promise\<CallMetadata>
8007
8008获取通话会话的元数据。结果通过Promise异步回调方式返回。
8009
8010**系统能力:** SystemCapability.Multimedia.AVSession.Core
8011
8012**返回值:**
8013
8014| 类型                                | 说明                          |
8015| ----------------------------------- | ----------------------------- |
8016| Promise<[CallMetadata](#callmetadata11)\> | Promise对象,返回会话元数据。 |
8017
8018**错误码:**
8019
8020以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8021
8022| 错误码ID | 错误信息 |
8023| -------- | ---------------------------------------- |
8024| 6600101  | Session service exception. |
8025| 6600102  | The session does not exist. |
8026| 6600103  | The session controller does not exist. |
8027
8028**示例:**
8029
8030```ts
8031import { BusinessError } from '@kit.BasicServicesKit';
8032
8033avsessionController.getCallMetadata().then((calldata: avSession.CallMetadata) => {
8034  console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
8035}).catch((err: BusinessError) => {
8036  console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
8037});
8038```
8039
8040### getCallMetadata<sup>11+</sup>
8041
8042getCallMetadata(callback: AsyncCallback\<CallMetadata>): void
8043
8044获取通话会话的元数据。结果通过callback异步回调方式返回。
8045
8046**系统能力:** SystemCapability.Multimedia.AVSession.Core
8047
8048**参数:**
8049
8050| 参数名   | 类型                                      | 必填 | 说明                       |
8051| -------- | ----------------------------------------- | ---- | -------------------------- |
8052| callback | AsyncCallback<[CallMetadata](#callmetadata11)\> | 是   | 回调函数,返回会话元数据。 |
8053
8054**错误码:**
8055
8056以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8057
8058| 错误码ID | 错误信息 |
8059| -------- | ---------------------------------------- |
8060| 6600101  | Session service exception. |
8061| 6600102  | The session does not exist. |
8062| 6600103  | The session controller does not exist. |
8063
8064**示例:**
8065
8066```ts
8067import { BusinessError } from '@kit.BasicServicesKit';
8068
8069avsessionController.getCallMetadata((err: BusinessError, calldata: avSession.CallMetadata) => {
8070  if (err) {
8071    console.error(`getCallMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
8072  } else {
8073    console.info(`getCallMetadata : SUCCESS : name : ${calldata.name}`);
8074  }
8075});
8076```
8077
8078### getAVQueueTitleSync<sup>10+</sup>
8079
8080getAVQueueTitleSync(): string
8081
8082使用同步方法获取当前会话播放列表的名称。
8083
8084**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8085
8086**系统能力:** SystemCapability.Multimedia.AVSession.Core
8087
8088**返回值:**
8089
8090| 类型             | 说明                           |
8091| ---------------- | ----------------------------- |
8092| string | 当前会话播放列表名称。 |
8093
8094**错误码:**
8095
8096以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8097
8098| 错误码ID | 错误信息 |
8099| -------- | ---------------------------------------- |
8100| 6600101  | Session service exception. |
8101| 6600102  | The session does not exist. |
8102| 6600103  | The session controller does not exist. |
8103
8104**示例:**
8105
8106```ts
8107import { BusinessError } from '@kit.BasicServicesKit';
8108
8109try {
8110  let currentQueueTitle: string = avsessionController.getAVQueueTitleSync();
8111} catch (err) {
8112  let error = err as BusinessError;
8113  console.error(`getAVQueueTitleSync error, error code: ${error.code}, error message: ${error.message}`);
8114}
8115```
8116
8117### getAVQueueItemsSync<sup>10+</sup>
8118
8119getAVQueueItemsSync(): Array\<AVQueueItem\>
8120
8121使用同步方法获取当前会话播放列表相关信息。
8122
8123**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8124
8125**系统能力:** SystemCapability.Multimedia.AVSession.Core
8126
8127**返回值:**
8128
8129| 类型                                          | 说明                           |
8130| --------------------------------------------- | ----------------------------- |
8131| Array<[AVQueueItem](#avqueueitem10)\> | 当前会话播放列表队列。 |
8132
8133**错误码:**
8134
8135以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8136
8137| 错误码ID | 错误信息 |
8138| -------- | ---------------------------------------- |
8139| 6600101  | Session service exception. |
8140| 6600102  | The session does not exist. |
8141| 6600103  | The session controller does not exist. |
8142
8143**示例:**
8144
8145```ts
8146import { BusinessError } from '@kit.BasicServicesKit';
8147
8148try {
8149  let currentQueueItems: Array<avSession.AVQueueItem> = avsessionController.getAVQueueItemsSync();
8150} catch (err) {
8151  let error = err as BusinessError;
8152  console.error(`getAVQueueItemsSync error, error code: ${error.code}, error message: ${error.message}`);
8153}
8154```
8155
8156### getOutputDeviceSync<sup>10+</sup>
8157
8158getOutputDeviceSync(): OutputDeviceInfo
8159
8160使用同步方法获取当前输出设备信息。
8161
8162**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8163
8164**系统能力:** SystemCapability.Multimedia.AVSession.Core
8165
8166**返回值:**
8167
8168| 类型                                            | 说明                              |
8169| ----------------------------------------------- | --------------------------------- |
8170| [OutputDeviceInfo](#outputdeviceinfo10) | 当前输出设备信息。 |
8171
8172**错误码:**
8173
8174以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8175
8176| 错误码ID | 错误信息 |
8177| -------- | ---------------------------------------- |
8178| 6600101  | Session service exception. |
8179| 6600103  | The session controller does not exist. |
8180
8181**示例:**
8182
8183```ts
8184import { BusinessError } from '@kit.BasicServicesKit';
8185
8186try {
8187  let currentOutputDevice: avSession.OutputDeviceInfo = avsessionController.getOutputDeviceSync();
8188} catch (err) {
8189  let error = err as BusinessError;
8190  console.error(`getOutputDeviceSync error, error code: ${error.code}, error message: ${error.message}`);
8191}
8192```
8193
8194### isActiveSync<sup>10+</sup>
8195
8196isActiveSync(): boolean
8197
8198使用同步方法判断会话是否被激活。
8199
8200**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8201
8202**系统能力:** SystemCapability.Multimedia.AVSession.Core
8203
8204**返回值:**
8205
8206| 类型              | 说明                                                         |
8207| ----------------- | ------------------------------------------------------------ |
8208| boolean | 会话是否为激活状态,true表示被激活,false表示禁用。 |
8209
8210**错误码:**
8211
8212以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8213
8214| 错误码ID | 错误信息 |
8215| -------- | ---------------------------------------- |
8216| 6600101  | Session service exception. |
8217| 6600102  | The session does not exist. |
8218| 6600103  | The session controller does not exist. |
8219
8220**示例:**
8221
8222```ts
8223import { BusinessError } from '@kit.BasicServicesKit';
8224
8225try {
8226  let isActive: boolean = avsessionController.isActiveSync();
8227} catch (err) {
8228  let error = err as BusinessError;
8229  console.error(`isActiveSync error, error code: ${error.code}, error message: ${error.message}`);
8230}
8231```
8232
8233### getValidCommandsSync<sup>10+</sup>
8234
8235getValidCommandsSync(): Array\<AVControlCommandType\>
8236
8237使用同步方法获取会话支持的有效命令。
8238
8239**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8240
8241**系统能力:** SystemCapability.Multimedia.AVSession.Core
8242
8243**返回值:**
8244
8245| 类型                                                         | 说明                              |
8246| ------------------------------------------------------------ | --------------------------------- |
8247| Array<[AVControlCommandType](#avcontrolcommandtype10)\> | 会话支持的有效命令的集合。 |
8248
8249**错误码:**
8250
8251以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8252
8253| 错误码ID | 错误信息 |
8254| -------- | ---------------------------------------- |
8255| 6600101  | Session service exception. |
8256| 6600102  | The session does not exist. |
8257| 6600103  | The session controller does not exist. |
8258
8259**示例:**
8260
8261```ts
8262import { BusinessError } from '@kit.BasicServicesKit';
8263
8264try {
8265  let validCommands: Array<avSession.AVControlCommandType> = avsessionController.getValidCommandsSync();
8266} catch (err) {
8267  let error = err as BusinessError;
8268  console.error(`getValidCommandsSync error, error code: ${error.code}, error message: ${error.message}`);
8269}
8270```
8271
8272## AVControlCommandType<sup>10+</sup>
8273
8274type AVControlCommandType = 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind' |
8275  'seek' | 'setSpeed' | 'setLoopMode' | 'toggleFavorite' | 'playFromAssetId' | 'answer' | 'hangUp' | 'toggleCallMute' | 'setTargetLoopMode'
8276
8277会话可传递的命令。
8278
8279该类型可取的值为下表字符串的并集。
8280
8281**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8282
8283**系统能力:** SystemCapability.Multimedia.AVSession.Core
8284
8285| 类型             | 说明         |
8286| ---------------- | ------------ |
8287| 'play'           | 播放。         |
8288| 'pause'          | 暂停。         |
8289| 'stop'           | 停止。         |
8290| 'playNext'       | 下一首。       |
8291| 'playPrevious'   | 上一首。       |
8292| 'fastForward'    | 快进。         |
8293| 'rewind'         | 快退。         |
8294| 'seek'           | 跳转某一节点。 |
8295| 'setSpeed'       | 设置播放倍速。 |
8296| 'setLoopMode'    | 设置循环模式。 |
8297| 'toggleFavorite' | 是否收藏。     |
8298| 'playFromAssetId'| 播放指定的assetid。 |
8299|'answer'          | 接听。        |
8300| 'hangUp'         | 挂断。        |
8301|'toggleCallMute'  | 设置通话静音状态。 |
8302| 'setTargetLoopMode' <sup>18+</sup>   | 设置目标循环模式。 |
8303
8304## AVControlCommand<sup>10+</sup>
8305
8306会话接受的命令的对象描述。
8307
8308**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
8309
8310**系统能力:** SystemCapability.Multimedia.AVSession.Core
8311
8312| 名称      | 类型                                              | 必填 | 说明           |
8313| --------- | ------------------------------------------------- | ---- | -------------- |
8314| command   | [AVControlCommandType](#avcontrolcommandtype10)     | 是   | 命令。           |
8315| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | 否   | 命令对应的参数。 |
8316
8317
8318## AVCastPickerOptions<sup>14+</sup>
8319
8320拉起的投播半模态窗口相关属性。
8321
8322**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8323
8324**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8325
8326| 名称            | 类型                      | 必填 | 说明                                                                  |
8327| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
8328| sessionType         | [AVSessionType](#avsessiontype10)  | 否   | 会话类型,默认值为'audio'。<br>当前仅支持'audio'、'video'会话类型。如果传入'voice_call'、'video_call',将按照传入默认值'audio'处理。            |
8329
8330## AVCastPickerHelper<sup>14+</sup>
8331
8332投播半模态对象,可拉起半模态窗口,选择投播设备。在使用前,需要创建AVCastPickerHelper实例。
8333
8334**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8335
8336**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8337
8338### constructor<sup>14+</sup>
8339
8340constructor(context: Context)
8341
8342创建AVCastPickerHelper对象,获取context参考[getContext](../apis-arkui/js-apis-getContext.md)。
8343
8344**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8345
8346**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8347
8348**参数:**
8349
8350| 参数名    | 类型                                                        | 必填 | 说明                                                         |
8351| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
8352| context  | Context | 是   | 应用上下文(仅支持[UIAbilityContext](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md))。 |
8353
8354**错误码:**
8355
8356以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8357
8358| 错误码ID | 错误信息 |
8359| -------- | ---------------------------------------- |
8360| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8361| 6600101  | Session service exception. |
8362
8363**示例:**
8364
8365```ts
8366import { common } from '@kit.AbilityKit';
8367import { avSession } from '@kit.AVSessionKit';
8368@Entry
8369@Component
8370struct Index {
8371  @State message: string = 'hello world';
8372
8373  build() {
8374    Row() {
8375      Column() {
8376        Text(this.message)
8377          .fontSize(40)
8378          .fontWeight(FontWeight.Bold)
8379          .onClick(()=>{
8380            let context = this.getUIContext().getHostContext() as Context;
8381            let avCastPicker = new avSession.AVCastPickerHelper(context);
8382          })
8383      }
8384      .width('100%')
8385    }
8386    .height('100%')
8387  }
8388}
8389```
8390
8391### select<sup>14+</sup>
8392
8393select(options?: AVCastPickerOptions): Promise\<void>
8394
8395通过选择模式拉起AVCastPicker界面,用户可以选择投播设备。接口采用Promise异步返回形式,传入可选参数AVCastPickerOptions对象,无返回值。
8396
8397**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8398
8399**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8400
8401**参数:**
8402
8403| 参数名    | 类型                                                        | 必填 | 说明                                                         |
8404| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
8405| options  | [AVCastPickerOptions](#avcastpickeroptions14) | 否   | AVCastPicker选择选项。无此参数时,以AVCastPickerOptions默认值拉起。 |
8406
8407**返回值:**
8408
8409| 类型           | 说明                          |
8410| -------------- | ----------------------------- |
8411| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
8412
8413**错误码:**
8414
8415以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8416
8417| 错误码ID | 错误信息 |
8418| -------- | ---------------------------------------- |
8419| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8420
8421**示例:**
8422
8423```ts
8424import { common } from '@kit.AbilityKit';
8425import { BusinessError } from '@kit.BasicServicesKit';
8426
8427async function avCastPicker(context: common.Context) {
8428  let avCastPickerOptions : avSession.AVCastPickerOptions = {
8429    sessionType : 'video',
8430  }
8431  let avCastPicker = new avSession.AVCastPickerHelper(context);
8432  avCastPicker.select(avCastPickerOptions).then(() => {
8433    console.info('select successfully');
8434  }).catch((err: BusinessError) => {
8435    console.error(`AVCastPicker.select failed with err: ${err.code}, ${err.message}`);
8436  });
8437}
8438```
8439### on('pickerStateChange')<sup>14+</sup>
8440
8441on(type: 'pickerStateChange', callback: Callback<AVCastPickerState\>) : void
8442
8443设置半模态窗口变化的监听事件。
8444
8445**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8446
8447**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8448
8449**参数:**
8450
8451| 参数名   | 类型       | 必填 | 说明      |
8452| --------| -----------|-----|------------|
8453| type     | string    | 是   | 事件回调类型,支持事件`'pickerStateChange'`:当半模态窗口变化时,触发该事件。 |
8454| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)>       | 是   | 回调函数,参数state是变化后的半模态窗口状态。|
8455
8456**错误码:**
8457
8458以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8459
8460| 错误码ID | 错误信息 |
8461| -------- | ---------------------------------------- |
8462| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8463| 6600101  | Session service exception. |
8464
8465**示例:**
8466
8467```ts
8468import { common } from '@kit.AbilityKit';
8469import { AVCastPickerState } from '@kit.AVSessionKit';
8470
8471async function onPickerStateChange(context: common.Context) {
8472  let avCastPicker = new avSession.AVCastPickerHelper(context);
8473  avCastPicker.on('pickerStateChange', (state: AVCastPickerState) => {
8474    console.info(`picker state change : ${state}`);
8475  });
8476}
8477```
8478
8479### off('pickerStateChange')<sup>14+</sup>
8480
8481off(type: 'pickerStateChange', callback?: Callback<AVCastPickerState\>) : void
8482
8483取消半模态窗口变化的监听事件,关闭后,不再进行该事件回调。
8484
8485**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
8486
8487**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
8488
8489**参数:**
8490
8491| 参数名   | 类型                                               | 必填 | 说明                                                    |
8492| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
8493| type     | string                                           | 是   | 取消对应的监听事件,支持事件`'pickerStateChange'`。         |
8494| callback | Callback\<[AVCastPickerState](js-apis-avCastPickerParam.md#avcastpickerstate11)> | 否   | 回调函数,参数state是变化后的半模态窗口状态。<br>当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                           |
8495
8496**错误码:**
8497
8498以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
8499
8500| 错误码ID | 错误信息 |
8501| -------- | ---------------------------------------- |
8502| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
8503| 6600101  | Session service exception. |
8504
8505**示例:**
8506
8507```ts
8508import { common } from '@kit.AbilityKit';
8509
8510async function onPickerStateChange(context: common.Context) {
8511  let avCastPicker = new avSession.AVCastPickerHelper(context);
8512  avCastPicker.off('pickerStateChange');
8513}
8514```
8515
8516## AVSessionErrorCode<sup>10+</sup>
8517
8518会话发生错误时的错误码。
8519
8520| 名称                                   | 值      | 说明                             |
8521| -------------------------------------- | ------- | ------------------------------- |
8522| ERR_CODE_SERVICE_EXCEPTION             | 6600101 | 会话服务端异常。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core|
8523| ERR_CODE_SESSION_NOT_EXIST             | 6600102 | 会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8524| ERR_CODE_CONTROLLER_NOT_EXIST          | 6600103 | 会话控制器不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8525| ERR_CODE_REMOTE_CONNECTION_ERR         | 6600104 | 远端会话连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core|
8526| ERR_CODE_COMMAND_INVALID               | 6600105 | 无效会话命令。<br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 <br>**系统能力:** SystemCapability.Multimedia.AVSession.Core|
8527| ERR_CODE_SESSION_INACTIVE              | 6600106 | 会话未激活。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8528| ERR_CODE_MESSAGE_OVERLOAD              | 6600107 | 命令&消息过载。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8529| ERR_CODE_DEVICE_CONNECTION_FAILED      | 6600108 | 设备连接失败。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8530| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST   | 6600109 | 远端会话不存在。 <br>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.Core |
8531| ERR_CODE_CAST_CONTROL_UNSPECIFIED<sup>13+</sup>    | 6611000 | 未被定义的投播错误码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8532| ERR_CODE_CAST_CONTROL_REMOTE_ERROR<sup>13+</sup>    | 6611001 | 远端播放器中发生不明错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8533| ERR_CODE_CAST_CONTROL_BEHIND_LIVE_WINDOW<sup>13+</sup>     | 6611002 | 播放出现延迟。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8534| ERR_CODE_CAST_CONTROL_TIMEOUT<sup>13+</sup>     | 6611003 | 投播控制进程超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8535| ERR_CODE_CAST_CONTROL_RUNTIME_CHECK_FAILED<sup>13+</sup>      | 6611004 | 运行时检查失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8536| ERR_CODE_CAST_CONTROL_PLAYER_NOT_WORKING<sup>13+</sup>      | 6611100 | 跨设备数据传输被锁定。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8537| ERR_CODE_CAST_CONTROL_SEEK_MODE_UNSUPPORTED<sup>13+</sup>      | 6611101 | 不支持指定的查找模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8538| ERR_CODE_CAST_CONTROL_ILLEGAL_SEEK_TARGET<sup>13+</sup>      | 6611102 | 要搜索的位置超出媒体的范围,或者不支持当前搜索模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8539| ERR_CODE_CAST_CONTROL_PLAY_MODE_UNSUPPORTED<sup>13+</sup>      | 6611103 |  不支持指定的播放模式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8540| ERR_CODE_CAST_CONTROL_PLAY_SPEED_UNSUPPORTED<sup>13+</sup>      | 6611104 | 不支持指定的播放速度。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8541| ERR_CODE_CAST_CONTROL_DEVICE_MISSING<sup>13+</sup>      | 6611105 | 操作失败,因为媒体源设备或媒体接收器设备已被销毁。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8542| ERR_CODE_CAST_CONTROL_INVALID_PARAM<sup>13+</sup>       | 6611106 | 该参数无效。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8543| ERR_CODE_CAST_CONTROL_NO_MEMORY<sup>13+</sup>       | 6611107 | 内存分配失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8544| ERR_CODE_CAST_CONTROL_OPERATION_NOT_ALLOWED<sup>13+</sup>       | 6611108 | 不被允许的操作。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8545| ERR_CODE_CAST_CONTROL_IO_UNSPECIFIED<sup>13+</sup>       | 6612000 | 未指定的输入/输出错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8546| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_FAILED<sup>13+</sup>       | 6612001 | 网络连接失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8547| ERR_CODE_CAST_CONTROL_IO_NETWORK_CONNECTION_TIMEOUT<sup>13+</sup>       | 6612002 | 网络连接超时。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8548| ERR_CODE_CAST_CONTROL_IO_INVALID_HTTP_CONTENT_TYPE <sup>13+</sup>      | 6612003 | 无效的"Content-Type"。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8549| ERR_CODE_CAST_CONTROL_IO_BAD_HTTP_STATUS<sup>13+</sup>        | 6612004 | HTTP服务器返回一个意外的HTTP响应状态码。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8550| ERR_CODE_CAST_CONTROL_IO_FILE_NOT_FOUND<sup>13+</sup>   | 6612005 | 文件不存在。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8551| ERR_CODE_CAST_CONTROL_IO_NO_PERMISSION<sup>13+</sup>    | 6612006 | 不允许执行输入/输出的IO操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8552| ERR_CODE_CAST_CONTROL_IO_CLEARTEXT_NOT_PERMITTED<sup>13+</sup>    | 6612007 | 应用的网络安全配置不允许访问明文HTTP流量。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8553| ERR_CODE_CAST_CONTROL_IO_READ_POSITION_OUT_OF_RANGE<sup>13+</sup>        | 6612008 | 从数据绑定中读取数据。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8554| ERR_CODE_CAST_CONTROL_IO_NO_CONTENTS<sup>13+</sup>     | 6612100 | 媒体中没有可播放的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8555| ERR_CODE_CAST_CONTROL_IO_READ_ERROR<sup>13+</sup>        | 6612101 | 媒体无法读取。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8556| ERR_CODE_CAST_CONTROL_IO_CONTENT_BUSY<sup>13+</sup>         | 6612102 | 该资源正在使用中。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8557| ERR_CODE_CAST_CONTROL_IO_CONTENT_EXPIRED<sup>13+</sup>    | 6612103 | 输入/输出的IO请求内容已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8558| ERR_CODE_CAST_CONTROL_IO_USE_FORBIDDEN<sup>13+</sup>    | 6612104 | 不允许播放请求内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8559| ERR_CODE_CAST_CONTROL_IO_NOT_VERIFIED<sup>13+</sup>     | 6612105 | 无法验证所允许的内容。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8560| ERR_CODE_CAST_CONTROL_IO_EXHAUSTED_ALLOWED_USES<sup>13+</sup>     | 6612106 | 此内容已达到允许的最大使用次数。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8561| ERR_CODE_CAST_CONTROL_IO_NETWORK_PACKET_SENDING_FAILED<sup>13+</sup>   | 6612107 | 从源设备发送数据包到接收设备时出现错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8562| ERR_CODE_CAST_CONTROL_PARSING_UNSPECIFIED<sup>13+</sup>    | 6613000 | 未指定的内容解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8563| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_MALFORMED<sup>13+</sup>    | 6613001 | 媒体容器比特流的格式解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8564| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_MALFORMED<sup>13+</sup>     | 6613002 | 媒体清单解析错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8565| ERR_CODE_CAST_CONTROL_PARSING_CONTAINER_UNSUPPORTED<sup>13+</sup>   | 6613003 | 文件的媒体容器格式/媒体容器特性不被支持。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8566| ERR_CODE_CAST_CONTROL_PARSING_MANIFEST_UNSUPPORTED<sup>13+</sup>      | 6613004 | 媒体清单中不支持的特性。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8567| ERR_CODE_CAST_CONTROL_DECODING_UNSPECIFIED<sup>13+</sup>     | 6614000 | 未指定的解码错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8568| ERR_CODE_CAST_CONTROL_DECODING_INIT_FAILED<sup>13+</sup>   | 6614001 | 解码器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8569| ERR_CODE_CAST_CONTROL_DECODING_QUERY_FAILED<sup>13+</sup>     | 6614002 | 解码器查询失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8570| ERR_CODE_CAST_CONTROL_DECODING_FAILED<sup>13+</sup>     | 6614003 | 媒体样本解码失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8571| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_EXCEEDS_CAPABILITIES<sup>13+</sup>    | 6614004 | 设备的能力无法解码当前格式。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8572| ERR_CODE_CAST_CONTROL_DECODING_FORMAT_UNSUPPORTED<sup>13+</sup>    | 6614005 | 不支持的解码格式。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8573| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_UNSPECIFIED<sup>13+</sup>       | 6615000 | 未指定的音频渲染器错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8574| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_INIT_FAILED <sup>13+</sup>     | 6615001 | 音频渲染器初始化失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8575| ERR_CODE_CAST_CONTROL_AUDIO_RENDERER_WRITE_FAILED<sup>13+</sup>    | 6615002 | 音频渲染器写入数据失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8576| ERR_CODE_CAST_CONTROL_DRM_UNSPECIFIED<sup>13+</sup>      | 6616000 | 未指定的DRM相关错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8577| ERR_CODE_CAST_CONTROL_DRM_SCHEME_UNSUPPORTED<sup>13+</sup>  | 6616001 | 设备不支持所选择的DRM保护方案。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8578| ERR_CODE_CAST_CONTROL_DRM_PROVISIONING_FAILED<sup>13+</sup>   | 6616002 | 设备配置失败。<br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8579| ERR_CODE_CAST_CONTROL_DRM_CONTENT_ERROR<sup>13+</sup>  | 6616003 | 受DRM保护的内容无法播放。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8580| ERR_CODE_CAST_CONTROL_DRM_LICENSE_ACQUISITION_FAILED<sup>13+</sup>    | 6616004 | 获取许可证失败。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8581| ERR_CODE_CAST_CONTROL_DRM_DISALLOWED_OPERATION<sup>13+</sup>     | 6616005 | 许可证策略不允许该操作。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8582| ERR_CODE_CAST_CONTROL_DRM_SYSTEM_ERROR<sup>13+</sup>     | 6616006 | DRM系统中发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8583| ERR_CODE_CAST_CONTROL_DRM_DEVICE_REVOKED<sup>13+</sup>     | 6616007 | 设备已撤销DRM权限。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8584| ERR_CODE_CAST_CONTROL_DRM_LICENSE_EXPIRED<sup>13+</sup>   | 6616008 | 加载中的DRM许可证已过期。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8585| ERR_CODE_CAST_CONTROL_DRM_PROVIDE_KEY_RESPONSE_ERROR<sup>13+</sup>    | 6616100 | DRM处理密钥响应时发生错误。 <br>**原子化服务API:** 从API version 13开始,该接口支持在原子化服务中使用。<br>**系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
8586
8587## SkipIntervals<sup>11+</sup>
8588
8589表示session支持的快进快退时间间隔的枚举。
8590
8591**系统能力:** SystemCapability.Multimedia.AVSession.Core
8592
8593| 名称                   | 值 | 说明                     |
8594| ---------------------- | -- | ----------------------- |
8595| SECONDS_10             | 10 | 时间为10秒。             |
8596| SECONDS_15             | 15 | 时间为15秒。             |
8597| SECONDS_30             | 30 | 时间为30秒。             |
8598