• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.multimedia.avsession (AVSession Management)
2
3The **avSession** module provides APIs for media playback control so that applications can access the system's Media Controller.
4
5This module provides the following typical features related to media sessions:
6- [AVSession](#avsession): used to set session metadata, playback state information, and more.
7- [AVSessionController](#avsessioncontroller): used to obtain session IDs, send commands and events to sessions, and obtain the session metadata and playback state information.
8
9> **NOTE**
10>
11> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
12>
13> All the APIs provided by this module are system APIs.
14
15## Modules to Import
16
17```js
18import avSession from '@ohos.multimedia.avsession';
19```
20
21## avSession.createAVSession
22
23createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession>
24
25Creates a media session. This API uses a promise to return the result. An ability can have only one session, and repeated calling of this API fails.
26
27**System capability**: SystemCapability.Multimedia.AVSession.Core
28
29**System API**: This is a system API.
30
31**Parameters**
32
33| Name| Type                           | Mandatory| Description                          |
34| ------ | ------------------------------- | ---- | ------------------------------ |
35| context| [Context](js-apis-inner-app-context.md) | Yes| Application context, which provides application environment information.|
36| tag    | string                          | Yes  | Custom session name.            |
37| type   | [AVSessionType](#avsessiontype) | Yes  | Session type, which can be audio or video.|
38
39
40**Return value**
41
42| Type                             | Description                                                        |
43| --------------------------------- | ------------------------------------------------------------ |
44| Promise<[AVSession](#avsession)\> | Promise used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.|
45
46**Error codes**
47
48For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
49
50| ID| Error Message|
51| -------- | ---------------------------------------- |
52| 6600101  | Session service exception. |
53
54**Example**
55
56```js
57import featureAbility from '@ohos.ability.featureAbility';
58
59let session;
60let tag = "createNewSession";
61let context = featureAbility.getContext();
62
63await avSession.createAVSession(context, tag, "audio").then((data) => {
64    session = data;
65    console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
66}).catch((err) => {
67    console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
68});
69```
70
71## avSession.createAVSession
72
73createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void
74
75Creates a media session. This API uses an asynchronous callback to return the result. An ability can have only one session, and repeated calling of this API fails.
76
77**System capability**: SystemCapability.Multimedia.AVSession.Core
78
79**System API**: This is a system API.
80
81**Parameters**
82
83| Name  | Type                                   | Mandatory| Description                                                        |
84| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
85| context| [Context](js-apis-inner-app-context.md) | Yes| Application context, which provides application environment information.    |
86| tag      | string                                  | Yes  | Custom session name.                                          |
87| type     | [AVSessionType](#avsessiontype)         | Yes  | Session type, which can be audio or video.                              |
88| callback | AsyncCallback<[AVSession](#avsession)\> | Yes  | Callback used to return the media session obtained, which can be used to obtain the session ID, set the metadata and playback state information, and send key events.|
89
90**Error codes**
91
92For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
93
94| ID| Error Message|
95| -------- | ---------------------------------------- |
96| 6600101  | Session service exception. |
97
98**Example**
99
100```js
101import featureAbility from '@ohos.ability.featureAbility';
102
103let session;
104let tag = "createNewSession";
105let context = featureAbility.getContext();
106
107avSession.createAVSession(context, tag, "audio", function (err, data) {
108    if (err) {
109        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
110    } else {
111        session = data;
112        console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
113    }
114});
115```
116
117## avSession.getAllSessionDescriptors
118
119getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>>
120
121Obtains the descriptors of all sessions. This API uses a promise to return the result.
122
123**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
124
125**System capability**: SystemCapability.Multimedia.AVSession.Manager
126
127**System API**: This is a system API.
128
129**Return value**
130
131| Type                                                        | Description                                         |
132| ------------------------------------------------------------ | --------------------------------------------- |
133| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only.|
134
135**Error codes**
136
137For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
138
139| ID| Error Message|
140| -------- | ---------------------------------------- |
141| 6600101  | Session service exception. |
142
143**Example**
144
145```js
146avSession.getAllSessionDescriptors().then((descriptors) => {
147    console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
148    if(descriptors.length > 0 ){
149        console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
150        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
151        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
152    }
153}).catch((err) => {
154    console.info(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
155});
156```
157
158## avSession.getAllSessionDescriptors
159
160getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void
161
162Obtains the descriptors of all sessions. This API uses an asynchronous callback to return the result.
163
164**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
165
166**System capability**: SystemCapability.Multimedia.AVSession.Manager
167
168**System API**: This is a system API.
169
170**Parameters**
171
172| Name  | Type                                                        | Mandatory| Description                                      |
173| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
174| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes  | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only.|
175
176**Error codes**
177
178For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
179
180| ID| Error Message|
181| -------- | ---------------------------------------- |
182| 6600101  |Session service exception. |
183
184**Example**
185
186```js
187avSession.getAllSessionDescriptors(function (err, descriptors) {
188    if (err) {
189        console.info(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
190    } else {
191        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
192        if(descriptors.length > 0 ){
193            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
194            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
195            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
196        }
197    }
198});
199```
200
201## avSession.createController
202
203createController(sessionId: string): Promise\<AVSessionController>
204
205Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses a promise to return the result.
206
207**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
208
209**System capability**: SystemCapability.Multimedia.AVSession.Manager
210
211**System API**: This is a system API.
212
213**Parameters**
214
215| Name   | Type  | Mandatory| Description    |
216| --------- | ------ | ---- | -------- |
217| sessionId | string | Yes  | Session ID.|
218
219**Return value**
220
221| Type                                                 | Description                                                        |
222| ----------------------------------------------------- | ------------------------------------------------------------ |
223| Promise<[AVSessionController](#avsessioncontroller)\> | Promise used to return the session controller created, which can be used to obtain the session ID,<br>send commands and events to sessions, and obtain metadata and playback state information.|
224
225**Error codes**
226
227For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
228
229| ID| Error Message|
230| -------- | ---------------------------------------- |
231| 6600101  | Session service exception. |
232| 6600102  | The session does not exist. |
233
234**Example**
235
236```js
237import featureAbility from '@ohos.ability.featureAbility';
238
239let session;
240let tag = "createNewSession";
241let context = featureAbility.getContext();
242
243await avSession.createAVSession(context, tag, "audio").then((data) => {
244    session = data;
245    console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
246}).catch((err) => {
247    console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
248});
249
250let controller;
251await avSession.createController(session.sessionId).then((avcontroller) => {
252    controller = avcontroller;
253    console.info(`CreateController : SUCCESS : ${controller.sessionId}`);
254}).catch((err) => {
255    console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
256});
257```
258
259## avSession.createController
260
261createController(sessionId: string, callback: AsyncCallback\<AVSessionController>): void
262
263Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses an asynchronous callback to return the result.
264
265**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
266
267**System capability**: SystemCapability.Multimedia.AVSession.Manager
268
269**System API**: This is a system API.
270
271**Parameters**
272
273| Name   | Type                                                       | Mandatory| Description                                                        |
274| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
275| sessionId | string                                                      | Yes  | Session ID.                                                    |
276| callback  | AsyncCallback<[AVSessionController](#avsessioncontroller)\> | Yes  | Callback used to return the session controller created, which can be used to obtain the session ID,<br>send commands and events to sessions, and obtain metadata and playback state information.|
277
278**Error codes**
279
280For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
281
282| ID| Error Message|
283| -------- | ---------------------------------------- |
284| 6600101  | Session service exception. |
285| 6600102  | The session does not exist. |
286
287**Example**
288
289```js
290import featureAbility from '@ohos.ability.featureAbility';
291
292let session;
293let tag = "createNewSession";
294let context = featureAbility.getContext();
295
296await avSession.createAVSession(context, tag, "audio").then((data) => {
297    session = data;
298    console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`);
299}).catch((err) => {
300    console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
301});
302
303let controller;
304avSession.createController(session.sessionId, function (err, avcontroller) {
305    if (err) {
306        console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
307    } else {
308        controller = avcontroller;
309        console.info(`CreateController : SUCCESS : ${controller.sessionId}`);
310    }
311});
312```
313
314## avSession.castAudio
315
316castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise\<void>
317
318Casts a session to a list of devices. This API uses a promise to return the result.
319
320Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices.
321
322**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
323
324**System capability**: SystemCapability.Multimedia.AVSession.Manager
325
326**System API**: This is a system API.
327
328**Parameters**
329
330| Name      | Type                                                                                                                                                                | Mandatory| Description                                                        |
331| ------------ |--------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---- | ------------------------------------------------------------ |
332| session      | [SessionToken](#sessiontoken) &#124; 'all'                                                                                                                         | Yes  | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.|
333| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes  | Audio devices.                         |
334
335**Return value**
336
337| Type          | Description                         |
338| -------------- | ----------------------------- |
339| Promise<void\> | Promise used to return the result. If the casting is successful, no value is returned; otherwise, an error object is returned.|
340
341**Error codes**
342
343For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
344
345| ID| Error Message|
346| -------- | ---------------------------------------- |
347| 6600101  | Session service exception. |
348| 6600102  | The session does not exist. |
349| 6600104  | The remote session  connection failed. |
350
351**Example**
352
353```js
354import audio from '@ohos.multimedia.audio';
355
356let audioManager = audio.getAudioManager();
357let audioRoutingManager = audioManager.getRoutingManager();
358let audioDevices;
359await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
360    audioDevices = data;
361    console.info('Promise returned to indicate that the device list is obtained.');
362}).catch((err) => {
363    console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
364});
365
366avSession.castAudio('all', audioDevices).then(() => {
367    console.info('CreateController : SUCCESS');
368}).catch((err) => {
369    console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
370});
371```
372
373## avSession.castAudio
374
375castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void
376
377Casts a session to a list of devices. This API uses an asynchronous callback to return the result.
378
379Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices.
380
381**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
382
383**System capability**: SystemCapability.Multimedia.AVSession.Manager
384
385**System API**: This is a system API.
386
387**Parameters**
388
389| Name      | Type                                        | Mandatory| Description                                                        |
390| ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ |
391| session      | [SessionToken](#sessiontoken) &#124; 'all' | Yes  | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.|
392| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\>   | Yes  | Audio devices.                      |
393| callback     | AsyncCallback<void\>                       | Yes  | Callback used to return the result. If the casting is successful, **err** is **undefined**; otherwise, **err** is an error object.                       |
394
395**Error codes**
396
397For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
398
399| ID| Error Message|
400| -------- | ---------------------------------------- |
401| 6600101  | Session service exception. |
402| 6600102  | The session does not exist. |
403| 6600104  | The remote session  connection failed. |
404
405**Example**
406
407```js
408import audio from '@ohos.multimedia.audio';
409
410let audioManager = audio.getAudioManager();
411let audioRoutingManager = audioManager.getRoutingManager();
412let audioDevices;
413await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
414    audioDevices = data;
415    console.info('Promise returned to indicate that the device list is obtained.');
416}).catch((err) => {
417    console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
418});
419
420avSession.castAudio('all', audioDevices, function (err) {
421    if (err) {
422        console.info(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`);
423    } else {
424        console.info('CastAudio : SUCCESS ');
425    }
426});
427```
428
429## avSession.on('sessionCreate' | 'sessionDestroy' | 'topSessionChange')
430
431on(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void
432
433Subscribes to session creation, session destruction, and top session change events.
434
435**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
436
437**System capability**: SystemCapability.Multimedia.AVSession.Manager
438
439**System API**: This is a system API.
440
441**Parameters**
442
443| Name  | Type                                                        | Mandatory| Description                                                        |
444| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
445| type     | string                                                       | Yes  | Event type.<br>- **'sessionCreate'**: session creation event, which is reported when a session is created.<br>- **'sessionDestroy'**: session destruction event, which is reported when a session is destroyed.<br>- **'topSessionChange'**: top session change event, which is reported when the top session is changed.|
446| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes  | Callback used to report the session descriptor.                              |
447
448**Error codes**
449
450For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
451
452| ID| Error Message|
453| -------- | ---------------------------------------- |
454| 6600101  | Session service exception. |
455
456**Example**
457
458```js
459avSession.on('sessionCreate', (descriptor) => {
460    console.info(`on sessionCreate : isActive : ${descriptor.isActive}`);
461    console.info(`on sessionCreate : type : ${descriptor.type}`);
462    console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`);
463});
464
465avSession.on('sessionDestroy', (descriptor) => {
466    console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`);
467    console.info(`on sessionDestroy : type : ${descriptor.type}`);
468    console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`);
469});
470
471avSession.on('topSessionChange', (descriptor) => {
472    console.info(`on topSessionChange : isActive : ${descriptor.isActive}`);
473    console.info(`on topSessionChange : type : ${descriptor.type}`);
474    console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`);
475});
476```
477
478## avSession.off('sessionCreate' | 'sessionDestroy' | 'topSessionChange')
479
480off(type: 'sessionCreate' | 'sessionDestroy' | 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void
481
482Unsubscribes from session creation, session destruction, and top session change events.
483
484**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
485
486**System capability**: SystemCapability.Multimedia.AVSession.Manager
487
488**System API**: This is a system API.
489
490**Parameters**
491
492| Name  | Type                                                        | Mandatory| Description                                                        |
493| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
494| type     | string                                                       | Yes  | Event type.<br>- **'sessionCreate'**: session creation event, which is reported when a session is created.<br>- **'sessionDestroy'**: session destruction event, which is reported when a session is destroyed.<br>- **'topSessionChange'**: top session change event, which is reported when the top session is changed.|
495| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **session** parameter in the callback describes a media session. The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                              |
496
497**Error codes**
498
499For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
500
501| ID| Error Message|
502| -------- | ---------------------------------------- |
503| 6600101  | Session service exception. |
504
505**Example**
506
507```js
508avSession.off('sessionCreate');
509avSession.off('sessionDestroy');
510avSession.off('topSessionChange');
511```
512
513## avSession.on('sessionServiceDie')
514
515on(type: 'sessionServiceDie', callback: () => void): void
516
517Subscribes to session service death events.
518
519**System capability**: SystemCapability.Multimedia.AVSession.Core
520
521**System API**: This is a system API.
522
523**Parameters**
524
525| Name  | Type                | Mandatory| Description                                                        |
526| -------- | -------------------- | ---- | ------------------------------------------------------------ |
527| type     | string               | Yes  | Event type. The event **'sessionServiceDie'** is reported when the session service dies.|
528| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                               |
529
530**Error codes**
531
532For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
533
534| ID| Error Message|
535| -------- | ---------------------------------------- |
536| 6600101  | Session service exception. |
537
538**Example**
539
540```js
541avSession.on('sessionServiceDie', () => {
542    console.info('on sessionServiceDie  : session is  Died ');
543});
544```
545
546## avSession.off('sessionServiceDie')
547
548off(type: 'sessionServiceDie', callback?: () => void): void
549
550Unsubscribes from session service death events.
551
552**System capability**: SystemCapability.Multimedia.AVSession.Core
553
554**System API**: This is a system API.
555
556**Parameters**
557
558| Name   | Type                   | Mandatory |      Description                                              |
559| ------   | ---------------------- | ---- | ------------------------------------------------------- |
560| type     | string                 | Yes   | Event type. The event **'sessionServiceDie'** is reported when the session service dies.|
561| callback | callback: () => void   | No   | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.           |
562
563**Error codes**
564
565For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
566
567| ID| Error Message|
568| -------- | ---------------------------------------- |
569| 6600101  | Session service exception. |
570
571**Example**
572
573```js
574avSession.off('sessionServiceDie');
575```
576
577## avSession.sendSystemAVKeyEvent
578
579sendSystemAVKeyEvent(event: KeyEvent): Promise\<void>
580
581Sends a system key event to the top session. This API uses a promise to return the result.
582
583**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
584
585**System capability**: SystemCapability.Multimedia.AVSession.Manager
586
587**System API**: This is a system API.
588
589**Parameters**
590
591| Name| Type                           | Mandatory| Description      |
592| ------ | ------------------------------- | ---- | ---------- |
593| event  | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|
594
595**Return value**
596
597| Type          | Description                         |
598| -------------- | ----------------------------- |
599| Promise<void\> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
600
601**Error codes**
602
603For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
604
605| ID| Error Message|
606| -------- | ---------------------------------------- |
607| 6600101  | Session service exception. |
608| 6600105  | Invalid session command. |
609
610**Example**
611
612```js
613
614let keyItem = {code:0x49, pressedTime:2, deviceId:0};
615let event = {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};
616
617avSession.sendSystemAVKeyEvent(event).then(() => {
618    console.info('SendSystemAVKeyEvent Successfully');
619}).catch((err) => {
620    console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
621});
622
623```
624
625## avSession.sendSystemAVKeyEvent
626
627sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
628
629Sends a system key event to the top session. This API uses an asynchronous callback to return the result.
630
631**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
632
633**System capability**: SystemCapability.Multimedia.AVSession.Manager
634
635**System API**: This is a system API.
636
637**Parameters**
638
639| Name  | Type                                                        | Mandatory| Description                                 |
640| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- |
641| event    | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.                           |
642| callback | AsyncCallback<void\>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
643
644**Error codes**
645
646For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
647
648| ID| Error Message|
649| -------- | ---------------------------------------- |
650| 6600101  | Session service exception. |
651| 6600105  | Invalid session command. |
652
653**Example**
654
655```js
656let keyItem = {code:0x49, pressedTime:2, deviceId:0};
657let event = {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};
658
659avSession.sendSystemAVKeyEvent(event, function (err) {
660    if (err) {
661        console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
662    } else {
663        console.info('SendSystemAVKeyEvent : SUCCESS ');
664    }
665});
666```
667
668## avSession.sendSystemControlCommand
669
670sendSystemControlCommand(command: AVControlCommand): Promise\<void>
671
672Sends a system control command to the top session. This API uses a promise to return the result.
673
674**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
675
676**System capability**: SystemCapability.Multimedia.AVSession.Manager
677
678**System API**: This is a system API.
679
680**Parameters**
681
682| Name | Type                                 | Mandatory| Description                               |
683| ------- | ------------------------------------- | ---- | ----------------------------------- |
684| command | [AVControlCommand](#avcontrolcommand) | Yes  | Command to send.|
685
686**Return value**
687
688| Type          | Description                         |
689| -------------- | ----------------------------- |
690| Promise<void\> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
691
692**Error codes**
693
694For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
695
696| ID| Error Message|
697| -------- | ---------------------------------------- |
698| 6600101  | Session service exception. |
699| 6600105  | Invalid session command. |
700| 6600107  | Too many commands or events. |
701
702**Example**
703
704```js
705let cmd : avSession.AVControlCommandType = 'play';
706// let cmd : avSession.AVControlCommandType = 'pause';
707// let cmd : avSession.AVControlCommandType = 'stop';
708// let cmd : avSession.AVControlCommandType = 'playNext';
709// let cmd : avSession.AVControlCommandType = 'playPrevious';
710// let cmd : avSession.AVControlCommandType = 'fastForward';
711// let cmd : avSession.AVControlCommandType = 'rewind';
712let avcommand = {command:cmd};
713// let cmd : avSession.AVControlCommandType = 'seek';
714// let avcommand = {command:cmd, parameter:10};
715// let cmd : avSession.AVControlCommandType = 'setSpeed';
716// let avcommand = {command:cmd, parameter:2.6};
717// let cmd : avSession.AVControlCommandType = 'setLoopMode';
718// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
719// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
720// let avcommand = {command:cmd, parameter:"false"};
721avSession.sendSystemControlCommand(avcommand).then(() => {
722    console.info('SendSystemControlCommand successfully');
723}).catch((err) => {
724    console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
725});
726```
727
728## avSession.sendSystemControlCommand
729
730sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
731
732Sends a system control command to the top session. This API uses an asynchronous callback to return the result.
733
734**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
735
736**System capability**: SystemCapability.Multimedia.AVSession.Manager
737
738**System API**: This is a system API.
739
740**Parameters**
741
742| Name  | Type                                 | Mandatory| Description                                 |
743| -------- | ------------------------------------- | ---- | ------------------------------------- |
744| command  | [AVControlCommand](#avcontrolcommand) | Yes  | Command to send.  |
745| callback | AsyncCallback<void\>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
746
747**Error codes**
748
749For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
750
751| ID| Error Message|
752| -------- | ---------------------------------------- |
753| 6600101  | Session service exception. |
754| 6600105  | Invalid session command. |
755| 6600107  | Too many commands or events. |
756
757**Example**
758
759```js
760let cmd : avSession.AVControlCommandType = 'play';
761// let cmd : avSession.AVControlCommandType = 'pause';
762// let cmd : avSession.AVControlCommandType = 'stop';
763// let cmd : avSession.AVControlCommandType = 'playNext';
764// let cmd : avSession.AVControlCommandType = 'playPrevious';
765// let cmd : avSession.AVControlCommandType = 'fastForward';
766// let cmd : avSession.AVControlCommandType = 'rewind';
767let avcommand = {command:cmd};
768// let cmd : avSession.AVControlCommandType = 'seek';
769// let avcommand = {command:cmd, parameter:10};
770// let cmd : avSession.AVControlCommandType = 'setSpeed';
771// let avcommand = {command:cmd, parameter:2.6};
772// let cmd : avSession.AVControlCommandType = 'setLoopMode';
773// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
774// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
775// let avcommand = {command:cmd, parameter:"false"};
776avSession.sendSystemControlCommand(avcommand, function (err) {
777    if (err) {
778        console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
779    } else {
780        console.info('sendSystemControlCommand successfully');
781    }
782});
783```
784
785## AVSession
786
787An **AVSession** object is created by calling [avSession.createAVSession](#avsessioncreateavsession). The object enables you to obtain the session ID and set the metadata and playback state.
788
789### Attributes
790
791**System capability**: SystemCapability.Multimedia.AVSession.Core
792
793**System API**: This is a system API.
794
795
796| Name     | Type  | Readable| Writable| Description                         |
797| :-------- | :----- | :--- | :--- | :---------------------------- |
798| sessionId | string | Yes  | No  | Unique session ID of the **AVSession** object.|
799
800
801**Example**
802```js
803let sessionId = session.sessionId;
804```
805
806### setAVMetadata
807
808setAVMetadata(data: AVMetadata): Promise\<void>
809
810Sets session metadata. This API uses a promise to return the result.
811
812**System capability**: SystemCapability.Multimedia.AVSession.Core
813
814**System API**: This is a system API.
815
816**Parameters**
817
818| Name| Type                     | Mandatory| Description        |
819| ------ | ------------------------- | ---- | ------------ |
820| data   | [AVMetadata](#avmetadata) | Yes  | Session metadata.|
821
822**Return value**
823
824| Type          | Description                         |
825| -------------- | ----------------------------- |
826| Promise<void\> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
827
828**Error codes**
829
830For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
831
832| ID| Error Message|
833| -------- | ---------------------------------------- |
834| 6600101  | Session service exception. |
835| 6600102  | The session does not exist. |
836
837**Example**
838
839```js
840let metadata  = {
841    assetId: "121278",
842    title: "lose yourself",
843    artist: "Eminem",
844    author: "ST",
845    album: "Slim shady",
846    writer: "ST",
847    composer: "ST",
848    duration: 2222,
849    mediaImage: "https://www.example.com/example.jpg",
850    subtitle: "8 Mile",
851    description: "Rap",
852    lyric: "https://www.example.com/example.lrc",
853    previousAssetId: "121277",
854    nextAssetId: "121279",
855};
856session.setAVMetadata(metadata).then(() => {
857    console.info('SetAVMetadata successfully');
858}).catch((err) => {
859    console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
860});
861```
862
863### setAVMetadata
864
865setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void
866
867Sets session metadata. This API uses an asynchronous callback to return the result.
868
869**System capability**: SystemCapability.Multimedia.AVSession.Core
870
871**System API**: This is a system API.
872
873**Parameters**
874
875| Name  | Type                     | Mandatory| Description                                 |
876| -------- | ------------------------- | ---- | ------------------------------------- |
877| data     | [AVMetadata](#avmetadata) | Yes  | Session metadata.                         |
878| callback | AsyncCallback<void\>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
879
880**Error codes**
881
882For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
883
884| ID| Error Message|
885| -------- | ---------------------------------------- |
886| 6600101  | Session service exception. |
887| 6600102  | The session does not exist. |
888
889**Example**
890
891```js
892let metadata  = {
893    assetId: "121278",
894    title: "lose yourself",
895    artist: "Eminem",
896    author: "ST",
897    album: "Slim shady",
898    writer: "ST",
899    composer: "ST",
900    duration: 2222,
901    mediaImage: "https://www.example.com/example.jpg",
902    subtitle: "8 Mile",
903    description: "Rap",
904    lyric: "https://www.example.com/example.lrc",
905    previousAssetId: "121277",
906    nextAssetId: "121279",
907};
908session.setAVMetadata(metadata, function (err) {
909    if (err) {
910        console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
911    } else {
912        console.info('SetAVMetadata successfully');
913    }
914});
915```
916
917### setAVPlaybackState
918
919setAVPlaybackState(state: AVPlaybackState): Promise\<void>
920
921Sets information related to the session playback state. This API uses a promise to return the result.
922
923**System capability**: SystemCapability.Multimedia.AVSession.Core
924
925**System API**: This is a system API.
926
927**Parameters**
928
929| Name| Type                               | Mandatory| Description                                          |
930| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
931| data   | [AVPlaybackState](#avplaybackstate) | Yes  | Information related to the session playback state.|
932
933**Return value**
934
935| Type          | Description                         |
936| -------------- | ----------------------------- |
937| Promise<void\> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
938
939**Error codes**
940
941For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
942
943| ID| Error Message|
944| -------- | ---------------------------------------- |
945| 6600101  | Session service exception. |
946| 6600102  | The session does not exist. |
947
948**Example**
949
950```js
951let playbackState = {
952    state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
953    speed: 1.0,
954    position:{elapsedTime:10, updateTime:(new Date()).getTime()},
955    bufferedTime:1000,
956    loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
957    isFavorite:true,
958};
959session.setAVPlaybackState(playbackState).then(() => {
960    console.info('SetAVPlaybackState successfully');
961}).catch((err) => {
962    console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
963});
964```
965
966### setAVPlaybackState
967
968setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void
969
970Sets information related to the session playback state. This API uses an asynchronous callback to return the result.
971
972**System capability**: SystemCapability.Multimedia.AVSession.Core
973
974**System API**: This is a system API.
975
976**Parameters**
977
978| Name  | Type                               | Mandatory| Description                                          |
979| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
980| data     | [AVPlaybackState](#avplaybackstate) | Yes  | Information related to the session playback state.|
981| callback | AsyncCallback<void\>                | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.         |
982
983**Error codes**
984
985For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
986
987| ID| Error Message|
988| -------- | ---------------------------------------- |
989| 6600101  | Session service exception. |
990| 6600102  | The session does not exist. |
991
992**Example**
993
994```js
995let PlaybackState = {
996    state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
997    speed: 1.0,
998    position:{elapsedTime:10, updateTime:(new Date()).getTime()},
999    bufferedTime:1000,
1000    loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
1001    isFavorite:true,
1002};
1003session.setAVPlaybackState(PlaybackState, function (err) {
1004    if (err) {
1005        console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
1006    } else {
1007        console.info('SetAVPlaybackState successfully');
1008    }
1009});
1010```
1011
1012### setLaunchAbility
1013
1014setLaunchAbility(ability: WantAgent): Promise\<void>
1015
1016Sets a launcher ability. This API uses a promise to return the result.
1017
1018**System capability**: SystemCapability.Multimedia.AVSession.Core
1019
1020**System API**: This is a system API.
1021
1022**Parameters**
1023
1024| Name | Type                                         | Mandatory| Description                                                       |
1025| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
1026| ability | [WantAgent](js-apis-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID.|
1027
1028**Return value**
1029
1030| Type          | Description                         |
1031| -------------- | ----------------------------- |
1032| Promise<void\> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|
1033
1034**Error codes**
1035
1036For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1037
1038| ID| Error Message|
1039| -------- | ---------------------------------------- |
1040| 6600101  | Session service exception. |
1041| 6600102  | The session does not exist. |
1042
1043**Example**
1044
1045```js
1046import wantAgent from '@ohos.wantAgent';
1047
1048// WantAgentInfo object
1049let wantAgentInfo = {
1050    wants: [
1051        {
1052            deviceId: "deviceId",
1053            bundleName: "com.neu.setResultOnAbilityResultTest1",
1054            abilityName: "com.example.test.MainAbility",
1055            action: "action1",
1056            entities: ["entity1"],
1057            type: "MIMETYPE",
1058            uri: "key={true,true,false}",
1059            parameters:
1060                {
1061                    mykey0: 2222,
1062                    mykey1: [1, 2, 3],
1063                    mykey2: "[1, 2, 3]",
1064                    mykey3: "ssssssssssssssssssssssssss",
1065                    mykey4: [false, true, false],
1066                    mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
1067                    mykey6: true,
1068                }
1069        }
1070    ],
1071    operationType: wantAgent.OperationType.START_ABILITIES,
1072    requestCode: 0,
1073    wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1074}
1075
1076wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
1077    session.setLaunchAbility(agent).then(() => {
1078        console.info('SetLaunchAbility successfully');
1079    }).catch((err) => {
1080        console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
1081    });
1082});
1083```
1084
1085### setLaunchAbility
1086
1087setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void
1088
1089Sets a launcher ability. This API uses an asynchronous callback to return the result.
1090
1091**System capability**: SystemCapability.Multimedia.AVSession.Core
1092
1093**System API**: This is a system API.
1094
1095**Parameters**
1096
1097| Name  | Type                                         | Mandatory| Description                                                        |
1098| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
1099| ability  | [WantAgent](js-apis-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID. |
1100| callback | AsyncCallback<void\>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1101
1102**Error codes**
1103
1104For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1105
1106| ID| Error Message|
1107| -------- | ---------------------------------------- |
1108| 6600101  | Session service exception. |
1109| 6600102  | The session does not exist. |
1110
1111**Example**
1112
1113```js
1114import wantAgent from '@ohos.wantAgent';
1115
1116// WantAgentInfo object
1117let wantAgentInfo = {
1118    wants: [
1119        {
1120            deviceId: "deviceId",
1121            bundleName: "com.neu.setResultOnAbilityResultTest1",
1122            abilityName: "com.example.test.MainAbility",
1123            action: "action1",
1124            entities: ["entity1"],
1125            type: "MIMETYPE",
1126            uri: "key={true,true,false}",
1127            parameters:
1128                {
1129                    mykey0: 2222,
1130                    mykey1: [1, 2, 3],
1131                    mykey2: "[1, 2, 3]",
1132                    mykey3: "ssssssssssssssssssssssssss",
1133                    mykey4: [false, true, false],
1134                    mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
1135                    mykey6: true,
1136                }
1137        }
1138    ],
1139    operationType: wantAgent.OperationType.START_ABILITIES,
1140    requestCode: 0,
1141    wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
1142}
1143
1144wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
1145    session.setLaunchAbility(agent, function (err) {
1146        if (err) {
1147            console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
1148        } else {
1149            console.info('SetLaunchAbility successfully');
1150        }
1151    });
1152});
1153```
1154
1155### getController
1156
1157getController(): Promise\<AVSessionController>
1158
1159Obtains the controller corresponding to this session. This API uses a promise to return the result.
1160
1161**System capability**: SystemCapability.Multimedia.AVSession.Core
1162
1163**System API**: This is a system API.
1164
1165**Return value**
1166
1167| Type                                                | Description                         |
1168| ---------------------------------------------------- | ----------------------------- |
1169| Promise<[AVSessionController](#avsessioncontroller)> | Promise used to return the session controller.|
1170
1171**Error codes**
1172
1173For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1174
1175| ID| Error Message|
1176| -------- | ---------------------------------------- |
1177| 6600101  | Session service exception. |
1178| 6600102  | The session does not exist. |
1179
1180**Example**
1181
1182```js
1183let controller;
1184session.getController().then((avcontroller) => {
1185    controller = avcontroller;
1186    console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`);
1187}).catch((err) => {
1188    console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1189});
1190```
1191
1192### getController
1193
1194getController(callback: AsyncCallback\<AVSessionController>): void
1195
1196Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result.
1197
1198**System capability**: SystemCapability.Multimedia.AVSession.Core
1199
1200**System API**: This is a system API.
1201
1202**Parameters**
1203
1204| Name  | Type                                                       | Mandatory| Description                      |
1205| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
1206| callback | AsyncCallback<[AVSessionController](#avsessioncontroller)\> | Yes  | Callback used to return the session controller.|
1207
1208**Error codes**
1209
1210For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1211
1212| ID| Error Message|
1213| -------- | ---------------------------------------- |
1214| 6600101  | Session service exception. |
1215| 6600102  | The session does not exist. |
1216
1217**Example**
1218
1219```js
1220let controller;
1221session.getController(function (err, avcontroller) {
1222    if (err) {
1223        console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
1224    } else {
1225        controller = avcontroller;
1226        console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`);
1227    }
1228});
1229```
1230
1231### getOutputDevice
1232
1233getOutputDevice(): Promise\<OutputDeviceInfo>
1234
1235Obtains information about the output device for this session. This API uses a promise to return the result.
1236
1237**System capability**: SystemCapability.Multimedia.AVSession.Core
1238
1239**System API**: This is a system API.
1240
1241**Return value**
1242
1243| Type                                          | Description                             |
1244| ---------------------------------------------- | --------------------------------- |
1245| Promise<[OutputDeviceInfo](#outputdeviceinfo)> | Promise used to return the output device information.|
1246
1247**Error codes**
1248
1249For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1250
1251| ID| Error Message|
1252| -------- | ---------------------------------------- |
1253| 6600101  | Session service exception. |
1254| 6600102  | The session does not exist. |
1255
1256**Example**
1257
1258```js
1259session.getOutputDevice().then((outputDeviceInfo) => {
1260    console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`);
1261}).catch((err) => {
1262    console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1263});
1264```
1265
1266### getOutputDevice
1267
1268getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
1269
1270Obtains information about the output device for this session. This API uses an asynchronous callback to return the result.
1271
1272**System capability**: SystemCapability.Multimedia.AVSession.Core
1273
1274**System API**: This is a system API.
1275
1276**Parameters**
1277
1278| Name  | Type                                                 | Mandatory| Description                          |
1279| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
1280| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo)\> | Yes  | Callback used to return the information obtained.|
1281
1282**Error codes**
1283
1284For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1285
1286| ID| Error Message|
1287| -------- | ---------------------------------------- |
1288| 6600101  | Session service exception. |
1289| 6600102  | The session does not exist. |
1290
1291**Example**
1292
1293```js
1294session.getOutputDevice(function (err, outputDeviceInfo) {
1295    if (err) {
1296        console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
1297    } else {
1298        console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`);
1299    }
1300});
1301```
1302
1303### activate
1304
1305activate(): Promise\<void>
1306
1307Activates this session. A session can be used only after being activated. This API uses a promise to return the result.
1308
1309**System capability**: SystemCapability.Multimedia.AVSession.Core
1310
1311**System API**: This is a system API.
1312
1313**Return value**
1314
1315| Type          | Description                         |
1316| -------------- | ----------------------------- |
1317| Promise<void\> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|
1318
1319**Error codes**
1320
1321For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1322
1323| ID| Error Message|
1324| -------- | ---------------------------------------- |
1325| 6600101  | Session service exception. |
1326| 6600102  | The session does not exist. |
1327
1328**Example**
1329
1330```js
1331session.activate().then(() => {
1332    console.info('Activate : SUCCESS ');
1333}).catch((err) => {
1334    console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1335});
1336```
1337
1338### activate
1339
1340activate(callback: AsyncCallback\<void>): void
1341
1342Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result.
1343
1344**System capability**: SystemCapability.Multimedia.AVSession.Core
1345
1346**System API**: This is a system API.
1347
1348**Parameters**
1349
1350| Name  | Type                | Mandatory| Description      |
1351| -------- | -------------------- | ---- | ---------- |
1352| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|
1353
1354**Error codes**
1355
1356For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1357
1358| ID| Error Message|
1359| -------- | ---------------------------------------- |
1360| 6600101  | Session service exception. |
1361| 6600102  | The session does not exist. |
1362
1363**Example**
1364
1365```js
1366session.activate(function (err) {
1367    if (err) {
1368        console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
1369    } else {
1370        console.info('Activate : SUCCESS ');
1371    }
1372});
1373```
1374
1375### deactivate
1376
1377deactivate(): Promise\<void>
1378
1379Deactivates this session. You can use [activate](#activate) to activate the session again. This API uses a promise to return the result.
1380
1381**System capability**: SystemCapability.Multimedia.AVSession.Core
1382
1383**System API**: This is a system API.
1384
1385**Return value**
1386
1387| Type          | Description                         |
1388| -------------- | ----------------------------- |
1389| Promise<void\> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|
1390
1391**Error codes**
1392
1393For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1394
1395| ID| Error Message|
1396| -------- | ---------------------------------------- |
1397| 6600101  | Session service exception. |
1398| 6600102  | The session does not exist. |
1399
1400**Example**
1401
1402```js
1403session.deactivate().then(() => {
1404    console.info('Deactivate : SUCCESS ');
1405}).catch((err) => {
1406    console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1407});
1408```
1409
1410### deactivate
1411
1412deactivate(callback: AsyncCallback\<void>): void
1413
1414Deactivates this session. This API uses an asynchronous callback to return the result.
1415
1416Deactivates this session. You can use [activate](#activate) to activate the session again.
1417
1418**System capability**: SystemCapability.Multimedia.AVSession.Core
1419
1420**System API**: This is a system API.
1421
1422**Parameters**
1423
1424| Name  | Type                | Mandatory| Description      |
1425| -------- | -------------------- | ---- | ---------- |
1426| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|
1427
1428**Error codes**
1429
1430For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1431
1432| ID| Error Message|
1433| -------- | ---------------------------------------- |
1434| 6600101  | Session service exception. |
1435| 6600102  | The session does not exist. |
1436
1437**Example**
1438
1439```js
1440session.deactivate(function (err) {
1441    if (err) {
1442        console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
1443    } else {
1444        console.info('Deactivate : SUCCESS ');
1445    }
1446});
1447```
1448
1449### destroy
1450
1451destroy(): Promise\<void>
1452
1453Destroys this session. This API uses a promise to return the result.
1454
1455**System capability**: SystemCapability.Multimedia.AVSession.Core
1456
1457**System API**: This is a system API.
1458
1459**Return value**
1460
1461| Type          | Description                         |
1462| -------------- | ----------------------------- |
1463| Promise<void\> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|
1464
1465**Error codes**
1466
1467For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1468
1469| ID| Error Message|
1470| -------- | ---------------------------------------- |
1471| 6600101  | Session service exception. |
1472| 6600102  | The session does not exist. |
1473
1474**Example**
1475
1476```js
1477session.destroy().then(() => {
1478    console.info('Destroy : SUCCESS ');
1479}).catch((err) => {
1480    console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1481});
1482```
1483
1484### destroy
1485
1486destroy(callback: AsyncCallback\<void>): void
1487
1488Destroys this session. This API uses an asynchronous callback to return the result.
1489
1490**System capability**: SystemCapability.Multimedia.AVSession.Core
1491
1492**System API**: This is a system API.
1493
1494**Parameters**
1495
1496| Name  | Type                | Mandatory| Description      |
1497| -------- | -------------------- | ---- | ---------- |
1498| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
1499
1500**Error codes**
1501
1502For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1503
1504| ID| Error Message|
1505| -------- | ---------------------------------------- |
1506| 6600101  | Session service exception. |
1507| 6600102  | The session does not exist. |
1508
1509**Example**
1510
1511```js
1512session.destroy(function (err) {
1513    if (err) {
1514        console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
1515    } else {
1516        console.info('Destroy : SUCCESS ');
1517    }
1518});
1519```
1520
1521### on('play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind')
1522
1523on(type: 'play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind', callback: () => void): void
1524
1525Subscribes to playback command events.
1526
1527**System capability**: SystemCapability.Multimedia.AVSession.Core
1528
1529**System API**: This is a system API.
1530
1531**Parameters**
1532
1533| Name  | Type                | Mandatory| Description                                                        |
1534| -------- | -------------------- | ---- | ------------------------------------------------------------ |
1535| type     | string               | Yes  | Event type. The following events are supported: **'play'**, **'pause'**, **'stop'**, **'playNext'**, **'playPrevious'**, **'fastForward'**, and **'rewind'**.<br>The event is reported when the corresponding playback command is sent to the session.|
1536| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                                       |
1537
1538**Error codes**
1539
1540For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1541
1542| ID| Error Message|
1543| -------- | ---------------------------------------- |
1544| 6600101  | Session service exception. |
1545| 6600102  | The session does not exist. |
1546
1547**Example**
1548
1549```js
1550session.on('play', () => {
1551    console.info('on play entry');
1552});
1553session.on('pause', () => {
1554    console.info('on pause entry');
1555});
1556session.on('stop', () => {
1557    console.info('on stop entry');
1558});
1559session.on('playNext', () => {
1560    console.info('on playNext entry');
1561});
1562session.on('playPrevious', () => {
1563    console.info('on playPrevious entry');
1564});
1565session.on('fastForward', () => {
1566    console.info('on fastForward entry');
1567});
1568session.on('rewind', () => {
1569    console.info('on rewind entry');
1570});
1571```
1572
1573### on('seek')
1574
1575on(type: 'seek', callback: (time: number) => void): void
1576
1577Subscribes to the seek event.
1578
1579**System capability**: SystemCapability.Multimedia.AVSession.Core
1580
1581**System API**: This is a system API.
1582
1583**Parameters**
1584
1585| Name  | Type                  | Mandatory| Description                                                        |
1586| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
1587| type     | string                 | Yes  | Event type. The event **'seek'** is reported when the seek command is sent to the session.|
1588| callback | (time: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.                  |
1589
1590**Error codes**
1591
1592For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1593
1594| ID| Error Message|
1595| -------- | ---------------------------------------- |
1596| 6600101  | Session service exception. |
1597| 6600102  | The session does not exist. |
1598
1599**Example**
1600The session does not exist
1601```js
1602session.on('seek', (time) => {
1603    console.info(`on seek entry time : ${time}`);
1604});
1605```
1606
1607### on('setSpeed')
1608
1609on(type: 'setSpeed', callback: (speed: number) => void): void
1610
1611Subscribes to the event for setting the playback speed.
1612
1613**System capability**: SystemCapability.Multimedia.AVSession.Core
1614
1615**System API**: This is a system API.
1616
1617**Parameters**
1618
1619| Name  | Type                   | Mandatory| Description                                                        |
1620| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
1621| type     | string                  | Yes  | Event type. The event **'setSpeed'** is reported when the command for setting the playback speed is sent to the session.|
1622| callback | (speed: number) => void | Yes  | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed.                             |
1623
1624**Error codes**
1625
1626For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1627
1628| ID| Error Message|
1629| -------- | ---------------------------------------- |
1630| 6600101  | Session service exception. |
1631| 6600102  | The session does not exist. |
1632
1633**Example**
1634
1635```js
1636session.on('setSpeed', (speed) => {
1637    console.info(`on setSpeed speed : ${speed}`);
1638});
1639```
1640
1641### on('setLoopMode')
1642
1643on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void
1644
1645Subscribes to the event for setting the loop mode.
1646
1647**System capability**: SystemCapability.Multimedia.AVSession.Core
1648
1649**System API**: This is a system API.
1650
1651**Parameters**
1652
1653| Name   | Type                                  | Mandatory| Description |
1654| -------- | ------------------------------------- | ---- | ---- |
1655| type     | string                                | Yes  | Event type. The event **'setLoopMode'** is reported when the command for setting the loop mode is sent to the session.|
1656| callback | (mode: [LoopMode](#loopmode)) => void | Yes  | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode.                              |
1657
1658**Error codes**
1659
1660For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1661
1662| ID| Error Message|
1663| -------- | ---------------------------------------- |
1664| 6600101  | Session service exception. |
1665| 6600102  | The session does not exist. |
1666
1667**Example**
1668
1669```js
1670session.on('setLoopMode', (mode) => {
1671    console.info(`on setLoopMode mode : ${mode}`);
1672});
1673```
1674
1675### on('toggleFavorite')
1676
1677on(type: 'toggleFavorite', callback: (assetId: string) => void): void
1678
1679Subscribes to the event for favoriting a media asset.
1680
1681**System capability**: SystemCapability.Multimedia.AVSession.Core
1682
1683**System API**: This is a system API.
1684
1685**Parameters**
1686
1687| Name  | Type                     | Mandatory| Description                                                        |
1688| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
1689| type     | string                    | Yes  | Event type. The event **'toggleFavorite'** is reported when the command for favoriting the media asset is sent to the session.|
1690| callback | (assetId: string) => void | Yes  | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID.                             |
1691
1692**Error codes**
1693
1694For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1695
1696| ID| Error Message|
1697| -------- | ---------------------------------------- |
1698| 6600101  | Session service exception. |
1699| 6600102  | The session does not exist. |
1700
1701**Example**
1702
1703```js
1704session.on('toggleFavorite', (assetId) => {
1705    console.info(`on toggleFavorite mode : ${assetId}`);
1706});
1707```
1708
1709### on('handleKeyEvent')
1710
1711on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void
1712
1713Subscribes to the key event.
1714
1715**System capability**: SystemCapability.Multimedia.AVSession.Core
1716
1717**System API**: This is a system API.
1718
1719**Parameters**
1720
1721| Name  | Type                                                        | Mandatory| Description                                                        |
1722| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1723| type     | string                                                       | Yes  | Event type. The event **'handleKeyEvent'** is reported when a key event is sent to the session.|
1724| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | Yes  | Callback used for subscription. The **event** parameter in the callback indicates the key event.                             |
1725
1726**Error codes**
1727
1728For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1729
1730| ID| Error Message|
1731| -------- | ---------------------------------------- |
1732| 6600101  | Session service exception. |
1733| 6600102  | The session does not exist. |
1734
1735**Example**
1736
1737```js
1738session.on('handleKeyEvent', (event) => {
1739    console.info(`on handleKeyEvent event : ${event}`);
1740});
1741```
1742
1743### on('outputDeviceChange')
1744
1745on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void
1746
1747Subscribes to output device changes.
1748
1749**System capability**: SystemCapability.Multimedia.AVSession.Core
1750
1751**System API**: This is a system API.
1752
1753**Parameters**
1754
1755| Name  | Type                                                   | Mandatory| Description                                                        |
1756| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
1757| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is reported when the output device changes.|
1758| callback | (device: [OutputDeviceInfo](#outputdeviceinfo)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.                        |
1759
1760**Error codes**
1761
1762For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1763
1764| ID| Error Message|
1765| -------- | ---------------------------------------- |
1766| 6600101  | Session service exception. |
1767| 6600102  | The session does not exist. |
1768
1769**Example**
1770
1771```js
1772session.on('outputDeviceChange', (device) => {
1773    console.info(`on outputDeviceChange device isRemote : ${device.isRemote}`);
1774});
1775```
1776
1777### off('play'|'pause'|'stop'|'playNext'|'playPrevious'|'fastForward'|'rewind')
1778
1779off(type: 'play' | 'pause' | 'stop' | 'playNext' | 'playPrevious' | 'fastForward' | 'rewind', callback?: () => void): void
1780
1781Unsubscribes from playback command events.
1782
1783**System capability**: SystemCapability.Multimedia.AVSession.Core
1784
1785**System API**: This is a system API.
1786
1787**Parameters**
1788
1789| Name   | Type                 | Mandatory| Description                                                                                                                        |
1790| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
1791| type     | string               | Yes  | Event type. The following events are supported: **'play'**, **'pause'**, **'stop'**, **'playNext'**, **'playPrevious'**, **'fastForward'**, and **'rewind'**.|
1792| callback | callback: () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                           |
1793
1794**Error codes**
1795
1796For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1797
1798| ID| Error Message|
1799| -------- | ---------------------------------------- |
1800| 6600101  | Session service exception. |
1801| 6600102  | The session does not exist. |
1802
1803**Example**
1804
1805```js
1806session.off('play');
1807session.off('pause');
1808session.off('stop');
1809session.off('playNext');
1810session.off('playPrevious');
1811session.off('fastForward');
1812session.off('rewind');
1813```
1814
1815### off('seek')
1816
1817off(type: 'seek', callback?: (time: number) => void): void
1818
1819Unsubscribes from the seek event.
1820
1821**System capability**: SystemCapability.Multimedia.AVSession.Core
1822
1823**System API**: This is a system API.
1824
1825**Parameters**
1826
1827| Name  | Type                  | Mandatory| Description                                         |
1828| -------- | ---------------------- | ---- | ----------------------------------------- |
1829| type     | string                 | Yes  | Event type. The value is fixed at **'seek'**.      |
1830| callback | (time: number) => void | No  | Callback used for unsubscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.       |
1831
1832**Error codes**
1833
1834For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1835
1836| ID| Error Message|
1837| -------- | ---------------------------------------- |
1838| 6600101  | Session service exception. |
1839| 6600102  | The session does not exist. |
1840
1841**Example**
1842
1843```js
1844session.off('seek');
1845```
1846
1847### off('setSpeed')
1848
1849off(type: 'setSpeed', callback?: (speed: number) => void): void
1850
1851Unsubscribes from the event for setting the playback speed.
1852
1853**System capability**: SystemCapability.Multimedia.AVSession.Core
1854
1855**System API**: This is a system API.
1856
1857**Parameters**
1858
1859| Name  | Type                   | Mandatory| Description                                          |
1860| -------- | ----------------------- | ---- | -------------------------------------------|
1861| type     | string                  | Yes  | Event type. The value is fixed at **'setSpeed'**.   |
1862| callback | (speed: number) => void | No  | Callback used for unsubscription. The **speed** parameter in the callback indicates the playback speed.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                |
1863
1864**Error codes**
1865
1866For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1867
1868| ID| Error Message|
1869| -------- | ---------------------------------------- |
1870| 6600101  | Session service exception. |
1871| 6600102  | The session does not exist. |
1872
1873**Example**
1874
1875```js
1876session.off('setSpeed');
1877```
1878
1879### off('setLoopMode')
1880
1881off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void
1882
1883Unsubscribes from the event for setting loop mode.
1884
1885**System capability**: SystemCapability.Multimedia.AVSession.Core
1886
1887**System API**: This is a system API.
1888
1889**Parameters**
1890
1891| Name  | Type                                 | Mandatory| Description    |
1892| -------- | ------------------------------------- | ---- | ----- |
1893| type     | string | Yes  | Event type. The value is fixed at **'setLoopMode'**.|
1894| callback | (mode: [LoopMode](#loopmode)) => void | No  | Callback used for unsubscription. The **mode** parameter in the callback indicates the loop mode.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
1895
1896**Error codes**
1897
1898For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1899
1900| ID| Error Message|
1901| -------- | ---------------------------------------- |
1902| 6600101  | Session service exception. |
1903| 6600102  | The session does not exist. |
1904
1905**Example**
1906
1907```js
1908session.off('setLoopMode');
1909```
1910
1911### off('toggleFavorite')
1912
1913off(type: 'toggleFavorite', callback?: (assetId: string) => void): void
1914
1915Unsubscribes from the event for favoriting a media asset.
1916
1917**System capability**: SystemCapability.Multimedia.AVSession.Core
1918
1919**System API**: This is a system API.
1920
1921**Parameters**
1922
1923| Name  | Type                     | Mandatory| Description                                                        |
1924| -------- | ------------------------- | ---- | -------------------------------------------------------- |
1925| type     | string                    | Yes  | Event type. The value is fixed at **'toggleFavorite'**.           |
1926| callback | (assetId: string) => void | No  | Callback used for unsubscription. The **assetId** parameter in the callback indicates the media asset ID.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                              |
1927
1928**Error codes**
1929
1930For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1931
1932| ID| Error Message|
1933| -------- | ---------------------------------------- |
1934| 6600101  | Session service exception. |
1935| 6600102  | The session does not exist. |
1936
1937**Example**
1938
1939```js
1940session.off('toggleFavorite');
1941```
1942
1943### off('handleKeyEvent')
1944
1945off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
1946
1947Unsubscribes from the key event.
1948
1949**System capability**: SystemCapability.Multimedia.AVSession.Core
1950
1951**System API**: This is a system API.
1952
1953**Parameters**
1954
1955| Name  | Type                                                        | Mandatory| Description                                                        |
1956| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
1957| type     | string                                                       | Yes  | Event type. The value is fixed at **'handleKeyEvent'**.            |
1958| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | No  | Callback used for unsubscription. The **event** parameter in the callback indicates the key event.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                             |
1959
1960**Error codes**
1961
1962For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1963
1964| ID| Error Message|
1965| -------- | ---------------------------------------- |
1966| 6600101  | Session service exception. |
1967| 6600102  | The session does not exist. |
1968
1969**Example**
1970
1971```js
1972session.off('handleKeyEvent');
1973```
1974
1975### off('outputDeviceChange')
1976
1977off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void
1978
1979Unsubscribes from playback device changes.
1980
1981**System capability**: SystemCapability.Multimedia.AVSession.Core
1982
1983**System API**: This is a system API.
1984
1985**Parameters**
1986
1987| Name  | Type                                                   | Mandatory| Description                                                     |
1988| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
1989| type     | string                                                  | Yes  | Event type. The value is fixed at **'outputDeviceChange'**.    |
1990| callback | (device: [OutputDeviceInfo](#outputdeviceinfo)) => void | No  | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.<br>If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                       |
1991
1992**Error codes**
1993
1994For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
1995
1996| ID| Error Message|
1997| -------- | ---------------------------------------- |
1998| 6600101  | Session service exception. |
1999| 6600102  | The session does not exist. |
2000
2001**Example**
2002
2003```js
2004session.off('outputDeviceChange');
2005```
2006
2007
2008
2009## AVSessionController
2010
2011An AV session controller is created by calling [avSession.createController](#avsessioncreatecontroller). Through the AV session controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
2012
2013### Attributes
2014
2015**System capability**: SystemCapability.Multimedia.AVSession.Core
2016
2017**System API**: This is a system API.
2018
2019| Name     | Type  | Readable| Writable| Description                                   |
2020| :-------- | :----- | :--- | :--- | :-------------------------------------- |
2021| sessionId | string | Yes  | No  | Unique session ID of the **AVSessionController** object.|
2022
2023
2024**Example**
2025```js
2026let sessionId;
2027await avSession.createController(session.sessionId).then((controller) => {
2028    sessionId = controller.sessionId;
2029}).catch((err) => {
2030    console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
2031});
2032```
2033
2034### getAVPlaybackState
2035
2036getAVPlaybackState(): Promise\<AVPlaybackState>
2037
2038Obtains the information related to the playback state. This API uses a promise to return the result.
2039
2040**System capability**: SystemCapability.Multimedia.AVSession.Core
2041
2042**System API**: This is a system API.
2043
2044**Return value**
2045
2046| Type                                         | Description                       |
2047| --------------------------------------------- | --------------------------- |
2048| Promise<[AVPlaybackState](#avplaybackstate)\> | Promise used to return the **AVPlaybackState** object.|
2049
2050**Error codes**
2051
2052For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2053
2054| ID| Error Message|
2055| -------- | ---------------------------------------- |
2056| 6600101  | Session service exception. |
2057| 6600102  | The session does not exist. |
2058| 6600103  | The session controller does not exist. |
2059
2060**Example**
2061```js
2062controller.getAVPlaybackState().then((playbackState) => {
2063    console.info(`GetAVPlaybackState : SUCCESS : state : ${playbackState.state}`);
2064}).catch((err) => {
2065    console.info(`GetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
2066});
2067```
2068
2069### getAVPlaybackState
2070
2071getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
2072
2073Obtains the information related to the playback state. This API uses an asynchronous callback to return the result.
2074
2075**System capability**: SystemCapability.Multimedia.AVSession.Core
2076
2077**System API**: This is a system API.
2078
2079**Parameters**
2080
2081| Name  | Type                                               | Mandatory| Description                        |
2082| -------- | --------------------------------------------------- | ---- | ---------------------------- |
2083| callback | AsyncCallback<[AVPlaybackState](#avplaybackstate)\> | Yes  | Callback used to return the **AVPlaybackState** object.|
2084
2085**Error codes**
2086
2087For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2088
2089| ID| Error Message|
2090| -------- | ---------------------------------------- |
2091| 6600101  | Session service exception. |
2092| 6600102  | The session does not exist. |
2093| 6600103  | The session controller does not exist. |
2094
2095**Example**
2096```js
2097controller.getAVPlaybackState(function (err, playbackState) {
2098    if (err) {
2099        console.info(`GetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
2100    } else {
2101        console.info(`GetAVPlaybackState : SUCCESS : state : ${playbackState.state}`);
2102    }
2103});
2104```
2105
2106### getAVMetadata
2107
2108getAVMetadata(): Promise\<AVMetadata>
2109
2110Obtains the session metadata. This API uses a promise to return the result.
2111
2112**System capability**: SystemCapability.Multimedia.AVSession.Core
2113
2114**System API**: This is a system API.
2115
2116**Return value**
2117
2118| Type                               | Description                         |
2119| ----------------------------------- | ----------------------------- |
2120| Promise<[AVMetadata](#avmetadata)\> | Promise used to return the metadata obtained.|
2121
2122**Error codes**
2123
2124For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2125
2126| ID| Error Message|
2127| -------- | ---------------------------------------- |
2128| 6600101  | Session service exception. |
2129| 6600102  | The session does not exist. |
2130| 6600103  | The session controller does not exist. |
2131
2132**Example**
2133```js
2134controller.getAVMetadata().then((metadata) => {
2135    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
2136}).catch((err) => {
2137    console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
2138});
2139```
2140
2141### getAVMetadata
2142
2143getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
2144
2145Obtains the session metadata. This API uses an asynchronous callback to return the result.
2146
2147**System capability**: SystemCapability.Multimedia.AVSession.Core
2148
2149**System API**: This is a system API.
2150
2151**Parameters**
2152
2153| Name  | Type                                     | Mandatory| Description                      |
2154| -------- | ----------------------------------------- | ---- | -------------------------- |
2155| callback | AsyncCallback<[AVMetadata](#avmetadata)\> | Yes  | Callback used to return the metadata obtained.|
2156
2157**Error codes**
2158
2159For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2160
2161| ID| Error Message|
2162| -------- | ---------------------------------------- |
2163| 6600101  | Session service exception. |
2164| 6600102  | The session does not exist. |
2165| 6600103  | The session controller does not exist. |
2166
2167**Example**
2168```js
2169controller.getAVMetadata(function (err, metadata) {
2170    if (err) {
2171        console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
2172    } else {
2173        console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
2174    }
2175});
2176```
2177
2178### getOutputDevice
2179
2180getOutputDevice(): Promise\<OutputDeviceInfo>
2181
2182Obtains the output device information. This API uses a promise to return the result.
2183
2184**System capability**: SystemCapability.Multimedia.AVSession.Core
2185
2186**System API**: This is a system API.
2187
2188**Return value**
2189
2190| Type                                           | Description                             |
2191| ----------------------------------------------- | --------------------------------- |
2192| Promise<[OutputDeviceInfo](#outputdeviceinfo)\> | Promise used to return the information obtained.|
2193
2194**Error codes**
2195
2196For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2197
2198| ID| Error Message|
2199| -------- | ---------------------------------------- |
2200| 6600101  | Session service exception. |
2201| 6600103  | The session controller does not exist. |
2202
2203**Example**
2204```js
2205controller.getOutputDevice().then((deviceInfo) => {
2206    console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`);
2207}).catch((err) => {
2208    console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
2209});
2210```
2211
2212### getOutputDevice
2213
2214getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
2215
2216Obtains the output device information. This API uses an asynchronous callback to return the result.
2217
2218**System capability**: SystemCapability.Multimedia.AVSession.Core
2219
2220**System API**: This is a system API.
2221
2222**Parameters**
2223
2224| Name  | Type                                                 | Mandatory| Description                          |
2225| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
2226| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo)\> | Yes  | Callback used to return the information obtained.|
2227
2228**Error codes**
2229
2230For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2231
2232| ID| Error Message|
2233| -------- | ---------------------------------------- |
2234| 6600101  | Session service exception. |
2235| 6600103  | The session controller does not exist. |
2236
2237**Example**
2238
2239```js
2240controller.getOutputDevice(function (err, deviceInfo) {
2241    if (err) {
2242        console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
2243    } else {
2244        console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`);
2245    }
2246});
2247```
2248
2249### sendAVKeyEvent
2250
2251sendAVKeyEvent(event: KeyEvent): Promise\<void>
2252
2253Sends a key event to the session corresponding to this controller. This API uses a promise to return the result.
2254
2255**System capability**: SystemCapability.Multimedia.AVSession.Core
2256
2257**System API**: This is a system API.
2258
2259**Parameters**
2260
2261| Name| Type                                                        | Mandatory| Description      |
2262| ------ | ------------------------------------------------------------ | ---- | ---------- |
2263| event  | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|
2264
2265**Error codes**
2266
2267For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2268
2269| ID| Error Message|
2270| -------- | ---------------------------------------- |
2271| 6600101  | Session service exception. |
2272| 6600102  | The session does not exist. |
2273| 6600103  | The session controller does not exist. |
2274| 6600105  | Invalid session command. |
2275| 6600106  | The session is not activated. |
2276
2277**Return value**
2278
2279| Type          | Description                         |
2280| -------------- | ----------------------------- |
2281| Promise<void\> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
2282
2283**Example**
2284
2285```js
2286let keyItem = {code:0x49, pressedTime:2, deviceId:0};
2287let event = {action:2, key:keyItem, keys:[keyItem]};
2288
2289controller.sendAVKeyEvent(event).then(() => {
2290    console.info('SendAVKeyEvent Successfully');
2291}).catch((err) => {
2292    console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
2293});
2294```
2295
2296### sendAVKeyEvent
2297
2298sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
2299
2300Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.
2301
2302**System capability**: SystemCapability.Multimedia.AVSession.Core
2303
2304**System API**: This is a system API.
2305
2306**Parameters**
2307
2308| Name  | Type                                                        | Mandatory| Description      |
2309| -------- | ------------------------------------------------------------ | ---- | ---------- |
2310| event    | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|
2311| callback | AsyncCallback<void\>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
2312
2313**Error codes**
2314
2315For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2316
2317| ID| Error Message|
2318| -------- | ---------------------------------------- |
2319| 6600101  | Session service exception. |
2320| 6600102  | The session does not exist. |
2321| 6600103  | The session controller does not exist. |
2322| 6600105  | Invalid session command. |
2323| 6600106  | The session is not activated. |
2324
2325**Example**
2326
2327```js
2328let keyItem = {code:0x49, pressedTime:2, deviceId:0};
2329let event = {action:2, key:keyItem, keys:[keyItem]};
2330
2331controller.sendAVKeyEvent(event, function (err) {
2332    if (err) {
2333        console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
2334    } else {
2335        console.info('SendAVKeyEvent Successfully');
2336    }
2337});
2338```
2339
2340### getLaunchAbility
2341
2342getLaunchAbility(): Promise\<WantAgent>
2343
2344Obtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result.
2345
2346**System capability**: SystemCapability.Multimedia.AVSession.Core
2347
2348**System API**: This is a system API.
2349
2350**Return value**
2351
2352| Type                                                   | Description                                                        |
2353| ------------------------------------------------------- | ------------------------------------------------------------ |
2354| Promise<[WantAgent](js-apis-wantAgent.md)\> | Promise used to return the object saved by calling [setLaunchAbility](#setlaunchability). The object includes the application attribute, such as the bundle name, ability name, and device ID.|
2355
2356**Error codes**
2357
2358For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2359
2360| ID| Error Message|
2361| -------- | ---------------------------------------- |
2362| 6600101  | Session service exception. |
2363| 6600102  | The session does not exist. |
2364| 6600103  | The session controller does not exist. |
2365
2366**Example**
2367
2368```js
2369import wantAgent from '@ohos.wantAgent';
2370
2371controller.getLaunchAbility().then((agent) => {
2372    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
2373}).catch((err) => {
2374    console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
2375});
2376```
2377
2378### getLaunchAbility
2379
2380getLaunchAbility(callback: AsyncCallback\<WantAgent>): void
2381
2382Obtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result.
2383
2384**System capability**: SystemCapability.Multimedia.AVSession.Core
2385
2386**System API**: This is a system API.
2387
2388**Parameters**
2389
2390| Name  | Type                                                        | Mandatory| Description                                                        |
2391| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2392| callback | AsyncCallback<[WantAgent](js-apis-wantAgent.md)\> | Yes  | Callback used to return the object saved by calling [setLaunchAbility](#setlaunchability). The object includes the application attribute, such as the bundle name, ability name, and device ID.|
2393
2394**Error codes**
2395
2396For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2397
2398| ID| Error Message|
2399| -------- | ---------------------------------------- |
2400| 6600101  | Session service exception. |
2401| 6600102  | The session does not exist. |
2402| 6600103  | The session controller does not exist. |
2403
2404**Example**
2405
2406```js
2407import wantAgent from '@ohos.wantAgent';
2408
2409controller.getLaunchAbility(function (err, agent) {
2410    if (err) {
2411        console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
2412    } else {
2413        console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
2414    }
2415});
2416```
2417
2418### getRealPlaybackPositionSync
2419
2420getRealPlaybackPositionSync(): number
2421
2422Obtains the playback position.
2423
2424**System capability**: SystemCapability.Multimedia.AVSession.Core
2425
2426**System API**: This is a system API.
2427
2428**Return value**
2429
2430| Type  | Description              |
2431| ------ | ------------------ |
2432| number | Playback position, in milliseconds.|
2433
2434**Error codes**
2435
2436For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2437
2438| ID| Error Message|
2439| -------- | ---------------------------------------- |
2440| 6600101  | Session service exception. |
2441| 6600103  | The session controller does not exist. |
2442
2443**Example**
2444
2445```js
2446let time = controller.getRealPlaybackPositionSync();
2447```
2448
2449### isActive
2450
2451isActive(): Promise\<boolean>
2452
2453Checks whether the session is activated. This API uses a promise to return the result.
2454
2455**System capability**: SystemCapability.Multimedia.AVSession.Core
2456
2457**System API**: This is a system API.
2458
2459**Return value**
2460
2461| Type             | Description                                                        |
2462| ----------------- | ------------------------------------------------------------ |
2463| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
2464
2465**Error codes**
2466
2467For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2468
2469| ID| Error Message|
2470| -------- | ---------------------------------------- |
2471| 6600101  | Session service exception. |
2472| 6600102  | The session does not exist. |
2473| 6600103  | The session controller does not exist. |
2474
2475**Example**
2476
2477```js
2478controller.isActive().then((isActive) => {
2479    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
2480}).catch((err) => {
2481    console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
2482});
2483```
2484
2485### isActive
2486
2487isActive(callback: AsyncCallback\<boolean>): void
2488
2489Checks whether the session is activated. This API uses an asynchronous callback to return the result.
2490
2491**System capability**: SystemCapability.Multimedia.AVSession.Core
2492
2493**System API**: This is a system API.
2494
2495**Parameters**
2496
2497| Name  | Type                   | Mandatory| Description                                                        |
2498| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
2499| callback | AsyncCallback<boolean\> | Yes  | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|
2500
2501**Error codes**
2502
2503For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2504
2505| ID| Error Message|
2506| -------- | ---------------------------------------- |
2507| 6600101  | Session service exception. |
2508| 6600102  | The session does not exist. |
2509| 6600103  | The session controller does not exist. |
2510
2511**Example**
2512
2513```js
2514controller.isActive(function (err, isActive) {
2515    if (err) {
2516        console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
2517    } else {
2518        console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
2519    }
2520});
2521```
2522
2523### destroy
2524
2525destroy(): Promise\<void>
2526
2527Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.
2528
2529**System capability**: SystemCapability.Multimedia.AVSession.Core
2530
2531**System API**: This is a system API.
2532
2533**Return value**
2534
2535| Type          | Description                         |
2536| -------------- | ----------------------------- |
2537| Promise<void\> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.|
2538
2539**Error codes**
2540
2541For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2542
2543| ID| Error Message|
2544| -------- | ---------------------------------------- |
2545| 6600101  | Session service exception. |
2546| 6600103  | The session controller does not exist. |
2547
2548**Example**
2549
2550```js
2551controller.destroy().then(() => {
2552    console.info('Destroy : SUCCESS ');
2553}).catch((err) => {
2554    console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
2555});
2556```
2557
2558### destroy
2559
2560destroy(callback: AsyncCallback\<void>): void
2561
2562Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.
2563
2564**System capability**: SystemCapability.Multimedia.AVSession.Core
2565
2566**System API**: This is a system API.
2567
2568**Parameters**
2569
2570| Name  | Type                | Mandatory| Description      |
2571| -------- | -------------------- | ---- | ---------- |
2572| callback | AsyncCallback<void\> | Yes  | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
2573
2574**Error codes**
2575
2576For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2577
2578| ID| Error Message|
2579| -------- | ---------------------------------------- |
2580| 6600101  | Session service exception. |
2581| 6600103  | The session controller does not exist. |
2582
2583**Example**
2584
2585```js
2586controller.destroy(function (err) {
2587    if (err) {
2588        console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
2589    } else {
2590        console.info('Destroy : SUCCESS ');
2591    }
2592});
2593```
2594
2595### getValidCommands
2596
2597getValidCommands(): Promise\<Array\<AVControlCommandType>>
2598
2599Obtains valid commands supported by the session. This API uses a promise to return the result.
2600
2601**System capability**: SystemCapability.Multimedia.AVSession.Core
2602
2603**System API**: This is a system API.
2604
2605**Return value**
2606
2607| Type                                                        | Description                             |
2608| ------------------------------------------------------------ | --------------------------------- |
2609| Promise<Array<[AVControlCommandType](#avcontrolcommandtype)\>\> | Promise used to return a set of valid commands.|
2610
2611**Error codes**
2612
2613For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2614
2615| ID| Error Message|
2616| -------- | ---------------------------------------- |
2617| 6600101  | Session service exception. |
2618| 6600102  | The session does not exist. |
2619| 6600103  | The session controller does not exist. |
2620
2621**Example**
2622
2623```js
2624controller.getValidCommands.then((validCommands) => {
2625    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
2626}).catch((err) => {
2627    console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
2628});
2629```
2630
2631### getValidCommands
2632
2633getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void
2634
2635Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result.
2636
2637**System capability**: SystemCapability.Multimedia.AVSession.Core
2638
2639**System API**: This is a system API.
2640
2641**Parameters**
2642
2643| Name  | Type                                                        | Mandatory| Description                          |
2644| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
2645| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype)\>\> | Yes  | Callback used to return a set of valid commands.|
2646
2647**Error codes**
2648
2649For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2650
2651| ID| Error Message|
2652| -------- | ---------------------------------------- |
2653| 6600101  | Session service exception. |
2654| 6600102  | The session does not exist. |
2655| 6600103  | The session controller does not exist. |
2656
2657**Example**
2658
2659```js
2660controller.getValidCommands(function (err, validCommands) {
2661    if (err) {
2662        console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
2663    } else {
2664        console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
2665    }
2666});
2667```
2668
2669### sendControlCommand
2670
2671sendControlCommand(command: AVControlCommand): Promise\<void>
2672
2673Sends a control command to the session through the controller. This API uses a promise to return the result.
2674
2675**System capability**: SystemCapability.Multimedia.AVSession.Core
2676
2677**System API**: This is a system API.
2678
2679**Parameters**
2680
2681| Name   | Type                                 | Mandatory| Description                          |
2682| ------- | ------------------------------------- | ---- | ------------------------------ |
2683| command | [AVControlCommand](#avcontrolcommand) | Yes  | Command to send.|
2684
2685**Return value**
2686
2687| Type          | Description                         |
2688| -------------- | ----------------------------- |
2689| Promise<void\> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
2690
2691**Error codes**
2692
2693For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2694
2695| ID| Error Message|
2696| -------- | ---------------------------------------- |
2697| 6600101  | Session service exception. |
2698| 6600102  | The session does not exist. |
2699| 6600103  | The session controller does not exist. |
2700| 6600105  | Invalid session command. |
2701| 6600106  | The session is not activated. |
2702| 6600107  | Too many commands or events. |
2703
2704**Example**
2705
2706```js
2707let avCommand = {command:'play'};
2708// let avCommand = {command:'pause'};
2709// let avCommand = {command:'stop'};
2710// let avCommand = {command:'playNext'};
2711// let avCommand = {command:'playPrevious'};
2712// let avCommand = {command:'fastForward'};
2713// let avCommand = {command:'rewind'};
2714// let avCommand = {command:'seek', parameter:10};
2715// let avCommand = {command:'setSpeed', parameter:2.6};
2716// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
2717// let avCommand = {command:'toggleFavorite', parameter:"false"};
2718controller.sendControlCommand(avCommand).then(() => {
2719    console.info('SendControlCommand successfully');
2720}).catch((err) => {
2721    console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
2722});
2723```
2724
2725### sendControlCommand
2726
2727sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
2728
2729Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
2730
2731**System capability**: SystemCapability.Multimedia.AVSession.Core
2732
2733**System API**: This is a system API.
2734
2735**Parameters**
2736
2737| Name  | Type                                 | Mandatory| Description                          |
2738| -------- | ------------------------------------- | ---- | ------------------------------ |
2739| command  | [AVControlCommand](#avcontrolcommand) | Yes  | Command to send.|
2740| callback | AsyncCallback<void\>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
2741
2742**Error codes**
2743
2744For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2745
2746| ID| Error Message|
2747| -------- | ------------------------------- |
2748| 6600101  | Session service exception.                |
2749| 6600102  | The session does not exist.     |
2750| 6600103  | The session controller does not exist.   |
2751| 6600105  | Invalid session command.           |
2752| 6600106  | The session is not activated.                |
2753| 6600107  | Too many commands or events.      |
2754
2755**Example**
2756
2757```js
2758let avCommand = {command:'play'};
2759// let avCommand = {command:'pause'};
2760// let avCommand = {command:'stop'};
2761// let avCommand = {command:'playNext'};
2762// let avCommand = {command:'playPrevious'};
2763// let avCommand = {command:'fastForward'};
2764// let avCommand = {command:'rewind'};
2765// let avCommand = {command:'seek', parameter:10};
2766// let avCommand = {command:'setSpeed', parameter:2.6};
2767// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
2768// let avCommand = {command:'toggleFavorite', parameter:"false"};
2769controller.sendControlCommand(avCommand, function (err) {
2770    if (err) {
2771        console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
2772    } else {
2773        console.info('SendControlCommand successfully');
2774    }
2775});
2776```
2777
2778### on('metadataChange')
2779
2780on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
2781
2782Subscribes to the metadata change event.
2783
2784**System capability**: SystemCapability.Multimedia.AVSession.Core
2785
2786**System API**: This is a system API.
2787
2788**Parameters**
2789
2790| Name  | Type                                                        | Mandatory| Description                                                        |
2791| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2792| type     | string                                                       | Yes  | Event type. The event **'metadataChange'** is reported when the session metadata changes.|
2793| filter   | Array\<keyof&nbsp;[AVMetadata](#avmetadata)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any metadata field change will trigger the event, and **Array<keyof [AVMetadata](#avmetadata)\>** indicates that only changes to the listed metadata field will trigger the event.|
2794| callback | (data: [AVMetadata](#avmetadata)) => void                    | Yes  | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.                        |
2795
2796**Error codes**
2797
2798For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2799
2800| ID| Error Message|
2801| -------- | ------------------------------ |
2802| 6600101  | Session service exception. |
2803| 6600103  | The session controller does not exist. |
2804
2805**Example**
2806
2807```js
2808controller.on('metadataChange', 'all', (metadata) => {
2809    console.info(`on metadataChange assetId : ${metadata.assetId}`);
2810});
2811
2812let metaFilter = ['assetId', 'title', 'description'];
2813controller.on('metadataChange', metaFilter, (metadata) => {
2814    console.info(`on metadataChange assetId : ${metadata.assetId}`);
2815});
2816```
2817
2818### on('playbackStateChange')
2819
2820on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
2821
2822Subscribes to the playback state change event.
2823
2824**System capability**: SystemCapability.Multimedia.AVSession.Core
2825
2826**System API**: This is a system API.
2827
2828**Parameters**
2829
2830| Name  | Type                                                        | Mandatory| Description                                                        |
2831| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2832| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is reported when the playback state changes.|
2833| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof [AVPlaybackState](#avplaybackstate)\>** indicates that only changes to the listed playback state field will trigger the event.|
2834| callback | (state: [AVPlaybackState](#avplaybackstate)) => void         | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.                     |
2835
2836**Error codes**
2837
2838For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2839
2840| ID| Error Message|
2841| -------- | ------------------------------ |
2842| 6600101  | Session service exception. |
2843| 6600103  | The session controller does not exist. |
2844
2845**Example**
2846
2847```js
2848controller.on('playbackStateChange', 'all', (playbackState) => {
2849    console.info(`on playbackStateChange state : ${playbackState.state}`);
2850});
2851
2852let playbackFilter = ['state', 'speed', 'loopMode'];
2853controller.on('playbackStateChange', playbackFilter, (playbackState) => {
2854    console.info(`on playbackStateChange state : ${playbackState.state}`);
2855});
2856```
2857
2858### on('sessionDestroy')
2859
2860on(type: 'sessionDestroy', callback: () => void)
2861
2862Subscribes to the session destruction event.
2863
2864**System capability**: SystemCapability.Multimedia.AVSession.Core
2865
2866**System API**: This is a system API.
2867
2868**Parameters**
2869
2870| Name  | Type      | Mandatory| Description                                                        |
2871| -------- | ---------- | ---- | ------------------------------------------------------------ |
2872| type     | string     | Yes  | Event type. The event **'sessionDestroy'** is reported when the session is destroyed.|
2873| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                 |
2874
2875**Error codes**
2876
2877For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2878
2879| ID| Error Message|
2880| -------- | ------------------------------ |
2881| 6600101  | Session service exception. |
2882| 6600103  | The session controller does not exist. |
2883
2884**Example**
2885
2886```js
2887controller.on('sessionDestroy', () => {
2888    console.info('on sessionDestroy : SUCCESS ');
2889});
2890```
2891
2892### on('activeStateChange')
2893
2894on(type: 'activeStateChange', callback: (isActive: boolean) => void)
2895
2896Subscribes to the session activation state change event.
2897
2898**System capability**: SystemCapability.Multimedia.AVSession.Core
2899
2900**System API**: This is a system API.
2901
2902**Parameters**
2903
2904| Name  | Type                       | Mandatory| Description                                                        |
2905| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
2906| type     | string                      | Yes  | Event type. The event **'activeStateChange'** is reported when the activation state of the session changes.|
2907| callback | (isActive: boolean) => void | Yes  | Callback used for subscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the service is activated, and **false** means the opposite.                  |
2908
2909**Error codes**
2910
2911For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2912
2913| ID| Error Message|
2914| -------- | ----------------------------- |
2915| 6600101  | Session service exception. |
2916| 6600103  |The session controller does not exist. |
2917
2918**Example**
2919
2920```js
2921controller.on('activeStateChange', (isActive) => {
2922    console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
2923});
2924```
2925
2926### on('validCommandChange')
2927
2928on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
2929
2930Subscribes to valid command changes.
2931
2932**System capability**: SystemCapability.Multimedia.AVSession.Core
2933
2934**System API**: This is a system API.
2935
2936**Parameters**
2937
2938| Name  | Type                                                        | Mandatory| Description                                                        |
2939| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
2940| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is reported when the valid commands supported by the session changes.|
2941| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype)\>) => void | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
2942
2943**Error codes**
2944
2945For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2946
2947| ID| Error Message|
2948| -------- | ------------------------------ |
2949| 6600101  | Session service exception. |
2950| 6600103  | The session controller does not exist. |
2951
2952**Example**
2953
2954```js
2955controller.on('validCommandChange', (validCommands) => {
2956    console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`);
2957    console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
2958});
2959```
2960
2961### on('outputDeviceChange')
2962
2963on(type: 'outputDeviceChange', callback: (device: OutputDeviceInfo) => void): void
2964
2965Subscribes to output device changes.
2966
2967**System capability**: SystemCapability.Multimedia.AVSession.Core
2968
2969**System API**: This is a system API.
2970
2971**Parameters**
2972
2973| Name  | Type                                                   | Mandatory| Description                                                        |
2974| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
2975| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is reported when the output device changes.|
2976| callback | (device: [OutputDeviceInfo](#outputdeviceinfo)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.                        |
2977
2978**Error codes**
2979
2980For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
2981
2982| ID| Error Message|
2983| -------- | ----------------------- |
2984| 6600101  | Session service exception. |
2985| 6600103  | The session controller does not exist. |
2986
2987**Example**
2988
2989```js
2990controller.on('outputDeviceChange', (device) => {
2991    console.info(`on outputDeviceChange device isRemote : ${device.isRemote}`);
2992});
2993```
2994
2995### off('metadataChange')
2996
2997off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
2998
2999Unsubscribes from metadata changes.
3000
3001**System capability**: SystemCapability.Multimedia.AVSession.Core
3002
3003**System API**: This is a system API.
3004
3005**Parameters**
3006
3007| Name  | Type                                              | Mandatory| Description                                                   |
3008| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
3009| type     | string                                           | Yes  | Event type. The event **'metadataChange'** is reported when the session metadata changes.        |
3010| callback | (data: [AVMetadata](#avmetadata)) => void        | No  | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                        |
3011
3012**Error codes**
3013
3014For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3015
3016| ID| Error Message|
3017| -------- | ---------------- |
3018| 6600101  | Session service exception. |
3019
3020**Example**
3021
3022```js
3023controller.off('metadataChange');
3024```
3025
3026### off('playbackStateChange')
3027
3028off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
3029
3030Unsubscribes from playback state changes.
3031
3032**System capability**: SystemCapability.Multimedia.AVSession.Core
3033
3034**System API**: This is a system API.
3035
3036**Parameters**
3037
3038| Name  | Type                                                        | Mandatory| Description                                                    |
3039| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
3040| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is reported when the playback state changes.   |
3041| callback | (state: [AVPlaybackState](#avplaybackstate)) => void         | No  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
3042
3043**Error codes**
3044
3045For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3046
3047| ID| Error Message|
3048| -------- | ---------------- |
3049| 6600101  | Session service exception. |
3050
3051**Example**
3052
3053```js
3054controller.off('playbackStateChange');
3055```
3056
3057### off('sessionDestroy')
3058
3059off(type: 'sessionDestroy', callback?: () => void)
3060
3061Unsubscribes from the session destruction event.
3062
3063**System capability**: SystemCapability.Multimedia.AVSession.Core
3064
3065**System API**: This is a system API.
3066
3067**Parameters**
3068
3069| Name  | Type      | Mandatory| Description                                                     |
3070| -------- | ---------- | ---- | ----------------------------------------------------- |
3071| type     | string     | Yes  | Event type. The event **'sessionDestroy'** is reported when the session is destroyed.        |
3072| callback | () => void | No  | Callback used for unsubscription. If the unsubscription is successful, **err** is **undefined**; otherwise, **err** is an error object.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                                              |
3073
3074**Error codes**
3075
3076For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3077
3078| ID| Error Message|
3079| -------- | ---------------- |
3080| 6600101  | Session service exception. |
3081
3082**Example**
3083
3084```js
3085controller.off('sessionDestroy');
3086```
3087
3088### off('activeStateChange')
3089
3090off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
3091
3092Unsubscribes from session activation state changes.
3093
3094**System capability**: SystemCapability.Multimedia.AVSession.Core
3095
3096**System API**: This is a system API.
3097
3098**Parameters**
3099
3100| Name  | Type                       | Mandatory| Description                                                     |
3101| -------- | --------------------------- | ---- | ----------------------------------------------------- |
3102| type     | string                      | Yes  | Event type. The event **'activeStateChange'** is reported when the session activation state changes.     |
3103| callback | (isActive: boolean) => void | No  | Callback used for unsubscription. The **isActive** parameter in the callback specifies whether the session is activated. The value **true** means that the session is activated, and **false** means the opposite.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                  |
3104
3105**Error codes**
3106
3107For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3108
3109| ID| Error Message|
3110| -------- | ---------------- |
3111| 6600101  | Session service exception. |
3112
3113**Example**
3114
3115```js
3116controller.off('activeStateChange');
3117```
3118
3119### off('validCommandChange')
3120
3121off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
3122
3123Unsubscribes from valid command changes.
3124
3125**System capability**: SystemCapability.Multimedia.AVSession.Core
3126
3127**System API**: This is a system API.
3128
3129**Parameters**
3130
3131| Name  | Type                                                        | Mandatory| Description                                                       |
3132| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
3133| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is reported when the supported commands change.        |
3134| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype)\>) => void | No  | Callback used for unsubscription. The **commands** parameter in the callback is a set of valid commands.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.         |
3135
3136**Error codes**
3137
3138For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3139
3140| ID| Error Message          |
3141| -------- | ---------------- |
3142| 6600101  | Session service exception. |
3143
3144**Example**
3145
3146```js
3147controller.off('validCommandChange');
3148```
3149
3150### off('outputDeviceChange')
3151
3152off(type: 'outputDeviceChange', callback?: (device: OutputDeviceInfo) => void): void
3153
3154Unsubscribes from output device changes.
3155
3156**System capability**: SystemCapability.Multimedia.AVSession.Core
3157
3158**System API**: This is a system API.
3159
3160**Parameters**
3161
3162| Name  | Type                                                   | Mandatory| Description                                                     |
3163| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
3164| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is reported when the output device changes.     |
3165| callback | (device: [OutputDeviceInfo](#outputdeviceinfo)) => void | No  | Callback used for unsubscription. The **device** parameter in the callback indicates the output device information.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                        |
3166
3167**Error codes**
3168
3169For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3170
3171| ID | Error Message         |
3172| -------- | ---------------- |
3173| 6600101  | Session service exception. |
3174
3175**Example**
3176
3177```js
3178controller.off('outputDeviceChange');
3179```
3180
3181## SessionToken
3182
3183Describes the information about a session token.
3184
3185**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
3186
3187**System capability**: SystemCapability.Multimedia.AVSession.Manager
3188
3189**System API**: This is a system API.
3190
3191| Name     | Type  | Mandatory| Description        |
3192| :-------- | :----- | :--- | :----------- |
3193| sessionId | string | Yes  | Session ID.      |
3194| pid       | number | Yes  | Process ID of the session.|
3195| uid       | number | Yes  | User ID.      |
3196
3197## AVSessionType
3198Enumerates the session types supported by the session.
3199
3200**System capability**: SystemCapability.Multimedia.AVSession.Core
3201
3202**System API**: This is a system API.
3203
3204| Name | Type  | Description|
3205| ----- | ------ | ---- |
3206| audio | string | Audio session.|
3207| video | string | Video session.|
3208
3209## AVSessionDescriptor
3210
3211Declares the session descriptor.
3212
3213**System capability**: SystemCapability.Multimedia.AVSession.Manager
3214
3215**System API**: This is a system API.
3216
3217| Name        | Type                                                        | Readable| Writable| Description                                               |
3218| ------------ | ------------------------------------------------------------ | ---- | --------------------------------------------------- | --------------------------------------------------- |
3219| sessionId    | string                                                       | Yes | No| Session ID.                                             |
3220| type         | [AVSessionType](#avsessiontype)                              | Yes  | No | Session type.                                           |
3221| sessionTag   | string                                                       | Yes  | No | Custom session name.                                   |
3222| elementName  | [ElementName](js-apis-bundle-ElementName.md)                 | Yes  | No | Information about the application to which the session belongs, including the bundle name and ability name.|
3223| isActive     | boolean                                                      | Yes  | No | Whether the session is activated.                                     |
3224| isTopSession | boolean                                                      | Yes  | No | Whether the session is the top session.                               |
3225| outputDevice | [OutputDeviceInfo](#outputdeviceinfo)                        | Yes  | No | Information about the output device.                                 |
3226
3227## AVControlCommandType
3228
3229Enumerates the commands that can be sent to a session.
3230
3231**System capability**: SystemCapability.Multimedia.AVSession.Core
3232
3233**System API**: This is a system API.
3234
3235| Name          | Type  | Description        |
3236| -------------- | ------ | ------------ |
3237| play           | string | Play the media.        |
3238| pause          | string | Pause the playback.        |
3239| stop           | string | Stop the playback.        |
3240| playNext       | string | Play the next media asset.      |
3241| playPrevious   | string | Play the previous media asset.      |
3242| fastForward    | string | Fast-forward.        |
3243| rewind         | string | Rewind.        |
3244| seek           | string | Seek to a playback position.|
3245| setSpeed       | string | Set the playback speed.|
3246| setLoopMode    | string | Set the loop mode.|
3247| toggleFavorite | string | Favorite the media asset.    |
3248
3249## AVControlCommand
3250
3251Describes the command that can be sent to the session.
3252
3253**System capability**: SystemCapability.Multimedia.AVSession.Core
3254
3255**System API**: This is a system API.
3256
3257| Name     | Type                                             | Mandatory| Description          |
3258| --------- | ------------------------------------------------- | ---- | -------------- |
3259| command   | [AVControlCommandType](#avcontrolcommandtype)     | Yes  | Command.          |
3260| parameter | [LoopMode](#loopmode) &#124; string &#124; number | No  | Parameters carried in the command.|
3261
3262## AVMetadata
3263
3264Describes the media metadata.
3265
3266**System capability**: SystemCapability.Multimedia.AVSession.Core
3267
3268**System API**: This is a system API.
3269
3270| Name           | Type                     | Mandatory| Description                                                                 |
3271| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
3272| assetId         | string                  | Yes  | Media ID.                                                              |
3273| title           | string                  | No  | Title.                                                                |
3274| artist          | string                  | No  | Artist.                                                               |
3275| author          | string                  | No  | Author.                                                              |
3276| album           | string                  | No  | Album name.                                                              |
3277| writer          | string                  | No  | Writer.                                                               |
3278| composer        | string                  | No  | composer.                                                               |
3279| duration        | number                  | No  | Media duration, in ms.                                                 |
3280| mediaImage      | image.PixelMap &#124; string | No  | Pixel map or image path (local path or network path) of the image.                            |
3281| publishDate     | Date                    | No  | Release date.                                                              |
3282| subtitle        | string                  | No  | Subtitle.                                                               |
3283| description     | string                  | No  | Media description.                                                              |
3284| lyric           | string                  | No  | Lyric file path (local path or network path).|
3285| previousAssetId | string                  | No  | ID of the previous media asset.                                                           |
3286| nextAssetId     | string                  | No  | ID of the next media asset.                                                           |
3287
3288## AVPlaybackState
3289
3290Describes the information related to the media playback state.
3291
3292**System capability**: SystemCapability.Multimedia.AVSession.Core
3293
3294**System API**: This is a system API.
3295
3296| Name        | Type                                 | Mandatory| Description    |
3297| ------------ | ------------------------------------- | ---- | ------- |
3298| state        | [PlaybackState](#playbackstate)       | No  | Playback state.|
3299| speed        | number                                | No  | Playback speed.|
3300| position     | [PlaybackPosition](#playbackposition) | No  | Playback position.|
3301| bufferedTime | number                                | No  | Buffered time.|
3302| loopMode     | [LoopMode](#loopmode)                 | No  | Loop mode.|
3303| isFavorite   | boolean                               | No  | Whether the media asset is favorited.|
3304
3305## PlaybackPosition
3306
3307Describes the information related to the playback position.
3308
3309**System capability**: SystemCapability.Multimedia.AVSession.Core
3310
3311**System API**: This is a system API.
3312
3313| Name       | Type  | Mandatory| Description              |
3314| ----------- | ------ | ---- | ------------------ |
3315| elapsedTime | number | Yes  | Elapsed time, in ms.|
3316| updateTime  | number | Yes  | Updated time, in ms.|
3317
3318## OutputDeviceInfo
3319
3320Describes the information related to the output device.
3321
3322**System capability**: SystemCapability.Multimedia.AVSession.Core
3323
3324**System API**: This is a system API.
3325
3326| Name      | Type          | Mandatory| Description                  |
3327| ---------- | -------------- | ---- | ---------------------- |
3328| isRemote   | boolean        | Yes  | Whether the device is connected.        |
3329| audioDeviceId   | Array<number\> | Yes  | IDs of output devices. |
3330| deviceName | Array<string\> | Yes  | Names of output devices.   |
3331
3332## PlaybackState
3333
3334Enumerates the media playback states.
3335
3336**System capability**: SystemCapability.Multimedia.AVSession.Core
3337
3338**System API**: This is a system API.
3339
3340| Name                       | Value  | Description        |
3341| --------------------------- | ---- | ----------- |
3342| PLAYBACK_STATE_INITIAL      | 0    | Initial.    |
3343| PLAYBACK_STATE_PREPARE      | 1    | Preparing. |
3344| PLAYBACK_STATE_PLAY         | 2    | Playing.    |
3345| PLAYBACK_STATE_PAUSE        | 3    | Paused.        |
3346| PLAYBACK_STATE_FAST_FORWARD | 4    | Fast-forwarding.        |
3347| PLAYBACK_STATE_REWIND       | 5    | Rewinding.        |
3348| PLAYBACK_STATE_STOP         | 6    | Stopped.        |
3349
3350
3351## LoopMode
3352
3353Enumerates the loop modes of media playback.
3354
3355**System capability**: SystemCapability.Multimedia.AVSession.Core
3356
3357**System API**: This is a system API.
3358
3359| Name              | Value  | Description    |
3360| ------------------ | ---- | -------- |
3361| LOOP_MODE_SEQUENCE | 0    | Sequential playback.|
3362| LOOP_MODE_SINGLE   | 1    | Single loop.|
3363| LOOP_MODE_LIST     | 2    | Playlist loop.|
3364| LOOP_MODE_SHUFFLE  | 3    | Shuffle.|
3365
3366## AVSessionErrorCode
3367
3368Enumerates the error codes used in the media session.
3369
3370**System capability**: SystemCapability.Multimedia.AVSession.Core
3371
3372**System API**: This is a system API.
3373
3374| Name                          | Value     | Description                            |
3375| ------------------------------ | ------- | ------------------------------- |
3376| ERR_CODE_SERVICE_EXCEPTION     | 6600101 | Session service exception.               |
3377| ERR_CODE_SESSION_NOT_EXIST     | 6600102 | The session does not exist.      |
3378| ERR_CODE_CONTROLLER_NOT_EXIST  | 6600103 | The session controller does not exist.   |
3379| ERR_CODE_REMOTE_CONNECTION_ERR | 6600104 | The remote session  connection failed.         |
3380| ERR_CODE_COMMAND_INVALID       | 6600105 | Invalid session command.           |
3381| ERR_CODE_SESSION_INACTIVE      | 6600106 | The session is not activated.                |
3382| ERR_CODE_MESSAGE_OVERLOAD      | 6600107 | Too many commands or events.       |
3383