js-apis-avsession.md 263.4 KB
Newer Older
1
# @ohos.multimedia.avsession (AVSession Management)
2 3 4

The **avSession** module provides APIs for media playback control so that applications can access the system's Media Controller.

G
Gloria 已提交
5
This module provides the following typical features related to media sessions:
6

G
Gloria 已提交
7 8
- [AVSession](#avsession10): used to set session metadata, playback state information, and more.
- [AVSessionController](#avsessioncontroller10): used to obtain session IDs, send commands and events to sessions, and obtain the session metadata and playback state information.
G
Gloria 已提交
9
- [AVCastController](#avcastcontroller10): used to control playback, listen for remote playback state changes, and obtain the remote playback state in casting scenarios.
10 11 12 13 14 15 16 17 18 19 20

> **NOTE**
>
> 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.

## Modules to Import

```js
import avSession from '@ohos.multimedia.avsession';
```

G
Gloria 已提交
21
## avSession.createAVSession<sup>10+</sup>
22 23 24 25 26 27 28 29 30 31 32

createAVSession(context: Context, tag: string, type: AVSessionType): Promise\<AVSession>

Creates 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.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name| Type                           | Mandatory| Description                          |
| ------ | ------------------------------- | ---- | ------------------------------ |
33
| context| [Context](js-apis-inner-app-context.md) | Yes| Application context, which provides application environment information.|
34
| tag    | string                          | Yes  | Custom session name.            |
G
Gloria 已提交
35
| type   | [AVSessionType](#avsessiontype10) | Yes  | Session type, which can be audio or video.|
36 37 38 39 40

**Return value**

| Type                             | Description                                                        |
| --------------------------------- | ------------------------------------------------------------ |
G
Gloria 已提交
41
| Promise<[AVSession](#avsession10)\> | 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.|
42

43
**Error codes**
G
Gloria 已提交
44

45 46 47 48
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
49
| 6600101  | Session service exception. |
50 51 52 53 54 55

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

G
Gloria 已提交
56
let currentAVSession;
57 58
let tag = "createNewSession";
let context = featureAbility.getContext();
G
Gloria 已提交
59
let sessionId; // Used as an input parameter of subsequent functions.
60

G
Gloria 已提交
61 62 63 64
avSession.createAVSession(context, tag, "audio").then((data) => {
    currentAVSession = data;
    sessionId = currentAVSession.sessionId;
    console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
65 66 67 68 69
}).catch((err) => {
    console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

G
Gloria 已提交
70
## avSession.createAVSession<sup>10+</sup>
71 72 73 74 75 76 77 78 79 80 81

createAVSession(context: Context, tag: string, type: AVSessionType, callback: AsyncCallback\<AVSession>): void

Creates 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.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                   | Mandatory| Description                                                        |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
82
| context| [Context](js-apis-inner-app-context.md) | Yes| Application context, which provides application environment information.    |
83
| tag      | string                                  | Yes  | Custom session name.                                          |
G
Gloria 已提交
84 85
| type     | [AVSessionType](#avsessiontype10)         | Yes  | Session type, which can be audio or video.                              |
| callback | AsyncCallback<[AVSession](#avsession10)\> | 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.|
86 87

**Error codes**
G
Gloria 已提交
88

89 90 91 92
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
93
| 6600101  | Session service exception. |
94 95 96 97 98 99

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

G
Gloria 已提交
100
let currentAVSession;
101 102
let tag = "createNewSession";
let context = featureAbility.getContext();
G
Gloria 已提交
103
let sessionId; // Used as an input parameter of subsequent functions.
104 105 106 107 108

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
G
Gloria 已提交
109 110 111
        currentAVSession = data;
        sessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    }
});
```

## avSession.getAllSessionDescriptors

getAllSessionDescriptors(): Promise\<Array\<Readonly\<AVSessionDescriptor>>>

Obtains the descriptors of all sessions. This API uses a promise to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Return value**

| Type                                                        | Description                                         |
| ------------------------------------------------------------ | --------------------------------------------- |
| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only.|

**Error codes**
G
Gloria 已提交
135

136 137 138 139
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
140
| 6600101  | Session service exception. |
141 142 143 144 145 146 147 148 149 150 151 152

**Example**

```js
avSession.getAllSessionDescriptors().then((descriptors) => {
    console.info(`getAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
    if(descriptors.length > 0 ){
        console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
    }
}).catch((err) => {
G
Gloria 已提交
153
    console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
154 155 156 157 158 159 160 161 162
});
```

## avSession.getAllSessionDescriptors

getAllSessionDescriptors(callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void

Obtains the descriptors of all sessions. This API uses an asynchronous callback to return the result.

G
Gloria 已提交
163
**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES
164 165 166 167 168 169 170 171 172 173 174 175

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                      |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ |
| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes  | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only.|

**Error codes**
G
Gloria 已提交
176

177 178 179 180
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
181
| 6600101  |Session service exception. |
182 183 184 185 186 187

**Example**

```js
avSession.getAllSessionDescriptors(function (err, descriptors) {
    if (err) {
G
Gloria 已提交
188
        console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
189 190 191 192 193 194 195 196 197 198 199
    } else {
        console.info(`GetAllSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
        if(descriptors.length > 0 ){
            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
            console.info(`getAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
        }
    }
});
```

G
Gloria 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
## avSession.getHistoricalSessionDescriptors<sup>10+</sup>

getHistoricalSessionDescriptors(maxSize?: number): Promise\<Array\<Readonly\<AVSessionDescriptor>>>

Obtains the descriptors of all sessions. This API uses a promise to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type   | Mandatory| Description                                                            |
| -------- | ------ | ---- | -----------------------------------------------------------------|
| maxSize  | number | No  | Maximum number of descriptors to obtain. The value ranges from 0 to 10. If this parameter is left blank, the default value **3** is used.|

**Return value**

| Type                                                                       | Description                                  |
| --------------------------------------------------------------------------- | -------------------------------------- |
| Promise\<Array\<Readonly\<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Promise used to return an array of **AVSessionDescriptor** objects, each of which is read only.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
avSession.getHistoricalSessionDescriptors().then((descriptors) => {
    console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
    if(descriptors.length > 0 ){
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`);
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`);
    }
}).catch((err) => {
G
Gloria 已提交
245
    console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
});
```

## avSession.getHistoricalSessionDescriptors<sup>10+</sup>

getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\<Array\<Readonly\<AVSessionDescriptor>>>): void

Obtains the descriptors of all sessions. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type                                                                           | Mandatory| Description                                                            |
| -------- | ------------------------------------------------------------------------------ | ---- | -----------------------------------------------------------------|
| maxSize  | number                                                                         | Yes  | Maximum number of descriptors to obtain. The value ranges from 0 to 10. If this parameter is left blank, the default value **3** is used.|
| callback | AsyncCallback<Array<Readonly<[AVSessionDescriptor](#avsessiondescriptor)\>\>\> | Yes  | Callback used to return an array of **AVSessionDescriptor** objects, each of which is read only.                             |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  |Session service exception. |

**Example**

```js
avSession.getHistoricalSessionDescriptors(1, function (err, descriptors) {
    if (err) {
G
Gloria 已提交
281
        console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
282 283 284 285 286 287 288 289 290 291 292 293 294
    } else {
        console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors.length : ${descriptors.length}`);
        if(descriptors.length > 0 ){
            console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].isActive : ${descriptors[0].isActive}`);
            console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].type : ${descriptors[0].type}`);
            console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`);
            console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].sessionId : ${descriptors[0].sessionId}`);
            console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`);
        }
    }
});
```

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
## avSession.createController

createController(sessionId: string): Promise\<AVSessionController>

Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses a promise to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name   | Type  | Mandatory| Description    |
| --------- | ------ | ---- | -------- |
| sessionId | string | Yes  | Session ID.|

**Return value**

G
Gloria 已提交
315 316 317
| Type                                                 | Description                                                        |
| ----------------------------------------------------- | ------------------------------------------------------------ |
| Promise<[AVSessionController](#avsessioncontroller10)\> | Promise used to return the session controller created, which can be used to obtain the session ID, send commands and events to sessions, and obtain metadata and playback state information.|
318 319

**Error codes**
G
Gloria 已提交
320

321 322 323 324
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
325 326
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
327 328 329 330 331 332

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

G
Gloria 已提交
333
let currentAVSession;
334 335
let tag = "createNewSession";
let context = featureAbility.getContext();
G
Gloria 已提交
336
let sessionId; // Used as an input parameter of subsequent functions.
337

G
Gloria 已提交
338 339 340 341 342 343 344 345
avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        sessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
    }
346 347
});

G
Gloria 已提交
348 349 350 351
let currentAVcontroller;
avSession.createController(sessionId).then((avcontroller) => {
    currentAVcontroller = avcontroller;
    console.info('CreateController : SUCCESS ');
352
}).catch((err) => {
G
Gloria 已提交
353
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
});
```

## avSession.createController

createController(sessionId: string, callback: AsyncCallback\<AVSessionController>): void

Creates a session controller based on the session ID. Multiple session controllers can be created. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name   | Type                                                       | Mandatory| Description                                                        |
| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| sessionId | string                                                      | Yes  | Session ID.                                                    |
G
Gloria 已提交
374
| callback  | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 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.|
375 376

**Error codes**
G
Gloria 已提交
377

378 379 380 381
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
382 383
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
384 385 386 387 388 389

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

G
Gloria 已提交
390
let currentAVSession;
391 392
let tag = "createNewSession";
let context = featureAbility.getContext();
G
Gloria 已提交
393
let sessionId; // Used as an input parameter of subsequent functions.
394

G
Gloria 已提交
395 396 397 398 399 400 401 402
avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        sessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
    }
403 404
});

G
Gloria 已提交
405 406
let currentAVcontroller;
avSession.createController(sessionId, function (err, avcontroller) {
407
    if (err) {
G
Gloria 已提交
408
        console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
409
    } else {
G
Gloria 已提交
410 411
        currentAVcontroller = avcontroller;
        console.info('CreateController : SUCCESS ');
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    }
});
```

## avSession.castAudio

castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>): Promise\<void>

Casts a session to a list of devices. This API uses a promise to return the result.

Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
432 433 434 435
| Name       | Type          | Mandatory| Description|
| ------------ | -------------- |------|------|
| session      | [SessionToken](#sessiontoken) &#124; 'all' | Yes  | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.|
| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | Yes  | Audio devices. |
436 437 438 439 440

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
G
Gloria 已提交
441
| Promise\<void> | Promise used to return the result. If casting is successful, no value is returned; otherwise, an error object is returned.|
442 443

**Error codes**
G
Gloria 已提交
444

445 446 447 448
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
449 450
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
G
Gloria 已提交
451
| 6600104  | The remote session connection failed. |
452 453 454 455 456 457 458

**Example**

```js
import audio from '@ohos.multimedia.audio';

let audioManager = audio.getAudioManager();
459
let audioRoutingManager = audioManager.getRoutingManager();
460
let audioDevices;
461
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
462
    audioDevices = data;
463
    console.info(`Promise returned to indicate that the device list is obtained.`);
464
}).catch((err) => {
G
Gloria 已提交
465
    console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
466 467 468
});

avSession.castAudio('all', audioDevices).then(() => {
469
    console.info(`CreateController : SUCCESS`);
470
}).catch((err) => {
G
Gloria 已提交
471
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
});
```

## avSession.castAudio

castAudio(session: SessionToken | 'all', audioDevices: Array<audio.AudioDeviceDescriptor>, callback: AsyncCallback\<void>): void

Casts a session to a list of devices. This API uses an asynchronous callback to return the result.

Before calling this API, import the **ohos.multimedia.audio** module to obtain the descriptors of these audio devices.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name      | Type                                        | Mandatory| Description                                                        |
| ------------ |--------------------------------------------| ---- | ------------------------------------------------------------ |
| session      | [SessionToken](#sessiontoken) &#124; 'all' | Yes  | Session token. **SessionToken** indicates a specific token, and **'all'** indicates all tokens.|
G
Gloria 已提交
494 495
| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\>   | Yes  | Audio devices.|
| callback     | AsyncCallback\<void>     | Yes  | Callback used to return the result. If the casting is successful, **err** is **undefined**; otherwise, **err** is an error object.     |
496 497

**Error codes**
G
Gloria 已提交
498

499 500 501 502
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
503 504
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
G
Gloria 已提交
505
| 6600104  | The remote session connection failed. |
506 507 508 509 510 511 512

**Example**

```js
import audio from '@ohos.multimedia.audio';

let audioManager = audio.getAudioManager();
513
let audioRoutingManager = audioManager.getRoutingManager();
514
let audioDevices;
515
await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data) => {
516
    audioDevices = data;
517
    console.info(`Promise returned to indicate that the device list is obtained.`);
518
}).catch((err) => {
G
Gloria 已提交
519
    console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`);
520 521 522 523
});

avSession.castAudio('all', audioDevices, function (err) {
    if (err) {
G
Gloria 已提交
524
        console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`);
525
    } else {
526
        console.info(`CastAudio : SUCCESS `);
527 528 529 530
    }
});
```

G
Gloria 已提交
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
## SessionToken

Describes the information about a session token.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

| Name     | Type  | Mandatory| Description        |
| :-------- | :----- | :--- | :----------- |
| sessionId | string | Yes  | Session ID.      |
| pid       | number | No  | Process ID of the session.|
| uid       | number | No  | User ID.      |

## avSession.on('sessionCreate')
548

G
Gloria 已提交
549
on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void
550

G
Gloria 已提交
551
Subscribes to session creation events.
552 553 554 555 556 557 558 559 560

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
561 562 563 564
| Name   | Type                  | Mandatory| Description                                                        |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| type     | string                 | Yes  | Event type. The event **'sessionCreate'** is triggered when a session is created.|
| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes  | Callback used to report the session descriptor.|
565 566

**Error codes**
G
Gloria 已提交
567

568 569 570 571
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
572
| 6600101  | Session service exception. |
573 574 575 576 577 578 579 580 581 582

**Example**

```js
avSession.on('sessionCreate', (descriptor) => {
    console.info(`on sessionCreate : isActive : ${descriptor.isActive}`);
    console.info(`on sessionCreate : type : ${descriptor.type}`);
    console.info(`on sessionCreate : sessionTag : ${descriptor.sessionTag}`);
});

G
Gloria 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
```

## avSession.on('sessionDestroy')

on(type: 'sessionDestroy', callback: (session: AVSessionDescriptor) => void): void

Subscribes to session destruction events.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type           | Mandatory| Description                                                        |
| -------- | ---------------| ---- | ------------------------------------------------------------ |
| type     | string         | Yes  | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.|
| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes  | Callback used to report the session descriptor.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
615 616 617 618 619
avSession.on('sessionDestroy', (descriptor) => {
    console.info(`on sessionDestroy : isActive : ${descriptor.isActive}`);
    console.info(`on sessionDestroy : type : ${descriptor.type}`);
    console.info(`on sessionDestroy : sessionTag : ${descriptor.sessionTag}`);
});
G
Gloria 已提交
620 621 622 623 624 625 626 627 628
```

## avSession.on('topSessionChange')

on(type: 'topSessionChange', callback: (session: AVSessionDescriptor) => void): void

Subscribes to top session change events.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)
629

G
Gloria 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | --------------------| ---- | ------------------------------------------------------------ |
| type     | string      | Yes  | Event type. The event **'topSessionChange'** is triggered when the top session is changed.|
| callback | (session: [AVSessionDescriptor](#avsessiondescriptor)) => void | Yes  | Callback used to report the session descriptor.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
652 653 654 655 656 657 658
avSession.on('topSessionChange', (descriptor) => {
    console.info(`on topSessionChange : isActive : ${descriptor.isActive}`);
    console.info(`on topSessionChange : type : ${descriptor.type}`);
    console.info(`on topSessionChange : sessionTag : ${descriptor.sessionTag}`);
});
```

G
Gloria 已提交
659
## avSession.off('sessionCreate')
660

G
Gloria 已提交
661
off(type: 'sessionCreate', callback?: (session: AVSessionDescriptor) => void): void
662

G
Gloria 已提交
663
Unsubscribes from session creation events.
664 665 666 667 668 669 670 671 672

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
673 674 675
| Name  | Type      | Mandatory| Description      |
| -------- | ----------| ---- | ----------|
| type     | string    | Yes  | Event type, which is **'sessionCreate'** in this case.|
G
Gloria 已提交
676
| 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.                              |
677 678

**Error codes**
G
Gloria 已提交
679

680 681 682 683
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
684
| 6600101  | Session service exception. |
685 686 687 688 689

**Example**

```js
avSession.off('sessionCreate');
G
Gloria 已提交
690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
```

## avSession.off('sessionDestroy')

off(type: 'sessionDestroy', callback?: (session: AVSessionDescriptor) => void): void

Unsubscribes from session destruction events.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type       | Mandatory| Description                     |
| -------- | -----------| ---- | -------------------------|
| type     | string     | Yes  | Event type, which is **'sessionDestroy'** in this case.|
| 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.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
722
avSession.off('sessionDestroy');
G
Gloria 已提交
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
```

## avSession.off('topSessionChange')

off(type: 'topSessionChange', callback?: (session: AVSessionDescriptor) => void): void

Unsubscribes from top session change events.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

| Name  | Type             | Mandatory| Description                       |
| -------- | -----------------| ---- | ---------------------------- |
| type     | string           | Yes  | Event type, which is **'topSessionChange'** in this case.|
| 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.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
755 756 757 758 759 760 761 762 763 764 765
avSession.off('topSessionChange');
```

## avSession.on('sessionServiceDie')

on(type: 'sessionServiceDie', callback: () => void): void

Subscribes to session service death events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
766 767
**System API**: This is a system API.

768 769 770 771
**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
772
| type     | string               | Yes  | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.|
773 774 775
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                               |

**Error codes**
G
Gloria 已提交
776

777 778 779 780
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
781
| 6600101  | Session service exception. |
782 783 784 785 786

**Example**

```js
avSession.on('sessionServiceDie', () => {
787
    console.info(`on sessionServiceDie  : session is  Died `);
788 789 790 791 792 793 794 795 796 797 798
});
```

## avSession.off('sessionServiceDie')

off(type: 'sessionServiceDie', callback?: () => void): void

Unsubscribes from session service death events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
799 800
**System API**: This is a system API.

801 802 803 804
**Parameters**

| Name   | Type                   | Mandatory |      Description                                              |
| ------   | ---------------------- | ---- | ------------------------------------------------------- |
G
Gloria 已提交
805
| type     | string                 | Yes   | Event type. The event **'sessionServiceDie'** is triggered when the session service dies.|
G
Gloria 已提交
806
| 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.           |
807 808

**Error codes**
G
Gloria 已提交
809

810 811 812 813
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
814
| 6600101  | Session service exception. |
815 816 817 818 819 820 821 822 823

**Example**

```js
avSession.off('sessionServiceDie');
```

## avSession.sendSystemAVKeyEvent

G
Gloria 已提交
824
sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void
825

G
Gloria 已提交
826
Sends a system key event to the top session. This API uses an asynchronous callback to return the result.
827 828 829 830 831 832 833 834 835

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
836 837 838 839
| Name  | Type                                                        | Mandatory| Description                                 |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- |
| event    | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.                           |
| callback | AsyncCallback\<void>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
840 841

**Error codes**
G
Gloria 已提交
842

843 844 845 846
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
847 848
| 6600101  | Session service exception. |
| 6600105  | Invalid session command. |
849 850 851 852 853 854 855

**Example**

```js
let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let 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}; 

G
Gloria 已提交
856 857 858 859 860 861
avSession.sendSystemAVKeyEvent(event, function (err) {
    if (err) {
        console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`SendSystemAVKeyEvent : SUCCESS `);
    }
862 863 864 865 866
});
```

## avSession.sendSystemAVKeyEvent

G
Gloria 已提交
867
sendSystemAVKeyEvent(event: KeyEvent): Promise\<void>
868

G
Gloria 已提交
869
Sends a system key event to the top session. This API uses a promise to return the result.
870 871 872 873 874 875 876 877 878

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
879 880 881 882 883 884 885 886 887
| Name| Type                           | Mandatory| Description      |
| ------ | ------------------------------- | ---- | ---------- |
| event  | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
888 889

**Error codes**
G
Gloria 已提交
890

891 892 893 894
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
895 896
| 6600101  | Session service exception. |
| 6600105  | Invalid session command. |
897 898 899 900

**Example**

```js
G
Gloria 已提交
901

