• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.avsession (媒体会话管理)(系统接口)
2
3媒体会话管理提供媒体播控相关功能的接口,目的是让应用接入播控中心。
4
5该模块提供以下媒体会话相关的常用功能:
6
7- [AVCastController](#avcastcontroller10): 投播控制器,可用于投播场景下,完成播放控制、远端播放状态监听、远端播放状态信息获取等操作。
8
9> **说明:**
10>
11> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
12> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.multimedia.avsession (媒体会话管理)](js-apis-avsession.md)。
13
14## 导入模块
15
16```ts
17import { avSession } from '@kit.AVSessionKit';
18```
19
20## 使用说明
21
22本文档仅提供系统接口说明,以下接口的使用说明均需先创建实例,请参考公开接口[avSession.createAVSession](js-apis-avsession.md#avsessioncreateavsession10)的说明及示例,创建对应实例。
23
24## avSession.getAllSessionDescriptors
25
26getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>>
27
28获取所有设置过媒体信息且注册控制回调的会话的相关描述。结果通过Promise异步回调方式返回。
29
30**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
31
32**系统能力:** SystemCapability.Multimedia.AVSession.Manager
33
34**系统接口:** 该接口为系统接口。
35
36**返回值:**
37
38| 类型                                                         | 说明                                          |
39| ------------------------------------------------------------ | --------------------------------------------- |
40| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise对象。返回所有会话描述的只读对象。 |
41
42**错误码:**
43
44以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
45
46| 错误码ID | 错误信息 |
47| -------- | ---------------------------------------- |
48| 201 | permission denied. |
49| 6600101  | Session service exception. |
50
51**示例:**
52
53```ts
54import { BusinessError } from '@kit.BasicServicesKit';
55
56avSession.getAllSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => {
57  console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
58  if (descriptors.length > 0 ) {
59    console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
60    console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
61    console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
62  }
63}).catch((err: BusinessError) => {
64  console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
65});
66```
67
68## avSession.getAllSessionDescriptors
69
70getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void
71
72获取所有设置过媒体信息且注册控制回调的会话的相关描述。结果通过callback异步回调方式返回。
73
74**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
75
76**系统能力:** SystemCapability.Multimedia.AVSession.Manager
77
78**系统接口:** 该接口为系统接口。
79
80**参数:**
81
82| 参数名   | 类型                                                         | 必填 | 说明                                       |
83| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
84| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | 是   | 回调函数。返回所有会话描述的只读对象。 |
85
86**错误码:**
87
88以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
89
90| 错误码ID | 错误信息 |
91| -------- | ---------------------------------------- |
92| 201 | permission denied. |
93| 6600101  |Session service exception. |
94
95**示例:**
96
97```ts
98import { BusinessError } from '@kit.BasicServicesKit';
99
100avSession.getAllSessionDescriptors((err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => {
101  if (err) {
102    console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
103  } else {
104    console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
105    if (descriptors.length > 0 ) {
106        console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
107        console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
108        console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
109    }
110  }
111});
112```
113
114## avSession.getHistoricalSessionDescriptors<sup>10+</sup>
115
116getHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVSessionDescriptor>>>
117
118获取所有已被销毁的会话相关描述。结果通过Promise异步回调方式返回。
119
120**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
121
122**系统能力:** SystemCapability.Multimedia.AVSession.Manager
123
124**系统接口:** 该接口为系统接口。
125
126**参数:**
127
128| 参数名   | 类型    | 必填 | 说明                                                             |
129| -------- | ------ | ---- | -----------------------------------------------------------------|
130| maxSize  | number | 否   | 指定获取描述符数量的最大值,可选范围是0-10,不填则取默认值,默认值为3。|
131
132**返回值:**
133
134| 类型                                                                        | 说明                                   |
135| --------------------------------------------------------------------------- | -------------------------------------- |
136| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise对象。返回所有会话描述的只读对象。 |
137
138**错误码:**
139
140以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
141
142| 错误码ID | 错误信息 |
143| -------- | ---------------------------------------- |
144| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
145| 6600101  | Session service exception. |
146
147**示例:**
148
149```ts
150import { BusinessError } from '@kit.BasicServicesKit';
151
152avSession.getHistoricalSessionDescriptors().then((descriptors: avSession.AVSessionDescriptor[]) => {
153  console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
154  if (descriptors.length > 0 ) {
155    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
156    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
157    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
158    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`);
159    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`);
160  }
161}).catch((err: BusinessError) => {
162  console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
163});
164```
165
166## avSession.getHistoricalSessionDescriptors<sup>10+</sup>
167
168getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void
169
170获取所有已被销毁的会话相关描述。结果通过callback异步回调方式返回。
171
172**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES173
174**系统能力:** SystemCapability.Multimedia.AVSession.Manager
175
176**系统接口:** 该接口为系统接口。
177
178**参数:**
179
180| 参数名   | 类型                                                                            | 必填 | 说明                                                             |
181| -------- | ------------------------------------------------------------------------------ | ---- | -----------------------------------------------------------------|
182| maxSize  | number                                                                         | 是  | 指定获取描述符数量的最大值,可选范围是0-10。|
183| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | 是   | 回调函数。返回所有会话描述的只读对象。                              |
184
185**错误码:**
186
187以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
188
189| 错误码ID | 错误信息 |
190| -------- | ---------------------------------------- |
191| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
192| 6600101  |Session service exception. |
193
194**示例:**
195
196```ts
197import { BusinessError } from '@kit.BasicServicesKit';
198
199avSession.getHistoricalSessionDescriptors(1, (err: BusinessError, descriptors: avSession.AVSessionDescriptor[]) => {
200  if (err) {
201    console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
202  } else {
203    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
204    if (descriptors.length > 0 ) {
205      console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
206      console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
207      console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
208      console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`);
209      console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`);
210    }
211  }
212});
213```
214
215## avSession.getHistoricalAVQueueInfos<sup>11+</sup>
216
217getHistoricalAVQueueInfos(maxSize: number, maxAppSize: number) : Promise\<Array\<Readonly\<AVQueueInfo>>>
218
219获取全部的历史播放歌单。结果通过Promise异步回调方式返回。
220
221**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
222
223**系统能力:** SystemCapability.Multimedia.AVSession.Manager
224
225**系统接口:** 该接口为系统接口。
226
227**参数:**
228
229| 参数名   | 类型    | 必填 | 说明                                                             |
230| -------- | ------ | ---- | ---------------------------------------------------------------|
231| maxSize  | number | 是   | 指定获取歌曲列表数量的最大值,暂与获取歌单数量无关。                     |
232| maxAppSize | number | 是   | 指定获取歌曲列表所属应用数量的最大值,暂与获取歌单数量无关。             |
233
234**返回值:**
235
236| 类型                                                                        | 说明                                   |
237| --------------------------------------------------------------------------- | ------------------------------------- |
238| Promise\<Array\<Readonly\<[AVQueueInfo](#avqueueinfo11)\>\>\> | Promise对象。返回所有历史播放歌单的只读对象。                |
239
240**错误码:**
241
242以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
243
244| 错误码ID | 错误信息 |
245| -------- | ---------------------------------------- |
246| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
247| 6600101  | Session service exception. |
248
249**示例:**
250
251```ts
252import { BusinessError } from '@kit.BasicServicesKit';
253
254avSession.getHistoricalAVQueueInfos(3, 5).then((avQueueInfos: avSession.AVQueueInfo[]) => {
255  console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`);
256}).catch((err: BusinessError) => {
257  console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`);
258});
259```
260
261## avSession.getHistoricalAVQueueInfos<sup>11+</sup>
262
263getHistoricalAVQueueInfos(maxSize: number, maxAppSize: number, callback: AsyncCallback\<Array\<Readonly\<AVQueueInfo>>>): void;
264
265获取全部的历史播放歌单。结果通过callback异步回调方式返回。
266
267**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES268
269**系统能力:** SystemCapability.Multimedia.AVSession.Manager
270
271**系统接口:** 该接口为系统接口。
272
273**参数:**
274
275| 参数名   | 类型                                                                            | 必填 | 说明                                                             |
276| -------- | ----------------------------------------------------------------------------- | ---- | ---------------------------------------------------------------|
277| maxSize  | number                                                                        | 是   | 指定获取歌曲列表数量的最大值,暂与获取歌单数量无关。                      |
278| maxAppSize | number                                                                      | 是   | 指定获取歌曲列表所属应用数量的最大值,暂与获取歌单数量无关。               |
279| callback | AsyncCallback<Array<Readonly<[AVQueueInfo](#avqueueinfo11)\>\>\> | 是   | 回调函数。返回所有历史播放歌单的只读对象。                              |
280
281**错误码:**
282
283以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
284
285| 错误码ID | 错误信息 |
286| -------- | ---------------------------------------- |
287| 201 | permission denied. |
288| 202 | Not System App. |
289| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
290| 6600101  |Session service exception. |
291
292**示例:**
293
294```ts
295import { BusinessError } from '@kit.BasicServicesKit';
296
297avSession.getHistoricalAVQueueInfos(3, 5, (err: BusinessError, avQueueInfos: avSession.AVQueueInfo[]) => {
298  if (err) {
299    console.error(`getHistoricalAVQueueInfos BusinessError: code: ${err.code}, message: ${err.message}`);
300  } else {
301    console.info(`getHistoricalAVQueueInfos : SUCCESS : avQueueInfos.length : ${avQueueInfos.length}`);
302  }
303});
304```
305
306## avSession.createController
307
308createController(sessionId: string): Promise\<AVSessionController>
309
310根据会话ID创建会话控制器,可以创建多个会话控制器。结果通过Promise异步回调方式返回。
311
312**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
313
314**系统能力:** SystemCapability.Multimedia.AVSession.Manager
315
316**系统接口:** 该接口为系统接口。
317
318**参数:**
319
320| 参数名    | 类型   | 必填 | 说明     |
321| --------- | ------ | ---- | -------- |
322| sessionId | string | 是   | 会话ID,如果提供 'default',系统将创建一个默认控制器,用于控制系统默认会话。 |
323
324**返回值:**
325
326| 类型                                                  | 说明                                                         |
327| ----------------------------------------------------- | ------------------------------------------------------------ |
328| Promise<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\> | Promise对象。返回会话控制器实例,可查看会话ID,<br>并完成对会话发送命令及事件,获取元数据、播放状态信息等操作。|
329
330**错误码:**
331
332以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
333
334| 错误码ID | 错误信息 |
335| -------- | ---------------------------------------- |
336| 201 | permission denied. |
337| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
338| 6600101  | Session service exception. |
339| 6600102  | The session does not exist. |
340
341**示例:**
342
343```ts
344import { BusinessError } from '@kit.BasicServicesKit';
345
346let currentAVcontroller: avSession.AVSessionController | undefined = undefined;
347currentAvSession.createController(sessionId).then((avcontroller: avSession.AVSessionController) => {
348  currentAVcontroller = avcontroller;
349  console.info('CreateController : SUCCESS ');
350}).catch((err: BusinessError) => {
351  console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
352});
353```
354
355## avSession.createController
356
357createController(sessionId: string, callback: AsyncCallback\<AVSessionController>): void
358
359根据会话ID创建会话控制器,可以创建多个会话控制器。结果通过callback异步回调方式返回。
360
361**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
362
363**系统能力:** SystemCapability.Multimedia.AVSession.Manager
364
365**系统接口:** 该接口为系统接口。
366
367**参数:**
368
369| 参数名    | 类型                                                        | 必填 | 说明                                                         |
370| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
371| sessionId | string                                                      | 是   | 会话ID,如果提供 'default',系统将创建一个默认控制器,用于控制系统默认会话。                                                     |
372| callback  | AsyncCallback<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\> | 是   | 回调函数。返回会话控制器实例,可查看会话ID,<br>并完成对会话发送命令及事件,获取元数据、播放状态信息等操作。 |
373
374**错误码:**
375
376以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
377
378| 错误码ID | 错误信息 |
379| -------- | ---------------------------------------- |
380| 201 | permission denied. |
381| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
382| 6600101  | Session service exception. |
383| 6600102  | The session does not exist. |
384
385**示例:**
386
387```ts
388import { BusinessError } from '@kit.BasicServicesKit';
389
390let currentAVcontroller: avSession.AVSessionController | undefined = undefined;
391currentAvSession.createController(sessionId, (err: BusinessError, avcontroller: avSession.AVSessionController) => {
392  if (err) {
393    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
394  } else {
395    currentAVcontroller = avcontroller;
396    console.info('CreateController : SUCCESS ');
397  }
398});
399```
400
401## avSession.castAudio
402
403castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise\<void>
404
405投播会话到指定设备列表。结果通过Promise异步回调方式返回。
406
407调用此接口之前,需要导入`ohos.multimedia.audio`模块获取AudioDeviceDescriptor的相关描述。
408
409**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
410
411**系统能力:** SystemCapability.Multimedia.AVSession.Manager
412
413**系统接口:** 该接口为系统接口。
414
415**参数:**
416
417| 参数名        | 类型           | 必填 | 说明 |
418| ------------ | -------------- |------|------|
419| session      | [SessionToken](#sessiontoken) &#124; 'all' | 是   | 会话令牌。SessionToken表示单个token;字符串`'all'`指所有token。 |
420| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/js-apis-audio.md#audiodevicedescriptor)\> | 是   | 媒体设备列表。  |
421
422**返回值:**
423
424| 类型           | 说明                          |
425| -------------- | ----------------------------- |
426| Promise\<void> | Promise对象。当投播成功,无返回结果,否则返回错误对象。 |
427
428**错误码:**
429
430以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
431
432| 错误码ID | 错误信息 |
433| -------- | ---------------------------------------- |
434| 201 | permission denied. |
435| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
436| 6600101  | Session service exception. |
437| 6600102  | The session does not exist. |
438| 6600104  | The remote session connection failed. |
439
440**示例:**
441
442```ts
443import { audio } from '@kit.AudioKit';
444import { BusinessError } from '@kit.BasicServicesKit';
445
446let audioManager = audio.getAudioManager();
447let audioRoutingManager = audioManager.getRoutingManager();
448let audioDevices: audio.AudioDeviceDescriptors | undefined = undefined;
449audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
450  audioDevices = data;
451  console.info('Promise returned to indicate that the device list is obtained.');
452}).catch((err: BusinessError) => {
453  console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
454});
455
456if (audioDevices !== undefined) {
457  avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors).then(() => {
458    console.info('CreateController : SUCCESS');
459  }).catch((err: BusinessError) => {
460    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
461  });
462}
463```
464
465## avSession.castAudio
466
467castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void
468
469投播会话到指定设备列表。结果通过callback异步回调方式返回。
470
471需要导入`ohos.multimedia.audio`模块获取AudioDeviceDescriptor的相关描述。
472
473**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
474
475**系统能力:** SystemCapability.Multimedia.AVSession.Manager
476
477**系统接口:** 该接口为系统接口。
478
479**参数:**
480
481| 参数名       | 类型                                         | 必填 | 说明                                                         |
482| ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ |
483| session      | [SessionToken](#sessiontoken) &#124; 'all' | 是   | 会话令牌。SessionToken表示单个token;字符串`'all'`指所有token。 |
484| audioDevices | Array\<[audio.AudioDeviceDescriptor](../apis-audio-kit/js-apis-audio.md#audiodevicedescriptor)\>   | 是   | 媒体设备列表。 |
485| callback     | AsyncCallback\<void>     | 是   | 回调函数。当投播成功,err为undefined,否则返回错误对象。      |
486
487**错误码:**
488
489以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
490
491| 错误码ID | 错误信息 |
492| -------- | ---------------------------------------- |
493| 201 | permission denied. |
494| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
495| 6600101  | Session service exception. |
496| 6600102  | The session does not exist. |
497| 6600104  | The remote session connection failed. |
498
499**示例:**
500
501```ts
502import { audio } from '@kit.AudioKit';
503import { BusinessError } from '@kit.BasicServicesKit';
504
505let audioManager = audio.getAudioManager();
506let audioRoutingManager = audioManager.getRoutingManager();
507let audioDevices: audio.AudioDeviceDescriptors | undefined = undefined;
508audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
509  audioDevices = data;
510  console.info('Promise returned to indicate that the device list is obtained.');
511}).catch((err: BusinessError) => {
512  console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
513});
514
515if (audioDevices !== undefined) {
516  avSession.castAudio('all', audioDevices as audio.AudioDeviceDescriptors, (err: BusinessError) => {
517    if (err) {
518      console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`);
519    } else {
520      console.info('CastAudio : SUCCESS ');
521    }
522  });
523}
524```
525
526## avSession.startAVPlayback<sup>11+</sup>
527
528startAVPlayback(bundleName: string, assetId: string): Promise\<void>
529
530启动媒体播放应用程序。结果通过Promise异步回调方式返回。
531
532**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
533
534**系统能力:** SystemCapability.Multimedia.AVSession.Manager
535
536**系统接口:** 该接口为系统接口。
537
538**参数:**
539
540| 参数名        | 类型           | 必填 | 说明 |
541| ------------ | -------------- |------|------|
542| bundleName   | string         | 是   | 指定应用包名。 |
543| assetId      |string           | 是   | 指定媒体ID。  |
544
545**返回值:**
546
547| 类型           | 说明                          |
548| -------------- | ----------------------------- |
549| Promise\<void> | Promise对象。当播放成功,无返回结果,否则返回错误对象。 |
550
551**错误码:**
552
553以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
554
555| 错误码ID | 错误信息 |
556| -------- | ---------------------------------------- |
557| 201 | permission denied. |
558| 202 | Not System App. Interface caller is not a system app. |
559| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
560| 6600101  | Session service exception. |
561
562**示例:**
563
564```ts
565import { audio } from '@kit.AudioKit';
566import { BusinessError } from '@kit.BasicServicesKit';
567
568avSession.startAVPlayback("com.example.myapplication", "121278").then(() => {
569  console.info('startAVPlayback : SUCCESS');
570}).catch((err: BusinessError) => {
571  console.error(`startAVPlayback BusinessError: code: ${err.code}, message: ${err.message}`);
572});
573```
574
575## avSession.getDistributedSessionController<sup>18+</sup>
576
577getDistributedSessionController(distributedSessionType: DistributedSessionType): Promise<Array\<AVSessionController>>
578
579根据远端会话类型,获取远端分布式会话控制器。结果通过Promise异步回调方式返回。
580
581**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
582
583**系统能力:** SystemCapability.Multimedia.AVSession.Manager
584
585**系统接口:** 该接口为系统接口。
586
587**参数:**
588
589| 参数名    | 类型                                                                      | 必填 | 说明      |
590| --------- |-------------------------------------------------------------------------| ---- |---------|
591| distributedSessionType | [DistributedSessionType](#distributedsessiontype18) | 是   | 远端会话类型。 |
592
593**返回值:**
594
595| 类型                                                                                 | 说明                                                                    |
596|------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
597| Promise<Array<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\>> | Promise对象。返回对应类型的会话控制器实例列表,可查看会话ID,并完成对会话发送命令及事件,获取元数据、播放状态信息等操作。 |
598
599**错误码:**
600
601以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
602
603| 错误码ID   | 错误信息                                                                                                  |
604|---------|-------------------------------------------------------------------------------------------------------|
605| 201     | permission denied.                                                                                    |
606| 202     | Not System App. Interface caller is not a system app.                                                                                       |
607| 6600101 | Session service exception.                                                                            |
608| 6600109 | The remote connection is not established.                                                             |
609
610**示例:**
611
612```ts
613import { BusinessError } from '@kit.BasicServicesKit';
614
615avSession.getDistributedSessionController(avSession.DistributedSessionType.TYPE_SESSION_REMOTE).then((sessionControllers: Array<avSession.AVSessionController>) => {
616  console.info(`getDistributedSessionController : SUCCESS : sessionControllers.length : ${sessionControllers.length}`);
617}).catch((err: BusinessError) => {
618  console.error(`getDistributedSessionController BusinessError: code: ${err.code}, message: ${err.message}`);
619});
620```
621
622
623## SessionToken
624
625会话令牌的信息。
626
627**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
628
629**系统能力:** SystemCapability.Multimedia.AVSession.Manager
630
631**系统接口:** 该接口为系统接口。
632
633| 名称      | 类型   | 必填 | 说明         |
634| :-------- | :----- | :--- | :----------- |
635| sessionId | string | 是   | 会话ID。       |
636| pid       | number | 否   | 会话的进程ID。 |
637| uid       | number | 否   | 用户ID。       |
638
639## avSession.on('sessionCreate')
640
641on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void
642
643会话的创建监听事件。
644
645**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
646
647**系统能力:** SystemCapability.Multimedia.AVSession.Manager
648
649**系统接口:** 该接口为系统接口。
650
651**参数:**
652
653| 参数名    | 类型                   | 必填 | 说明                                                         |
654| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
655| type     | string                 | 是   | 事件回调类型,支持的事件是'sessionCreate':会话创建事件,检测到会话创建时触发。|
656| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 是   | 回调函数。参数为会话相关描述。 |
657
658**错误码:**
659
660以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
661
662| 错误码ID | 错误信息 |
663| -------- | ---------------------------------------- |
664| 201 | permission denied. |
665| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
666| 6600101  | Session service exception. |
667
668**示例:**
669
670```ts
671avSession.on('sessionCreate', (descriptor: avSession.AVSessionDescriptor) => {
672  console.info(`on sessionCreate : isActive : ${descriptor.isActive}`);
673  console.info(`on sessionCreate : type : ${descriptor.type}`);
674  console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`);
675});
676
677```
678
679## avSession.on('sessionDestroy')
680
681on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void
682
683会话的销毁监听事件。
684
685**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
686
687**系统能力:** SystemCapability.Multimedia.AVSession.Manager
688
689**系统接口:** 该接口为系统接口。
690
691**参数:**
692
693| 参数名   | 类型            | 必填 | 说明                                                         |
694| -------- | ---------------| ---- | ------------------------------------------------------------ |
695| type     | string         | 是   | 事件回调类型,支持的事件包括是`'sessionDestroy'`:会话销毁事件,检测到会话销毁时触发。|
696| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 是   | 回调函数。参数为会话相关描述。 |
697
698**错误码:**
699
700以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
701
702| 错误码ID | 错误信息 |
703| -------- | ---------------------------------------- |
704| 201 | permission denied. |
705| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
706| 6600101  | Session service exception. |
707
708**示例:**
709
710```ts
711avSession.on('sessionDestroy', (descriptor: avSession.AVSessionDescriptor) => {
712  console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`);
713  console.info(`on sessionDestroy : type : ${descriptor.type}`);
714  console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`);
715});
716```
717
718## avSession.on('topSessionChange')
719
720on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void
721
722最新会话变更的监听事件。
723
724**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
725
726**系统能力:** SystemCapability.Multimedia.AVSession.Manager
727
728**系统接口:** 该接口为系统接口。
729
730**参数:**
731
732| 参数名   | 类型                 | 必填 | 说明                                                         |
733| -------- | --------------------| ---- | ------------------------------------------------------------ |
734| type     | string      | 是   | 事件回调类型,支持的事件包括是 `'topSessionChange'`:最新会话的变化事件,检测到最新的会话改变时触发。|
735| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 是   | 回调函数。参数为会话相关描述。 |
736
737**错误码:**
738
739以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
740
741| 错误码ID | 错误信息 |
742| -------- | ---------------------------------------- |
743| 201 | permission denied. |
744| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
745| 6600101  | Session service exception. |
746
747**示例:**
748
749```ts
750avSession.on('topSessionChange', (descriptor: avSession.AVSessionDescriptor) => {
751  console.info(`on topSessionChange : isActive : ${descriptor.isActive}`);
752  console.info(`on topSessionChange : type : ${descriptor.type}`);
753  console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`);
754});
755```
756
757## avSession.off('sessionCreate')
758
759off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void
760
761取消会话创建事件监听,取消后,不再进行该事件的监听。
762
763**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
764
765**系统能力:** SystemCapability.Multimedia.AVSession.Manager
766
767**系统接口:** 该接口为系统接口。
768
769**参数:**
770
771| 参数名   | 类型       | 必填 | 说明       |
772| -------- | ----------| ---- | ----------|
773| type     | string    | 是   | 事件回调类型,支持的事件为:`'sessionCreate'`。|
774| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为会话相关描述,为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。                               |
775
776**错误码:**
777
778以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
779
780| 错误码ID | 错误信息 |
781| -------- | ---------------------------------------- |
782| 201 | permission denied. |
783| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
784| 6600101  | Session service exception. |
785
786**示例:**
787
788```ts
789avSession.off('sessionCreate');
790```
791
792## avSession.off('sessionDestroy')
793
794off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void
795
796取消会话销毁事件监听,取消后,不再进行该事件的监听。
797
798**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
799
800**系统能力:** SystemCapability.Multimedia.AVSession.Manager
801
802**系统接口:** 该接口为系统接口。
803
804**参数:**
805
806| 参数名   | 类型        | 必填 | 说明                      |
807| -------- | -----------| ---- | -------------------------|
808| type     | string     | 是   | 事件回调类型,支持的事件为`'sessionDestroy'`。|
809| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为会话相关描述,为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。|
810
811**错误码:**
812
813以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
814
815| 错误码ID | 错误信息 |
816| -------- | ---------------------------------------- |
817| 201 | permission denied. |
818| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
819| 6600101  | Session service exception. |
820
821**示例:**
822
823```ts
824avSession.off('sessionDestroy');
825```
826
827## avSession.off('topSessionChange')
828
829off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void
830
831取消最新会话变更事件监听,取消后,不再进行该事件的监听。
832
833**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
834
835**系统能力:** SystemCapability.Multimedia.AVSession.Manager
836
837**系统接口:** 该接口为系统接口。
838
839**参数:**
840
841| 参数名   | 类型              | 必填 | 说明                        |
842| -------- | -----------------| ---- | ---------------------------- |
843| type     | string           | 是   | 事件回调类型,支持的事件为`'topSessionChange'`。|
844| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | 否   | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为会话相关描述,为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 |
845
846**错误码:**
847
848以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
849
850| 错误码ID | 错误信息 |
851| -------- | ---------------------------------------- |
852| 201 | permission denied. |
853| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
854| 6600101  | Session service exception. |
855
856**示例:**
857
858```ts
859avSession.off('topSessionChange');
860```
861
862## avSession.on('sessionServiceDie')
863
864on(type: 'sessionServiceDie', callback: () => void): void
865
866监听会话的服务死亡事件。通知应用清理资源。
867
868**系统能力:** SystemCapability.Multimedia.AVSession.Core
869
870**系统接口:** 该接口为系统接口。
871
872**参数:**
873
874| 参数名   | 类型                 | 必填 | 说明                                                         |
875| -------- | -------------------- | ---- | ------------------------------------------------------------ |
876| type     | string               | 是   | 事件回调类型,支持事件`'sessionServiceDie'`:会话服务死亡事件,检测到会话的服务死亡时触发。 |
877| callback | callback: () => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。                                |
878
879**错误码:**
880
881以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
882
883| 错误码ID | 错误信息 |
884| -------- | ---------------------------------------- |
885| 201 | permission denied. |
886| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
887| 6600101  | Session service exception. |
888
889**示例:**
890
891```ts
892avSession.on('sessionServiceDie', () => {
893  console.info('on sessionServiceDie  : session is  Died ');
894});
895```
896
897## avSession.off('sessionServiceDie')
898
899off(type: 'sessionServiceDie', callback?: () => void): void
900
901取消会话服务死亡监听,取消后,不再进行服务死亡监听。
902
903**系统能力:** SystemCapability.Multimedia.AVSession.Core
904
905**系统接口:** 该接口为系统接口。
906
907**参数:**
908
909| 参数名    | 类型                    | 必填  |      说明                                               |
910| ------   | ---------------------- | ---- | ------------------------------------------------------- |
911| type     | string                 | 是    | 事件回调类型,支持事件`'sessionServiceDie'`:会话服务死亡事件。|
912| callback | callback: () => void   | 否    | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。<br>该参数为可选参数,若不填写该参数,则认为取消所有相关会话的服务死亡监听。            |
913
914**错误码:**
915
916以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
917
918| 错误码ID | 错误信息 |
919| -------- | ---------------------------------------- |
920| 201 | permission denied. |
921| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
922| 6600101  | Session service exception. |
923
924**示例:**
925
926```ts
927avSession.off('sessionServiceDie');
928```
929
930
931## avSession.on('distributedSessionChange')<sup>18+</sup>
932
933on(type: 'distributedSessionChange', distributedSessionType: DistributedSessionType, callback: Callback<Array\<AVSessionController>>): void
934
935最新分布式远端会话变更的监听事件。
936
937**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
938
939**系统能力:** SystemCapability.Multimedia.AVSession.Manager
940
941**系统接口:** 该接口为系统接口。
942
943**参数:**
944
945| 参数名   | 类型                                                                                  | 必填 | 说明                                                                       |
946| -------- |-------------------------------------------------------------------------------------| ---- |--------------------------------------------------------------------------|
947| type     | string                                                                              | 是   | 事件回调类型,支持的事件为 `'distributedSessionChange'`:最新远端分布式会话的变化事件,检测到最新的会话改变时触发。 |
948| distributedSessionType     | [DistributedSessionType](#distributedsessiontype18)             | 是   | 远端会话类型。                                                                  |
949| callback | Callback<Array<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\>> | 是   | 回调函数。参数为对应类型的会话控制器实例列表,可查看会话ID,并完成对会话发送命令及事件,获取元数据、播放状态信息等操作。            |
950
951**错误码:**
952
953以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
954
955| 错误码ID   | 错误信息                                                                                              |
956|---------|---------------------------------------------------------------------------------------------------|
957| 202     | Not System App. Interface caller is not a system app.                                                                                   |
958| 6600101 | Session service exception.                                                                        |
959
960**示例:**
961
962```ts
963avSession.on('distributedSessionChange', avSession.DistributedSessionType.TYPE_SESSION_REMOTE, (sessionControllers: Array<avSession.AVSessionController>) => {
964  console.info(`on distributedSessionChange size: ${sessionControllers.length}`);
965});
966```
967
968
969## avSession.off('distributedSessionChange')<sup>18+</sup>
970
971off(type: 'distributedSessionChange', distributedSessionType: DistributedSessionType, callback?: Callback<Array\<AVSessionController>>): void
972
973取消最新分布式远端会话变更的监听事件,取消后,不再进行该事件的监听。
974
975**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
976
977**系统能力:** SystemCapability.Multimedia.AVSession.Manager
978
979**系统接口:** 该接口为系统接口。
980
981**参数:**
982
983| 参数名   | 类型                                                                                  | 必填 | 说明                                                            |
984| -------- |-------------------------------------------------------------------------------------|----|---------------------------------------------------------------|
985| type     | string                                                                              | 是  | 事件回调类型,支持的事件为`'distributedSessionChange'`。                    |
986| distributedSessionType     | [DistributedSessionType](#distributedsessiontype18)             | 是  | 远端会话类型。                                                       |
987| callback | Callback<Array<[AVSessionController](js-apis-avsession.md#avsessioncontroller10)\>> | 否  | 回调函数。参数为对应类型的会话控制器实例列表,可查看会话ID,并完成对会话发送命令及事件,获取元数据、播放状态信息等操作。 |
988
989**错误码:**
990
991以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
992
993| 错误码ID   | 错误信息                                                                                              |
994|---------|---------------------------------------------------------------------------------------------------|
995| 202     | Not System App. Interface caller is not a system app.                                                                                   |
996| 6600101 | Session service exception.                                                                        |
997
998**示例:**
999
1000```ts
1001avSession.off('distributedSessionChange', avSession.DistributedSessionType.TYPE_SESSION_REMOTE);
1002```
1003
1004## avSession.sendSystemAVKeyEvent
1005
1006sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
1007
1008发送按键事件给置顶会话。结果通过callback异步回调方式返回。
1009
1010**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1011
1012**系统能力:** SystemCapability.Multimedia.AVSession.Manager
1013
1014**系统接口:** 该接口为系统接口。
1015
1016**参数:**
1017
1018| 参数名   | 类型                                                         | 必填 | 说明                                  |
1019| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- |
1020| event    | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | 是   | 按键事件。                            |
1021| callback | AsyncCallback\<void>                                         | 是   | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 |
1022
1023**错误码:**
1024
1025以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1026
1027| 错误码ID | 错误信息 |
1028| -------- | ---------------------------------------- |
1029| 201 | permission denied. |
1030| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1031| 6600101  | Session service exception. |
1032| 6600105  | Invalid session command. |
1033
1034**示例:**
1035
1036```ts
1037import { KeyEvent } from '@kit.InputKit';
1038import { BusinessError } from '@kit.BasicServicesKit';
1039
1040let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0};
1041let event: keyEvent.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};
1042
1043avSession.sendSystemAVKeyEvent(event, (err: BusinessError) => {
1044  if (err) {
1045    console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
1046  } else {
1047    console.info('SendSystemAVKeyEvent : SUCCESS ');
1048  }
1049});
1050```
1051
1052## avSession.sendSystemAVKeyEvent
1053
1054sendSystemAVKeyEvent(event: KeyEvent): Promise\<void>
1055
1056发送按键事件给置顶会话。结果通过Promise异步回调方式返回。
1057
1058**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1059
1060**系统能力:** SystemCapability.Multimedia.AVSession.Manager
1061
1062**系统接口:** 该接口为系统接口。
1063
1064**参数:**
1065
1066| 参数名 | 类型                            | 必填 | 说明       |
1067| ------ | ------------------------------- | ---- | ---------- |
1068| event  | [KeyEvent](../apis-input-kit/js-apis-keyevent.md#keyevent) | 是   | 按键事件。 |
1069
1070**返回值:**
1071
1072| 类型           | 说明                          |
1073| -------------- | ----------------------------- |
1074| Promise\<void> | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 |
1075
1076**错误码:**
1077
1078以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1079
1080| 错误码ID | 错误信息 |
1081| -------- | ---------------------------------------- |
1082| 201 | permission denied. |
1083| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1084| 6600101  | Session service exception. |
1085| 6600105  | Invalid session command. |
1086
1087**示例:**
1088
1089```ts
1090import { KeyEvent } from '@kit.InputKit';
1091import { BusinessError } from '@kit.BasicServicesKit';
1092
1093let keyItem: keyEvent.Key = {code:0x49, pressedTime:2, deviceId:0};
1094let event: keyEvent.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};
1095
1096avSession.sendSystemAVKeyEvent(event).then(() => {
1097  console.info('SendSystemAVKeyEvent Successfully');
1098}).catch((err: BusinessError) => {
1099  console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
1100});
1101```
1102
1103## avSession.sendSystemControlCommand
1104
1105sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
1106
1107发送控制命令给置顶会话。结果通过callback异步回调方式返回。
1108
1109**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1110
1111**系统能力:** SystemCapability.Multimedia.AVSession.Manager
1112
1113**系统接口:** 该接口为系统接口。
1114
1115**参数:**
1116
1117| 参数名   | 类型                                  | 必填 | 说明                                  |
1118| -------- | ------------------------------------- | ---- | ------------------------------------- |
1119| command  | [AVControlCommand](js-apis-avsession.md#avcontrolcommand10) | 是   | AVSession的相关命令和命令相关参数。   |
1120| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 |
1121
1122**错误码:**
1123
1124以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1125
1126| 错误码ID | 错误信息 |
1127| -------- | ---------------------------------------- |
1128| 201 | permission denied. |
1129| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1130| 6600101  | Session service exception. |
1131| 6600105  | Invalid session command. |
1132| 6600107  | Too many commands or events. |
1133
1134**示例:**
1135
1136```ts
1137let cmd : avSession.AVControlCommandType = 'play';
1138// let cmd : avSession.AVControlCommandType = 'pause';
1139// let cmd : avSession.AVControlCommandType = 'stop';
1140// let cmd : avSession.AVControlCommandType = 'playNext';
1141// let cmd : avSession.AVControlCommandType = 'playPrevious';
1142// let cmd : avSession.AVControlCommandType = 'fastForward';
1143// let cmd : avSession.AVControlCommandType = 'rewind';
1144let avcommand: avSession.AVControlCommand = {command:cmd};
1145// let cmd : avSession.AVControlCommandType = 'seek';
1146// let avcommand = {command:cmd, parameter:10};
1147// let cmd : avSession.AVControlCommandType = 'setSpeed';
1148// let avcommand = {command:cmd, parameter:2.6};
1149// let cmd : avSession.AVControlCommandType = 'setLoopMode';
1150// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
1151// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
1152// let avcommand = {command:cmd, parameter:"false"};
1153avSession.sendSystemControlCommand(avcommand, (err) => {
1154  if (err) {
1155    console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
1156  } else {
1157    console.info('sendSystemControlCommand successfully');
1158  }
1159});
1160```
1161
1162## avSession.sendSystemControlCommand
1163
1164sendSystemControlCommand(command: AVControlCommand): Promise\<void>
1165
1166发送控制命令给置顶会话。结果通过Promise异步回调方式返回。
1167
1168**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1169
1170**系统能力:** SystemCapability.Multimedia.AVSession.Manager
1171
1172**系统接口:** 该接口为系统接口。
1173
1174**参数:**
1175
1176| 参数名  | 类型                                  | 必填 | 说明                                |
1177| ------- | ------------------------------------- | ---- | ----------------------------------- |
1178| command | [AVControlCommand](js-apis-avsession.md#avcontrolcommand10) | 是   | AVSession的相关命令和命令相关参数。 |
1179
1180**返回值:**
1181
1182| 类型           | 说明                          |
1183| -------------- | ----------------------------- |
1184| Promise\<void> | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 |
1185
1186**错误码:**
1187
1188以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1189
1190| 错误码ID | 错误信息 |
1191| -------- | ---------------------------------------- |
1192| 201 | permission denied. |
1193| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1194| 6600101  | Session service exception. |
1195| 6600105  | Invalid session command. |
1196| 6600107  | Too many commands or events. |
1197
1198**示例:**
1199
1200```ts
1201import { BusinessError } from '@kit.BasicServicesKit';
1202
1203let cmd : avSession.AVControlCommandType = 'play';
1204// let cmd : avSession.AVControlCommandType = 'pause';
1205// let cmd : avSession.AVControlCommandType = 'stop';
1206// let cmd : avSession.AVControlCommandType = 'playNext';
1207// let cmd : avSession.AVControlCommandType = 'playPrevious';
1208// let cmd : avSession.AVControlCommandType = 'fastForward';
1209// let cmd : avSession.AVControlCommandType = 'rewind';
1210let avcommand: avSession.AVControlCommand = {command:cmd};
1211// let cmd : avSession.AVControlCommandType = 'seek';
1212// let avcommand = {command:cmd, parameter:10};
1213// let cmd : avSession.AVControlCommandType = 'setSpeed';
1214// let avcommand = {command:cmd, parameter:2.6};
1215// let cmd : avSession.AVControlCommandType = 'setLoopMode';
1216// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
1217// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
1218// let avcommand = {command:cmd, parameter:"false"};
1219avSession.sendSystemControlCommand(avcommand).then(() => {
1220  console.info('SendSystemControlCommand successfully');
1221}).catch((err: BusinessError) => {
1222  console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
1223});
1224```
1225
1226## ProtocolType<sup>10+</sup>
1227
1228远端设备支持的协议类型。
1229
1230**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1231
1232| 名称                        | 值   | 说明         |
1233| --------------------------- | ---- | ----------- |
1234| TYPE_CAST_PLUS_MIRROR      | 1    | Cast+的镜像模式。 <br> **系统接口:** 该接口为系统接口。 |
1235
1236## DistributedSessionType<sup>18+</sup>
1237
1238远端分布式设备支持的会话类型。
1239
1240**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。
1241
1242**系统能力:** SystemCapability.Multimedia.AVSession.Manager
1243
1244| 名称                                     | 值 | 说明                        |
1245|----------------------------------------|---|---------------------------|
1246| TYPE_SESSION_REMOTE      | 0 | 远端设备会话。       |
1247| TYPE_SESSION_MIGRATE_IN  | 1 | 迁移至本端的设备会话。 |
1248| TYPE_SESSION_MIGRATE_OUT | 2 | 迁移至远端的设备会话。 |
1249
1250## avSession.startCastDeviceDiscovery<sup>10+</sup>
1251
1252startCastDeviceDiscovery(callback: AsyncCallback\<void>): void
1253
1254开始设备搜索发现。结果通过callback异步回调方式返回。
1255
1256**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1257
1258**系统接口:** 该接口为系统接口。
1259
1260**参数:**
1261
1262| 参数名   | 类型                                  | 必填 | 说明                                  |
1263| -------- | ------------------------------------- | ---- | ------------------------------------- |
1264| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功并开始搜索,err为undefined,否则返回错误对象。 |
1265
1266
1267**示例:**
1268
1269```ts
1270import { BusinessError } from '@kit.BasicServicesKit';
1271
1272avSession.startCastDeviceDiscovery((err: BusinessError) => {
1273  if (err) {
1274    console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
1275  } else {
1276    console.info('startCastDeviceDiscovery successfully');
1277  }
1278});
1279```
1280
1281## avSession.startCastDeviceDiscovery<sup>10+</sup>
1282
1283startCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void
1284
1285指定过滤条件,开始设备搜索发现。结果通过callback异步回调方式返回。
1286
1287**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1288
1289**系统接口:** 该接口为系统接口。
1290
1291**参数:**
1292
1293| 参数名   | 类型                                  | 必填 | 说明                                  |
1294| -------- | ------------------------------------- | ---- | ------------------------------------- |
1295| filter | number | 是 | 进行设备发现的过滤条件,由ProtocolType的组合而成。 |
1296| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功并开始搜索,err为undefined,否则返回错误对象。 |
1297
1298**错误码:**
1299
1300以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1301
1302| 错误码ID | 错误信息 |
1303| -------- | ---------------------------------------- |
1304| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1305
1306**示例:**
1307
1308```ts
1309import { BusinessError } from '@kit.BasicServicesKit';
1310
1311let filter = 2;
1312avSession.startCastDeviceDiscovery(filter, (err: BusinessError) => {
1313  if (err) {
1314    console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
1315  } else {
1316    console.info('startCastDeviceDiscovery successfully');
1317  }
1318});
1319```
1320
1321## avSession.startCastDeviceDiscovery<sup>10+</sup>
1322
1323startCastDeviceDiscovery(filter?: number, drmSchemes?: Array\<string>): Promise\<void>
1324
1325开始设备搜索发现。结果通过Promise异步回调方式返回。
1326
1327**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1328
1329**系统接口:** 该接口为系统接口。
1330
1331**参数:**
1332
1333| 参数名   | 类型                                  | 必填 | 说明                                  |
1334| -------- | ------------------------------------- | ---- | ------------------------------------- |
1335| filter | number | 否 | 进行设备发现的过滤条件,由ProtocolType的组合而成。 |
1336| drmSchemes | Array\<string> | 否 | 进行支持DRM资源播放的设备发现的过滤条件,由DRM uuid组合而成。 <br/>从API version 12开始支持该可选参数。|
1337
1338**返回值:**
1339
1340| 类型           | 说明                          |
1341| -------------- | ----------------------------- |
1342| Promise\<void> | Promise对象。当命令发送成功并开始搜索,无返回结果,否则返回错误对象。 |
1343
1344**错误码:**
1345
1346以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1347
1348| 错误码ID | 错误信息 |
1349| -------- | ---------------------------------------- |
1350| 202 | Not System App. |
1351| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1352
1353**示例:**
1354
1355```ts
1356import { BusinessError } from '@kit.BasicServicesKit';
1357
1358let filter = 2;
1359let drmSchemes = ['3d5e6d35-9b9a-41e8-b843-dd3c6e72c42c'];
1360avSession.startCastDeviceDiscovery(filter, drmSchemes).then(() => {
1361  console.info('startCastDeviceDiscovery successfully');
1362}).catch((err: BusinessError) => {
1363  console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
1364});
1365```
1366
1367## avSession.stopCastDeviceDiscovery<sup>10+</sup>
1368
1369stopCastDeviceDiscovery(callback: AsyncCallback\<void>): void
1370
1371结束设备搜索发现。结果通过callback异步回调方式返回。
1372
1373**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1374
1375**系统接口:** 该接口为系统接口。
1376
1377**参数:**
1378
1379| 参数名   | 类型                                  | 必填 | 说明                                  |
1380| -------- | ------------------------------------- | ---- | ------------------------------------- |
1381| callback | AsyncCallback\<void>                  | 是   | 回调函数。当成功停止搜索,err为undefined,否则返回错误对象。 |
1382
1383
1384**示例:**
1385
1386```ts
1387import { BusinessError } from '@kit.BasicServicesKit';
1388
1389avSession.stopCastDeviceDiscovery((err: BusinessError) => {
1390  if (err) {
1391    console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
1392  } else {
1393    console.info('stopCastDeviceDiscovery successfully');
1394  }
1395});
1396```
1397
1398## avSession.stopCastDeviceDiscovery<sup>10+</sup>
1399
1400stopCastDeviceDiscovery(): Promise\<void>
1401
1402结束设备搜索发现。结果通过Promise异步回调方式返回。
1403
1404**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1405
1406**系统接口:** 该接口为系统接口。
1407
1408**返回值:**
1409
1410| 类型           | 说明                          |
1411| -------------- | ----------------------------- |
1412| Promise\<void> | Promise对象。当成功停止搜索,无返回结果,否则返回错误对象。 |
1413
1414**示例:**
1415
1416```ts
1417import { BusinessError } from '@kit.BasicServicesKit';
1418
1419avSession.stopCastDeviceDiscovery().then(() => {
1420  console.info('stopCastDeviceDiscovery successfully');
1421}).catch((err: BusinessError) => {
1422  console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
1423});
1424```
1425
1426## avSession.setDiscoverable<sup>10+</sup>
1427
1428setDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void
1429
1430设置设备是否可被发现,用于投播接收端。结果通过callback异步回调方式返回。
1431
1432**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1433
1434**系统接口:** 该接口为系统接口。
1435
1436**参数:**
1437
1438| 参数名   | 类型                                  | 必填 | 说明                                  |
1439| -------- | ------------------------------------- | ---- | ------------------------------------- |
1440| enable | boolean | 是 | 是否允许本设备被发现。true:允许被发现,false:不允许被发现。 |
1441| callback | AsyncCallback\<void>                  | 是   | 回调函数。当设置成功,err为undefined,否则返回错误对象。 |
1442
1443**错误码:**
1444
1445以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1446
1447| 错误码ID | 错误信息 |
1448| -------- | ---------------------------------------- |
1449| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1450
1451**示例:**
1452
1453```ts
1454import { BusinessError } from '@kit.BasicServicesKit';
1455
1456avSession.setDiscoverable(true, (err: BusinessError) => {
1457  if (err) {
1458    console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
1459  } else {
1460    console.info('setDiscoverable successfully');
1461  }
1462});
1463```
1464
1465## avSession.setDiscoverable<sup>10+</sup>
1466
1467setDiscoverable(enable: boolean): Promise\<void>
1468
1469设置设备是否可被发现,用于投播接收端。结果通过Promise异步回调方式返回。
1470
1471**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1472
1473**系统接口:** 该接口为系统接口。
1474
1475**参数:**
1476
1477| 参数名   | 类型                                  | 必填 | 说明                                  |
1478| -------- | ------------------------------------- | ---- | ------------------------------------- |
1479| enable | boolean | 是 | 是否允许本设备被发现。true:允许被发现,false:不允许被发现。 |
1480
1481**错误码:**
1482
1483以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1484
1485| 错误码ID | 错误信息 |
1486| -------- | ---------------------------------------- |
1487| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1488
1489**返回值:**
1490
1491| 类型           | 说明                          |
1492| -------------- | ----------------------------- |
1493| Promise\<void> | Promise对象。当设置成功,无返回结果,否则返回错误对象。 |
1494
1495**示例:**
1496
1497```ts
1498import { BusinessError } from '@kit.BasicServicesKit';
1499
1500avSession.setDiscoverable(true).then(() => {
1501  console.info('setDiscoverable successfully');
1502}).catch((err: BusinessError) => {
1503  console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
1504});
1505```
1506
1507## avSession.on('deviceAvailable')<sup>10+</sup>
1508
1509on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void
1510
1511设备发现回调监听。
1512
1513**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1514
1515**系统接口:** 该接口为系统接口。
1516
1517**参数:**
1518
1519| 参数名   | 类型                 | 必填 | 说明                                                         |
1520| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1521| type     | string               | 是   | 事件回调类型,支持事件`'deviceAvailable'`,有设备被发现时触发回调。 |
1522| callback | (device: [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)) => void | 是   | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。                                |
1523
1524**错误码:**
1525
1526以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1527
1528| 错误码ID | 错误信息 |
1529| -------- | ---------------------------------------- |
1530| 201 | permission denied. |
1531| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1532
1533**示例:**
1534
1535```ts
1536let castDevice: avSession.OutputDeviceInfo;
1537avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
1538  castDevice = device;
1539  console.info(`on deviceAvailable  : ${device} `);
1540});
1541```
1542
1543## avSession.off('deviceAvailable')<sup>10+</sup>
1544
1545off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void
1546
1547取消设备发现回调的监听。
1548
1549**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1550
1551**系统接口:** 该接口为系统接口。
1552
1553**参数:**
1554
1555| 参数名    | 类型                    | 必填  |      说明                                               |
1556| ------   | ---------------------- | ---- | ------------------------------------------------------- |
1557| type     | string                 | 是    | 事件回调类型,支持事件`'deviceAvailable'`:设备发现回调。|
1558| callback     | (device: [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)) => void                 | 否    | 用于返回设备信息。|
1559
1560**错误码:**
1561
1562以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1563
1564| 错误码ID | 错误信息 |
1565| -------- | ---------------------------------------- |
1566| 201 | permission denied. |
1567| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1568
1569**示例:**
1570
1571```ts
1572avSession.off('deviceAvailable');
1573```
1574
1575## avSession.on('deviceOffline')<sup>11+</sup>
1576
1577on(type: 'deviceOffline', callback: (deviceId: string) => void): void
1578
1579设备下线回调监听。
1580
1581**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1582
1583**系统接口:** 该接口为系统接口。
1584
1585**参数:**
1586
1587| 参数名   | 类型                 | 必填 | 说明                                                         |
1588| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1589| type     | string               | 是   | 事件回调类型,支持事件`'deviceOffline'`,有设备下线时触发回调。 |
1590| callback | (deviceId: string) => void | 是   | 回调函数,参数deviceId是设备的ID。当监听事件注册成功,err为undefined,否则返回错误对象。  |
1591
1592**错误码:**
1593
1594以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1595
1596| 错误码ID | 错误信息 |
1597| -------- | ---------------------------------------- |
1598| 201 | permission denied. |
1599| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1600
1601**示例:**
1602
1603```ts
1604let castDeviceId: string;
1605avSession.on('deviceOffline', (deviceId: string) => {
1606  castDeviceId = deviceId;
1607  console.info(`on deviceOffline  : ${deviceId} `);
1608});
1609```
1610
1611## avSession.off('deviceOffline')<sup>11+</sup>
1612
1613off(type: 'deviceOffline', callback?: (deviceId: string) => void): void
1614
1615取消设备下线回调的监听。
1616
1617**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
1618
1619**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1620
1621**系统接口:** 该接口为系统接口。
1622
1623**参数:**
1624
1625| 参数名    | 类型                    | 必填  |      说明                                               |
1626| ------   | ---------------------- | ---- | ------------------------------------------------------- |
1627| type     | string                 | 是    | 事件回调类型,支持事件`'deviceOffline'`:设备下线回调。|
1628| callback | (deviceId: string) => void | 否   | 回调函数,参数deviceId是设备的ID。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。|
1629
1630**错误码:**
1631
1632以下错误码的详细介绍请参见[ohos.multimedia.avsession(多媒体会话)错误码](errorcode-avsession.md)。
1633
1634| 错误码ID | 错误信息 |
1635| -------- | ---------------------------------------- |
1636| 201 | permission denied. |
1637| 202 | Not System App. |
1638| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
1639
1640**示例:**
1641
1642```ts
1643avSession.off('deviceOffline');
1644```
1645
1646## avSession.getAVCastController<sup>10+</sup>
1647
1648getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController>): void
1649
1650设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。
1651
1652此功能在本端和远端都可以使用,通过该接口可以获取一个相同的控制器,进行投播音频的播放控制。
1653
1654**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1655
1656**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
1657
1658**系统接口:** 该接口为系统接口。
1659
1660**参数:**
1661
1662| 参数名    | 类型                                                        | 必填 | 说明                                                         |
1663| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1664| sessionId | string                    | 是   |用于指定要获取的投播控制器的sessionId。 |
1665| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是   | 回调函数,返回投播控制器实例。 |
1666
1667**错误码:**
1668
1669以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1670
1671| 错误码ID | 错误信息 |
1672| -------- | ---------------------------------------- |
1673| 201 | permission denied. |
1674| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1675| 6600101  | Session service exception |
1676| 6600102  | session does not exist |
1677
1678**示例:**
1679
1680```ts
1681import { BusinessError } from '@kit.BasicServicesKit';
1682import { avSession } from '@kit.AVSessionKit';
1683@Entry
1684@Component
1685struct Index {
1686  @State message: string = 'hello world';
1687
1688  build() {
1689    Column() {
1690        Text(this.message)
1691          .onClick(()=>{
1692            let currentAVSession: avSession.AVSession | undefined = undefined;
1693            let tag = "createNewSession";
1694            let context = this.getUIContext().getHostContext() as Context;
1695            let sessionId: string = "";  // 供后续函数入参使用。
1696
1697            let aVCastController: avSession.AVCastController;
1698            avSession.getAVCastController(sessionId , (err: BusinessError, avcontroller: avSession.AVCastController) => {
1699            if (err) {
1700                console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1701            } else {
1702                aVCastController = avcontroller;
1703                console.info('getAVCastController : SUCCESS ');
1704            }
1705            });
1706          })
1707      }
1708    .width('100%')
1709    .height('100%')
1710  }
1711}
1712```
1713
1714## avSession.getAVCastController<sup>10+</sup>
1715
1716getAVCastController(sessionId: string): Promise\<AVCastController>
1717
1718设备建立连接后,获取投播控制器。结果通过Promise方式返回。
1719
1720此功能在本端和远端都可以使用,通过该接口可以获取一个相同的控制器,进行投播音频的播放控制。
1721
1722**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1723
1724**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES
1725
1726**系统接口:** 该接口为系统接口。
1727
1728**参数:**
1729
1730| 参数名    | 类型                       | 必填 | 说明                                                         |
1731| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
1732| sessionId | string                    | 是   |用于指定要获取的投播控制器的sessionId。 |
1733
1734**返回值:**
1735
1736| 类型                                                        | 说明             |
1737| --------- | ------------------------------------------------------------ |
1738| Promise<[AVCastController](#avcastcontroller10)\>  | Promise对象。返回投播控制器实例。 |
1739
1740**错误码:**
1741
1742以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1743
1744| 错误码ID | 错误信息 |
1745| -------- | ---------------------------------------- |
1746| 201 | permission denied. |
1747| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
1748| 6600101  | server exception |
1749| 6600102  | The session does not exist |
1750
1751**示例:**
1752
1753```ts
1754import { BusinessError } from '@kit.BasicServicesKit';
1755import { avSession } from '@kit.AVSessionKit';
1756@Entry
1757@Component
1758struct Index {
1759  @State message: string = 'hello world';
1760
1761  build() {
1762    Column() {
1763        Text(this.message)
1764          .onClick(()=>{
1765            let currentAVSession: avSession.AVSession | undefined = undefined;
1766            let tag = "createNewSession";
1767            let context = this.getUIContext().getHostContext() as Context;
1768            let sessionId: string = "";  // 供后续函数入参使用。
1769
1770            let aVCastController: avSession.AVCastController;
1771            avSession.getAVCastController(sessionId).then((avcontroller: avSession.AVCastController) => {
1772            aVCastController = avcontroller;
1773            console.info('getAVCastController : SUCCESS');
1774            }).catch((err: BusinessError) => {
1775            console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
1776            });
1777          })
1778      }
1779    .width('100%')
1780    .height('100%')
1781  }
1782}
1783```
1784
1785## avSession.startCasting<sup>10+</sup>
1786
1787startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\<void>): void
1788
1789启动投播。结果通过callback异步回调方式返回。
1790
1791**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1792
1793**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1794
1795**系统接口:** 该接口为系统接口。
1796
1797**参数:**
1798
1799| 参数名   | 类型                                  | 必填 | 说明                                  |
1800| -------- | ------------------------------------- | ---- | ------------------------------------- |
1801| session      | [SessionToken](#sessiontoken) | 是   | 会话令牌。SessionToken表示单个token。 |
1802| device | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)                        | 是   | 设备相关信息。 |
1803| callback | AsyncCallback\<void>                  | 是   | 回调函数。当命令发送成功并启动投播,err为undefined,否则返回错误对象。 |
1804
1805**错误码:**
1806
1807以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1808
1809| 错误码ID | 错误信息 |
1810| -------- | ---------------------------------------- |
1811| 201 | permission denied. |
1812| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1813| 6600101  | Session service exception. |
1814| 6600108 | Device connection failed.       |
1815
1816**示例:**
1817
1818```ts
1819import { BusinessError } from '@kit.BasicServicesKit';
1820
1821let myToken: avSession.SessionToken = {
1822  sessionId: sessionId,
1823}
1824let castDevice: avSession.OutputDeviceInfo | undefined = undefined;
1825avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
1826  castDevice = device;
1827  console.info(`on deviceAvailable  : ${device} `);
1828});
1829if (castDevice !== undefined) {
1830  avSession.startCasting(myToken, castDevice, (err: BusinessError) => {
1831    if (err) {
1832      console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
1833    } else {
1834      console.info('startCasting successfully');
1835    }
1836  });
1837}
1838```
1839
1840
1841## avSession.startCasting<sup>10+</sup>
1842
1843startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void>
1844
1845启动投播。结果通过Promise异步回调方式返回。
1846
1847**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。
1848
1849**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1850
1851**系统接口:** 该接口为系统接口。
1852
1853**参数:**
1854
1855| 参数名   | 类型                                  | 必填 | 说明                                  |
1856| -------- | ------------------------------------- | ---- | ------------------------------------- |
1857| session      | [SessionToken](#sessiontoken) | 是   | 会话令牌。SessionToken表示单个token。 |
1858| device | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)                        | 是   | 设备相关信息。 |
1859
1860**返回值:**
1861
1862| 类型           | 说明                          |
1863| -------------- | ----------------------------- |
1864| Promise\<void> | Promise对象。当命令发送成功并启动投播,无返回结果,否则返回错误对象。 |
1865
1866**错误码:**
1867
1868以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1869
1870| 错误码ID | 错误信息 |
1871| -------- | ---------------------------------------- |
1872| 201 | permission denied. |
1873| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1874| 6600101  | Session service exception. |
1875| 6600108 | Device connection failed.       |
1876
1877**示例:**
1878
1879```ts
1880import { BusinessError } from '@kit.BasicServicesKit';
1881
1882let myToken: avSession.SessionToken = {
1883  sessionId: sessionId,
1884}
1885let castDevice: avSession.OutputDeviceInfo | undefined = undefined;
1886avSession.on('deviceAvailable', (device: avSession.OutputDeviceInfo) => {
1887  castDevice = device;
1888  console.info(`on deviceAvailable  : ${device} `);
1889});
1890if (castDevice !== undefined) {
1891  avSession.startCasting(myToken, castDevice).then(() => {
1892    console.info('startCasting successfully');
1893  }).catch((err: BusinessError) => {
1894    console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
1895  });
1896}
1897```
1898
1899## avSession.stopCasting<sup>10+</sup>
1900
1901stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void
1902
1903结束投播。结果通过callback异步回调方式返回。
1904
1905**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1906
1907**系统接口:** 该接口为系统接口。
1908
1909**参数:**
1910
1911| 参数名   | 类型                                  | 必填 | 说明                                  |
1912| -------- | ------------------------------------- | ---- | ------------------------------------- |
1913| session      | [SessionToken](#sessiontoken) | 是   | 会话令牌。SessionToken表示单个token。 |
1914| callback | AsyncCallback\<void>                  | 是   | 回调函数。当成功结束投播,err为undefined,否则返回错误对象。 |
1915
1916**错误码:**
1917
1918以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1919
1920| 错误码ID | 错误信息 |
1921| -------- | ---------------------------------------- |
1922| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1923| 6600109  | The remote connection is not established. |
1924
1925**示例:**
1926
1927```ts
1928import { BusinessError } from '@kit.BasicServicesKit';
1929
1930let myToken: avSession.SessionToken = {
1931  sessionId: sessionId,
1932}
1933avSession.stopCasting(myToken, (err: BusinessError) => {
1934  if (err) {
1935    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
1936  } else {
1937    console.info('stopCasting successfully');
1938  }
1939});
1940```
1941
1942## avSession.stopCasting<sup>10+</sup>
1943
1944stopCasting(session: SessionToken): Promise\<void>
1945
1946结束投播。结果通过Promise异步回调方式返回。
1947
1948**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1949
1950**系统接口:** 该接口为系统接口。
1951
1952**参数:**
1953
1954| 参数名   | 类型                                  | 必填 | 说明                                  |
1955| -------- | ------------------------------------- | ---- | ------------------------------------- |
1956| session      | [SessionToken](#sessiontoken) | 是   | 会话令牌。SessionToken表示单个token。 |
1957
1958**返回值:**
1959
1960| 类型           | 说明                          |
1961| -------------- | ----------------------------- |
1962| Promise\<void> | Promise对象。当成功结束投播,无返回结果,否则返回错误对象。 |
1963
1964**错误码:**
1965
1966错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
1967
1968| 错误码ID | 错误信息 |
1969| -------- | ---------------------------------------- |
1970| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. 3.Parameter verification failed. |
1971| 6600109  | The remote connection is not established. |
1972
1973**示例:**
1974
1975```ts
1976import { BusinessError } from '@kit.BasicServicesKit';
1977
1978let myToken: avSession.SessionToken = {
1979  sessionId: sessionId,
1980}
1981avSession.stopCasting(myToken).then(() => {
1982  console.info('stopCasting successfully');
1983}).catch((err: BusinessError) => {
1984  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
1985});
1986```
1987
1988## avSession.startDeviceLogging<sup>13+</sup>
1989
1990startDeviceLogging(url: string, maxSize?: number): Promise\<void>
1991
1992开始将设备日志写入文件。结果通过Promise异步回调方式返回。
1993
1994**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
1995
1996**系统接口:** 该接口为系统接口。
1997
1998**参数:**
1999
2000| 参数名   | 类型                                  | 必填 | 说明                                  |
2001| -------- | ------------------------------------- | ---- | ------------------------------------- |
2002| url | string                   | 是   | 目标文件描述符(打开文件的唯一标识)。 |
2003| maxSize | number                   | 否   | 写入最大日志大小(以KB为单位)。 |
2004
2005**返回值:**
2006
2007| 类型           | 说明                          |
2008| -------------- | ----------------------------- |
2009| Promise\<void> | Promise对象。当设备日志写入文件成功时,无返回结果,否则返回错误对象。 |
2010
2011**错误码:**
2012
2013以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2014
2015| 错误码ID | 错误信息 |
2016| -------- | ---------------------------------------- |
2017| 202        | Not System App. |
2018| 401        | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
2019| 6600101    | Session service exception. |
2020| 6600102    | The session does not exist. |
2021
2022**示例:**
2023
2024```ts
2025import { BusinessError } from '@kit.BasicServicesKit';
2026import { fileIo } from '@kit.CoreFileKit';
2027
2028let file = await fileIo.open("filePath");
2029let url = file.fd.toString();
2030avSession.startDeviceLogging(url, 2048).then(() => {
2031  console.info('startDeviceLogging successfully');
2032}).catch((err: BusinessError) => {
2033  console.error(`startDeviceLogging BusinessError: code: ${err.code}, message: ${err.message}`);
2034})
2035```
2036
2037## avSession.stopDeviceLogging<sup>13+</sup>
2038
2039stopDeviceLogging(): Promise\<void>
2040
2041停止当前设备日志写入。结果通过Promise异步回调方式返回。
2042
2043**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2044
2045**系统接口:** 该接口为系统接口。
2046
2047**返回值:**
2048
2049| 类型           | 说明                          |
2050| -------------- | ----------------------------- |
2051| Promise\<void> | Promise对象。当停止当前设备日志写入,无返回结果,否则返回错误对象。 |
2052
2053**错误码:**
2054
2055以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2056
2057| 错误码ID | 错误信息 |
2058| -------- | ---------------------------------------- |
2059| 202        | Not System App. |
2060| 6600101    | Session service exception. |
2061| 6600102    | The session does not exist. |
2062
2063**示例:**
2064
2065```ts
2066import { BusinessError } from '@kit.BasicServicesKit';
2067
2068avSession.stopDeviceLogging().then(() => {
2069  console.info('stopCasting successfully');
2070}).catch((err: BusinessError) => {
2071  console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
2072});
2073```
2074
2075## avSession.on('deviceLogEvent')<sup>13+</sup>
2076
2077on(type: 'deviceLogEvent', callback: Callback\<DeviceLogEventCode>): void
2078
2079监听日志事件的回调。
2080
2081**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2082
2083**系统接口:** 该接口为系统接口。
2084
2085**参数:**
2086
2087| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2088| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2089| type     | string                                                       | 是   | 事件回调类型,支持事件`'deviceLogEvent'`。 |
2090| callback | (callback: [DeviceLogEventCode](#devicelogeventcode13)) => void        | 是   | 回调函数,参数DeviceLogEventCode是当前设备日志返回值。                      |
2091
2092**错误码:**
2093
2094以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2095
2096| 错误码ID | 错误信息 |
2097| -------- | ---------------------------------------- |
2098| 202        | Not System App. |
2099| 401        | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
2100| 6600101    | Session service exception. |
2101| 6600102    | The session does not exist. |
2102
2103**示例:**
2104
2105```ts
2106avSession.on('deviceLogEvent', (eventCode: avSession.DeviceLogEventCode) => {
2107  console.info(`on deviceLogEvent code : ${eventCode}`);
2108});
2109```
2110
2111## avSession.off('deviceLogEvent')<sup>13+</sup>
2112
2113off(type: 'deviceLogEvent', callback?: Callback\<DeviceLogEventCode>): void
2114
2115取消监听日志事件的回调。
2116
2117**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2118
2119**系统接口:** 该接口为系统接口。
2120
2121**参数:**
2122
2123| 参数名   | 类型                                                         | 必填 | 说明                                                         |
2124| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2125| type     | string                                                       | 是   | 取消对应的监听事件,支持事件`'deviceLogEvent'`。 |
2126| callback | (callback: [DeviceLogEventCode](#devicelogeventcode13)) => void        | 否  | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。            |
2127
2128**错误码:**
2129
2130以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2131
2132| 错误码ID | 错误信息 |
2133| -------- | ---------------------------------------- |
2134| 202        | Not System App. |
2135| 401        | Parameter check failed. 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.|
2136| 6600101    | Session service exception. |
2137| 6600102    | The session does not exist. |
2138
2139**示例:**
2140
2141```ts
2142avSession.off('deviceLogEvent');
2143```
2144
2145## AVCastController<sup>10+</sup>
2146
2147在投播建立后,调用[avSession.getAVCastController](js-apis-avsession.md#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。
2148
2149### setDisplaySurface<sup>10+</sup>
2150
2151setDisplaySurface(surfaceId: string): Promise\<void>
2152
2153设置播放的surfaceId,在投播sink端使用。结果通过Promise异步回调方式返回。
2154
2155**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2156
2157**系统接口:** 该接口为系统接口。
2158
2159**返回值:**
2160
2161| 类型                                          | 说明                        |
2162| --------------------------------------------- | --------------------------- |
2163| Promise\<void> | Promise对象。返回设置结果。 |
2164
2165**错误码:**
2166
2167以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2168
2169| 错误码ID | 错误信息 |
2170| -------- | ---------------------------------------- |
2171| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
2172| 6600109  | The remote connection is not established. |
2173
2174**示例:**
2175
2176```ts
2177import { media } from '@kit.MediaKit';
2178let surfaceID: string = '';
2179media.createAVRecorder().then((avRecorder) => {
2180  avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => {
2181    if (err == null) {
2182      console.info('getInputSurface success');
2183      surfaceID = surfaceId;
2184    } else {
2185      console.error('getInputSurface failed and error is ' + err.message);
2186    }
2187  });
2188})
2189aVCastController.setDisplaySurface(surfaceID).then(() => {
2190  console.info('setDisplaySurface : SUCCESS');
2191});
2192```
2193
2194### setDisplaySurface<sup>10+</sup>
2195
2196setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
2197
2198设置播放的surfaceId,在投播sink端使用。结果通过callback异步回调方式返回。
2199
2200**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2201
2202**系统接口:** 该接口为系统接口。
2203
2204**参数:**
2205
2206| 参数名   | 类型                                                | 必填 | 说明                         |
2207| -------- | --------------------------------------------------- | ---- | ---------------------------- |
2208| callback | AsyncCallback\<void> | 是   | 回调函数,返回当前设置结果。 |
2209| surfaceId | string | 是   | 设置播放的surfaceId。 |
2210
2211
2212**错误码:**
2213
2214以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2215
2216| 错误码ID | 错误信息 |
2217| -------- | ---------------------------------------- |
2218| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Parameter verification failed. |
2219| 6600109  | The remote connection is not established. |
2220
2221**示例:**
2222
2223```ts
2224import { BusinessError } from '@kit.BasicServicesKit';
2225import { media } from '@kit.MediaKit';
2226let surfaceID: string = '';
2227media.createAVRecorder().then((avRecorder) => {
2228  avRecorder.getInputSurface((err: BusinessError, surfaceId: string) => {
2229    if (err == null) {
2230      console.info('getInputSurface success');
2231      surfaceID = surfaceId;
2232    } else {
2233      console.error('getInputSurface failed and error is ' + err.message);
2234    }
2235  });
2236})
2237aVCastController.setDisplaySurface(surfaceID, (err: BusinessError) => {
2238  if (err) {
2239    console.error(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`);
2240  } else {
2241    console.info('setDisplaySurface : SUCCESS');
2242  }
2243});
2244```
2245
2246### on('videoSizeChange')<sup>12+</sup>
2247
2248on(type: 'videoSizeChange', callback: (width:number, height:number) => void): void
2249
2250设置video尺寸更改监听事件。
2251
2252**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2253
2254**系统接口:** 该接口为系统接口。
2255
2256**参数:**
2257
2258| 参数名   | 类型         | 必填 | 说明                                                         |
2259| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2260| type     | string      | 是   | 事件回调类型,支持事件`'videoSizeChange'`:当video尺寸更改时,触发该事件。 |
2261| callback | (width:number, height:number) => void    | 是   | 回调函数,返回video的宽度和高度。     |
2262
2263**错误码:**
2264
2265以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2266
2267| 错误码ID | 错误信息 |
2268| -------- | ---------------- |
2269| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2270| 6600101  | Session service exception. |
2271
2272**示例:**
2273
2274```ts
2275aVCastController.on('videoSizeChange', (width: number, height: number) => {
2276  console.info(`width :${width} `);
2277  console.info(`height:${height} `);
2278});
2279```
2280
2281### off('videoSizeChange')<sup>12+</sup>
2282
2283off(type: 'videoSizeChange'): void
2284
2285取消设置video尺寸更改监听事件。
2286
2287**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2288
2289**系统接口:** 该接口为系统接口。
2290
2291**参数:**
2292
2293| 参数名   | 类型     | 必填 | 说明      |
2294| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
2295| type     | string  | 是   | 取消对应的监听事件,支持事件`'videoSizeChange'`。    |
2296
2297**错误码:**
2298
2299以下错误码的详细介绍请参见[媒体会话管理错误码](errorcode-avsession.md)。
2300
2301| 错误码ID | 错误信息 |
2302| -------- | ---------------- |
2303| 401 |  parameter check failed. 1.Mandatory parameters are left unspecified. 2.Incorrect parameter types. |
2304| 6600101  | Session service exception. |
2305
2306**示例:**
2307
2308```ts
2309aVCastController.off('videoSizeChange');
2310```
2311
2312## AVMetadata<sup>10+</sup>
2313
2314媒体元数据的相关属性。
2315
2316**系统能力:** SystemCapability.Multimedia.AVSession.Core
2317
2318| 名称            | 类型                      | 必填 | 说明                                                                  |
2319| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
2320| avQueueName<sup>12+</sup>     | string                  | 否   | 歌单(歌曲列表)名称。<br/>此接口为系统接口。 |
2321
2322## AVQueueInfo<sup>11+</sup>
2323
2324歌单(歌曲列表)的相关属性。
2325
2326**系统能力:** SystemCapability.Multimedia.AVSession.Core
2327
2328**系统接口:** 该接口为系统接口。
2329
2330| 名称            | 类型                      | 必填 | 说明                                                                  |
2331| --------------- |-------------------------| ---- |--------------------------------------------------------------------- |
2332| bundleName      | string                  | 是   | 歌单所属应用包名。                                                        |
2333| avQueueName     | string                  | 是   | 歌单(歌曲列表)名称。                                                    |
2334| avQueueId       | string                  | 是   | 歌单(歌曲列表)唯一标识Id。                                               |
2335| avQueueImage    | image.PixelMap &#124; string |是   | 歌单(歌曲列表)封面图,图片的像素数据或者图片路径地址(本地路径或网络路径)。     |
2336| lastPlayedTime  | number                  | 否   | 歌单最后播放时间。                                                        |
2337
2338## DeviceInfo<sup>10+</sup>
2339
2340播放设备的相关信息。
2341
2342| 名称       | 类型           | 必填 | 说明                   |
2343| ---------- | -------------- | ---- | ---------------------- |
2344| ipAddress | string | 否   | 播放设备的ip地址。<br/>此接口为系统接口。<br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast     |
2345| providerId | number | 否   | 播放设备提供商。<br/>此接口为系统接口。<br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast    |
2346| authenticationStatus<sup>11+</sup> | number | 否   | 播放设备是否可信。默认为0。0代表设备不可信,1代表设备可信。<br/>此接口为系统接口。<br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast    |
2347| networkId<sup>13+</sup> | string | 否   | 播放设备的网络ID。 <br/>此接口为系统接口。<br> **系统能力:** SystemCapability.Multimedia.AVSession.AVCast|
2348
2349## AVSessionDescriptor
2350
2351会话的相关描述信息。
2352
2353**系统能力:** SystemCapability.Multimedia.AVSession.Manager
2354
2355**系统接口:** 该接口为系统接口。
2356
2357| 名称          | 类型              | 可读 | 可写 | 说明  |
2358| --------------| ---------------- | ---------------- | ---------------- |------|
2359| sessionId    | string    | 是 | 是  | 会话ID      |
2360| type         | [AVSessionType](js-apis-avsession.md#avsessiontype10)   | 是 | 是 | 会话类型。    |
2361| sessionTag   | string             | 是 | 是 | 会话的自定义名称。    |
2362| elementName  | [ElementName](../apis-ability-kit/js-apis-bundle-ElementName.md)  | 是 | 是 | 会话所属应用的信息(包含bundleName、abilityName等)。 |
2363| isActive     | boolean             | 是 | 是 | 会话是否被激活。<br>true:已被激活。 <br>false:没有被激活。                                      |
2364| isTopSession | boolean             | 是 | 是 | 会话是否为最新的会话。 <br>true:是最新的会话。<br>false:不是最新的会话。                |
2365| outputDevice | [OutputDeviceInfo](js-apis-avsession.md#outputdeviceinfo10)    | 是 | 是 | 分布式设备相关信息。   |
2366
2367## DeviceLogEventCode<sup>13+</sup>
2368
2369设备日志事件返回值的枚举。
2370
2371**系统能力:** SystemCapability.Multimedia.AVSession.AVCast
2372
2373**系统接口:** 该接口为系统接口。
2374
2375| 名称                        | 值   | 说明         |
2376| --------------------------- | ---- | ----------- |
2377| DEVICE_LOG_FULL       | 1    | 日志已满。    |
2378| DEVICE_LOG_EXCEPTION       | 2    | 日写入异常。 |