902 903 904
let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let 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}; 

G
Gloria 已提交
905 906 907 908
avSession.sendSystemAVKeyEvent(event).then(() => {
    console.info(`SendSystemAVKeyEvent Successfully`);
}).catch((err) => {
    console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
909 910 911 912 913
});
```

## avSession.sendSystemControlCommand

G
Gloria 已提交
914
sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void
915

G
Gloria 已提交
916
Sends a system control command to the top session. This API uses an asynchronous callback to return the result.
917 918 919 920 921 922 923 924 925

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
926 927 928 929
| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| command  | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.  |
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
930 931

**Error codes**
G
Gloria 已提交
932

933 934 935 936
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
937 938 939
| 6600101  | Session service exception. |
| 6600105  | Invalid session command. |
| 6600107  | Too many commands or events. |
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959

**Example**

```js
let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'pause';
// let cmd : avSession.AVControlCommandType = 'stop';
// let cmd : avSession.AVControlCommandType = 'playNext';
// let cmd : avSession.AVControlCommandType = 'playPrevious';
// let cmd : avSession.AVControlCommandType = 'fastForward';
// let cmd : avSession.AVControlCommandType = 'rewind';
let avcommand = {command:cmd};
// let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:cmd, parameter:10};
// let cmd : avSession.AVControlCommandType = 'setSpeed';
// let avcommand = {command:cmd, parameter:2.6};
// let cmd : avSession.AVControlCommandType = 'setLoopMode';
// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
// let avcommand = {command:cmd, parameter:"false"};
G
Gloria 已提交
960 961 962 963 964 965
avSession.sendSystemControlCommand(avcommand, function (err) {
    if (err) {
        console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`sendSystemControlCommand successfully`);
    }
966 967 968 969 970
});
```

## avSession.sendSystemControlCommand

G
Gloria 已提交
971
sendSystemControlCommand(command: AVControlCommand): Promise\<void>
972

G
Gloria 已提交
973
Sends a system control command to the top session. This API uses a promise to return the result.
974 975 976 977 978 979 980 981 982

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.

**Parameters**

G
Gloria 已提交
983 984 985 986 987 988 989 990 991
| Name | Type                                 | Mandatory| Description                               |
| ------- | ------------------------------------- | ---- | ----------------------------------- |
| command | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
992 993

**Error codes**
G
Gloria 已提交
994

995 996 997 998
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
999 1000 1001
| 6600101  | Session service exception. |
| 6600105  | Invalid session command. |
| 6600107  | Too many commands or events. |
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021

**Example**

```js
let cmd : avSession.AVControlCommandType = 'play';
// let cmd : avSession.AVControlCommandType = 'pause';
// let cmd : avSession.AVControlCommandType = 'stop';
// let cmd : avSession.AVControlCommandType = 'playNext';
// let cmd : avSession.AVControlCommandType = 'playPrevious';
// let cmd : avSession.AVControlCommandType = 'fastForward';
// let cmd : avSession.AVControlCommandType = 'rewind';
let avcommand = {command:cmd};
// let cmd : avSession.AVControlCommandType = 'seek';
// let avcommand = {command:cmd, parameter:10};
// let cmd : avSession.AVControlCommandType = 'setSpeed';
// let avcommand = {command:cmd, parameter:2.6};
// let cmd : avSession.AVControlCommandType = 'setLoopMode';
// let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let cmd : avSession.AVControlCommandType = 'toggleFavorite';
// let avcommand = {command:cmd, parameter:"false"};
G
Gloria 已提交
1022 1023 1024 1025
avSession.sendSystemControlCommand(avcommand).then(() => {
    console.info(`SendSystemControlCommand successfully`);
}).catch((err) => {
    console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
1026 1027 1028
});
```

G
Gloria 已提交
1029
## ProtocolType<sup>10+</sup>
1030

G
Gloria 已提交
1031
Enumerates the protocol types supported by the remote device.
1032

G
Gloria 已提交
1033
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1034

G
Gloria 已提交
1035
**System API**: This is a system API.
1036

G
Gloria 已提交
1037 1038 1039 1040 1041
| Name                       | Value  | Description        |
| --------------------------- | ---- | ----------- |
| TYPE_LOCAL      | 0    | Local device.   |
| TYPE_CAST_PLUS_MIRROR      | 1    | Cast+ mirror mode.|
| TYPE_CAST_PLUS_STREAM      | 2    | Cast+ stream mode.|
1042

G
Gloria 已提交
1043
## avSession.startCastDeviceDiscovery<sup>10+</sup>
1044

G
Gloria 已提交
1045
startCastDeviceDiscovery(callback: AsyncCallback\<void>): void
1046

G
Gloria 已提交
1047
Starts cast-enabled device discovery. This API uses an asynchronous callback to return the result.
1048

G
Gloria 已提交
1049
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
1050

G
Gloria 已提交
1051
**System API**: This is a system API.
1052

G
Gloria 已提交
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422
**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object.|


**Example**

```js
avSession.startCastDeviceDiscovery(function (err) {
    if (err) {
        console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`startCastDeviceDiscovery successfully`);
    }
});
```

## avSession.startCastDeviceDiscovery<sup>10+</sup>

startCastDeviceDiscovery(filter: number, callback: AsyncCallback\<void>): void

Starts cast-enabled device discovery with filter criteria specified. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| filter | number | Yes| Filter criteria for device discovery. The value consists of **ProtocolType**s.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent and device discovery starts, **err** is **undefined**; otherwise, **err** is an error object.|


**Example**

```js
let filter = 2;
avSession.startCastDeviceDiscovery(filter, function (err) {
    if (err) {
        console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`startCastDeviceDiscovery successfully`);
    }
});
```

## avSession.startCastDeviceDiscovery<sup>10+</sup>

startCastDeviceDiscovery(filter?: number): Promise\<void>

Starts cast-enabled device discovery. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| filter | number | No| Filter criteria for device discovery. The value consists of **ProtocolType**s.|

**Return value**
| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent and device discovery starts, no value is returned; otherwise, an error object is returned.|

**Example**

```js
let filter = 2;
avSession.startCastDeviceDiscovery(filter).then(() => {
    console.info(`startCastDeviceDiscovery successfully`);
}).catch((err) => {
    console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## avSession.stopCastDeviceDiscovery<sup>10+</sup>

stopCastDeviceDiscovery(callback: AsyncCallback\<void>): void

Stops cast-enabled device discovery. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If device discovery stops, **err** is **undefined**; otherwise, **err** is an error object.|


**Example**

```js
avSession.stopCastDeviceDiscovery(function (err) {
    if (err) {
        console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`stopCastDeviceDiscovery successfully`);
    }
});
```

## avSession.stopCastDeviceDiscovery<sup>10+</sup>

stopCastDeviceDiscovery(): Promise\<void>

Stops cast-enabled device discovery. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If device discovery stops, no value is returned; otherwise, an error object is returned.|

**Example**

```js
avSession.stopCastDeviceDiscovery().then(() => {
    console.info(`startCastDeviceDiscovery successfully`);
}).catch((err) => {
    console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## avSession.setDiscoverable<sup>10+</sup>

setDiscoverable(enable: boolean, callback: AsyncCallback\<void>): void

Sets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| enable | boolean | Yes| Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|


**Example**

```js
avSession.setDiscoverable(true, function (err) {
    if (err) {
        console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`setDiscoverable successfully`);
    }
});
```

## avSession.setDiscoverable<sup>10+</sup>

setDiscoverable(enable: boolean): Promise\<void>

Sets whether to allow the device discoverable. A discoverable device can be used as the cast receiver. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| enable | boolean | Yes| Whether to allow the device discoverable. The value **true** means to allow the device discoverable, and **false** means the opposite.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Example**

```js
avSession.setDiscoverable(true).then(() => {
    console.info(`setDiscoverable successfully`);
}).catch((err) => {
    console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## avSession.on('deviceAvailable')<sup>10+</sup>

on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void

Subscribes to device discovery events.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.|
| callback | (device: OutputDeviceInfo) => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                               |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
let castDevice;
avSession.on('deviceAvailable', (device) => {
    castDevice = device;
    console.info(`on deviceAvailable  : ${device} `);
});
```

## avSession.off('deviceAvailable')<sup>10+</sup>

off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void

Unsubscribes from device discovery events.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name   | Type                   | Mandatory |      Description                                              |
| ------   | ---------------------- | ---- | ------------------------------------------------------- |
| type     | string                 | Yes   | Event type. The event **'deviceAvailable'** is triggered when a device is discovered.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |

**Example**

```js
avSession.off('deviceAvailable');
```

## avSession.getAVCastController<sup>10+</sup>

getAVCastController(sessionId: string, callback: AsyncCallback\<AVCastController>): void

Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES

**System API**: This is a system API.

**Parameters**

| Name   | Type                                                       | Mandatory| Description                                                        |
| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| sessionId | string                    | Yes  |Session ID.|
| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes  | Callback used to return the cast controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception |
| 6600102  | session does not exist |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        sessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
    }
});

let aVCastController;
avSession.getAVCastController(sessionId ,function (err, avcontroller) {
    if (err) {
        console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        aVCastController = avcontroller;
        console.info('getAVCastController : SUCCESS ');
    }
});
```

## avSession.getAVCastController<sup>10+</sup>

getAVCastController(sessionId: string): Promise\<AVCastController>;

Obtains the cast controller when a casting connection is set up. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES

**System API**: This is a system API.

**Parameters**

| Name   | Type                      | Mandatory| Description                                                        |
| --------- | ------------------------- | ---- | ------------------------------------------------------------ |
| sessionId | string                    | Yes  |Session ID.|

**Return value**

| Type                                                       | Description            |
| --------- | ------------------------------------------------------------ |
| Promise<[AVCastController](#avcastcontroller10)\>  | Promise used to return the cast controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | server exception |
| 6600102  | The session does not exist |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let sessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        sessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${sessionId}`);
    }
});

let aVCastController;
avSession.getAVCastController(sessionId).then((avcontroller) => {
    aVCastController = avcontroller;
    console.info('getAVCastController : SUCCESS');
}).catch((err) => {
    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## avSession.startCasting<sup>10+</sup>

startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\<void>): void

Starts casting. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| session      | [SessionToken](#sessiontoken) | Yes  | Session token.  |
| device | [OutputDeviceInfo](#outputdeviceinfo10)                        | Yes  | Device-related information.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent and casting starts, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600108 | Device connecting failed.       |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        currSessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
    }
});

let myToken = {
    sessionId: currSessionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
    castDevice = device;
    console.info(`on deviceAvailable  : ${device} `);
});
avSession.startCasting(myToken, castDevice, function (err) {
    if (err) {
        console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`startCasting successfully`);
    }
});
```

## avSession.startCasting<sup>10+</sup>

startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\<void>

Starts casting. This API uses a promise to return the result.

**Required permissions**: ohos.permission.MANAGE_MEDIA_RESOURCES (available only to system applications)

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| session      | [SessionToken](#sessiontoken) | Yes  | Session token.  |
| device | [OutputDeviceInfo](#outputdeviceinfo10)                        | Yes  | Device-related information.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent and casting starts, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600108 | Device connecting failed.       |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        currSessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
    }
});

let myToken = {
    sessionId: currSessionId,
}
let castDevice;
avSession.on('deviceAvailable', (device) => {
    castDevice = device;
    console.info(`on deviceAvailable  : ${device} `);
});
avSession.startCasting(myToken, castDevice).then(() => {
    console.info(`startCasting successfully`);
}).catch((err) => {
    console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## avSession.stopCasting<sup>10+</sup>

stopCasting(session: SessionToken, callback: AsyncCallback\<void>): void

Stops castings. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| session      | [SessionToken](#sessiontoken) | Yes  | Session token.  | 
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If casting stops, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600109  | The remote connection is not established. |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        currSessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
    }
});

let myToken = {
    sessionId: currSessionId,
}
avSession.stopCasting(myToken, function (err) {
    if (err) {
        console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`stopCasting successfully`);
    }
});
```

## avSession.stopCasting<sup>10+</sup>

stopCasting(session: SessionToken): Promise\<void>

Stops castings. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**System API**: This is a system API.

**Parameters**

| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| session      | [SessionToken](#sessiontoken) | Yes  | Session token.  |

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600109  | The remote connection is not established. |

**Example**

```js
import featureAbility from '@ohos.ability.featureAbility';

let currentAVSession;
let tag = "createNewSession";
let context = featureAbility.getContext();
let currSessionId; // Used as an input parameter of subsequent functions.

avSession.createAVSession(context, tag, "audio", function (err, data) {
    if (err) {
        console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        currentAVSession = data;
        currSessionId = currentAVSession.sessionId;
        console.info(`CreateAVSession : SUCCESS : sessionId = ${currSessionId}`);
    }
});

let myToken = {
    sessionId: currSessionId,
}
avSession.stopCasting(myToken).then(() => {
    console.info(`stopCasting successfully`);
}).catch((err) => {
    console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

## AVSessionType<sup>10+<sup>
Enumerates the session types supported by the session.

**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name | Type  | Description|
| ----- | ------ | ---- |
| audio | string | Audio session.|
| video | string | Video session.|

## AVSession<sup>10+</sup>

An **AVSession** object is created by calling [avSession.createAVSession](#avsessioncreateavsession10). The object enables you to obtain the session ID and set the metadata and playback state. 

### Attributes

**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name     | Type  | Readable| Writable| Description                         |
| :-------- | :----- | :--- | :--- | :---------------------------- |
| sessionId | string | Yes  | No  | Unique session ID of the **AVSession** object.|
| sessionType<sup>10+</sup> | AVSessionType | Yes  | No  | AVSession type.|


**Example**
```js
let sessionId = currentAVSession.sessionId;
let sessionType = currentAVSession.sessionType;
```

### setAVMetadata<sup>10+</sup>

setAVMetadata(data: AVMetadata): Promise\<void>

Sets session metadata. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name| Type                     | Mandatory| Description        |
| ------ | ------------------------- | ---- | ------------ |
| data   | [AVMetadata](#avmetadata10) | Yes  | Session metadata.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let metadata  = {
    assetId: "121278",
    title: "lose yourself",
    artist: "Eminem",
    author: "ST",
    album: "Slim shady",
    writer: "ST",
    composer: "ST",
    duration: 2222,
    mediaImage: "https://www.example.com/example.jpg",
    subtitle: "8 Mile",
    description: "Rap",
    lyric: "https://www.example.com/example.lrc",
    previousAssetId: "121277",
    nextAssetId: "121279",
};
currentAVSession.setAVMetadata(metadata).then(() => {
    console.info(`SetAVMetadata successfully`);
}).catch((err) => {
    console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### setAVMetadata<sup>10+</sup>

setAVMetadata(data: AVMetadata, callback: AsyncCallback\<void>): void

Sets session metadata. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                                 |
| -------- | ------------------------- | ---- | ------------------------------------- |
| data     | [AVMetadata](#avmetadata10) | Yes  | Session metadata.                         |
| callback | AsyncCallback\<void>      | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let metadata  = {
    assetId: "121278",
    title: "lose yourself",
    artist: "Eminem",
    author: "ST",
    album: "Slim shady",
    writer: "ST",
    composer: "ST",
    duration: 2222,
    mediaImage: "https://www.example.com/example.jpg",
    subtitle: "8 Mile",
    description: "Rap",
    lyric: "https://www.example.com/example.lrc",
    previousAssetId: "121277",
    nextAssetId: "121279",
};
currentAVSession.setAVMetadata(metadata, function (err) {
    if (err) {
        console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`SetAVMetadata successfully`);
    }
});
```

### setAVPlaybackState<sup>10+</sup>

setAVPlaybackState(state: AVPlaybackState): Promise\<void>

Sets information related to the session playback state. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name| Type                               | Mandatory| Description                                          |
| ------ | ----------------------------------- | ---- | ---------------------------------------------- |
| data   | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let playbackState = {
    state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
    speed: 1.0,
    position:{elapsedTime:10, updateTime:(new Date()).getTime()},
    bufferedTime:1000,
    loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
    isFavorite:true,
};
currentAVSession.setAVPlaybackState(playbackState).then(() => {
    console.info(`SetAVPlaybackState successfully`);
}).catch((err) => {
    console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### setAVPlaybackState<sup>10+</sup>

setAVPlaybackState(state: AVPlaybackState, callback: AsyncCallback\<void>): void

Sets information related to the session playback state. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                               | Mandatory| Description                                          |
| -------- | ----------------------------------- | ---- | ---------------------------------------------- |
| data     | [AVPlaybackState](#avplaybackstate10) | Yes  | Information related to the session playback state.|
| callback | AsyncCallback\<void>                | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.         |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let PlaybackState = {
    state:avSession.PlaybackState.PLAYBACK_STATE_PLAY,
    speed: 1.0,
    position:{elapsedTime:10, updateTime:(new Date()).getTime()},
    bufferedTime:1000,
    loopMode:avSession.LoopMode.LOOP_MODE_SINGLE,
    isFavorite:true,
};
currentAVSession.setAVPlaybackState(PlaybackState, function (err) {
    if (err) {
        console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`SetAVPlaybackState successfully`);
    }
});
```

### setLaunchAbility<sup>10+</sup>

setLaunchAbility(ability: WantAgent): Promise\<void>

Sets a launcher ability. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                         | Mandatory| Description                                                       |
| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
import wantAgent from '@ohos.app.ability.wantAgent';

// WantAgentInfo object
let wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.example.myapplication",
            abilityName: "EntryAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
                {
                    mykey0: 2222,
                    mykey1: [1, 2, 3],
                    mykey2: "[1, 2, 3]",
                    mykey3: "ssssssssssssssssssssssssss",
                    mykey4: [false, true, false],
                    mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                    mykey6: true,
                }
        }
    ],
    operationType: wantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
    currentAVSession.setLaunchAbility(agent).then(() => {
        console.info(`SetLaunchAbility successfully`);
    }).catch((err) => {
        console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
    });
});
```

### setLaunchAbility<sup>10+</sup>

setLaunchAbility(ability: WantAgent, callback: AsyncCallback\<void>): void

Sets a launcher ability. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                         | Mandatory| Description                                                        |
| -------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| ability  | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes  | Application attributes, such as the bundle name, ability name, and deviceID. |
| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
import wantAgent from '@ohos.app.ability.wantAgent';

// WantAgentInfo object
let wantAgentInfo = {
    wants: [
        {
            deviceId: "deviceId",
            bundleName: "com.example.myapplication",
            abilityName: "EntryAbility",
            action: "action1",
            entities: ["entity1"],
            type: "MIMETYPE",
            uri: "key={true,true,false}",
            parameters:
                {
                    mykey0: 2222,
                    mykey1: [1, 2, 3],
                    mykey2: "[1, 2, 3]",
                    mykey3: "ssssssssssssssssssssssssss",
                    mykey4: [false, true, false],
                    mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
                    mykey6: true,
                }
        }
    ],
    operationType: wantAgent.OperationType.START_ABILITIES,
    requestCode: 0,
    wantAgentFlags:[wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
}

wantAgent.getWantAgent(wantAgentInfo).then((agent) => {
    currentAVSession.setLaunchAbility(agent, function (err) {
        if (err) {
            console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
        } else {
            console.info(`SetLaunchAbility successfully`);
        }
    });
});
```

### dispatchSessionEvent<sup>10+</sup>

dispatchSessionEvent(event: string, args: {[key: string]: Object}): Promise\<void>

Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses a promise to return the result. It is called by the provider.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                         | Mandatory| Description                                                       |
| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
| event | string | Yes  | Name of the session event.|
| args | {[key: string]: any} | Yes  | Event content in key-value pair format.|

> **NOTE**
>
> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let eventName = "dynamic_lyric";
let args = {
    lyric : "This is lyric"
}
currentAVSession.dispatchSessionEvent(eventName, args).catch((err) => {
    console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
})
```

### dispatchSessionEvent<sup>10+</sup>

dispatchSessionEvent(event: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void

Dispatches a custom event in the session, including the event name and event content in key-value pair format. This API uses an asynchronous callback to return the result. It is called by the provider.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                         | Mandatory| Description                                                       |
| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
| event | string | Yes  | Name of the session event.|
| args | {[key: string]: any} | Yes  | Event content in key-value pair format.|
| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

> **NOTE**
>
> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let eventName = "dynamic_lyric";
let args = {
    lyric : "This is lyric"
}
currentAVSession.dispatchSessionEvent(eventName, args, (err) => {
    if(err) {
        console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`);
    }
})
```

### setAVQueueItems<sup>10+</sup>

setAVQueueItems(items: Array\<AVQueueItem>): Promise\<void>

Sets a playlist. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                | Mandatory| Description                              |
| ------ | ------------------------------------ | ---- | ---------------------------------- |
| items  | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
import image from '@ohos.multimedia.image';
import resourceManager from '@ohos.resourceManager';

let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI');
let imageSource : imageImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
let queueItemDescription_1 = {
    mediaId: '001',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    icon : imagePixel,
    iconUri: 'http://www.icon.uri.com',
    extras: {'extras':'any'}
};
let queueItem_1 = {
    itemId: 1,
    description: queueItemDescription_1
};
let queueItemDescription_2 = {
    mediaId: '002',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    icon: imagePixel,
    iconUri: 'http://www.xxx.com',
    extras: {'extras':'any'}
};
let queueItem_2 = {
    itemId: 2,
    description: queueItemDescription_2
};
let queueItemsArray = [queueItem_1, queueItem_2];
currentAVSession.setAVQueueItems(queueItemsArray).then(() => {
    console.info(`SetAVQueueItems successfully`);
}).catch((err) => {
    console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### setAVQueueItems<sup>10+</sup>

setAVQueueItems(items: Array\<AVQueueItem>, callback: AsyncCallback\<void>): void

Sets a playlist. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                 | Mandatory| Description                                                        |
| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- |
| items    | Array<[AVQueueItem](#avqueueitem10)\> | Yes  | Playlist to set.                         |
| callback | AsyncCallback\<void>                 | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
import image from '@ohos.multimedia.image';
import resourceManager from '@ohos.resourceManager';

let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI');
let imageSource : imageImageSource = image.createImageSource(value.buffer);
let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}});
let queueItemDescription_1 = {
    mediaId: '001',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    icon: imagePixel,
    iconUri: 'http://www.icon.uri.com',
    extras: {'extras':'any'}
};
let queueItem_1 = {
    itemId: 1,
    description: queueItemDescription_1
};
let queueItemDescription_2 = {
    mediaId: '002',
    title: 'music_name',
    subtitle: 'music_sub_name',
    description: 'music_description',
    icon: imagePixel,
    iconUri: 'http://www.icon.uri.com',
    extras: {'extras':'any'}
};
let queueItem_2 = {
    itemId: 2,
    description: queueItemDescription_2
};
let queueItemsArray = [queueItem_1, queueItem_2];
currentAVSession.setAVQueueItems(queueItemsArray, function (err) {
    if (err) {
        console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`SetAVQueueItems successfully`);
    }
});
```

### setAVQueueTitle<sup>10+</sup>

setAVQueueTitle(title: string): Promise\<void>

Sets a name for the playlist. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type  | Mandatory| Description          |
| ------ | ------ | ---- | -------------- |
| title  | string | Yes  | Name of the playlist.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle).then(() => {
    console.info(`SetAVQueueTitle successfully`);
}).catch((err) => {
    console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### setAVQueueTitle<sup>10+</sup>

setAVQueueTitle(title: string, callback: AsyncCallback\<void>): void

Sets a name for the playlist. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                 | Mandatory| Description                                                        |
| -------- | --------------------- | ---- | ----------------------------------------------------------- |
| title    | string                | Yes  | Name of the playlist.                         |
| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let queueTitle = 'QUEUE_TITLE';
currentAVSession.setAVQueueTitle(queueTitle, function (err) {
    if (err) {
        console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.error(`SetAVQueueTitle successfully`);
    }
});
```

### setExtras<sup>10+</sup>

setExtras(extras: {[key: string]: Object}): Promise\<void>

Sets a custom media packet in the form of key-value pairs. This API uses a promise to return the result. It is called by the provider.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                         | Mandatory| Description                                                       |
| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
| extras | {[key: string]: Object} | Yes  | Key-value pairs of the custom media packet.|

> **NOTE**
>
> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the setting is successful, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let extras = {
    extras : "This is custom media packet"
}
currentAVSession.setExtras(extras).catch((err) => {
    console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
})
```

### setExtras<sup>10+</sup>

setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\<void>): void

Sets a custom media packet in the form of key-value pairs. This API uses an asynchronous callback to return the result. It is called by the provider.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name | Type                                         | Mandatory| Description                                                       |
| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- |
| extras | {[key: string]: any} | Yes  | Key-value pairs of the custom media packet.|
| callback | AsyncCallback\<void>                          | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|

> **NOTE**
>
> The **extras** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let extras = {
    extras : "This is custom media packet"
}
currentAVSession.setExtras(extras, (err) => {
    if(err) {
        console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`);
    }
})
```

### getController<sup>10+</sup>

getController(): Promise\<AVSessionController>

Obtains the controller corresponding to this session. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type                                                | Description                         |
| ---------------------------------------------------- | ----------------------------- |
| Promise<[AVSessionController](#avsessioncontroller10)> | Promise used to return the session controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let avsessionController;
currentAVSession.getController().then((avcontroller) => {
    avsessionController = avcontroller;
    console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
}).catch((err) => {
    console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### getController<sup>10+</sup>

getController(callback: AsyncCallback\<AVSessionController>): void

Obtains the controller corresponding to this session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                       | Mandatory| Description                      |
| -------- | ----------------------------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | Yes  | Callback used to return the session controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
let avsessionController;
currentAVSession.getController(function (err, avcontroller) {
    if (err) {
        console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        avsessionController = avcontroller;
        console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`);
    }
});
```

### getAVCastController<sup>10+</sup>

getAVCastController(callback: AsyncCallback\<AVCastController>): void

Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**Parameters**

| Name   | Type                                                       | Mandatory| Description                                                        |
| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback  | AsyncCallback<[AVCastController](#avcastcontroller10)\> | Yes  | Callback used to return the cast controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600102  | The session does not exist. |
| 6600110  | The remote connection is not established. |

**Example**

```js
let aVCastController;
currentAVSession.getAVCastController().then((avcontroller) => {
    aVCastController = avcontroller;
    console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`);
}).catch((err) => {
    console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### getAVCastController<sup>10+</sup>

getAVCastController(): Promise\<AVCastController>;

Obtains the cast controller when a casting connection is set up. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**Return value**

| Type                                                       | Description                                                        |
| --------- | ------------------------------------------------------------ |
| Promise<[AVCastController](#avcastcontroller10)\>  | Promise used to return the cast controller.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600102  | The session does not exist. |
| 6600110  | The remote connection is not established. |

**Example**

```js
let aVCastController;
currentAVSession.getAVCastController(function (err, avcontroller) {
    if (err) {
        console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        aVCastController = avcontroller;
        console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`);
    }
});
```

### getOutputDevice<sup>10+</sup>

getOutputDevice(): Promise\<OutputDeviceInfo>

Obtains information about the output device for this session. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type                                          | Description                             |
| ---------------------------------------------- | --------------------------------- |
| Promise<[OutputDeviceInfo](#outputdeviceinfo10)> | Promise used to return the output device information.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.getOutputDevice().then((outputDeviceInfo) => {
    console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`);
}).catch((err) => {
    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### getOutputDevice<sup>10+</sup>

getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void

Obtains information about the output device for this session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                 | Mandatory| Description                          |
| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.getOutputDevice(function (err, outputDeviceInfo) {
    if (err) {
        console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`);
    }
});
```

### activate<sup>10+</sup>

activate(): Promise\<void>

Activates this session. A session can be used only after being activated. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the session is activated, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.activate().then(() => {
    console.info(`Activate : SUCCESS `);
}).catch((err) => {
    console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### activate<sup>10+</sup>

activate(callback: AsyncCallback\<void>): void

Activates this session. A session can be used only after being activated. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is activated, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.activate(function (err) {
    if (err) {
        console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`Activate : SUCCESS `);
    }
});
```

### deactivate<sup>10+</sup>

deactivate(): Promise\<void>

Deactivates this session. You can use [activate](#activate10) to activate the session again. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the session is deactivated, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.deactivate().then(() => {
    console.info(`Deactivate : SUCCESS `);
}).catch((err) => {
    console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### deactivate<sup>10+</sup>

deactivate(callback: AsyncCallback\<void>): void

Deactivates this session. This API uses an asynchronous callback to return the result.

Deactivates this session. You can use [activate](#activate10) to activate the session again.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is deactivated, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.deactivate(function (err) {
    if (err) {
        console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`Deactivate : SUCCESS `);
    }
});
```

### destroy<sup>10+</sup>

destroy(): Promise\<void>

Destroys this session. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the session is destroyed, no value is returned; otherwise, an error object is returned.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.destroy().then(() => {
    console.info(`Destroy : SUCCESS `);
}).catch((err) => {
    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
});
```

### destroy<sup>10+</sup>

destroy(callback: AsyncCallback\<void>): void

Destroys this session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the session is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.destroy(function (err) {
    if (err) {
        console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`Destroy : SUCCESS `);
    }
});
```

### on('play')<sup>10+</sup>

on(type: 'play', callback: () => void): void

Subscribes to playback started events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'play'** is triggered when the command for starting playback is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                                       |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('play', () => {
    console.info(`on play entry`);
});
```

### on('pause')<sup>10+</sup>

on(type: 'pause', callback: () => void): void

Subscribes to playback paused events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'pause'** is triggered when the command for pausing the playback is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('pause', () => {
    console.info(`on pause entry`);
});
```

### on('stop')<sup>10+</sup>

on(type:'stop', callback: () => void): void

Subscribes to playback stopped events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'stop'** is triggered when the command for stopping the playback is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.         |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('stop', () => {
    console.info(`on stop entry`);
});
```

### on('playNext')<sup>10+</sup>

on(type:'playNext', callback: () => void): void

Subscribes to playNext command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.    |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('playNext', () => {
    console.info(`on playNext entry`);
});
```

### on('playPrevious')<sup>10+</sup>

on(type:'playPrevious', callback: () => void): void

Subscribes to playPrevious command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous item sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.      |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('playPrevious', () => {
    console.info(`on playPrevious entry`);
});
```

### on('fastForward')<sup>10+</sup>

on(type: 'fastForward', callback: () => void): void

Subscribes to fastForward command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'fastForward'** is triggered when the command for fast forwarding is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.   |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('fastForward', () => {
    console.info(`on fastForward entry`);
});
```

### on('rewind')<sup>10+</sup>

on(type:'rewind', callback: () => void): void

Subscribes to rewind command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description                                                        |
| -------- | -------------------- | ---- | ------------------------------------------------------------ |
| type     | string               | Yes  | Event type. The event **'rewind'** is triggered when the command for rewinding is sent to the session.|
| callback | callback: () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.     |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('rewind', () => {
    console.info(`on rewind entry`);
});
```

### on('seek')<sup>10+</sup>

on(type: 'seek', callback: (time: number) => void): void

Subscribes to seek command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                  | Mandatory| Description                                                        |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| type     | string                 | Yes  | Event type. The event **'seek'** is triggered when the seek command is sent to the session.|
| callback | (time: number) => void | Yes  | Callback used for subscription. The **time** parameter in the callback indicates the time to seek to, in milliseconds.                  |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('seek', (time) => {
    console.info(`on seek entry time : ${time}`);
});
```

### on('setSpeed')<sup>10+</sup>

on(type: 'setSpeed', callback: (speed: number) => void): void

Subscribes to setSpeed command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                   | Mandatory| Description                                                        |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| type     | string                  | Yes  | Event type. The event **'setSpeed'** is triggered when the command for setting the playback speed is sent to the session.|
| callback | (speed: number) => void | Yes  | Callback used for subscription. The **speed** parameter in the callback indicates the playback speed.                             |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('setSpeed', (speed) => {
    console.info(`on setSpeed speed : ${speed}`);
});
```

### on('setLoopMode')<sup>10+</sup>

on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void

Subscribes to setLoopMode command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                                  | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---- |
| type     | string                                | Yes  | Event type. The event **'setLoopMode'** is triggered when the command for setting the loop mode is sent to the session.|
| callback | (mode: [LoopMode](#loopmode10)) => void | Yes  | Callback used for subscription. The **mode** parameter in the callback indicates the loop mode.                              |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('setLoopMode', (mode) => {
    console.info(`on setLoopMode mode : ${mode}`);
});
```

### on('toggleFavorite')<sup>10+</sup>

on(type: 'toggleFavorite', callback: (assetId: string) => void): void

Subscribes to toggleFavorite command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                                                        |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                    | Yes  | Event type. The event **'toggleFavorite'** is triggered when the command for favoriting the media asset is sent to the session.|
| callback | (assetId: string) => void | Yes  | Callback used for subscription. The **assetId** parameter in the callback indicates the media asset ID.                             |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('toggleFavorite', (assetId) => {
    console.info(`on toggleFavorite mode : ${assetId}`);
});
```

### on('skipToQueueItem')<sup>10+</sup>

on(type: 'skipToQueueItem', callback: (itemId: number) => void): void

Subscribes to the event that indicates an item in the playlist is selected. The session can play the selected item.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                                                                                     |
| -------- | ------------------------ | ---- | ---------------------------------------------------------------------------------------- |
| type     | string                   | Yes  | Event type. The event **'skipToQueueItem'** is triggered when an item in the playlist is selected.|
| callback | (itemId: number) => void | Yes  | Callback used for subscription. The **itemId** parameter in the callback indicates the ID of the selected item.                                               |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('skipToQueueItem', (itemId) => {
    console.info(`on skipToQueueItem id : ${itemId}`);
});
```

### on('handleKeyEvent')<sup>10+</sup>

on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void

Subscribes to key events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'handleKeyEvent'** is triggered when a key event is sent to the session.|
| callback | (event: [KeyEvent](js-apis-keyevent.md)) => void | Yes  | Callback used for subscription. The **event** parameter in the callback indicates the key event.                             |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('handleKeyEvent', (event) => {
    console.info(`on handleKeyEvent event : ${event}`);
});
```

### on('outputDeviceChange')<sup>10+</sup>

on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void

Subscribes to output device change events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes  | Callback used for subscription. 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.                        |

**Error codes**
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('outputDeviceChange', (state, device) => {
    console.info(`on outputDeviceChange device : ${device}`);
});
```

### on('commonCommand')<sup>10+</sup>

on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Object}) => void): void

Subscribes to custom control command change events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'commonCommand'** is triggered when a custom control command changes.|
| callback | (commonCommand: string, args: {[key:string]: Object}) => void         | Yes  | Callback used for subscription. The **commonCommand** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command. The parameters must be the same as those set in **sendCommand**.         |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------ |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.on('commonCommand', (commonCommand, args) => {
    console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`);
});
```

### off('play')<sup>10+</sup>

off(type: 'play', callback?: () => void): void

Unsubscribes from playback started events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'play'** in this case.|
| 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.                           |

**Error codes**
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.off('play');
```

### off('pause')<sup>10+</sup>

off(type: 'pause', callback?: () => void): void

Unsubscribes from playback paused events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'pause'** in this case.|
| 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.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.off('pause');
```

### off('stop')<sup>10+</sup>

off(type: 'stop', callback?: () => void): void

Unsubscribes from playback stopped events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'stop'** in this case.|
| 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.                           |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
3423

G
Gloria 已提交
3424 3425 3426 3427
| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3428

G
Gloria 已提交
3429
**Example**
3430

G
Gloria 已提交
3431 3432 3433
```js
currentAVSession.off('stop');
```
3434

G
Gloria 已提交
3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448
### off('playNext')<sup>10+</sup>

off(type: 'playNext', callback?: () => void): void

Unsubscribes from playNext command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'playNext'** in this case.|
| 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.                           |
3449 3450

**Error codes**
G
Gloria 已提交
3451

3452 3453 3454 3455
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
3456 3457
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3458 3459 3460 3461

**Example**

```js
G
Gloria 已提交
3462
currentAVSession.off('playNext');
3463 3464
```

G
Gloria 已提交
3465
### off('playPrevious')<sup>10+</sup>
3466

G
Gloria 已提交
3467
off(type: 'playPrevious', callback?: () => void): void
3468

G
Gloria 已提交
3469
Unsubscribes from playPrevious command events.
3470 3471 3472 3473 3474

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3475 3476 3477 3478
| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'playPrevious'** in this case.|
| 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.                           |
3479 3480

**Error codes**
G
Gloria 已提交
3481

3482 3483 3484 3485
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
3486 3487
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3488 3489 3490 3491

**Example**

```js
G
Gloria 已提交
3492
currentAVSession.off('playPrevious');
3493 3494
```

G
Gloria 已提交
3495
### off('fastForward')<sup>10+</sup>
3496

G
Gloria 已提交
3497
off(type: 'fastForward', callback?: () => void): void
3498

G
Gloria 已提交
3499
Unsubscribes from fastForward command events.
3500 3501 3502 3503 3504

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3505 3506 3507 3508
| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'fastForward'** in this case.|
| 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.                           |
3509

G
Gloria 已提交
3510
**Error codes**
3511

G
Gloria 已提交
3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.off('fastForward');
```

### off('rewind')<sup>10+</sup>

off(type: 'rewind', callback?: () => void): void

Unsubscribes from rewind command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                 | Mandatory| Description                                                                                                                        |
| -------- | -------------------- | ---- | ---------------------------------------------------------------------------------------------------------------------------- |
| type     | string               | Yes  | Event type, which is **'rewind'** in this case.|
| 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.                           |
3539 3540

**Error codes**
G
Gloria 已提交
3541

3542 3543 3544 3545
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
3546 3547
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3548 3549 3550 3551

**Example**

```js
G
Gloria 已提交
3552
currentAVSession.off('rewind');
3553 3554
```

G
Gloria 已提交
3555
### off('seek')<sup>10+</sup>
3556

G
Gloria 已提交
3557
off(type: 'seek', callback?: (time: number) => void): void
3558

G
Gloria 已提交
3559
Unsubscribes from seek command events.
3560 3561 3562 3563 3564

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3565 3566 3567 3568
| Name  | Type                  | Mandatory| Description                                         |
| -------- | ---------------------- | ---- | ----------------------------------------- |
| type     | string                 | Yes  | Event type, which is **'seek'** in this case.      |
| 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.       |
3569 3570

**Error codes**
G
Gloria 已提交
3571

3572 3573 3574 3575
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
3576 3577
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3578 3579 3580 3581

**Example**

```js
G
Gloria 已提交
3582
currentAVSession.off('seek');
3583 3584
```

G
Gloria 已提交
3585
### off('setSpeed')<sup>10+</sup>
G
Gloria 已提交
3586

G
Gloria 已提交
3587
off(type: 'setSpeed', callback?: (speed: number) => void): void
G
Gloria 已提交
3588

G
Gloria 已提交
3589
Unsubscribes from setSpeed command events.
G
Gloria 已提交
3590 3591 3592 3593 3594

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3595 3596 3597 3598
| Name  | Type                   | Mandatory| Description                                          |
| -------- | ----------------------- | ---- | -------------------------------------------|
| type     | string                  | Yes  | Event type, which is **'setSpeed'** in this case.   |
| 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.                |
G
Gloria 已提交
3599

G
Gloria 已提交
3600
**Error codes**
G
Gloria 已提交
3601

G
Gloria 已提交
3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.off('setSpeed');
```

### off('setLoopMode')<sup>10+</sup>

off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void

Unsubscribes from setSpeed command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                 | Mandatory| Description    |
| -------- | ------------------------------------- | ---- | ----- |
| type     | string | Yes  | Event type, which is **'setLoopMode'** in this case.|
| callback | (mode: [LoopMode](#loopmode10)) => 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.|
G
Gloria 已提交
3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
G
Gloria 已提交
3642 3643
currentAVSession.off('setLoopMode');
```
G
Gloria 已提交
3644

G
Gloria 已提交
3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672
### off('toggleFavorite')<sup>10+</sup>

off(type: 'toggleFavorite', callback?: (assetId: string) => void): void

Unsubscribes from toggleFavorite command events.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                     | Mandatory| Description                                                        |
| -------- | ------------------------- | ---- | -------------------------------------------------------- |
| type     | string                    | Yes  | Event type, which is **'toggleFavorite'** in this case.           |
| 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.                              |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
currentAVSession.off('toggleFavorite');
G
Gloria 已提交
3673 3674
```

G
Gloria 已提交
3675
### off('skipToQueueItem')<sup>10+</sup>
G
Gloria 已提交
3676

G
Gloria 已提交
3677
off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void
G
Gloria 已提交
3678

G
Gloria 已提交
3679
Unsubscribes from the event that indicates an item in the playlist is selected.
G
Gloria 已提交
3680 3681 3682 3683 3684

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3685 3686 3687 3688
| Name  | Type                     | Mandatory| Description                                                                                                                                                       |
| -------- | ------------------------ | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| type     | string                   | Yes  | Event type, which is **'skipToQueueItem'** in this case.                                                                                                         |
| callback | (itemId: number) => void | No  | Callback used for unsubscription. The **itemId** parameter in the callback indicates the ID of the item.<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.|
G
Gloria 已提交
3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
G
Gloria 已提交
3702
currentAVSession.off('skipToQueueItem');
G
Gloria 已提交
3703 3704
```

G
Gloria 已提交
3705
### off('handleKeyEvent')<sup>10+</sup>
G
Gloria 已提交
3706

G
Gloria 已提交
3707
off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void
G
Gloria 已提交
3708

G
Gloria 已提交
3709
Unsubscribes from key events.
G
Gloria 已提交
3710 3711 3712 3713 3714

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3715 3716 3717 3718
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type, which is **'handleKeyEvent'** in this case.            |
| 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.                             |
G
Gloria 已提交
3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
G
Gloria 已提交
3732
currentAVSession.off('handleKeyEvent');
G
Gloria 已提交
3733 3734
```

G
Gloria 已提交
3735
### off('outputDeviceChange')<sup>10+</sup>
G
Gloria 已提交
3736

G
Gloria 已提交
3737
off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
G
Gloria 已提交
3738

G
Gloria 已提交
3739
Unsubscribes from playback device change events.
G
Gloria 已提交
3740 3741 3742 3743 3744

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3745 3746 3747 3748
| Name  | Type                                                   | Mandatory| Description                                                     |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.    |
| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => 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.                       |
G
Gloria 已提交
3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |

**Example**

```js
G
Gloria 已提交
3762
currentAVSession.off('outputDeviceChange');
G
Gloria 已提交
3763 3764
```

3765

G
Gloria 已提交
3766
### off('commonCommand')<sup>10+</sup>
3767

G
Gloria 已提交
3768 3769 3770
off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Object}) => void): void

Unsubscribes from custom control command change events.
3771 3772 3773 3774 3775

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
3776 3777 3778 3779
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'commonCommand'** in this case.   |
| callback | (command: string, args: {[key:string]: Object}) => void         | No  | Callback used for unsubscription. The **command** parameter in the callback indicates the name of the changed custom control command, and **args** indicates the parameters carried in the command.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
3780 3781

**Error codes**
G
Gloria 已提交
3782

3783 3784 3785
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
3786
| -------- | ---------------- |
3787 3788
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
3789 3790 3791 3792

**Example**

```js
G
Gloria 已提交
3793
currentAVSession.off('commonCommand');
3794 3795
```

G
Gloria 已提交
3796
### stopCasting<sup>10+</sup>
3797

G
Gloria 已提交
3798
stopCasting(callback: AsyncCallback\<void>): void
3799

G
Gloria 已提交
3800
Stops castings. This API uses an asynchronous callback to return the result.
3801

G
Gloria 已提交
3802
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3803 3804 3805

**Parameters**

G
Gloria 已提交
3806 3807 3808
| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
3809 3810

**Error codes**
G
Gloria 已提交
3811

3812 3813 3814 3815
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
3816
| 6600109  | The remote connection is not established. |
3817 3818 3819 3820

**Example**

```js
G
Gloria 已提交
3821 3822 3823 3824 3825 3826
currentAVSession.stopCasting(function (err) {
    if (err) {
        console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`stopCasting successfully`);
    }
3827 3828 3829
});
```

G
Gloria 已提交
3830
### stopCasting<sup>10+</sup>
3831

G
Gloria 已提交
3832
stopCasting(): Promise\<void>
G
Gloria 已提交
3833

G
Gloria 已提交
3834
Stops castings. This API uses a promise to return the result.
G
Gloria 已提交
3835

G
Gloria 已提交
3836
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3837

3838 3839
**Return value**

G
Gloria 已提交
3840 3841
| Type          | Description                         |
| -------------- | ----------------------------- |
G
Gloria 已提交
3842
| Promise\<void> | Promise used to return the result. If casting stops, no value is returned; otherwise, an error object is returned.|
3843 3844

**Error codes**
G
Gloria 已提交
3845

3846 3847 3848 3849
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
3850
| 6600109  | The remote connection is not established. |
3851 3852 3853 3854

**Example**

```js
G
Gloria 已提交
3855 3856 3857 3858 3859
currentAVSession.stopCasting().then(() => {
    console.info(`stopCasting successfully`);
}).catch((err) => {
    console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`);
});
G
Gloria 已提交
3860 3861
```

G
Gloria 已提交
3862
## AVCastControlCommandType<sup>10+</sup>
G
Gloria 已提交
3863

G
Gloria 已提交
3864
Enumerates the commands that can be sent by a cast controller.
3865

G
Gloria 已提交
3866
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
G
Gloria 已提交
3867

G
Gloria 已提交
3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881
| Name          | Type  | Description        |
| -------------- | ------ | ------------ |
| play           | string | Play the media.        |
| pause          | string | Pause the playback.        |
| stop           | string | Stop the playback.        |
| playNext       | string | Play the next media asset.      |
| playPrevious   | string | Play the previous media asset.      |
| fastForward    | string | Fast-forward.        |
| rewind         | string | Rewind.        |
| seek           | numbder | Seek to a playback position.|
| setSpeed       | number | Set the playback speed.|
| setLoopMode    | string | Set the loop mode.|
| toggleFavorite | string | Favorite the media asset.    |
| setVolume      | number | Set the volume.    |
G
Gloria 已提交
3882

G
Gloria 已提交
3883
## AVCastControlCommand<sup>10+</sup>
G
Gloria 已提交
3884

G
Gloria 已提交
3885
Defines the command that can be sent by a cast controller.
G
Gloria 已提交
3886

G
Gloria 已提交
3887
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
G
Gloria 已提交
3888

G
Gloria 已提交
3889 3890 3891 3892
| Name     | Type                                             | Mandatory| Description          |
| --------- | ------------------------------------------------- | ---- | -------------- |
| command   | [AVCastControlCommandType](#avcastcontrolcommandtype10)     | Yes  | Command.          |
| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | No  | Parameters carried in the command.|
G
Gloria 已提交
3893

G
Gloria 已提交
3894
## AVCastController<sup>10+</sup>
3895

G
Gloria 已提交
3896
After a casting connection is set up, you can call [avSession.getAVCastController](#getavcastcontroller10) to obtain the cast controller. Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
3897

G
Gloria 已提交
3898
### setDisplaySurface<sup>10+</sup>
3899

G
Gloria 已提交
3900
setDisplaySurface(surfaceId: string): Promise\<void>
3901

G
Gloria 已提交
3902
Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses a promise to return the result.
3903

G
Gloria 已提交
3904
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3905

G
Gloria 已提交
3906
**System API**: This is a system API.
3907 3908 3909

**Return value**

G
Gloria 已提交
3910 3911 3912
| Type                                         | Description                       |
| --------------------------------------------- | --------------------------- |
| Promise\<void> | Promise used to return the result.|
3913 3914 3915 3916 3917 3918 3919

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
3920
| 6600109  | The remote connection is not established. |
3921 3922 3923

**Example**
```js
G
Gloria 已提交
3924 3925 3926
aVCastController.setDisplaySurface().then(() => {
    console.info(`setDisplaySurface : SUCCESS :`);
});
3927 3928
```

G
Gloria 已提交
3929
### setDisplaySurface<sup>10+</sup>
3930

G
Gloria 已提交
3931
setDisplaySurface(surfaceId: string, callback: AsyncCallback\<void>): void
3932

G
Gloria 已提交
3933
Sets the surface ID for playback, which is used at the cast receiver (sink). This API uses an asynchronous callback to return the result.
3934

G
Gloria 已提交
3935
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
3936

G
Gloria 已提交
3937
**System API**: This is a system API.
3938

G
Gloria 已提交
3939
**Parameters**
3940

G
Gloria 已提交
3941 3942 3943
| Name  | Type                                               | Mandatory| Description                        |
| -------- | --------------------------------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
3944 3945 3946 3947 3948 3949 3950

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
3951
| 6600109  | The remote connection is not established. |
3952 3953 3954

**Example**
```js
G
Gloria 已提交
3955 3956 3957 3958 3959
aVCastController.setDisplaySurface(function (err, value) {
    if (err) {
        console.info(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`setDisplaySurface : SUCCESS : state : ${value}`);
3960
    }
G
Gloria 已提交
3961
});
3962 3963
```

G
Gloria 已提交
3964
### getAVPlaybackState<sup>10+</sup>
G
Gloria 已提交
3965

G
Gloria 已提交
3966
getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
G
Gloria 已提交
3967

G
Gloria 已提交
3968
Obtains the remote playback state. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
3969

G
Gloria 已提交
3970
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
G
Gloria 已提交
3971

G
Gloria 已提交
3972
**Parameters**
G
Gloria 已提交
3973

G
Gloria 已提交
3974 3975 3976
| Name   | Type                                                       | Mandatory| Description                                                        |
| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback  | AsyncCallback<[[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
G
Gloria 已提交
3977 3978 3979 3980 3981 3982 3983

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
3984
| 6600101  | Session service exception |
G
Gloria 已提交
3985 3986 3987 3988

**Example**

```js
G
Gloria 已提交
3989 3990 3991 3992 3993 3994
aVCastController.getAVPlaybackState(function (err, state) {
    if (err) {
        console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`getAVPlaybackState : SUCCESS`);
    }
3995 3996 3997
});
```

G
Gloria 已提交
3998
### getAVPlaybackState<sup>10+</sup>
3999

G
Gloria 已提交
4000
getAVPlaybackState(): Promise\<AVPlaybackState>;
4001

G
Gloria 已提交
4002
Obtains the remote playback state. This API uses a promise to return the result.
4003

G
Gloria 已提交
4004
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4005

G
Gloria 已提交
4006
**Return value**
4007

G
Gloria 已提交
4008 4009 4010
| Type                                                       | Description                                                        |
| --------- | ------------------------------------------------------------ |
| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state.|
4011 4012

**Error codes**
G
Gloria 已提交
4013

4014 4015 4016 4017
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
4018
| 6600101  | Session service exception |
4019 4020 4021 4022

**Example**

```js
G
Gloria 已提交
4023 4024 4025 4026
aVCastController.getAVPlaybackState().then((state) => {
    console.info(`getAVPlaybackState : SUCCESS :`);
}).catch((err) => {
    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
4027 4028 4029
});
```

G
Gloria 已提交
4030
### sendControlCommand<sup>10+</sup>
4031

G
Gloria 已提交
4032
sendControlCommand(command: AVCastControlCommand): Promise\<void>
4033

G
Gloria 已提交
4034
Sends a control command to the session through the controller. This API uses a promise to return the result.
4035

G
Gloria 已提交
4036 4037 4038 4039 4040 4041 4042 4043

**System capability**: SystemCapability.Multimedia.AVSession.AVCast

**Parameters**

| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| command | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
4044 4045 4046

**Return value**

G
Gloria 已提交
4047 4048 4049
| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
4050 4051

**Error codes**
G
Gloria 已提交
4052

4053 4054 4055 4056
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4057
| 6600101  | Session service exception. |
G
Gloria 已提交
4058 4059
| 6600105  | Invalid session command. |
| 6600109  | The remote connection is not established. |
4060 4061 4062 4063

**Example**

```js
G
Gloria 已提交
4064 4065 4066 4067 4068 4069 4070 4071 4072 4073
let avCommand = {command:'play'};
// let avCommand = {command:'pause'};
// let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'};
// let avCommand = {command:'playPrevious'};
// let avCommand = {command:'fastForward'};
// let avCommand = {command:'rewind'};
// let avCommand = {command:'seek', parameter:10};
aVCastController.sendControlCommand(avCommand).then(() => {
    console.info(`SendControlCommand successfully`);
4074
}).catch((err) => {
G
Gloria 已提交
4075
    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
4076 4077 4078
});
```

G
Gloria 已提交
4079
### sendControlCommand<sup>10+</sup>
4080

G
Gloria 已提交
4081
sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\<void>): void
4082

G
Gloria 已提交
4083
Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.
4084

G
Gloria 已提交
4085 4086

**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4087 4088 4089

**Parameters**

G
Gloria 已提交
4090 4091 4092 4093
| Name  | Type                                 | Mandatory| Description                          |
| -------- | ------------------------------------- | ---- | ------------------------------ |
| command  | [AVCastControlCommand](#avcastcontrolcommand10) | Yes  | Command to send.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
4094 4095

**Error codes**
G
Gloria 已提交
4096

4097 4098 4099
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4100
| -------- | ------------------------------- |
4101
| 6600101  | Session service exception. |
G
Gloria 已提交
4102 4103
| 6600105  | Invalid session command. |
| 6600109  | The remote connection is not established. |
4104 4105 4106 4107

**Example**

```js
G
Gloria 已提交
4108 4109 4110 4111 4112 4113 4114 4115 4116
let avCommand = {command:'play'};
// let avCommand = {command:'pause'};
// let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'};
// let avCommand = {command:'playPrevious'};
// let avCommand = {command:'fastForward'};
// let avCommand = {command:'rewind'};
// let avCommand = {command:'seek', parameter:10};
aVCastController.sendControlCommand(avCommand, function (err) {
4117
    if (err) {
G
Gloria 已提交
4118
        console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
4119
    } else {
G
Gloria 已提交
4120
        console.info(`SendControlCommand successfully`);
4121 4122 4123 4124
    }
});
```

G
Gloria 已提交
4125
### prepare<sup>10+</sup>
4126

G
Gloria 已提交
4127
prepare(item: AVQueueItem, callback: AsyncCallback\<void>): void
4128

G
Gloria 已提交
4129
Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
4130

G
Gloria 已提交
4131
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4132

G
Gloria 已提交
4133
**Parameters**
4134

G
Gloria 已提交
4135 4136 4137 4138
| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.   
4139 4140

**Error codes**
G
Gloria 已提交
4141

4142 4143 4144 4145
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4146
| 6600101  | Session service exception. |
4147 4148 4149 4150

**Example**

```js
G
Gloria 已提交
4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172
// Set playback parameters.
var playItem = {
    itemId: 0,
    description: {
    mediaId: '12345',
    mediaName: 'song1',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    iconUri: "http://resource1_icon_address",
    appName: 'MyMusic'
    }
};
// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
aVCastController.prepare(playItem, () => {
  console.info('prepare done');
4173 4174 4175 4176
});
```


G
Gloria 已提交
4177
### prepare<sup>10+</sup>
4178

G
Gloria 已提交
4179
prepare(item: AVQueueItem): Promise\<void>
4180

G
Gloria 已提交
4181 4182 4183 4184
Prepares for the playback of a media asset. This API uses a promise to return the result.


**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4185 4186 4187

**Parameters**

G
Gloria 已提交
4188 4189 4190 4191 4192 4193 4194 4195 4196
| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
4197 4198

**Error codes**
G
Gloria 已提交
4199

4200 4201 4202 4203
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4204
| 6600101  | Session service exception. |
G
Gloria 已提交
4205

4206 4207 4208 4209

**Example**

```js
G
Gloria 已提交
4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226
// Set playback parameters.
var playItem = {
    itemId: 0,
    description: {
        mediaId: '12345',
        mediaName: 'song1',
        mediaType: 'AUDIO',
        mediaUri: 'http://resource1_address',
        mediaSize: 12345,
        startPosition: 0,
        duration: 0,
        artist: 'mysong',
        albumTitle: 'song1_title',
        albumCoverUri: "http://resource1_album_address",
        lyricUri: "http://resource1_lyric_address",
        iconUri: "http://resource1_icon_address",
        appName: 'MyMusic'
4227
    }
G
Gloria 已提交
4228 4229 4230 4231
};
// Prepare for playback. This operation triggers loading and buffering, but not the actual playback.
aVCastController.prepare(playItem, () => {
    console.info('prepare done');
4232 4233 4234
});
```

G
Gloria 已提交
4235
### start<sup>10+</sup>
4236

G
Gloria 已提交
4237
start(item: AVQueueItem, callback: AsyncCallback\<void>): void
4238

G
Gloria 已提交
4239
Prepares for the playback of a media asset. This API uses an asynchronous callback to return the result.
4240

G
Gloria 已提交
4241
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4242

G
Gloria 已提交
4243
**Parameters**
4244

G
Gloria 已提交
4245 4246 4247 4248
| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.   
4249 4250

**Error codes**
G
Gloria 已提交
4251

4252 4253 4254 4255
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4256
| 6600101  | Session service exception. |
4257 4258 4259 4260

**Example**

```js
G
Gloria 已提交
4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283
// Set playback parameters.
var playItem = {
itemId: 0,
description: {
  mediaId: '12345',
  mediaName: 'song1',
  mediaType: 'AUDIO',
  mediaUri: 'http://resource1_address',
  mediaSize: 12345,
  startPosition: 0,
  duration: 0,
  artist: 'mysong',
  albumTitle: 'song1_title',
  albumCoverUri: "http://resource1_album_address",
  lyricUri: "http://resource1_lyric_address",
  iconUri: "http://resource1_icon_address",
  appName: 'MyMusic'
}
};

// Start playback.
aVCastController.start(playItem, () => {
  console.info('play done');
4284 4285 4286
});
```

G
Gloria 已提交
4287
### start<sup>10+</sup>
4288

G
Gloria 已提交
4289
start(item: AVQueueItem): Promise\<void>
4290

G
Gloria 已提交
4291
Prepares for the playback of a media asset. This API uses a promise to return the result.
4292 4293


G
Gloria 已提交
4294
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4295 4296 4297

**Parameters**

G
Gloria 已提交
4298 4299 4300 4301 4302 4303 4304 4305 4306
| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| item | [AVQueueItem](#avqueueitem10) | Yes  | Attributes of an item in the playlist.|

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
4307 4308

**Error codes**
G
Gloria 已提交
4309

4310 4311 4312 4313
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4314
| 6600101  | Session service exception. |
G
Gloria 已提交
4315

4316 4317 4318 4319

**Example**

```js
G
Gloria 已提交
4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343
// Set playback parameters.
var playItem = {
itemId: 0,
description: {
    mediaId: '12345',
    mediaName: 'song1',
    mediaType: 'AUDIO',
    mediaUri: 'http://resource1_address',
    mediaSize: 12345,
    startPosition: 0,
    duration: 0,
    artist: 'mysong',
    albumTitle: 'song1_title',
    albumCoverUri: "http://resource1_album_address",
    lyricUri: "http://resource1_lyric_address",
    iconUri: "http://resource1_icon_address",
    appName: 'MyMusic'
}
};
// Start playback.
aVCastController.start(playItem).then(() => {
    console.info(`start successfully`);
}).catch((err) => {
    console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`);
4344 4345 4346
});
```

G
Gloria 已提交
4347
### getCurrentItem<sup>10+</sup>
4348

G
Gloria 已提交
4349
getCurrentItem(callback: AsyncCallback\<AVQueueItem>): void
4350

G
Gloria 已提交
4351
Obtains the information about the media asset that is being played. This API uses an asynchronous callback to return the result.
4352

G
Gloria 已提交
4353
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4354

G
Gloria 已提交
4355
**Parameters**
4356

G
Gloria 已提交
4357 4358 4359
| Name  | Type                                 | Mandatory| Description                                 |
| -------- | ------------------------------------- | ---- | ------------------------------------- |
| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.|
4360 4361

**Error codes**
G
Gloria 已提交
4362

4363 4364 4365 4366
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4367
| 6600101  | Session service exception. |
4368 4369 4370 4371

**Example**

```js
G
Gloria 已提交
4372 4373 4374 4375 4376 4377
aVCastController.getCurrentItem(function (err, value) {
    if (err) {
        console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`getCurrentItem successfully`);
    }
4378 4379 4380
});
```

G
Gloria 已提交
4381
### getCurrentItem<sup>10+</sup>
4382

G
Gloria 已提交
4383
getCurrentItem(): Promise\<AVQueueItem>
4384

G
Gloria 已提交
4385
Obtains the information about the media asset that is being played. This API uses a promise to return the result.
4386

G
Gloria 已提交
4387
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4388

G
Gloria 已提交
4389
**Return value**
4390

G
Gloria 已提交
4391 4392 4393
| Type          | Description                         |
| -------------- | ----------------------------- |
| Promise\<[AVQueueItem](#avqueueitem10)> | Promise used to return the media asset obtained. If the operation fails, an error object is returned.|
4394 4395

**Error codes**
G
Gloria 已提交
4396

4397 4398 4399 4400
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
4401
| 6600101  | Session service exception. |
4402 4403 4404 4405

**Example**

```js
G
Gloria 已提交
4406 4407 4408 4409
aVCastController.getCurrentItem().then((AVQueueItem) => {
    console.info(`getCurrentItem successfully`);
}).catch((err) => {
    console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`);
4410 4411 4412
});
```

G
Gloria 已提交
4413
### on('playbackStateChange')<sup>10+</sup>
4414

G
Gloria 已提交
4415
on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void): void
4416

G
Gloria 已提交
4417
Subscribes to playback state change events.
4418

G
Gloria 已提交
4419
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4420 4421 4422

**Parameters**

G
Gloria 已提交
4423 4424 4425 4426 4427
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.|
| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.                     |
4428 4429

**Error codes**
G
Gloria 已提交
4430

4431 4432 4433
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4434
| -------- | ------------------------------ |
4435
| 6600101  | Session service exception. |
4436 4437 4438 4439

**Example**

```js
G
Gloria 已提交
4440 4441
aVCastController.on('playbackStateChange', 'all', (playbackState) => {
    console.info(`on playbackStateChange state : ${playbackState.state}`);
4442
});
G
Gloria 已提交
4443 4444 4445 4446

let playbackFilter = ['state', 'speed', 'loopMode'];
aVCastController.on('playbackStateChange', playbackFilter, (playbackState) => {
    console.info(`on playbackStateChange state : ${playbackState.state}`);
4447 4448 4449
});
```

G
Gloria 已提交
4450
### off('playbackStateChange')<sup>10+</sup>
4451

G
Gloria 已提交
4452
off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void
4453

G
Gloria 已提交
4454
Unsubscribes from playback state change events. This API is called by the controller.
4455

G
Gloria 已提交
4456
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4457 4458 4459

**Parameters**

G
Gloria 已提交
4460 4461 4462 4463
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | No  | Callback used for unsubscription. 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.                     |
4464 4465

**Error codes**
G
Gloria 已提交
4466

4467 4468 4469
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4470
| -------- | ---------------- |
4471
| 6600101  | Session service exception. |
4472 4473

**Example**
G
Gloria 已提交
4474

4475
```js
G
Gloria 已提交
4476
aVCastController.off('playbackStateChange');
4477 4478
```

G
Gloria 已提交
4479
### on('mediaItemChange')<sup>10+</sup>
4480

G
Gloria 已提交
4481
on(type: 'mediaItemChange', callback: Callback\<AVQueueItem>): void
4482

G
Gloria 已提交
4483
Subscribes to media asset change events.
4484

G
Gloria 已提交
4485
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4486 4487 4488

**Parameters**

G
Gloria 已提交
4489 4490 4491 4492
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'mediaItemChange'** is triggered when the media content being played changes.|
| callback | (state: [AVQueueItem](#avqueueitem10)) => void         | Yes  | Callback used for subscription. **AVQueueItem** is the media asset that is being played.                     |
4493 4494

**Error codes**
G
Gloria 已提交
4495

4496 4497 4498
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4499
| -------- | ------------------------------ |
4500
| 6600101  | Session service exception. |
4501 4502 4503 4504

**Example**

```js
G
Gloria 已提交
4505 4506
aVCastController.on('mediaItemChange', (item) => {
    console.info(`on mediaItemChange state : ${item.itemId}`);
4507 4508 4509
});
```

G
Gloria 已提交
4510
### off('mediaItemChange')<sup>10+</sup>
4511

G
Gloria 已提交
4512
off(type: 'mediaItemChange'): void
4513

G
Gloria 已提交
4514
Unsubscribes from media asset change events.
4515

G
Gloria 已提交
4516
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4517 4518 4519

**Parameters**

G
Gloria 已提交
4520 4521 4522
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'mediaItemChange'** in this case.   |
4523 4524

**Error codes**
G
Gloria 已提交
4525

4526 4527 4528
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4529
| -------- | ---------------- |
4530
| 6600101  | Session service exception. |
4531 4532 4533 4534

**Example**

```js
G
Gloria 已提交
4535
aVCastController.off('mediaItemChange');
4536 4537
```

G
Gloria 已提交
4538
### on('playNext')<sup>10+</sup>
4539

G
Gloria 已提交
4540
on(type: 'playNext', callback: Callback\<void>): void
4541

G
Gloria 已提交
4542
Subscribes to playNext command events.
4543

G
Gloria 已提交
4544
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4545 4546 4547

**Parameters**

G
Gloria 已提交
4548 4549 4550 4551
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'playNext'** is triggered when the command for playing the next item is received.|
| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4552 4553

**Error codes**
G
Gloria 已提交
4554

4555 4556 4557
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4558
| -------- | ------------------------------ |
4559
| 6600101  | Session service exception. |
4560 4561 4562 4563

**Example**

```js
G
Gloria 已提交
4564 4565
aVCastController.on('playNext', () => {
    console.info(`on playNext`);
4566 4567 4568
});
```

G
Gloria 已提交
4569
### off('playNext')<sup>10+</sup>
G
Gloria 已提交
4570

G
Gloria 已提交
4571
off(type: 'playNext'): void
G
Gloria 已提交
4572

G
Gloria 已提交
4573
Unsubscribes from playNext command events.
G
Gloria 已提交
4574

G
Gloria 已提交
4575
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
G
Gloria 已提交
4576 4577 4578

**Parameters**

G
Gloria 已提交
4579 4580 4581
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'playNext'** in this case.   |
G
Gloria 已提交
4582 4583 4584 4585 4586 4587

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4588
| -------- | ---------------- |
G
Gloria 已提交
4589 4590 4591 4592 4593
| 6600101  | Session service exception. |

**Example**

```js
G
Gloria 已提交
4594
aVCastController.off('playNext');
G
Gloria 已提交
4595 4596
```

G
Gloria 已提交
4597
### on('playPrevious')<sup>10+</sup>
4598

G
Gloria 已提交
4599
on(type: 'playPrevious', callback: Callback\<void>): void
4600

G
Gloria 已提交
4601
Subscribes to playPrevious command events.
4602

G
Gloria 已提交
4603
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4604 4605 4606 4607 4608

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
4609 4610
| type     | string                                                       | Yes  | Event type. The event **'playPrevious'** is triggered when the command for playing the previous event is received.|
| callback | Callback\<void\>         | Yes  | Callback used to return the result.                     |
4611 4612

**Error codes**
G
Gloria 已提交
4613

4614 4615 4616
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4617
| -------- | ------------------------------ |
4618
| 6600101  | Session service exception. |
4619 4620 4621 4622

**Example**

```js
G
Gloria 已提交
4623 4624
aVCastController.on('playPrevious', () => {
    console.info(`on playPrevious`);
4625 4626 4627
});
```

G
Gloria 已提交
4628
### off('playPrevious')<sup>10+</sup>
4629

G
Gloria 已提交
4630
off(type: 'playPrevious'): void
4631

G
Gloria 已提交
4632
Unsubscribes from the playPrevious command event.
4633

G
Gloria 已提交
4634
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4635 4636 4637

**Parameters**

G
Gloria 已提交
4638 4639 4640
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'playPrevious'** in this case.   |
4641 4642

**Error codes**
G
Gloria 已提交
4643

4644 4645 4646
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4647
| -------- | ---------------- |
4648
| 6600101  | Session service exception. |
4649 4650 4651 4652

**Example**

```js
G
Gloria 已提交
4653
aVCastController.off('playPrevious');
4654 4655
```

G
Gloria 已提交
4656
### on('seekDone')<sup>10+</sup>
G
Gloria 已提交
4657

G
Gloria 已提交
4658
on(type: 'seekDone', callback: Callback\<number>): void
G
Gloria 已提交
4659

G
Gloria 已提交
4660
Subscribes to seek done events.
G
Gloria 已提交
4661

G
Gloria 已提交
4662
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
G
Gloria 已提交
4663 4664 4665 4666 4667

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
4668 4669
| type     | string                                                       | Yes  | Event type. The event **'seekDone'** is triggered when the seek operation is complete.|
| callback | Callback\<number\>         | Yes  | Callback used to return the position after the seek operation.                     |
G
Gloria 已提交
4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------ |
| 6600101  | Session service exception. |

**Example**

```js
G
Gloria 已提交
4682 4683
aVCastController.on('seekDone', (pos) => {
    console.info(`on seekDone pos: ${pos} `);
G
Gloria 已提交
4684 4685 4686
});
```

G
Gloria 已提交
4687
### off('seekDone')<sup>10+</sup>
4688

G
Gloria 已提交
4689
off(type: 'seekDone'): void
4690

G
Gloria 已提交
4691
Unsubscribes from the seek done events.
4692

G
Gloria 已提交
4693
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4694 4695 4696

**Parameters**

G
Gloria 已提交
4697 4698 4699
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'seekDone'** in this case.   |
4700 4701

**Error codes**
G
Gloria 已提交
4702

4703 4704 4705
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
4706
| -------- | ---------------- |
4707
| 6600101  | Session service exception. |
4708 4709 4710 4711

**Example**

```js
G
Gloria 已提交
4712
aVCastController.off('seekDone');
4713 4714
```

G
Gloria 已提交
4715
### on('videoSizeChange')<sup>10+</sup>
4716

G
Gloria 已提交
4717
on(type: 'videoSizeChange', callback: (width:number, height:number) => void): void
4718

G
Gloria 已提交
4719
Subscribes to video size change events.
4720

G
Gloria 已提交
4721
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4722

G
Gloria 已提交
4723
**System API**: This is a system API.
G
Gloria 已提交
4724

G
Gloria 已提交
4725
**Parameters**
4726

G
Gloria 已提交
4727 4728 4729
| Parameter | Type | Mandatory | Description |
| type | string | Yes  | Event type. The event **'videoSizeChange'** is triggered when the video size changes. |
| callback | (width:number, height:number) => void | Yes |  Callback used to return the video width and height. |
4730 4731 4732 4733

**Example**

```js
G
Gloria 已提交
4734 4735 4736 4737
aVCastController.on('videoSizeChange', (width, height) => {
    console.info(`width : ${width} `);
    console.info(`height: ${height} `);
});
4738 4739
```

G
Gloria 已提交
4740
### off('videoSizeChange')<sup>10+</sup>
4741

G
Gloria 已提交
4742
off(type: 'videoSizeChange'): void
4743

G
Gloria 已提交
4744
Unsubscribes from video size changes.
4745

G
Gloria 已提交
4746
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4747

G
Gloria 已提交
4748
**System API**: This is a system API.
G
Gloria 已提交
4749

G
Gloria 已提交
4750
**Parameters**
4751

G
Gloria 已提交
4752 4753
| Name | Type | Mandatory | Description |
| type | string | Yes | Event type, which is **'videoSizeChange'** in this case.    |
4754 4755 4756 4757

**Example**

```js
G
Gloria 已提交
4758
aVCastController.off('videoSizeChange');
4759 4760
```

G
Gloria 已提交
4761
### on('error')<sup>10+</sup>
4762

G
Gloria 已提交
4763
on(type: 'error', callback: ErrorCallback): void
4764

G
Gloria 已提交
4765
Subscribes to remote AVPlayer errors. This event is used only for error prompt and does not require the user to stop playback control.
4766

G
Gloria 已提交
4767
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4768 4769 4770

**Parameters**

G
Gloria 已提交
4771 4772 4773 4774
| Name  | Type    | Mandatory| Description                                                        |
| -------- | -------- | ---- | ------------------------------------------------------------ |
| type     | string   | Yes  | Event type, which is **'error'** in this case. This event can be triggered by both user operations and the system.|
| callback | function | Yes  | Callback used to return the error code ID and error message.|
4775 4776

**Error codes**
G
Gloria 已提交
4777

G
Gloria 已提交
4778
For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md).
4779

G
Gloria 已提交
4780 4781 4782 4783 4784 4785 4786 4787
| ID| Error Message             |
| -------- | --------------------- |
| 5400101  | No memory.            |
| 5400102  | Operation not allowed.   |
| 5400103  | I/O error.             |
| 5400104  | Time out.      |
| 5400105  | Service died.         |
| 5400106  | Unsupport format.     |
4788 4789 4790 4791

**Example**

```js
G
Gloria 已提交
4792 4793 4794 4795
aVCastController.on('error', (error) => {
  console.error('error happened,and error message is :' + error.message)
  console.error('error happened,and error code is :' + error.code)
})
4796 4797
```

G
Gloria 已提交
4798
### off('error')<sup>10+</sup>
4799

G
Gloria 已提交
4800
off(type: 'error'): void
4801

G
Gloria 已提交
4802
Unsubscribes from remote AVPlayer errors.
4803

G
Gloria 已提交
4804
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4805 4806 4807

**Parameters**

G
Gloria 已提交
4808 4809 4810
| Name| Type  | Mandatory| Description                                     |
| ------ | ------ | ---- | ----------------------------------------- |
| type   | string | Yes  | Event type, which is **'error'** in this case.|
4811 4812

**Error codes**
G
Gloria 已提交
4813

G
Gloria 已提交
4814
For details about the error codes, see [Media Error Codes](../errorcodes/errorcode-media.md).
4815

G
Gloria 已提交
4816 4817 4818 4819 4820 4821 4822 4823
| ID| Error Message             |
| -------- | --------------------- |
| 5400101  | No memory.            |
| 5400102  | Operation not allowed.   |
| 5400103  | I/O error.             |
| 5400104  | Time out.      |
| 5400105  | Service died.         |
| 5400106  | Unsupport format.     |
4824 4825 4826 4827

**Example**

```js
G
Gloria 已提交
4828
aVCastController.off('error')
4829 4830
```

G
Gloria 已提交
4831
## ConnectionState<sup>10+</sup>
G
Gloria 已提交
4832

G
Gloria 已提交
4833
Enumerates the connection states.
G
Gloria 已提交
4834

G
Gloria 已提交
4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845
**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name                       | Value  | Description        |
| --------------------------- | ---- | ----------- |
| STATE_CONNECTING      | 0    | The device is connecting.   |
| STATE_CONNECTED      | 1    | The device is connected.|
| STATE_DISCONNECTED      | 6    | The device is disconnected.|

## AVMetadata<sup>10+</sup>

Describes the media metadata.
G
Gloria 已提交
4846 4847 4848

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865
| Name           | Type                     | Mandatory| Description                                                                 |
| --------------- |-------------------------| ---- |---------------------------------------------------------------------|
| assetId         | string                  | Yes  | Media ID.                                                              |
| title           | string                  | No  | Title.                                                                |
| artist          | string                  | No  | Artist.                                                               |
| author          | string                  | No  | Author.                                                              |
| album           | string                  | No  | Album name.                                                              |
| writer          | string                  | No  | Writer.                                                               |
| composer        | string                  | No  | composer.                                                               |
| duration        | number                  | No  | Media duration, in ms.                                                 |
| mediaImage      | image.PixelMap &#124; string | No  | Pixel map or image path (local path or network path) of the image.                            |
| publishDate     | Date                    | No  | Release date.                                                              |
| subtitle        | string                  | No  | Subtitle.                                                               |
| description     | string                  | No  | Media description.                                                              |
| lyric           | string                  | No  | Lyric file path (local path or network path).|
| previousAssetId | string                  | No  | ID of the previous media asset.                                                           |
| nextAssetId     | string                  | No  | ID of the next media asset.                                                           |
G
Gloria 已提交
4866

G
Gloria 已提交
4867
## AVMediaDescription<sup>10+</sup>
G
Gloria 已提交
4868

G
Gloria 已提交
4869
Describes the attributes related to the media metadata in the playlist.
G
Gloria 已提交
4870

G
Gloria 已提交
4871
**System capability**: SystemCapability.Multimedia.AVSession.Core
G
Gloria 已提交
4872

G
Gloria 已提交
4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894
| Name        | Type                   | Mandatory | Description                    |
| ------------ | ----------------------- | ---- | ----------------------- |
| mediaId      | string                  | Yes  | Media ID in the playlist.         |
| title        | string                  | No  | Name of the media asset in the playlist.       |
| subtitle     | string                  | No  | Subname of the media asset in the playlist.     |
| description  | string                  | No  | Description of the media asset in the playlist.  |
| icon         | image.PixelMap          | No  | Pixel map of the image of the media asset in the playlist.|
| iconUri      | string                  | No  | Path of the image of the media asset in the playlist.|
| extras       | {[key: string]: any}    | No  | Additional fields of the media asset in the playlist.    |
| mediaUri     | string                  | No  | URI of the media asset in the playlist.        |
| mediaType     | string                  | No  | Type of the media asset in the playlist.        |
| mediaSize     | number                  | No  | Size of the media asset in the playlist.        |
| albumTitle     | string                  | No  | Album name of the media asset in the playlist.        |
| albumCoverUri     | string                  | No  | URI of the album title of the media asset in the playlist.   |
| lyricContent     | string                  | No  | Lyric content of the media asset in the playlist.        |
| lyricUri     | string                  | No  | Lyric URI of the media asset in the playlist.        |
| artist     | string                  | No  | Author of the lyric of the media asset in the playlist.        |
| fdSrc     | media.AVFileDescriptor        | No  | Handle to the local media file in the playlist.        |
| duration     | number                  | No  | Playback duration of the media asset in the playlist.        |
| startPosition     | number                  | No  | Start position for playing the media asset in the playlist.        |
| creditsPosition     | number                  | No  | Position for playing the closing credits of the media asset in the playlist.        |
| appName     | string                  | No  | Name of the application provided by the playlist.        |
G
Gloria 已提交
4895

G
Gloria 已提交
4896
## AVQueueItem<sup>10+</sup>
G
Gloria 已提交
4897

G
Gloria 已提交
4898
Describes the attributes of an item in the playlist.
G
Gloria 已提交
4899

G
Gloria 已提交
4900
**System capability**: SystemCapability.Multimedia.AVSession.Core
4901

G
Gloria 已提交
4902 4903 4904 4905
| Name        | Type                                       | Mandatory| Description                       |
| ------------ | ------------------------------------------ | ---- | --------------------------- |
| itemId       | number                                     | Yes  | ID of an item in the playlist.         |
| description  | [AVMediaDescription](#avmediadescription10)  | Yes  | Media metadata of the item in the playlist.  |
4906

G
Gloria 已提交
4907 4908 4909
## AVPlaybackState<sup>10+</sup>

Describes the information related to the media playback state.
4910 4911 4912

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925
| Name        | Type                                 | Mandatory| Description    |
| ------------ | ------------------------------------- | ---- | ------- |
| state        | [PlaybackState](#playbackstate)       | No  | Playback state.|
| speed        | number                                | No  | Playback speed.|
| position     | [PlaybackPosition](#playbackposition) | No  | Playback position.|
| bufferedTime | number                                | No  | Buffered time.|
| loopMode     | [LoopMode](#loopmode10)                 | No  | Loop mode.|
| isFavorite   | boolean                               | No  | Whether the media asset is favorited.|
| activeItemId<sup>10+</sup> | number                  | No  | ID of the item that is being played.|
| volume<sup>10+</sup> | number                  | No  | Media volume.|
| extras<sup>10+</sup> | {[key: string]: Object}       | No  | Custom media data.|

## PlaybackPosition<sup>10+</sup>
4926

G
Gloria 已提交
4927
Describes the information related to the playback position.
4928

G
Gloria 已提交
4929
**System capability**: SystemCapability.Multimedia.AVSession.Core
G
Gloria 已提交
4930

G
Gloria 已提交
4931 4932 4933 4934
| Name       | Type  | Mandatory| Description              |
| ----------- | ------ | ---- | ------------------ |
| elapsedTime | number | Yes  | Elapsed time, in ms.|
| updateTime  | number | Yes  | Updated time, in ms.|
4935

G
Gloria 已提交
4936
## AVCastCategory<sup>10+</sup>
4937

G
Gloria 已提交
4938
Enumerates the cast categories.
4939

G
Gloria 已提交
4940
**System capability**: SystemCapability.Multimedia.AVSession.AVCast
4941

G
Gloria 已提交
4942 4943 4944 4945
| Name                       | Value  | Description        |
| --------------------------- | ---- | ----------- |
| CATEGORY_LOCAL      | 0    | Local playback. The sound is played from the local device or a connected Bluetooth headset by default.    |
| CATEGORY_REMOTE      | 1    | Remote playback. The sound or images are played from a remote device. |
4946

G
Gloria 已提交
4947
## DeviceType<sup>10+</sup>
4948

G
Gloria 已提交
4949
Enumerates the output device types.
4950 4951 4952

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
4953 4954 4955 4956 4957 4958
| Name                       | Value  | Description        |
| --------------------------- | ---- | ----------- |
| DEVICE_TYPE_LOCAL      | 0    | Local device.    |
| DEVICE_TYPE_BLUETOOTH      | 10   | Bluetooth device. |
| DEVICE_TYPE_TV      | 2    | TV.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast|
| DEVICE_TYPE_SMART_SPEAKER      | 3   | Speaker.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast|
4959

G
Gloria 已提交
4960
## DeviceInfo<sup>10+</sup>
4961

G
Gloria 已提交
4962
Describes the information related to the output device.
G
Gloria 已提交
4963

G
Gloria 已提交
4964
**System capability**: SystemCapability.Multimedia.AVSession.Core
4965

G
Gloria 已提交
4966 4967 4968 4969 4970 4971 4972 4973
| Name      | Type          | Mandatory| Description                  |
| ---------- | -------------- | ---- | ---------------------- |
| castCategory   | AVCastCategory        | Yes  | Cast category.        |
| deviceId   | string | Yes  | ID of the output device. |
| deviceName | string | Yes  | Name of the output device.   |
| deviceType | DeviceType | Yes  | Type of the output device.   |
| ipAddress | string | No  | IP address of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast    |
| providerId | number | No  | Vendor of the output device.<br>This is a system API.<br> **System capability**: SystemCapability.Multimedia.AVSession.AVCast   |
4974

G
Gloria 已提交
4975
## OutputDeviceInfo<sup>10+</sup>
4976

G
Gloria 已提交
4977
Describes the information related to the output device.
4978

G
Gloria 已提交
4979
**System capability**: SystemCapability.Multimedia.AVSession.Core
4980

G
Gloria 已提交
4981 4982 4983
| Name      | Type          | Mandatory| Description                  |
| ---------- | -------------- | ---- | ---------------------- |
| devices | Array\<DeviceInfo\> | Yes  | Output devices.   |
G
Gloria 已提交
4984

G
Gloria 已提交
4985
## LoopMode<sup>10+</sup>
G
Gloria 已提交
4986

G
Gloria 已提交
4987
Enumerates the loop modes of media playback.
G
Gloria 已提交
4988 4989 4990

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
4991 4992 4993 4994 4995 4996
| Name              | Value  | Description    |
| ------------------ | ---- | -------- |
| LOOP_MODE_SEQUENCE | 0    | Sequential playback.|
| LOOP_MODE_SINGLE   | 1    | Single loop.|
| LOOP_MODE_LIST     | 2    | Playlist loop.|
| LOOP_MODE_SHUFFLE  | 3    | Shuffle.|
G
Gloria 已提交
4997

G
Gloria 已提交
4998
## PlaybackState<sup>10+</sup>
G
Gloria 已提交
4999

G
Gloria 已提交
5000
Enumerates the media playback states.
G
Gloria 已提交
5001

G
Gloria 已提交
5002
**System capability**: SystemCapability.Multimedia.AVSession.Core
G
Gloria 已提交
5003

G
Gloria 已提交
5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015
| Name                       | Value  | Description        |
| --------------------------- | ---- | ----------- |
| PLAYBACK_STATE_INITIAL      | 0    | Initial.    |
| PLAYBACK_STATE_PREPARE      | 1    | Preparing. |
| PLAYBACK_STATE_PLAY         | 2    | Playing.    |
| PLAYBACK_STATE_PAUSE        | 3    | Paused.        |
| PLAYBACK_STATE_FAST_FORWARD | 4    | Fast-forwarding.        |
| PLAYBACK_STATE_REWIND       | 5    | Rewinding.        |
| PLAYBACK_STATE_STOP         | 6    | Stop the playback.        |
| PLAYBACK_STATE_COMPLETED    | 7    | Playback complete.    |
| PLAYBACK_STATE_RELEASED     | 8    | Released.        |
| PLAYBACK_STATE_ERROR        | 9    | Error.        |
G
Gloria 已提交
5016

G
Gloria 已提交
5017
## AVSessionDescriptor
G
Gloria 已提交
5018

G
Gloria 已提交
5019
Declares the session descriptor.
G
Gloria 已提交
5020

G
Gloria 已提交
5021 5022 5023
**System capability**: SystemCapability.Multimedia.AVSession.Manager

**System API**: This is a system API.
G
Gloria 已提交
5024

G
Gloria 已提交
5025 5026 5027 5028 5029 5030 5031 5032 5033
| Name         | Type             | Readable| Writable| Description |
| --------------| ---------------- |-----|-----|------|
| sessionId    | string    | Yes | No| Session ID.     |
| type         | [AVSessionType](#avsessiontype10)   | Yes  | No | Session type.   |
| sessionTag   | string             | Yes  | No | Custom session name.   |
| 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.|
| isActive     | boolean             | Yes  | No | Whether the session is activated.                                     |
| isTopSession | boolean             | Yes  | No | Whether the session is the top session.                               |
| outputDevice | [OutputDeviceInfo](#outputdeviceinfo10)    | Yes  | No | Information about the output device.  |
5034

G
Gloria 已提交
5035
## AVSessionController<sup>10+</sup>
5036

G
Gloria 已提交
5037
An AV session controller is created by calling [avSession.createController](#avsessioncreatecontroller). Through the controller, you can query the session ID, send commands and events to a session, and obtain session metadata and playback state information.
5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049

### Attributes

**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name     | Type  | Readable| Writable| Description                                   |
| :-------- | :----- | :--- | :--- | :-------------------------------------- |
| sessionId | string | Yes  | No  | Unique session ID of the **AVSessionController** object.|


**Example**
```js
G
Gloria 已提交
5050 5051 5052
let AVSessionController;
avSession.createController(currentAVSession.sessionId).then((controller) => {
    AVSessionController = controller;
5053
}).catch((err) => {
G
Gloria 已提交
5054
    console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`);
5055 5056 5057
});
```

G
Gloria 已提交
5058
### getAVPlaybackState<sup>10+</sup>
5059

G
Gloria 已提交
5060
getAVPlaybackState(callback: AsyncCallback\<AVPlaybackState>): void
5061

G
Gloria 已提交
5062
Obtains the remote playback state. This API uses an asynchronous callback to return the result.
5063 5064 5065

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
5066
**Parameters**
5067

G
Gloria 已提交
5068 5069 5070
| Name   | Type                                                       | Mandatory| Description                                                        |
| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback  | AsyncCallback<[[AVPlaybackState](#avplaybackstate10)\> | Yes  | Callback used to return the remote playback state.|
5071 5072

**Error codes**
G
Gloria 已提交
5073

5074 5075 5076 5077
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5078 5079 5080
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5081 5082

**Example**
G
Gloria 已提交
5083

5084
```js
G
Gloria 已提交
5085 5086 5087 5088 5089 5090
avsessionController.getAVPlaybackState(function (err, state) {
    if (err) {
        console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`getAVPlaybackState : SUCCESS`);
    }
5091 5092 5093
});
```

G
Gloria 已提交
5094
### getAVPlaybackState<sup>10+</sup>
5095

G
Gloria 已提交
5096
getAVPlaybackState(): Promise\<AVPlaybackState>;
5097

G
Gloria 已提交
5098
Obtains the remote playback state. This API uses a promise to return the result.
5099 5100 5101

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
5102
**Return value**
5103

G
Gloria 已提交
5104 5105 5106
| Type                                                       | Description                                                        |
| --------- | ------------------------------------------------------------ |
| Promise<[AVPlaybackState](#avplaybackstate10)\>  | Promise used to return the remote playback state. |
5107 5108

**Error codes**
G
Gloria 已提交
5109

5110 5111 5112 5113
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5114 5115 5116
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5117 5118

**Example**
G
Gloria 已提交
5119

5120
```js
G
Gloria 已提交
5121 5122 5123 5124
avsessionController.getAVPlaybackState().then((state) => {
    console.info(`getAVPlaybackState : SUCCESS :`);
}).catch((err) => {
    console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`);
5125 5126 5127
});
```

G
Gloria 已提交
5128
### getAVMetadata<sup>10+</sup>
5129

G
Gloria 已提交
5130
getAVMetadata(): Promise\<AVMetadata>
5131

G
Gloria 已提交
5132
Obtains the session metadata. This API uses a promise to return the result.
5133 5134 5135 5136 5137

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

G
Gloria 已提交
5138 5139 5140
| Type                               | Description                         |
| ----------------------------------- | ----------------------------- |
| Promise<[AVMetadata](#avmetadata10)\> | Promise used to return the metadata obtained.|
5141 5142

**Error codes**
G
Gloria 已提交
5143

5144 5145 5146 5147
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5148 5149 5150
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5151 5152 5153

**Example**
```js
G
Gloria 已提交
5154 5155
avsessionController.getAVMetadata().then((metadata) => {
    console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
5156
}).catch((err) => {
G
Gloria 已提交
5157
    console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
5158 5159 5160
});
```

G
Gloria 已提交
5161
### getAVMetadata<sup>10+</sup>
5162

G
Gloria 已提交
5163
getAVMetadata(callback: AsyncCallback\<AVMetadata>): void
5164

G
Gloria 已提交
5165
Obtains the session metadata. This API uses an asynchronous callback to return the result.
5166 5167 5168

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
5169 5170
**Parameters**

G
Gloria 已提交
5171 5172 5173
| Name  | Type                                     | Mandatory| Description                      |
| -------- | ----------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | Yes  | Callback used to return the metadata obtained.|
G
Gloria 已提交
5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |

**Example**
```js
G
Gloria 已提交
5187
avsessionController.getAVMetadata(function (err, metadata) {
G
Gloria 已提交
5188
    if (err) {
G
Gloria 已提交
5189
        console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
5190
    } else {
G
Gloria 已提交
5191
        console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`);
G
Gloria 已提交
5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220
    }
});
```

### getAVQueueTitle<sup>10+</sup>

getAVQueueTitle(): Promise\<string>

Obtains the name of the playlist. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type            | Description                          |
| ---------------- | ----------------------------- |
| Promise<string\> | Promise used to return the playlist name.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |

**Example**
G
Gloria 已提交
5221

G
Gloria 已提交
5222
```js
G
Gloria 已提交
5223
avsessionController.getAVQueueTitle().then((title) => {
G
Gloria 已提交
5224 5225
    console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
}).catch((err) => {
G
Gloria 已提交
5226
    console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255
});
```

### getAVQueueTitle<sup>10+</sup>

getAVQueueTitle(callback: AsyncCallback\<string>): void

Obtains the name of the playlist. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                   | Mandatory| Description                     |
| -------- | ---------------------- | ---- | ------------------------- |
| callback | AsyncCallback<string\> | Yes  | Callback used to return the playlist name.|

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |

**Example**
```js
G
Gloria 已提交
5256
avsessionController.getAVQueueTitle(function (err, title) {
G
Gloria 已提交
5257
    if (err) {
G
Gloria 已提交
5258
        console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
5259 5260 5261 5262 5263 5264
    } else {
        console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`);
    }
});
```

G
Gloria 已提交
5265
### getAVQueueItems<sup>10+</sup>
G
Gloria 已提交
5266

G
Gloria 已提交
5267
getAVQueueItems(): Promise\<Array\<AVQueueItem>>
G
Gloria 已提交
5268

G
Gloria 已提交
5269
Obtains the information related to the items in the queue. This API uses a promise to return the result.
G
Gloria 已提交
5270 5271 5272 5273 5274

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

G
Gloria 已提交
5275 5276 5277
| Type                                         | Description                          |
| --------------------------------------------- | ----------------------------- |
| Promise<Array<[AVQueueItem](#avqueueitem10)\>\> | Promise used to return the items in the queue.|
G
Gloria 已提交
5278 5279 5280 5281 5282 5283 5284 5285 5286

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
G
Gloria 已提交
5287
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
5288 5289 5290 5291

**Example**

```js
G
Gloria 已提交
5292 5293
avsessionController.getAVQueueItems().then((items) => {
    console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
G
Gloria 已提交
5294
}).catch((err) => {
G
Gloria 已提交
5295
    console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
5296 5297 5298
});
```

G
Gloria 已提交
5299
### getAVQueueItems<sup>10+</sup>
G
Gloria 已提交
5300

G
Gloria 已提交
5301
getAVQueueItems(callback: AsyncCallback\<Array\<AVQueueItem>>): void
G
Gloria 已提交
5302

G
Gloria 已提交
5303
Obtains the information related to the items in the playlist. This API uses an asynchronous callback to return the result.
G
Gloria 已提交
5304 5305 5306 5307 5308

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
5309 5310 5311
| Name  | Type                                                | Mandatory| Description                     |
| -------- | --------------------------------------------------- | ---- | ------------------------- |
| callback | AsyncCallback<Array<[AVQueueItem](#avqueueitem10)\>\> | Yes  | Callback used to return the items in the playlist.|
G
Gloria 已提交
5312 5313 5314 5315 5316 5317 5318 5319 5320

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
G
Gloria 已提交
5321
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
5322 5323 5324 5325

**Example**

```js
G
Gloria 已提交
5326
avsessionController.getAVQueueItems(function (err, items) {
G
Gloria 已提交
5327
    if (err) {
G
Gloria 已提交
5328
        console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`);
G
Gloria 已提交
5329
    } else {
G
Gloria 已提交
5330
        console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`);
G
Gloria 已提交
5331 5332 5333 5334
    }
});
```

G
Gloria 已提交
5335
### skipToQueueItem<sup>10+</sup>
G
Gloria 已提交
5336

G
Gloria 已提交
5337
skipToQueueItem(itemId: number): Promise\<void>
G
Gloria 已提交
5338

G
Gloria 已提交
5339
Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses a promise to return the result.
G
Gloria 已提交
5340 5341 5342

**System capability**: SystemCapability.Multimedia.AVSession.Core

5343 5344
**Parameters**

G
Gloria 已提交
5345 5346 5347
| Name | Type   | Mandatory| Description                                       |
| ------ | ------- | ---- | ------------------------------------------- |
| itemId | number  | Yes  | ID of an item in the playlist.|
5348 5349 5350

**Return value**

G
Gloria 已提交
5351 5352 5353
| Type          | Description                                                            |
| -------------- | --------------------------------------------------------------- |
| Promise\<void> | Promise used to return the result. If the item ID is sent, no value is returned; otherwise, an error object is returned.|
5354 5355

**Error codes**
G
Gloria 已提交
5356

5357 5358 5359 5360
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5361
| 6600101  | Session service exception. |
G
Gloria 已提交
5362
| 6600102  | The session does not exist. |
5363
| 6600103  | The session controller does not exist. |
5364 5365

**Example**
G
Gloria 已提交
5366

5367
```js
G
Gloria 已提交
5368 5369 5370
let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId).then(() => {
    console.info(`SkipToQueueItem successfully`);
5371
}).catch((err) => {
G
Gloria 已提交
5372
    console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5373 5374 5375
});
```

G
Gloria 已提交
5376
### skipToQueueItem<sup>10+</sup>
5377

G
Gloria 已提交
5378
skipToQueueItem(itemId: number, callback: AsyncCallback\<void>): void
5379

G
Gloria 已提交
5380
Sends the ID of an item in the playlist to the session for processing. The session can play the song. This API uses an asynchronous callback to return the result.
5381 5382 5383 5384 5385

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
5386 5387 5388 5389
| Name   | Type                 | Mandatory| Description                                                       |
| -------- | --------------------- | ---- | ----------------------------------------------------------- |
| itemId   | number                | Yes  | ID of an item in the playlist.               |
| callback | AsyncCallback\<void>  | Yes  | Callback used to return the result. If the setting is successful, **err** is **undefined**; otherwise, **err** is an error object.|
5390 5391

**Error codes**
G
Gloria 已提交
5392

5393 5394 5395 5396
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5397
| 6600101  | Session service exception. |
G
Gloria 已提交
5398
| 6600102  | The session does not exist. |
5399
| 6600103  | The session controller does not exist. |
5400 5401 5402 5403

**Example**

```js
G
Gloria 已提交
5404 5405
let queueItemId = 0;
avsessionController.skipToQueueItem(queueItemId, function (err) {
5406
    if (err) {
G
Gloria 已提交
5407
        console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`);
5408
    } else {
G
Gloria 已提交
5409
        console.info(`SkipToQueueItem successfully`);
5410 5411 5412 5413
    }
});
```

G
Gloria 已提交
5414
### getOutputDevice<sup>10+</sup>
5415

G
Gloria 已提交
5416
getOutputDevice(): Promise\<OutputDeviceInfo>
5417

G
Gloria 已提交
5418
Obtains the output device information. This API uses a promise to return the result.
5419 5420 5421 5422 5423

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

G
Gloria 已提交
5424 5425 5426
| Type                                           | Description                             |
| ----------------------------------------------- | --------------------------------- |
| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise used to return the information obtained.|
5427 5428 5429 5430 5431 5432 5433

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
5434 5435
| 600101  | Session service exception. |
| 600103  | The session controller does not exist. |
5436 5437 5438

**Example**
```js
G
Gloria 已提交
5439 5440 5441 5442
avsessionController.getOutputDevice().then((deviceInfo) => {
    console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`);
}).catch((err) => {
    console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5443 5444 5445
});
```

G
Gloria 已提交
5446
### getOutputDevice<sup>10+</sup>
5447

G
Gloria 已提交
5448
getOutputDevice(callback: AsyncCallback\<OutputDeviceInfo>): void
5449

G
Gloria 已提交
5450
Obtains the output device information. This API uses an asynchronous callback to return the result.
5451 5452 5453 5454 5455

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
5456 5457 5458
| Name  | Type                                                 | Mandatory| Description                          |
| -------- | ----------------------------------------------------- | ---- | ------------------------------ |
| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | Yes  | Callback used to return the information obtained.|
5459 5460 5461 5462 5463 5464 5465

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
5466 5467
| 600101  | Session service exception. |
| 600103  | The session controller does not exist. |
5468 5469

**Example**
G
Gloria 已提交
5470

5471
```js
G
Gloria 已提交
5472
avsessionController.getOutputDevice(function (err, deviceInfo) {
5473
    if (err) {
G
Gloria 已提交
5474
        console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`);
5475
    } else {
G
Gloria 已提交
5476
        console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`);
5477 5478 5479 5480
    }
});
```

G
Gloria 已提交
5481
### sendAVKeyEvent<sup>10+</sup>
5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495

sendAVKeyEvent(event: KeyEvent): Promise\<void>

Sends a key event to the session corresponding to this controller. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name| Type                                                        | Mandatory| Description      |
| ------ | ------------------------------------------------------------ | ---- | ---------- |
| event  | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|

**Error codes**
G
Gloria 已提交
5496

5497 5498 5499 5500
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
5501 5502 5503 5504 5505
| 600101  | Session service exception. |
| 600102  | The session does not exist. |
| 600103  | The session controller does not exist. |
| 600105  | Invalid session command. |
| 600106  | The session is not activated. |
5506 5507 5508 5509 5510

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
5511
| Promise\<void> | Promise used to return the result. If the event is sent, no value is returned; otherwise, an error object is returned.|
5512 5513 5514 5515 5516 5517 5518

**Example**

```js
let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let event = {action:2, key:keyItem, keys:[keyItem]};

G
Gloria 已提交
5519
avsessionController.sendAVKeyEvent(event).then(() => {
5520
    console.info(`SendAVKeyEvent Successfully`);
5521
}).catch((err) => {
G
Gloria 已提交
5522
    console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5523 5524 5525
});
```

G
Gloria 已提交
5526
### sendAVKeyEvent<sup>10+</sup>
5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538

sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\<void>): void

Sends a key event to the session corresponding to this controller. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description      |
| -------- | ------------------------------------------------------------ | ---- | ---------- |
| event    | [KeyEvent](js-apis-keyevent.md) | Yes  | Key event.|
5539
| callback | AsyncCallback\<void>                                         | Yes  | Callback used to return the result. If the event is sent, **err** is **undefined**; otherwise, **err** is an error object.|
5540 5541

**Error codes**
G
Gloria 已提交
5542

5543 5544 5545 5546
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
G
Gloria 已提交
5547 5548 5549 5550 5551
| 600101  | Session service exception. |
| 600102  | The session does not exist. |
| 600103  | The session controller does not exist. |
| 600105  | Invalid session command. |
| 600106  | The session is not activated. |
5552 5553 5554 5555 5556 5557 5558

**Example**

```js
let keyItem = {code:0x49, pressedTime:2, deviceId:0};
let event = {action:2, key:keyItem, keys:[keyItem]};

G
Gloria 已提交
5559
avsessionController.sendAVKeyEvent(event, function (err) {
5560
    if (err) {
G
Gloria 已提交
5561
        console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`);
5562
    } else {
5563
        console.info(`SendAVKeyEvent Successfully`);
5564 5565 5566 5567
    }
});
```

G
Gloria 已提交
5568
### getLaunchAbility<sup>10+</sup>
5569 5570 5571 5572 5573 5574 5575 5576 5577

getLaunchAbility(): Promise\<WantAgent>

Obtains the **WantAgent** object saved by the application in the session. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

5578 5579
| Type                                                   | Description                                                        |
| ------------------------------------------------------- | ------------------------------------------------------------ |
G
Gloria 已提交
5580
| Promise<[WantAgent](js-apis-app-ability-wantAgent.md)\> | Promise used to return the object saved by calling [setLaunchAbility](#setlaunchability10). The object includes the application attribute, such as the bundle name, ability name, and device ID.|
5581 5582

**Error codes**
G
Gloria 已提交
5583

5584 5585 5586 5587
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5588 5589 5590
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5591 5592 5593 5594

**Example**

```js
G
Gloria 已提交
5595
avsessionController.getLaunchAbility().then((agent) => {
5596 5597
    console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
}).catch((err) => {
G
Gloria 已提交
5598
    console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5599 5600 5601
});
```

G
Gloria 已提交
5602
### getLaunchAbility<sup>10+</sup>
5603 5604 5605 5606 5607 5608 5609 5610 5611

getLaunchAbility(callback: AsyncCallback\<WantAgent>): void

Obtains the **WantAgent** object saved by the application in the session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

5612 5613
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
5614
| callback | AsyncCallback<[WantAgent](js-apis-app-ability-wantAgent.md)\> | Yes  | Callback used to return the object saved by calling [setLaunchAbility](#setlaunchability10). The object includes the application attribute, such as the bundle name, ability name, and device ID.|
5615 5616

**Error codes**
G
Gloria 已提交
5617

5618 5619 5620 5621
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5622 5623 5624
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5625 5626 5627 5628

**Example**

```js
G
Gloria 已提交
5629
avsessionController.getLaunchAbility(function (err, agent) {
5630
    if (err) {
G
Gloria 已提交
5631
        console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`);
5632 5633 5634 5635 5636 5637
    } else {
        console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`);
    }
});
```

G
Gloria 已提交
5638
### getRealPlaybackPositionSync<sup>10+</sup>
5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652

getRealPlaybackPositionSync(): number

Obtains the playback position.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type  | Description              |
| ------ | ------------------ |
| number | Playback position, in milliseconds.|

**Error codes**
G
Gloria 已提交
5653

5654 5655 5656 5657
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5658 5659
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
5660 5661 5662 5663

**Example**

```js
G
Gloria 已提交
5664
let time = avsessionController.getRealPlaybackPositionSync();
5665 5666
```

G
Gloria 已提交
5667
### isActive<sup>10+</sup>
5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681

isActive(): Promise\<boolean>

Checks whether the session is activated. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type             | Description                                                        |
| ----------------- | ------------------------------------------------------------ |
| Promise<boolean\> | Promise used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|

**Error codes**
G
Gloria 已提交
5682

5683 5684 5685 5686
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5687 5688 5689
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5690 5691 5692 5693

**Example**

```js
G
Gloria 已提交
5694
avsessionController.isActive().then((isActive) => {
5695 5696
    console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
}).catch((err) => {
G
Gloria 已提交
5697
    console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
5698 5699 5700
});
```

G
Gloria 已提交
5701
### isActive<sup>10+</sup>
5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715

isActive(callback: AsyncCallback\<boolean>): void

Checks whether the session is activated. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                   | Mandatory| Description                                                        |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback<boolean\> | Yes  | Callback used to return the activation state. If the session is activated, **true** is returned; otherwise, **false** is returned.|

**Error codes**
G
Gloria 已提交
5716

5717 5718 5719 5720
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5721 5722 5723
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5724 5725 5726 5727

**Example**

```js
G
Gloria 已提交
5728
avsessionController.isActive(function (err, isActive) {
5729
    if (err) {
G
Gloria 已提交
5730
        console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`);
5731 5732 5733 5734 5735 5736
    } else {
        console.info(`IsActive : SUCCESS : isactive : ${isActive}`);
    }
});
```

G
Gloria 已提交
5737
### destroy<sup>10+</sup>
5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748

destroy(): Promise\<void>

Destroys this controller. A controller can no longer be used after being destroyed. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
5749
| Promise\<void> | Promise used to return the result. If the controller is destroyed, no value is returned; otherwise, an error object is returned.|
5750 5751

**Error codes**
G
Gloria 已提交
5752

5753 5754 5755 5756
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5757 5758
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
5759 5760 5761 5762

**Example**

```js
G
Gloria 已提交
5763
avsessionController.destroy().then(() => {
5764
    console.info(`Destroy : SUCCESS `);
5765
}).catch((err) => {
G
Gloria 已提交
5766
    console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
5767 5768 5769
});
```

G
Gloria 已提交
5770
### destroy<sup>10+</sup>
5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781

destroy(callback: AsyncCallback\<void>): void

Destroys this controller. A controller can no longer be used after being destroyed. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                | Mandatory| Description      |
| -------- | -------------------- | ---- | ---------- |
5782
| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. If the controller is destroyed, **err** is **undefined**; otherwise, **err** is an error object.|
5783 5784

**Error codes**
G
Gloria 已提交
5785

5786 5787 5788 5789
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5790 5791
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
5792 5793 5794 5795

**Example**

```js
G
Gloria 已提交
5796
avsessionController.destroy(function (err) {
5797
    if (err) {
G
Gloria 已提交
5798
        console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`);
5799
    } else {
5800
        console.info(`Destroy : SUCCESS `);
5801 5802 5803 5804
    }
});
```

G
Gloria 已提交
5805
### getValidCommands<sup>10+</sup>
5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816

getValidCommands(): Promise\<Array\<AVControlCommandType>>

Obtains valid commands supported by the session. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Return value**

| Type                                                        | Description                             |
| ------------------------------------------------------------ | --------------------------------- |
G
Gloria 已提交
5817
| Promise<Array<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Promise used to return a set of valid commands.|
5818 5819

**Error codes**
G
Gloria 已提交
5820

5821 5822 5823 5824
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5825 5826 5827
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5828 5829 5830 5831

**Example**

```js
G
Gloria 已提交
5832
avsessionController.getValidCommands.then((validCommands) => {
5833 5834
    console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
}).catch((err) => {
G
Gloria 已提交
5835
    console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
5836 5837 5838
});
```

G
Gloria 已提交
5839
### getValidCommands<sup>10+</sup>
5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850

getValidCommands(callback: AsyncCallback\<Array\<AVControlCommandType>>): void

Obtains valid commands supported by the session. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                          |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------ |
G
Gloria 已提交
5851
| callback | AsyncCallback\<Array\<[AVControlCommandType](#avcontrolcommandtype10)\>\> | Yes  | Callback used to return a set of valid commands.|
5852 5853

**Error codes**
G
Gloria 已提交
5854

5855 5856 5857 5858
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5859 5860 5861
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
5862 5863 5864 5865

**Example**

```js
G
Gloria 已提交
5866
avsessionController.getValidCommands(function (err, validCommands) {
5867
    if (err) {
G
Gloria 已提交
5868
        console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`);
5869 5870 5871 5872 5873 5874
    } else {
        console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`);
    }
});
```

G
Gloria 已提交
5875
### sendControlCommand<sup>10+</sup>
5876 5877 5878 5879 5880

sendControlCommand(command: AVControlCommand): Promise\<void>

Sends a control command to the session through the controller. This API uses a promise to return the result.

5881 5882
> **NOTE**
>
G
Gloria 已提交
5883
> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like.
5884

5885 5886 5887 5888 5889 5890
**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
G
Gloria 已提交
5891
| command | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
5892 5893 5894 5895 5896

**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
5897
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
5898 5899

**Error codes**
G
Gloria 已提交
5900

5901 5902 5903 5904
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
5905 5906 5907 5908 5909 5910
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
| 6600105  | Invalid session command. |
| 6600106  | The session is not activated. |
| 6600107  | Too many commands or events. |
5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925

**Example**

```js
let avCommand = {command:'play'};
// let avCommand = {command:'pause'};
// let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'};
// let avCommand = {command:'playPrevious'};
// let avCommand = {command:'fastForward'};
// let avCommand = {command:'rewind'};
// let avCommand = {command:'seek', parameter:10};
// let avCommand = {command:'setSpeed', parameter:2.6};
// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let avCommand = {command:'toggleFavorite', parameter:"false"};
G
Gloria 已提交
5926
avsessionController.sendControlCommand(avCommand).then(() => {
5927
    console.info(`SendControlCommand successfully`);
5928
}).catch((err) => {
G
Gloria 已提交
5929
    console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
5930 5931 5932
});
```

G
Gloria 已提交
5933
### sendControlCommand<sup>10+</sup>
5934 5935 5936 5937 5938

sendControlCommand(command: AVControlCommand, callback: AsyncCallback\<void>): void

Sends a control command to the session through the controller. This API uses an asynchronous callback to return the result.

5939 5940
> **NOTE**
>
G
Gloria 已提交
5941
> Before using **sendControlCommand**, the controller must ensure that the corresponding listeners are registered for the media session. For details about how to register the listeners, see [on'play'](#onplay10), [on'pause'](#onpause10), and the like.
5942

5943 5944 5945 5946 5947 5948
**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                 | Mandatory| Description                          |
| -------- | ------------------------------------- | ---- | ------------------------------ |
G
Gloria 已提交
5949
| command  | [AVControlCommand](#avcontrolcommand10) | Yes  | Command to send.|
5950
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
5951 5952

**Error codes**
G
Gloria 已提交
5953

5954 5955 5956 5957
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------- |
5958 5959 5960 5961 5962 5963
| 6600101  | Session service exception.                |
| 6600102  | The session does not exist.     |
| 6600103  | The session controller does not exist.   |
| 6600105  | Invalid session command.           |
| 6600106  | The session is not activated.                |
| 6600107  | Too many commands or events.      |
5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978

**Example**

```js
let avCommand = {command:'play'};
// let avCommand = {command:'pause'};
// let avCommand = {command:'stop'};
// let avCommand = {command:'playNext'};
// let avCommand = {command:'playPrevious'};
// let avCommand = {command:'fastForward'};
// let avCommand = {command:'rewind'};
// let avCommand = {command:'seek', parameter:10};
// let avCommand = {command:'setSpeed', parameter:2.6};
// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE};
// let avCommand = {command:'toggleFavorite', parameter:"false"};
G
Gloria 已提交
5979
avsessionController.sendControlCommand(avCommand, function (err) {
5980 5981 5982
    if (err) {
        console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
G
Gloria 已提交
5983
        console.error(`SendControlCommand successfully`);
5984 5985 5986 5987
    }
});
```

G
Gloria 已提交
5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002
### sendCommonCommand<sup>10+</sup>

sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\<void>

Sends a custom control command to the session through the controller. This API uses a promise to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| command | string | Yes  | Name of the custom control command.|
| args | {[key: string]: any} | Yes  | Parameters in key-value pair format carried in the custom control command.|

6003
> **NOTE**
G
Gloria 已提交
6004
> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).
6005

G
Gloria 已提交
6006 6007 6008 6009
**Return value**

| Type          | Description                         |
| -------------- | ----------------------------- |
6010
| Promise\<void> | Promise used to return the result. If the command is sent, no value is returned; otherwise, an error object is returned.|
G
Gloria 已提交
6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 6600101  | Session service exception. |
| 6600102  | The session does not exist. |
| 6600103  | The session controller does not exist. |
| 6600105  | Invalid session command. |
| 6600106  | The session is not activated. |
| 6600107  | Too many commands or events. |

**Example**

```js
let commandName = "my_command";
let args = {
    command : "This is my command"
}
G
Gloria 已提交
6032
avsessionController.sendCommonCommand(commandName, args).catch((err) => {
G
Gloria 已提交
6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050
    console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
})
```

### sendCommonCommand<sup>10+</sup>

sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\<void>): void

Sends a custom control command to the session through the controller. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name   | Type                                 | Mandatory| Description                          |
| ------- | ------------------------------------- | ---- | ------------------------------ |
| command | string | Yes  | Name of the custom control command.|
| args | {[key: string]: any} | Yes  | Parameters in key-value pair format carried in the custom control command.|
6051
| callback | AsyncCallback\<void>                  | Yes  | Callback used to return the result. If the command is sent, **err** is **undefined**; otherwise, **err** is an error object.                    |
G
Gloria 已提交
6052

6053
> **NOTE**
G
Gloria 已提交
6054
> The **args** parameter supports the following data types: string, number, Boolean, object, array, and file descriptor. For details, see [@ohos.app.ability.Want (Want)](./js-apis-app-ability-want.md).
G
Gloria 已提交
6055

6056
**Error codes**
G
Gloria 已提交
6057

G
Gloria 已提交
6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------- |
| 6600101  | Session service exception.                |
| 6600102  | The session does not exist.     |
| 6600103  | The session controller does not exist.   |
| 6600105  | Invalid session command.           |
| 6600106  | The session is not activated.                |
| 6600107  | Too many commands or events.      |

**Example**

```js
let commandName = "my_command";
let args = {
    command : "This is my command"
}
G
Gloria 已提交
6076
avsessionController.sendCommonCommand(commandName, args, (err) => {
G
Gloria 已提交
6077 6078 6079 6080 6081 6082
    if(err) {
        console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`);
    }
})
```

G
Gloria 已提交
6083
### getExtras<sup>10+</sup>
6084

G
Gloria 已提交
6085
getExtras(): Promise\<{[key: string]: Object}>
6086

G
Gloria 已提交
6087
Obtains the custom media packet set by the provider. This API uses a promise to return the result.
6088 6089 6090

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
6091
**Return value**
6092

G
Gloria 已提交
6093 6094 6095
| Type                               | Description                         |
| ----------------------------------- | ----------------------------- |
| Promise<{[key: string]: Object}\>   | Promise used to return the custom media packet. The content of the packet is the same as that set in **setExtras**.|
6096 6097

**Error codes**
G
Gloria 已提交
6098

6099 6100 6101
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6102
| -------- | ---------------------------------------- |
6103
| 6600101  | Session service exception. |
G
Gloria 已提交
6104
| 6600102  | The session does not exist. |
6105
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
6106 6107
| 6600105  | Invalid session command. |
| 6600107  | Too many commands or events. |
6108 6109 6110

**Example**
```js
G
Gloria 已提交
6111 6112
let extras = await avsessionController.getExtras().catch((err) => {
    console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
6113 6114 6115
});
```

G
Gloria 已提交
6116
### getExtras<sup>10+</sup>
6117

G
Gloria 已提交
6118
getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void
6119

G
Gloria 已提交
6120
Obtains the custom media packet set by the provider. This API uses an asynchronous callback to return the result.
6121 6122 6123 6124 6125

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6126 6127 6128
| Name  | Type                                     | Mandatory| Description                      |
| -------- | ----------------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<{[key: string]: Object}\> | Yes  | Callback used to return the custom media packet. The content of the packet is the same as that set in **setExtras**.|
6129 6130

**Error codes**
G
Gloria 已提交
6131

6132 6133 6134
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6135
| -------- | ---------------------------------------- |
6136
| 6600101  | Session service exception. |
G
Gloria 已提交
6137
| 6600102  | The session does not exist. |
6138
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
6139 6140
| 6600105  | Invalid session command. |
| 6600107  | Too many commands or events. |
6141 6142 6143

**Example**
```js
G
Gloria 已提交
6144 6145 6146 6147 6148 6149
avsessionController.getExtras(function (err, extras) {
    if (err) {
        console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`);
    } else {
        console.info(`getExtras : SUCCESS : assetId : ${extras}`);
    }
6150 6151 6152
});
```

G
Gloria 已提交
6153
### on('metadataChange')<sup>10+</sup>
G
Gloria 已提交
6154

G
Gloria 已提交
6155
on(type: 'metadataChange', filter: Array\<keyof AVMetadata> | 'all', callback: (data: AVMetadata) => void)
G
Gloria 已提交
6156

G
Gloria 已提交
6157
Subscribes to metadata change events.
G
Gloria 已提交
6158 6159 6160 6161 6162 6163 6164

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
6165 6166 6167
| type     | string                                                       | Yes  | Event type. The event **'metadataChange'** is triggered when the session metadata changes.|
| filter   | Array\<keyof&nbsp;[AVMetadata](#avmetadata10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any metadata field change will trigger the event, and **Array<keyof&nbsp;[AVMetadata](#avmetadata10)\>** indicates that only changes to the listed metadata field will trigger the event.|
| callback | (data: [AVMetadata](#avmetadata10)) => void                    | Yes  | Callback used for subscription. The **data** parameter in the callback indicates the changed metadata.                        |
G
Gloria 已提交
6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------ |
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |

**Example**

```js
G
Gloria 已提交
6181 6182 6183 6184 6185 6186 6187
avsessionController.on('metadataChange', 'all', (metadata) => {
    console.info(`on metadataChange assetId : ${metadata.assetId}`);
});

let metaFilter = ['assetId', 'title', 'description'];
avsessionController.on('metadataChange', metaFilter, (metadata) => {
    console.info(`on metadataChange assetId : ${metadata.assetId}`);
G
Gloria 已提交
6188 6189 6190
});
```

G
Gloria 已提交
6191
### off('metadataChange')<sup>10+</sup>
G
Gloria 已提交
6192

G
Gloria 已提交
6193
off(type: 'metadataChange', callback?: (data: AVMetadata) => void)
G
Gloria 已提交
6194

G
Gloria 已提交
6195
Unsubscribes from metadata change events. This API is called by the controller.
G
Gloria 已提交
6196 6197 6198 6199 6200

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6201 6202 6203 6204
| Name  | Type                                              | Mandatory| Description                                                   |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ |
| type     | string                                           | Yes  | Event type, which is **'metadataChange'** in this case.        |
| callback | (data: [AVMetadata](#avmetadata10)) => 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.                        |
G
Gloria 已提交
6205 6206 6207 6208 6209 6210

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6211
| -------- | ---------------- |
G
Gloria 已提交
6212 6213 6214 6215 6216 6217
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |

**Example**

```js
G
Gloria 已提交
6218
avsessionController.off('metadataChange');
G
Gloria 已提交
6219 6220
```

G
Gloria 已提交
6221
### on('playbackStateChange')<sup>10+</sup>
G
Gloria 已提交
6222

G
Gloria 已提交
6223
on(type: 'playbackStateChange', filter: Array\<keyof AVPlaybackState> | 'all', callback: (state: AVPlaybackState) => void)
G
Gloria 已提交
6224

G
Gloria 已提交
6225
Subscribes to playback state change events.
G
Gloria 已提交
6226 6227 6228 6229 6230

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6231 6232 6233 6234 6235
| Name  | Type      | Mandatory| Description     |
| --------| -----------|-----|------------|
| type     | string    | Yes  | Event type. The event **'playbackStateChange'** is triggered when the playback state changes.|
| filter   | Array\<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>&nbsp;&#124;&nbsp;'all' | Yes  | The value **'all'** indicates that any playback state field change will trigger the event, and **Array<keyof&nbsp;[AVPlaybackState](#avplaybackstate10)\>** indicates that only changes to the listed playback state field will trigger the event.|
| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void       | Yes  | Callback used for subscription. The **state** parameter in the callback indicates the changed playback state.|
G
Gloria 已提交
6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------ |
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |

**Example**

```js
G
Gloria 已提交
6249 6250 6251 6252 6253 6254 6255
avsessionController.on('playbackStateChange', 'all', (playbackState) => {
    console.info(`on playbackStateChange state : ${playbackState.state}`);
});

let playbackFilter = ['state', 'speed', 'loopMode'];
avsessionController.on('playbackStateChange', playbackFilter, (playbackState) => {
    console.info(`on playbackStateChange state : ${playbackState.state}`);
G
Gloria 已提交
6256 6257 6258
});
```

G
Gloria 已提交
6259
### off('playbackStateChange')<sup>10+</sup>
6260

G
Gloria 已提交
6261
off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void)
6262

G
Gloria 已提交
6263
Unsubscribes from playback state change events. This API is called by the controller.
6264 6265 6266 6267 6268

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6269 6270 6271 6272
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'playbackStateChange'** in this case.   |
| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void         | No  | Callback used for unsubscription. 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.                     |
6273 6274 6275 6276 6277 6278

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6279
| -------- | ---------------- |
6280 6281 6282 6283 6284 6285
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |

**Example**

```js
G
Gloria 已提交
6286
avsessionController.off('playbackStateChange');
6287 6288
```

G
Gloria 已提交
6289
### on('sessionDestroy')<sup>10+</sup>
6290 6291 6292

on(type: 'sessionDestroy', callback: () => void)

G
Gloria 已提交
6293
Subscribes to session destruction events.
6294 6295 6296 6297 6298 6299 6300

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type      | Mandatory| Description                                                        |
| -------- | ---------- | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
6301
| type     | string     | Yes  | Event type. The event **'sessionDestroy'** is triggered when a session is destroyed.|
6302 6303 6304
| callback | () => void | Yes  | Callback used for subscription. If the subscription is successful, **err** is **undefined**; otherwise, **err** is an error object.                 |

**Error codes**
G
Gloria 已提交
6305

6306 6307 6308 6309
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ------------------------------ |
6310 6311
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
6312 6313 6314 6315

**Example**

```js
G
Gloria 已提交
6316
avsessionController.on('sessionDestroy', () => {
6317
    console.info(`on sessionDestroy : SUCCESS `);
6318 6319 6320
});
```

G
Gloria 已提交
6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350
### off('sessionDestroy')<sup>10+</sup>

off(type: 'sessionDestroy', callback?: () => void)

Unsubscribes from session destruction events. This API is called by the controller.

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type      | Mandatory| Description                                                     |
| -------- | ---------- | ---- | ----------------------------------------------------- |
| type     | string     | Yes  | Event type, which is **'sessionDestroy'** in this case.        |
| 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.                                              |

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------- |
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |

**Example**

```js
avsessionController.off('sessionDestroy');
```

G
Gloria 已提交
6351
### on('activeStateChange')<sup>10+</sup>
6352 6353 6354

on(type: 'activeStateChange', callback: (isActive: boolean) => void)

G
Gloria 已提交
6355
Subscribes to session activation state change events.
6356 6357 6358 6359 6360 6361 6362

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

| Name  | Type                       | Mandatory| Description                                                        |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
G
Gloria 已提交
6363
| type     | string                      | Yes  | Event type. The event **'activeStateChange'** is triggered when the activation state of the session changes.|
6364 6365 6366
| 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.                  |

**Error codes**
G
Gloria 已提交
6367

6368 6369 6370 6371
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ----------------------------- |
6372 6373
| 6600101  | Session service exception. |
| 6600103  |The session controller does not exist. |
6374 6375 6376 6377

**Example**

```js
G
Gloria 已提交
6378
avsessionController.on('activeStateChange', (isActive) => {
6379 6380 6381 6382
    console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`);
});
```

G
Gloria 已提交
6383
### off('activeStateChange')<sup>10+</sup>
6384

G
Gloria 已提交
6385
off(type: 'activeStateChange', callback?: (isActive: boolean) => void)
6386

G
Gloria 已提交
6387
Unsubscribes from session activation state change events. This API is called by the controller.
6388 6389 6390 6391 6392

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6393 6394 6395 6396
| Name  | Type                       | Mandatory| Description                                                     |
| -------- | --------------------------- | ---- | ----------------------------------------------------- |
| type     | string                      | Yes  | Event type, which is **'activeStateChange'** in this case.     |
| 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.                  |
6397 6398

**Error codes**
G
Gloria 已提交
6399

6400 6401 6402
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6403
| -------- | ---------------- |
6404 6405
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
6406 6407 6408 6409

**Example**

```js
G
Gloria 已提交
6410
avsessionController.off('activeStateChange');
6411 6412
```

G
Gloria 已提交
6413
### on('validCommandChange')<sup>10+</sup>
6414

G
Gloria 已提交
6415
on(type: 'validCommandChange', callback: (commands: Array\<AVControlCommandType>) => void)
6416

G
Gloria 已提交
6417
Subscribes to valid command change events.
6418 6419 6420 6421 6422

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6423 6424 6425 6426
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'validCommandChange'** is triggered when the valid commands supported by the session changes.|
| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | Yes  | Callback used for subscription. The **commands** parameter in the callback is a set of valid commands.                    |
6427 6428

**Error codes**
G
Gloria 已提交
6429

6430 6431 6432
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6433
| -------- | ------------------------------ |
6434 6435
| 6600101  | Session service exception. |
| 6600103  | The session controller does not exist. |
6436 6437 6438 6439

**Example**

```js
G
Gloria 已提交
6440 6441 6442
avsessionController.on('validCommandChange', (validCommands) => {
    console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`);
    console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`);
6443 6444 6445
});
```

G
Gloria 已提交
6446
### off('validCommandChange')<sup>10+</sup>
6447

G
Gloria 已提交
6448
off(type: 'validCommandChange', callback?: (commands: Array\<AVControlCommandType>) => void)
6449

G
Gloria 已提交
6450
Unsubscribes from valid command change events. This API is called by the controller.
6451 6452 6453 6454 6455

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6456 6457 6458 6459
| Name  | Type                                                        | Mandatory| Description                                                       |
| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'validCommandChange'** in this case.        |
| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => 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.         |
6460 6461

**Error codes**
G
Gloria 已提交
6462

6463 6464
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

G
Gloria 已提交
6465
| ID| Error Message          |
6466
| -------- | ---------------- |
6467
| 6600101  | Session service exception. |
G
Gloria 已提交
6468
| 6600103  | The session controller does not exist. |
6469 6470 6471 6472

**Example**

```js
G
Gloria 已提交
6473
avsessionController.off('validCommandChange');
6474 6475
```

G
Gloria 已提交
6476
### on('outputDeviceChange')<sup>10+</sup>
6477

G
Gloria 已提交
6478
on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void
6479

G
Gloria 已提交
6480
Subscribes to output device change events.
6481 6482 6483 6484 6485

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6486 6487 6488 6489
| Name  | Type                                                   | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| type     | string                                                  | Yes  | Event type. The event **'outputDeviceChange'** is triggered when the output device changes.|
| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | Yes  | Callback used for subscription. The **device** parameter in the callback indicates the output device information.                        |
6490 6491

**Error codes**
G
Gloria 已提交
6492

6493 6494 6495
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6496
| -------- | ----------------------- |
6497
| 6600101  | Session service exception. |
G
Gloria 已提交
6498
| 6600103  | The session controller does not exist. |
6499 6500 6501 6502

**Example**

```js
G
Gloria 已提交
6503 6504 6505
avsessionController.on('outputDeviceChange', (state, device) => {
    console.info(`on outputDeviceChange state: ${state}, device : ${device}`);
});
6506 6507
```

G
Gloria 已提交
6508
### off('outputDeviceChange')<sup>10+</sup>
G
Gloria 已提交
6509

G
Gloria 已提交
6510
off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void
G
Gloria 已提交
6511

G
Gloria 已提交
6512
Unsubscribes from output device change events. This API is called by the controller.
G
Gloria 已提交
6513 6514 6515 6516 6517

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6518 6519 6520 6521
| Name  | Type                                                   | Mandatory| Description                                                     |
| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ |
| type     | string                                                  | Yes  | Event type, which is **'outputDeviceChange'** in this case.     |
| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => 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.                        |
G
Gloria 已提交
6522 6523 6524 6525 6526

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

G
Gloria 已提交
6527
| ID | Error Message         |
G
Gloria 已提交
6528 6529
| -------- | ---------------- |
| 6600101  | Session service exception. |
G
Gloria 已提交
6530
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
6531 6532 6533 6534

**Example**

```js
G
Gloria 已提交
6535
avsessionController.off('outputDeviceChange');
G
Gloria 已提交
6536 6537
```

G
Gloria 已提交
6538
### on('sessionEvent')<sup>10+</sup>
G
Gloria 已提交
6539

G
Gloria 已提交
6540
on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void
G
Gloria 已提交
6541

G
Gloria 已提交
6542
Subscribes to session event change events. This API is called by the controller.
G
Gloria 已提交
6543 6544 6545 6546 6547

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6548 6549 6550 6551
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'sessionEvent'** is triggered when the session event changes.|
| callback | (sessionEvent: string, args: {[key:string]: object}) => void         | Yes  | Callback used for subscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event.         |
G
Gloria 已提交
6552 6553 6554 6555 6556 6557

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6558
| -------- | ------------------------------ |
G
Gloria 已提交
6559
| 6600101  | Session service exception. |
G
Gloria 已提交
6560
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
6561 6562 6563 6564

**Example**

```js
G
Gloria 已提交
6565 6566 6567
avsessionController.on('sessionEvent', (sessionEvent, args) => {
    console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`);
});
G
Gloria 已提交
6568 6569
```

G
Gloria 已提交
6570
### off('sessionEvent')<sup>10+</sup>
G
Gloria 已提交
6571

G
Gloria 已提交
6572
off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void
G
Gloria 已提交
6573

G
Gloria 已提交
6574
Unsubscribes from session event change events. This API is called by the controller.
G
Gloria 已提交
6575 6576 6577 6578 6579

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6580 6581 6582 6583
| Name  | Type                                                        | Mandatory| Description                                                    |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- |
| type     | string                                                       | Yes  | Event type, which is **'sessionEvent'** in this case.   |
| callback | (sessionEvent: string, args: {[key:string]: Object}) => void         | No  | Callback used for unsubscription. **sessionEvent** in the callback indicates the name of the session event that changes, and **args** indicates the parameters carried in the event.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.                     |
G
Gloria 已提交
6584 6585 6586 6587 6588 6589 6590 6591

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------- |
| 6600101  | Session service exception. |
G
Gloria 已提交
6592
| 6600103  | The session controller does not exist. |
G
Gloria 已提交
6593 6594 6595 6596

**Example**

```js
G
Gloria 已提交
6597
avsessionController.off('sessionEvent');
G
Gloria 已提交
6598 6599
```

G
Gloria 已提交
6600
### on('queueItemsChange')<sup>10+</sup>
6601

G
Gloria 已提交
6602
on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
6603

G
Gloria 已提交
6604
Subscribes to playlist item change events. This API is called by the controller.
6605 6606 6607 6608 6609

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6610 6611 6612 6613
| Name  | Type                                                  | Mandatory| Description                                                                        |
| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- |
| type     | string                                                | Yes  | Event type. The event **'queueItemsChange'** is triggered when one or more items in the playlist changes.|
| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void  | Yes  | Callback used for subscription. The **items** parameter in the callback indicates the changed items in the playlist.                           |
6614 6615 6616 6617 6618 6619

**Error codes**

For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6620 6621
| -------- | ------------------------------ |
| 6600101  | Session service exception. |
6622 6623 6624 6625 6626
| 6600103  | The session controller does not exist. |

**Example**

```js
G
Gloria 已提交
6627 6628 6629
avsessionController.on('queueItemsChange', (items) => {
    console.info(`OnQueueItemsChange, items length is ${items.length}`);
});
6630 6631
```

G
Gloria 已提交
6632
### off('queueItemsChange')<sup>10+</sup>
6633

G
Gloria 已提交
6634
off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void
6635

G
Gloria 已提交
6636
Unsubscribes from playback item change events. This API is called by the controller.
6637 6638 6639 6640 6641

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6642 6643 6644 6645
| Name   | Type                                                | Mandatory| Description                                                                                               |
| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- |
| type     | string                                               | Yes  | Event type, which is **'queueItemsChange'** in this case.                                                    |
| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | No  | Callback used for unsubscription. The **items** parameter in the callback indicates the changed items in the playlist.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
6646 6647

**Error codes**
G
Gloria 已提交
6648

6649 6650 6651 6652
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
| -------- | ---------------- |
6653
| 6600101  | Session service exception. |
G
Gloria 已提交
6654
| 6600103  | The session controller does not exist. |
6655 6656 6657 6658

**Example**

```js
G
Gloria 已提交
6659
avsessionController.off('queueItemsChange');
6660 6661
```

G
Gloria 已提交
6662
### on('queueTitleChange')<sup>10+</sup>
6663

G
Gloria 已提交
6664
on(type: 'queueTitleChange', callback: (title: string) => void): void
6665

G
Gloria 已提交
6666
Subscribes to playlist name change events. This API is called by the controller.
6667 6668 6669 6670 6671

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6672 6673 6674 6675
| Name  | Type                    | Mandatory| Description                                                                            |
| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- |
| type     | string                  | Yes  | Event type. The event **'queueTitleChange'** is triggered when the playlist name changes.|
| callback | (title: string) => void | Yes  | Callback used for subscription. The **title** parameter in the callback indicates the changed playlist name.                               |
6676 6677

**Error codes**
G
Gloria 已提交
6678

6679 6680 6681
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

| ID| Error Message|
G
Gloria 已提交
6682
| -------- | ------------------------------ |
6683
| 6600101  | Session service exception. |
G
Gloria 已提交
6684
| 6600103  | The session controller does not exist. |
6685 6686 6687 6688

**Example**

```js
G
Gloria 已提交
6689 6690 6691
avsessionController.on('queueTitleChange', (title) => {
    console.info(`queueTitleChange, title is ${title}`);
});
6692 6693
```

G
Gloria 已提交
6694
### off('queueTitleChange')<sup>10+</sup>
6695

G
Gloria 已提交
6696
off(type: 'queueTitleChange', callback?: (title: string) => void): void
6697

G
Gloria 已提交
6698
Unsubscribes from playlist name change events. This API is called by the controller.
6699 6700 6701 6702 6703

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6704 6705 6706 6707
| Name   | Type                   | Mandatory| Description                                                                                                   |
| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
| type     | string                  | Yes  | Event type, which is **'queueTitleChange'** in this case.                                                        |
| callback | (title: string) => void | No  | Callback used for unsubscription. The **items** parameter in the callback indicates the changed playlist name.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
6708 6709

**Error codes**
G
Gloria 已提交
6710

6711 6712
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

G
Gloria 已提交
6713
| ID| Error Message|
6714
| -------- | ---------------- |
6715
| 6600101  | Session service exception. |
G
Gloria 已提交
6716
| 6600103  | The session controller does not exist. |
6717 6718 6719 6720

**Example**

```js
G
Gloria 已提交
6721
avsessionController.off('queueTitleChange');
6722 6723
```

G
Gloria 已提交
6724
### on('extrasChange')<sup>10+</sup>
6725

G
Gloria 已提交
6726
on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void
6727

G
Gloria 已提交
6728
Subscribes to custom media packet change events. This API is called by the controller.
6729 6730 6731 6732 6733

**System capability**: SystemCapability.Multimedia.AVSession.Core

**Parameters**

G
Gloria 已提交
6734 6735 6736 6737
| Name  | Type                                                        | Mandatory| Description                                                        |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| type     | string                                                       | Yes  | Event type. The event **'extrasChange'** is triggered when the provider sets a custom media packet.|
| callback | (extras: {[key:string]: object}) => void         | Yes  | Callback used for subscription. The **extras** parameter in the callback indicates the custom media packet set by the provider. This packet is the same as that set in **dispatchSessionEvent**.         |
6738 6739

**Error codes**
G
Gloria 已提交
6740

6741 6742
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).

G
Gloria 已提交
6743 6744
| ID| Error Message|
| -------- | ------------------------------ |
6745
| 6600101  | Session service exception. |
G
Gloria 已提交
6746
| 6600103  | The session controller does not exist. |
6747 6748 6749 6750

**Example**

```js
G
Gloria 已提交
6751 6752 6753
avsessionController.on('extrasChange', (extras) => {
    console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`);
});
6754 6755
```

G
Gloria 已提交
6756
### off('extrasChange')<sup>10+</sup>
6757

G
Gloria 已提交
6758
off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void
6759

G
Gloria 已提交
6760
Unsubscribes from custom media packet change events. This API is called by the controller.
6761 6762 6763

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
6764
**Parameters**
6765

G
Gloria 已提交
6766 6767 6768 6769
| Name   | Type                   | Mandatory| Description                                                                                                   |
| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- |
| type     | string                  | Yes  | Event type, which is **'extrasChange'** in this case.                                                        |
| callback | ({[key:string]: Object}) => void | No  | Callback used for unsubscription.<br>The **callback** parameter is optional. If it is not specified, all the subscriptions to the specified event are canceled for this session.|
6770

G
Gloria 已提交
6771
**Error codes**
6772

G
Gloria 已提交
6773
For details about the error codes, see [AVSession Management Error Codes](../errorcodes/errorcode-avsession.md).
6774

G
Gloria 已提交
6775 6776 6777 6778 6779 6780
| ID| Error Message|
| -------- | ----------------                       |
| 6600101  | Session service exception.             |
| 6600103  | The session controller does not exist. |

**Example**
6781

G
Gloria 已提交
6782 6783 6784
```js
avsessionController.off('extrasChange');
```
6785

G
Gloria 已提交
6786
## AVControlCommandType<sup>10+</sup>
6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805

Enumerates the commands that can be sent to a session.

**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name          | Type  | Description        |
| -------------- | ------ | ------------ |
| play           | string | Play the media.        |
| pause          | string | Pause the playback.        |
| stop           | string | Stop the playback.        |
| playNext       | string | Play the next media asset.      |
| playPrevious   | string | Play the previous media asset.      |
| fastForward    | string | Fast-forward.        |
| rewind         | string | Rewind.        |
| seek           | string | Seek to a playback position.|
| setSpeed       | string | Set the playback speed.|
| setLoopMode    | string | Set the loop mode.|
| toggleFavorite | string | Favorite the media asset.    |

G
Gloria 已提交
6806
## AVControlCommand<sup>10+</sup>
6807 6808 6809 6810 6811 6812 6813

Describes the command that can be sent to the session.

**System capability**: SystemCapability.Multimedia.AVSession.Core

| Name     | Type                                             | Mandatory| Description          |
| --------- | ------------------------------------------------- | ---- | -------------- |
G
Gloria 已提交
6814 6815
| command   | [AVControlCommandType](#avcontrolcommandtype10)     | Yes  | Command.          |
| parameter | [LoopMode](#loopmode10) &#124; string &#124; number | No  | Parameters carried in the command.|
6816

G
Gloria 已提交
6817
## AVSessionErrorCode<sup>10+</sup>
6818 6819 6820 6821 6822

Enumerates the error codes used in the media session.

**System capability**: SystemCapability.Multimedia.AVSession.Core

G
Gloria 已提交
6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833
| Name                                  | Value     | Description                            |
| -------------------------------------- | ------- | ------------------------------- |
| ERR_CODE_SERVICE_EXCEPTION             | 6600101 | Session service exception.               |
| ERR_CODE_SESSION_NOT_EXIST             | 6600102 | The session does not exist.      |
| ERR_CODE_CONTROLLER_NOT_EXIST          | 6600103 | The session controller does not exist.   |
| ERR_CODE_REMOTE_CONNECTION_ERR         | 6600104 | The remote session  connection failed.         |
| ERR_CODE_COMMAND_INVALID               | 6600105 | Invalid session command.           |
| ERR_CODE_SESSION_INACTIVE              | 6600106 | The session is not activated.                |
| ERR_CODE_MESSAGE_OVERLOAD              | 6600107 | Too many commands or events.       |
| ERR_CODE_DEVICE_CONNECTION_FAILED      | 6600108 | Device connecting failed.       |
| ERR_CODE_REMOTE_CONNECTION_NOT_EXIST   | 6600109 | The remote connection is not established.       |